2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
12 #include "webrtc/modules/video_coding/main/source/encoded_frame.h"
13 #include "webrtc/modules/video_coding/main/source/generic_encoder.h"
14 #include "webrtc/modules/video_coding/main/source/jitter_buffer_common.h"
18 VCMEncodedFrame::VCMEncodedFrame()
20 webrtc::EncodedImage(),
24 _codec(kVideoCodecUnknown),
27 _codecSpecificInfo.codecType = kVideoCodecUnknown;
30 VCMEncodedFrame::VCMEncodedFrame(const webrtc::EncodedImage& rhs)
32 webrtc::EncodedImage(rhs),
36 _codec(kVideoCodecUnknown),
39 _codecSpecificInfo.codecType = kVideoCodecUnknown;
43 if (rhs._buffer != NULL)
45 VerifyAndAllocate(rhs._length);
46 memcpy(_buffer, rhs._buffer, rhs._length);
50 VCMEncodedFrame::VCMEncodedFrame(const VCMEncodedFrame& rhs)
52 webrtc::EncodedImage(rhs),
53 _renderTimeMs(rhs._renderTimeMs),
54 _payloadType(rhs._payloadType),
55 _missingFrame(rhs._missingFrame),
56 _codecSpecificInfo(rhs._codecSpecificInfo),
62 if (rhs._buffer != NULL)
64 VerifyAndAllocate(rhs._length);
65 memcpy(_buffer, rhs._buffer, rhs._length);
66 _length = rhs._length;
68 _fragmentation.CopyFrom(rhs._fragmentation);
71 VCMEncodedFrame::~VCMEncodedFrame()
76 void VCMEncodedFrame::Free()
86 void VCMEncodedFrame::Reset()
91 _frameType = kDeltaFrame;
94 _completeFrame = false;
95 _missingFrame = false;
97 _codecSpecificInfo.codecType = kVideoCodecUnknown;
98 _codec = kVideoCodecUnknown;
101 void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header)
104 switch (header->codec) {
106 if (_codecSpecificInfo.codecType != kVideoCodecVP8) {
107 // This is the first packet for this frame.
108 _codecSpecificInfo.codecSpecific.VP8.pictureId = -1;
109 _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0;
110 _codecSpecificInfo.codecSpecific.VP8.layerSync = false;
111 _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1;
112 _codecSpecificInfo.codecType = kVideoCodecVP8;
114 _codecSpecificInfo.codecSpecific.VP8.nonReference =
115 header->codecHeader.VP8.nonReference;
116 if (header->codecHeader.VP8.pictureId != kNoPictureId) {
117 _codecSpecificInfo.codecSpecific.VP8.pictureId =
118 header->codecHeader.VP8.pictureId;
120 if (header->codecHeader.VP8.temporalIdx != kNoTemporalIdx) {
121 _codecSpecificInfo.codecSpecific.VP8.temporalIdx =
122 header->codecHeader.VP8.temporalIdx;
123 _codecSpecificInfo.codecSpecific.VP8.layerSync =
124 header->codecHeader.VP8.layerSync;
126 if (header->codecHeader.VP8.keyIdx != kNoKeyIdx) {
127 _codecSpecificInfo.codecSpecific.VP8.keyIdx =
128 header->codecHeader.VP8.keyIdx;
132 case kRtpVideoH264: {
133 _codecSpecificInfo.codecType = kVideoCodecH264;
137 _codecSpecificInfo.codecType = kVideoCodecUnknown;
144 const RTPFragmentationHeader* VCMEncodedFrame::FragmentationHeader() const {
145 return &_fragmentation;
148 void VCMEncodedFrame::VerifyAndAllocate(const uint32_t minimumSize)
150 if(minimumSize > _size)
152 // create buffer of sufficient size
153 uint8_t* newBuffer = new uint8_t[minimumSize];
157 memcpy(newBuffer, _buffer, _size);
165 webrtc::FrameType VCMEncodedFrame::ConvertFrameType(VideoFrameType frameType)
169 return kVideoFrameKey;
171 return kVideoFrameDelta;
175 return kVideoFrameDelta;
179 VideoFrameType VCMEncodedFrame::ConvertFrameType(webrtc::FrameType frame_type) {
180 switch (frame_type) {
183 case kVideoFrameDelta:
191 void VCMEncodedFrame::ConvertFrameTypes(
192 const std::vector<webrtc::FrameType>& frame_types,
193 std::vector<VideoFrameType>* video_frame_types) {
194 assert(video_frame_types);
195 video_frame_types->reserve(frame_types.size());
196 for (size_t i = 0; i < frame_types.size(); ++i) {
197 (*video_frame_types)[i] = ConvertFrameType(frame_types[i]);