Home | History | Annotate | Download | only in test
      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   int32_t
     36   SendData(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);
     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     // will write decoded frame into file
     77     int32_t FrameToRender(webrtc::I420VideoFrame& videoFrame);
     78     int32_t DecodedBytes();
     79 private:
     80     FILE*             _decodedFile;
     81     std::string       _outname;
     82     int               _decodedBytes;
     83     int               _currentWidth;
     84     int               _currentHeight;
     85 }; // end of VCMDecodeCompleCallback class
     86 
     87 class NormalTest
     88 {
     89 public:
     90     NormalTest(webrtc::VideoCodingModule* vcm,
     91                webrtc::Clock* clock);
     92     ~NormalTest();
     93     static int RunTest(const CmdArgs& args);
     94     int32_t    Perform(const CmdArgs& args);
     95     // option:: turn into private and call from perform
     96     int   Width() const { return _width; };
     97     int   Height() const { return _height; };
     98     webrtc::VideoCodecType VideoType() const { return _videoType; };
     99 
    100 
    101 protected:
    102     // test setup - open files, general initializations
    103     void            Setup(const CmdArgs& args);
    104    // close open files, delete used memory
    105     void            Teardown();
    106     // print results to std output and to log file
    107     void            Print();
    108     // calculating pipeline delay, and encoding time
    109     void            FrameEncoded(uint32_t timeStamp);
    110     // calculating pipeline delay, and decoding time
    111     void            FrameDecoded(uint32_t timeStamp);
    112 
    113     webrtc::Clock*                   _clock;
    114     webrtc::VideoCodingModule*       _vcm;
    115     webrtc::VideoCodec               _sendCodec;
    116     webrtc::VideoCodec               _receiveCodec;
    117     std::string                      _inname;
    118     std::string                      _outname;
    119     std::string                      _encodedName;
    120     int32_t                    _sumEncBytes;
    121     FILE*                            _sourceFile;
    122     FILE*                            _decodedFile;
    123     FILE*                            _encodedFile;
    124     std::fstream                     _log;
    125     int                              _width;
    126     int                              _height;
    127     float                            _frameRate;
    128     float                            _bitRate;
    129     uint32_t                   _lengthSourceFrame;
    130     uint32_t                   _timeStamp;
    131     webrtc::VideoCodecType           _videoType;
    132     double                           _totalEncodeTime;
    133     double                           _totalDecodeTime;
    134     double                           _decodeCompleteTime;
    135     double                           _encodeCompleteTime;
    136     double                           _totalEncodePipeTime;
    137     double                           _totalDecodePipeTime;
    138     double                           _testTotalTime;
    139     std::map<int, double>            _encodeTimes;
    140     std::map<int, double>            _decodeTimes;
    141     int32_t                    _frameCnt;
    142     int32_t                    _encFrameCnt;
    143     int32_t                    _decFrameCnt;
    144 
    145 }; // end of VCMNormalTestClass
    146 
    147 #endif // WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_
    148