1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_ 13 14 #include "webrtc/modules/video_coding/main/interface/video_coding.h" 15 #include "webrtc/modules/video_coding/main/test/test_util.h" 16 #include "webrtc/modules/video_coding/main/test/video_source.h" 17 18 #include <fstream> 19 #include <map> 20 21 class NormalTest; 22 23 //Send Side - Packetization callback - 24 // will create and send a packet to the VCMReceiver 25 class VCMNTEncodeCompleteCallback : public webrtc::VCMPacketizationCallback 26 { 27 public: 28 // constructor input: file in which encoded data will be written 29 VCMNTEncodeCompleteCallback(FILE* encodedFile, NormalTest& test); 30 virtual ~VCMNTEncodeCompleteCallback(); 31 // Register transport callback 32 void RegisterTransportCallback(webrtc::VCMPacketizationCallback* transport); 33 // process encoded data received from the encoder, 34 // pass stream to the VCMReceiver module 35 virtual int32_t SendData( 36 const webrtc::FrameType frameType, 37 const uint8_t payloadType, 38 const uint32_t timeStamp, 39 int64_t capture_time_ms, 40 const uint8_t* payloadData, 41 const uint32_t payloadSize, 42 const webrtc::RTPFragmentationHeader& fragmentationHeader, 43 const webrtc::RTPVideoHeader* videoHdr) OVERRIDE; 44 45 // Register exisitng VCM. 46 // Currently - encode and decode with the same vcm module. 47 void RegisterReceiverVCM(webrtc::VideoCodingModule *vcm); 48 // Return sum of encoded data (all frames in the sequence) 49 int32_t EncodedBytes(); 50 // return number of encoder-skipped frames 51 uint32_t SkipCnt();; 52 // conversion function for payload type (needed for the callback function) 53 // RTPVideoVideoCodecTypes ConvertPayloadType(uint8_t payloadType); 54 55 private: 56 FILE* _encodedFile; 57 uint32_t _encodedBytes; 58 uint32_t _skipCnt; 59 webrtc::VideoCodingModule* _VCMReceiver; 60 webrtc::FrameType _frameType; 61 uint16_t _seqNo; 62 NormalTest& _test; 63 }; // end of VCMEncodeCompleteCallback 64 65 class VCMNTDecodeCompleCallback: public webrtc::VCMReceiveCallback 66 { 67 public: 68 VCMNTDecodeCompleCallback(std::string outname): // or should it get a name? 69 _decodedFile(NULL), 70 _outname(outname), 71 _decodedBytes(0), 72 _currentWidth(0), 73 _currentHeight(0) {} 74 virtual ~VCMNTDecodeCompleCallback(); 75 void SetUserReceiveCallback(webrtc::VCMReceiveCallback* receiveCallback); 76 77 // will write decoded frame into file 78 virtual int32_t FrameToRender(webrtc::I420VideoFrame& videoFrame) OVERRIDE; 79 80 int32_t DecodedBytes(); 81 private: 82 FILE* _decodedFile; 83 std::string _outname; 84 int _decodedBytes; 85 int _currentWidth; 86 int _currentHeight; 87 }; // end of VCMDecodeCompleCallback class 88 89 class NormalTest 90 { 91 public: 92 NormalTest(webrtc::VideoCodingModule* vcm, 93 webrtc::Clock* clock); 94 ~NormalTest(); 95 static int RunTest(const CmdArgs& args); 96 int32_t Perform(const CmdArgs& args); 97 // option:: turn into private and call from perform 98 int Width() const { return _width; }; 99 int Height() const { return _height; }; 100 webrtc::VideoCodecType VideoType() const { return _videoType; }; 101 102 103 protected: 104 // test setup - open files, general initializations 105 void Setup(const CmdArgs& args); 106 // close open files, delete used memory 107 void Teardown(); 108 // print results to std output and to log file 109 void Print(); 110 // calculating pipeline delay, and encoding time 111 void FrameEncoded(uint32_t timeStamp); 112 // calculating pipeline delay, and decoding time 113 void FrameDecoded(uint32_t timeStamp); 114 115 webrtc::Clock* _clock; 116 webrtc::VideoCodingModule* _vcm; 117 webrtc::VideoCodec _sendCodec; 118 webrtc::VideoCodec _receiveCodec; 119 std::string _inname; 120 std::string _outname; 121 std::string _encodedName; 122 int32_t _sumEncBytes; 123 FILE* _sourceFile; 124 FILE* _decodedFile; 125 FILE* _encodedFile; 126 std::fstream _log; 127 int _width; 128 int _height; 129 float _frameRate; 130 float _bitRate; 131 uint32_t _lengthSourceFrame; 132 uint32_t _timeStamp; 133 webrtc::VideoCodecType _videoType; 134 double _totalEncodeTime; 135 double _totalDecodeTime; 136 double _decodeCompleteTime; 137 double _encodeCompleteTime; 138 double _totalEncodePipeTime; 139 double _totalDecodePipeTime; 140 double _testTotalTime; 141 std::map<int, double> _encodeTimes; 142 std::map<int, double> _decodeTimes; 143 int32_t _frameCnt; 144 int32_t _encFrameCnt; 145 int32_t _decFrameCnt; 146 147 }; // end of VCMNormalTestClass 148 149 #endif // WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_ 150