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_CODECS_TEST_FRAMEWORK_NORMAL_ASYNC_TEST_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_FRAMEWORK_NORMAL_ASYNC_TEST_H_ 13 14 #include "webrtc/common_types.h" 15 16 #include <list> 17 #include <map> 18 #include <queue> 19 #include "webrtc/modules/video_coding/codecs/test_framework/normal_test.h" 20 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" 21 22 class FrameQueueTuple 23 { 24 public: 25 FrameQueueTuple(webrtc::VideoFrame *frame, 26 const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL) 27 : 28 _frame(frame), 29 _codecSpecificInfo(codecSpecificInfo) 30 {}; 31 ~FrameQueueTuple(); 32 webrtc::VideoFrame* _frame; 33 const webrtc::CodecSpecificInfo* _codecSpecificInfo; 34 }; 35 36 class FrameQueue 37 { 38 public: 39 FrameQueue() 40 : 41 _queueRWLock(*webrtc::RWLockWrapper::CreateRWLock()) 42 { 43 } 44 45 ~FrameQueue() 46 { 47 delete &_queueRWLock; 48 } 49 50 void PushFrame(webrtc::VideoFrame *frame, 51 webrtc::CodecSpecificInfo* codecSpecificInfo = NULL); 52 FrameQueueTuple* PopFrame(); 53 bool Empty(); 54 55 private: 56 webrtc::RWLockWrapper& _queueRWLock; 57 std::queue<FrameQueueTuple *> _frameBufferQueue; 58 }; 59 60 // feedback signal to encoder 61 struct fbSignal 62 { 63 fbSignal(int d, uint8_t pid) : delay(d), id(pid) {}; 64 int delay; 65 uint8_t id; 66 }; 67 68 class NormalAsyncTest : public NormalTest 69 { 70 public: 71 NormalAsyncTest(); 72 NormalAsyncTest(uint32_t bitRate); 73 NormalAsyncTest(std::string name, std::string description, 74 unsigned int testNo); 75 NormalAsyncTest(std::string name, std::string description, 76 uint32_t bitRate, unsigned int testNo); 77 NormalAsyncTest(std::string name, std::string description, 78 uint32_t bitRate, unsigned int testNo, 79 unsigned int rttFrames); 80 virtual ~NormalAsyncTest() {}; 81 virtual void Perform(); 82 virtual void Encoded(const webrtc::EncodedImage& encodedImage); 83 virtual void Decoded(const webrtc::I420VideoFrame& decodedImage); 84 virtual webrtc::CodecSpecificInfo* 85 CopyCodecSpecificInfo( 86 const webrtc::CodecSpecificInfo* codecSpecificInfo) const; 87 virtual void CopyEncodedImage(webrtc::VideoFrame& dest, 88 webrtc::EncodedImage& src, 89 void* /*codecSpecificInfo*/) const; 90 virtual webrtc::CodecSpecificInfo* CreateEncoderSpecificInfo() const 91 { 92 return NULL; 93 }; 94 virtual int32_t ReceivedDecodedReferenceFrame( 95 const uint64_t pictureId); 96 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId); 97 98 protected: 99 virtual void Setup(); 100 virtual void Teardown(); 101 virtual bool Encode(); 102 virtual int Decode(int lossValue = 0); 103 virtual void CodecSpecific_InitBitrate(); 104 virtual int SetCodecSpecificParameters() {return 0;}; 105 double tGetTime();// return time in sec 106 107 FILE* _sourceFile; 108 FILE* _decodedFile; 109 uint32_t _decodedWidth; 110 uint32_t _decodedHeight; 111 double _totalEncodeTime; 112 double _totalDecodeTime; 113 double _decodeCompleteTime; 114 double _encodeCompleteTime; 115 double _totalEncodePipeTime; 116 double _totalDecodePipeTime; 117 int _framecnt; 118 int _encFrameCnt; 119 int _decFrameCnt; 120 bool _requestKeyFrame; 121 unsigned int _lengthEncFrame; 122 FrameQueueTuple* _frameToDecode; 123 bool _appendNext; 124 std::map<uint32_t, double> _encodeTimes; 125 std::map<uint32_t, double> _decodeTimes; 126 bool _missingFrames; 127 std::list<fbSignal> _signalSLI; 128 int _rttFrames; 129 mutable bool _hasReceivedSLI; 130 mutable bool _hasReceivedRPSI; 131 uint8_t _pictureIdSLI; 132 uint16_t _pictureIdRPSI; 133 uint64_t _lastDecRefPictureId; 134 uint64_t _lastDecPictureId; 135 std::list<fbSignal> _signalPLI; 136 bool _hasReceivedPLI; 137 bool _waitForKey; 138 }; 139 140 class VideoEncodeCompleteCallback : public webrtc::EncodedImageCallback 141 { 142 public: 143 VideoEncodeCompleteCallback(FILE* encodedFile, FrameQueue *frameQueue, 144 NormalAsyncTest& test) 145 : 146 _encodedFile(encodedFile), 147 _frameQueue(frameQueue), 148 _test(test), 149 _encodedBytes(0) 150 {} 151 152 int32_t 153 Encoded(webrtc::EncodedImage& encodedImage, 154 const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL, 155 const webrtc::RTPFragmentationHeader* fragmentation = NULL); 156 uint32_t EncodedBytes(); 157 private: 158 FILE* _encodedFile; 159 FrameQueue* _frameQueue; 160 NormalAsyncTest& _test; 161 uint32_t _encodedBytes; 162 }; 163 164 class VideoDecodeCompleteCallback : public webrtc::DecodedImageCallback 165 { 166 public: 167 VideoDecodeCompleteCallback(FILE* decodedFile, NormalAsyncTest& test) 168 : 169 _decodedFile(decodedFile), 170 _test(test), 171 _decodedBytes(0) 172 {} 173 174 virtual int32_t Decoded(webrtc::I420VideoFrame& decodedImage); 175 virtual int32_t 176 ReceivedDecodedReferenceFrame(const uint64_t pictureId); 177 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId); 178 179 uint32_t DecodedBytes(); 180 private: 181 FILE* _decodedFile; 182 NormalAsyncTest& _test; 183 uint32_t _decodedBytes; 184 }; 185 186 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_FRAMEWORK_NORMAL_ASYNC_TEST_H_ 187