1/*
2 *  Copyright (c) 2011 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_ENCODED_FRAME_H_
12#define WEBRTC_MODULES_VIDEO_CODING_ENCODED_FRAME_H_
13
14#include <vector>
15
16#include "webrtc/common_types.h"
17#include "webrtc/common_video/interface/video_image.h"
18#include "webrtc/modules/interface/module_common_types.h"
19#include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
20#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
21
22namespace webrtc
23{
24
25class VCMEncodedFrame : protected EncodedImage
26{
27public:
28    VCMEncodedFrame();
29    VCMEncodedFrame(const webrtc::EncodedImage& rhs);
30    VCMEncodedFrame(const VCMEncodedFrame& rhs);
31
32    ~VCMEncodedFrame();
33    /**
34    *   Delete VideoFrame and resets members to zero
35    */
36    void Free();
37    /**
38    *   Set render time in milliseconds
39    */
40    void SetRenderTime(const int64_t renderTimeMs) {_renderTimeMs = renderTimeMs;}
41
42    /**
43    *   Set the encoded frame size
44    */
45    void SetEncodedSize(uint32_t width, uint32_t height)
46                       { _encodedWidth  = width; _encodedHeight = height; }
47    /**
48    *   Get the encoded image
49    */
50    const webrtc::EncodedImage& EncodedImage() const
51                       { return static_cast<const webrtc::EncodedImage&>(*this); }
52    /**
53    *   Get pointer to frame buffer
54    */
55    const uint8_t* Buffer() const {return _buffer;}
56    /**
57    *   Get frame length
58    */
59    uint32_t Length() const {return _length;}
60    /**
61    *   Get frame timestamp (90kHz)
62    */
63    uint32_t TimeStamp() const {return _timeStamp;}
64    /**
65    *   Get render time in milliseconds
66    */
67    int64_t RenderTimeMs() const {return _renderTimeMs;}
68    /**
69    *   Get frame type
70    */
71    webrtc::FrameType FrameType() const {return ConvertFrameType(_frameType);}
72    /**
73    *   True if this frame is complete, false otherwise
74    */
75    bool Complete() const { return _completeFrame; }
76    /**
77    *   True if there's a frame missing before this frame
78    */
79    bool MissingFrame() const { return _missingFrame; }
80    /**
81    *   Payload type of the encoded payload
82    */
83    uint8_t PayloadType() const { return _payloadType; }
84    /**
85    *   Get codec specific info.
86    *   The returned pointer is only valid as long as the VCMEncodedFrame
87    *   is valid. Also, VCMEncodedFrame owns the pointer and will delete
88    *   the object.
89    */
90    const CodecSpecificInfo* CodecSpecific() const {return &_codecSpecificInfo;}
91
92    const RTPFragmentationHeader* FragmentationHeader() const;
93
94    static webrtc::FrameType ConvertFrameType(VideoFrameType frameType);
95    static VideoFrameType ConvertFrameType(webrtc::FrameType frameType);
96    static void ConvertFrameTypes(
97        const std::vector<webrtc::FrameType>& frame_types,
98        std::vector<VideoFrameType>* video_frame_types);
99
100protected:
101    /**
102    * Verifies that current allocated buffer size is larger than or equal to the input size.
103    * If the current buffer size is smaller, a new allocation is made and the old buffer data
104    * is copied to the new buffer.
105    * Buffer size is updated to minimumSize.
106    */
107    void VerifyAndAllocate(const uint32_t minimumSize);
108
109    void Reset();
110
111    void CopyCodecSpecific(const RTPVideoHeader* header);
112
113    int64_t                 _renderTimeMs;
114    uint8_t                 _payloadType;
115    bool                          _missingFrame;
116    CodecSpecificInfo             _codecSpecificInfo;
117    webrtc::VideoCodecType        _codec;
118    RTPFragmentationHeader        _fragmentation;
119};
120
121}  // namespace webrtc
122
123#endif // WEBRTC_MODULES_VIDEO_CODING_ENCODED_FRAME_H_
124