1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_TEST_CALLBACKS_H_
#define WEBRTC_MODULES_VIDEO_CODING_TEST_TEST_CALLBACKS_H_
/*
* Declaration of general callbacks that are used throughout VCM's offline tests
*/
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <list>
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc
{
class RTPPayloadRegistry;
class RtpDump;
// Send Side - Packetization callback - send an encoded frame to the VCMReceiver
class VCMEncodeCompleteCallback: public VCMPacketizationCallback
{
public:
// Constructor input: file in which encoded data will be written
VCMEncodeCompleteCallback(FILE* encodedFile);
virtual ~VCMEncodeCompleteCallback();
// Register transport callback
void RegisterTransportCallback(VCMPacketizationCallback* transport);
// Process encoded data received from the encoder, pass stream to the
// VCMReceiver module
virtual int32_t SendData(uint8_t payloadType,
const EncodedImage& encoded_image,
const RTPFragmentationHeader& fragmentationHeader,
const RTPVideoHeader* videoHdr) OVERRIDE;
// Register exisitng VCM. Currently - encode and decode under same module.
void RegisterReceiverVCM(VideoCodingModule *vcm) {_VCMReceiver = vcm;}
// Return size of last encoded frame data (all frames in the sequence)
// Good for only one call - after which will reset value
// (to allow detection of frame drop)
size_t EncodedBytes();
// Return encode complete (true/false)
bool EncodeComplete();
// Inform callback of codec used
void SetCodecType(RtpVideoCodecTypes codecType)
{_codecType = codecType;}
// Inform callback of frame dimensions
void SetFrameDimensions(int32_t width, int32_t height)
{
_width = width;
_height = height;
}
// Initialize callback data
void Initialize();
void ResetByteCount();
// Conversion function for payload type (needed for the callback function)
private:
FILE* _encodedFile;
size_t _encodedBytes;
VideoCodingModule* _VCMReceiver;
FrameType _frameType;
uint16_t _seqNo;
bool _encodeComplete;
int32_t _width;
int32_t _height;
RtpVideoCodecTypes _codecType;
}; // end of VCMEncodeCompleteCallback
// Send Side - Packetization callback - packetize an encoded frame via the
// RTP module
class VCMRTPEncodeCompleteCallback: public VCMPacketizationCallback
{
public:
VCMRTPEncodeCompleteCallback(RtpRtcp* rtp) :
_encodedBytes(0),
_encodeComplete(false),
_RTPModule(rtp) {}
virtual ~VCMRTPEncodeCompleteCallback() {}
// Process encoded data received from the encoder, pass stream to the
// RTP module
virtual int32_t SendData(uint8_t payloadType,
const EncodedImage& encoded_image,
const RTPFragmentationHeader& fragmentationHeader,
const RTPVideoHeader* videoHdr) OVERRIDE;
// Return size of last encoded frame. Value good for one call
// (resets to zero after call to inform test of frame drop)
size_t EncodedBytes();
// Return encode complete (true/false)
bool EncodeComplete();
// Inform callback of codec used
void SetCodecType(RtpVideoCodecTypes codecType)
{_codecType = codecType;}
// Inform callback of frame dimensions
void SetFrameDimensions(int16_t width, int16_t height)
{
_width = width;
_height = height;
}
private:
size_t _encodedBytes;
FrameType _frameType;
bool _encodeComplete;
RtpRtcp* _RTPModule;
int16_t _width;
int16_t _height;
RtpVideoCodecTypes _codecType;
}; // end of VCMEncodeCompleteCallback
// Decode Complete callback
// Writes the decoded frames to a given file.
class VCMDecodeCompleteCallback: public VCMReceiveCallback
{
public:
VCMDecodeCompleteCallback(FILE* decodedFile) :
_decodedFile(decodedFile), _decodedBytes(0) {}
virtual ~VCMDecodeCompleteCallback() {}
// Write decoded frame into file
virtual int32_t FrameToRender(webrtc::I420VideoFrame& videoFrame) OVERRIDE;
size_t DecodedBytes();
private:
FILE* _decodedFile;
size_t _decodedBytes;
}; // end of VCMDecodeCompleCallback class
// Transport callback
// Called by the RTP Sender - simulates sending packets through a network to the
// RTP receiver. User can set network conditions as: RTT, packet loss,
// burst length and jitter.
class RTPSendCompleteCallback: public Transport
{
public:
// Constructor input: (receive side) rtp module to send encoded data to
RTPSendCompleteCallback(Clock* clock,
const char* filename = NULL);
virtual ~RTPSendCompleteCallback();
void SetRtpModule(RtpRtcp* rtp_module) { _rtp = rtp_module; }
// Send Packet to receive side RTP module
virtual int SendPacket(int channel, const void *data, size_t len) OVERRIDE;
// Send RTCP Packet to receive side RTP module
virtual int SendRTCPPacket(int channel,
const void *data,
size_t len) OVERRIDE;
// Set percentage of channel loss in the network
void SetLossPct(double lossPct);
// Set average size of burst loss
void SetBurstLength(double burstLength);
// Set network delay in the network
void SetNetworkDelay(uint32_t networkDelayMs)
{_networkDelayMs = networkDelayMs;};
// Set Packet jitter delay
void SetJitterVar(uint32_t jitterVar)
{_jitterVar = jitterVar;};
// Return send count
int SendCount() {return _sendCount; }
// Return accumulated length in bytes of transmitted packets
size_t TotalSentLength() {return _totalSentLength;}
protected:
// Randomly decide whether to drop packets, based on the channel model
bool PacketLoss();
// Random uniform loss model
bool UnifomLoss(double lossPct);
Clock* _clock;
uint32_t _sendCount;
RTPPayloadRegistry* rtp_payload_registry_;
RtpReceiver* rtp_receiver_;
RtpRtcp* _rtp;
double _lossPct;
double _burstLength;
uint32_t _networkDelayMs;
double _jitterVar;
bool _prevLossState;
size_t _totalSentLength;
std::list<RtpPacket*> _rtpPackets;
RtpDump* _rtpDump;
};
// Request re-transmission of packets (NACK)
class PacketRequester: public VCMPacketRequestCallback
{
public:
PacketRequester(RtpRtcp& rtp) :
_rtp(rtp) {}
virtual int32_t ResendPackets(const uint16_t* sequenceNumbers,
uint16_t length) OVERRIDE;
private:
webrtc::RtpRtcp& _rtp;
};
// Key frame request
class KeyFrameReqTest: public VCMFrameTypeCallback
{
public:
virtual int32_t RequestKeyFrame() OVERRIDE;
};
// VCM statistics
class SendStatsTest: public webrtc::VCMSendStatisticsCallback
{
public:
SendStatsTest() : _framerate(15), _bitrate(500) {}
virtual int32_t SendStatistics(const uint32_t bitRate,
const uint32_t frameRate) OVERRIDE;
void set_framerate(uint32_t frameRate) {_framerate = frameRate;}
void set_bitrate(uint32_t bitrate) {_bitrate = bitrate;}
private:
uint32_t _framerate;
uint32_t _bitrate;
};
// Protection callback - allows the VCM (media optimization) to inform the RTP
// module of the required protection(FEC rates/settings and NACK mode).
class VideoProtectionCallback: public VCMProtectionCallback
{
public:
VideoProtectionCallback();
virtual ~VideoProtectionCallback();
void RegisterRtpModule(RtpRtcp* rtp) {_rtp = rtp;}
virtual int32_t ProtectionRequest(
const FecProtectionParams* delta_fec_params,
const FecProtectionParams* key_fec_params,
uint32_t* sent_video_rate_bps,
uint32_t* sent_nack_rate_bps,
uint32_t* sent_fec_rate_bps) OVERRIDE;
FecProtectionParams DeltaFecParameters() const;
FecProtectionParams KeyFecParameters() const;
private:
RtpRtcp* _rtp;
FecProtectionParams delta_fec_params_;
FecProtectionParams key_fec_params_;
};
} // namespace webrtc
#endif
|