aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/video_coding/main/test/normal_test.h
blob: 0015171e80951c6ce091e7190a2d67a599d86a1e (plain)
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
/*
 *  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_NORMAL_TEST_H_
#define WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_

#include "webrtc/modules/video_coding/main/interface/video_coding.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/modules/video_coding/main/test/video_source.h"

#include <fstream>
#include <map>

class NormalTest;

//Send Side - Packetization callback -
// will create and send a packet to the VCMReceiver
class VCMNTEncodeCompleteCallback : public webrtc::VCMPacketizationCallback
{
 public:
  // constructor input: file in which encoded data will be written
  VCMNTEncodeCompleteCallback(FILE* encodedFile, NormalTest& test);
  virtual ~VCMNTEncodeCompleteCallback();
  // Register transport callback
  void RegisterTransportCallback(webrtc::VCMPacketizationCallback* transport);
  // process encoded data received from the encoder,
  // pass stream to the VCMReceiver module
  int32_t SendData(uint8_t payloadType,
                   const webrtc::EncodedImage& encoded_image,
                   const webrtc::RTPFragmentationHeader& fragmentationHeader,
                   const webrtc::RTPVideoHeader* videoHdr) override;

  // Register existing VCM.
  // Currently - encode and decode with the same vcm module.
  void RegisterReceiverVCM(webrtc::VideoCodingModule *vcm);
  // Return sum of encoded data (all frames in the sequence)
  size_t EncodedBytes();
  // return number of encoder-skipped frames
  uint32_t SkipCnt();

 private:
  FILE*                       _encodedFile;
  size_t                _encodedBytes;
  uint32_t              _skipCnt;
  webrtc::VideoCodingModule*  _VCMReceiver;
  webrtc::FrameType           _frameType;
  uint16_t              _seqNo;
  NormalTest&                 _test;
}; // end of VCMEncodeCompleteCallback

class VCMNTDecodeCompleteCallback: public webrtc::VCMReceiveCallback
{
public:
    VCMNTDecodeCompleteCallback(std::string outname) // or should it get a name?
        : _decodedFile(NULL),
          _outname(outname),
          _decodedBytes(0),
          _currentWidth(0),
          _currentHeight(0) {}
    virtual ~VCMNTDecodeCompleteCallback();
    void SetUserReceiveCallback(webrtc::VCMReceiveCallback* receiveCallback);

    // will write decoded frame into file
    int32_t FrameToRender(webrtc::I420VideoFrame& videoFrame) override;

    size_t DecodedBytes();
private:
    FILE*             _decodedFile;
    std::string       _outname;
    size_t            _decodedBytes;
    int               _currentWidth;
    int               _currentHeight;
}; // end of VCMNTDecodeCompleteCallback class

class NormalTest
{
public:
    NormalTest(webrtc::VideoCodingModule* vcm,
               webrtc::Clock* clock);
    ~NormalTest();
    static int RunTest(const CmdArgs& args);
    int32_t    Perform(const CmdArgs& args);
    // option:: turn into private and call from perform
    int   Width() const { return _width; };
    int   Height() const { return _height; };
    webrtc::VideoCodecType VideoType() const { return _videoType; };


protected:
    // test setup - open files, general initializations
    void            Setup(const CmdArgs& args);
   // close open files, delete used memory
    void            Teardown();
    // print results to std output and to log file
    void            Print();
    // calculating pipeline delay, and encoding time
    void            FrameEncoded(uint32_t timeStamp);
    // calculating pipeline delay, and decoding time
    void            FrameDecoded(uint32_t timeStamp);

    webrtc::Clock*                   _clock;
    webrtc::VideoCodingModule*       _vcm;
    webrtc::VideoCodec               _sendCodec;
    webrtc::VideoCodec               _receiveCodec;
    std::string                      _inname;
    std::string                      _outname;
    std::string                      _encodedName;
    size_t                     _sumEncBytes;
    FILE*                            _sourceFile;
    FILE*                            _decodedFile;
    FILE*                            _encodedFile;
    std::fstream                     _log;
    int                              _width;
    int                              _height;
    float                            _frameRate;
    float                            _bitRate;
    uint32_t                   _lengthSourceFrame;
    uint32_t                   _timeStamp;
    webrtc::VideoCodecType           _videoType;
    double                           _totalEncodeTime;
    double                           _totalDecodeTime;
    double                           _decodeCompleteTime;
    double                           _encodeCompleteTime;
    double                           _totalEncodePipeTime;
    double                           _totalDecodePipeTime;
    double                           _testTotalTime;
    std::map<int, double>            _encodeTimes;
    std::map<int, double>            _decodeTimes;
    int32_t                    _frameCnt;
    int32_t                    _encFrameCnt;
    int32_t                    _decFrameCnt;

}; // end of VCMNormalTestClass

#endif // WEBRTC_MODULES_VIDEO_CODING_TEST_NORMAL_TEST_H_