| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 11 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 12 #include "webrtc/modules/video_coding/encoded_frame.h" | 12 #include "webrtc/modules/video_coding/encoded_frame.h" |
| 13 #include "webrtc/modules/video_coding/generic_encoder.h" | 13 #include "webrtc/modules/video_coding/generic_encoder.h" |
| 14 #include "webrtc/modules/video_coding/jitter_buffer_common.h" | 14 #include "webrtc/modules/video_coding/jitter_buffer_common.h" |
| 15 | 15 |
| 16 namespace webrtc { | 16 namespace webrtc { |
| 17 | 17 |
| 18 VCMEncodedFrame::VCMEncodedFrame() | 18 VCMEncodedFrame::VCMEncodedFrame() |
| 19 : webrtc::EncodedImage(), | 19 : webrtc::EncodedImage(), |
| 20 _renderTimeMs(-1), | 20 _renderTimeMs(-1), |
| 21 _payloadType(0), | 21 _payloadType(0), |
| 22 _missingFrame(false), | 22 _missingFrame(false), |
| 23 _codec(kVideoCodecUnknown), | 23 _codec(kVideoCodecUnknown), |
| 24 _fragmentation(), | 24 _fragmentation(), |
| 25 _rotation(kVideoRotation_0), | 25 _rotation(kVideoRotation_0), |
| 26 _rotation_set(false) { | 26 _rotation_set(false) { |
| 27 _codecSpecificInfo.codecType = kVideoCodecUnknown; | 27 _codecSpecificInfo.codecType = kVideoCodecUnknown; |
| 28 } | 28 } |
| 29 | 29 |
| 30 VCMEncodedFrame::VCMEncodedFrame(const webrtc::EncodedImage& rhs) | 30 VCMEncodedFrame::VCMEncodedFrame(const webrtc::EncodedImage& rhs) |
| 31 : webrtc::EncodedImage(rhs), | 31 : webrtc::EncodedImage(rhs), |
| 32 _renderTimeMs(-1), | 32 _renderTimeMs(-1), |
| 33 _payloadType(0), | 33 _payloadType(0), |
| 34 _missingFrame(false), | 34 _missingFrame(false), |
| 35 _codec(kVideoCodecUnknown), | 35 _codec(kVideoCodecUnknown), |
| 36 _fragmentation(), | 36 _fragmentation(), |
| 37 _rotation(kVideoRotation_0), | 37 _rotation(kVideoRotation_0), |
| 38 _rotation_set(false) { | 38 _rotation_set(false) { |
| 39 _codecSpecificInfo.codecType = kVideoCodecUnknown; | 39 _codecSpecificInfo.codecType = kVideoCodecUnknown; |
| 40 _buffer = NULL; | 40 _buffer = NULL; |
| 41 _size = 0; | 41 _size = 0; |
| 42 _length = 0; | 42 _length = 0; |
| 43 if (rhs._buffer != NULL) | 43 if (rhs._buffer != NULL) { |
| 44 { | 44 VerifyAndAllocate(rhs._length); |
| 45 VerifyAndAllocate(rhs._length); | 45 memcpy(_buffer, rhs._buffer, rhs._length); |
| 46 memcpy(_buffer, rhs._buffer, rhs._length); | 46 } |
| 47 } | |
| 48 } | 47 } |
| 49 | 48 |
| 50 VCMEncodedFrame::VCMEncodedFrame(const VCMEncodedFrame& rhs) | 49 VCMEncodedFrame::VCMEncodedFrame(const VCMEncodedFrame& rhs) |
| 51 : webrtc::EncodedImage(rhs), | 50 : webrtc::EncodedImage(rhs), |
| 52 _renderTimeMs(rhs._renderTimeMs), | 51 _renderTimeMs(rhs._renderTimeMs), |
| 53 _payloadType(rhs._payloadType), | 52 _payloadType(rhs._payloadType), |
| 54 _missingFrame(rhs._missingFrame), | 53 _missingFrame(rhs._missingFrame), |
| 55 _codecSpecificInfo(rhs._codecSpecificInfo), | 54 _codecSpecificInfo(rhs._codecSpecificInfo), |
| 56 _codec(rhs._codec), | 55 _codec(rhs._codec), |
| 57 _fragmentation(), | 56 _fragmentation(), |
| 58 _rotation(rhs._rotation), | 57 _rotation(rhs._rotation), |
| 59 _rotation_set(rhs._rotation_set) { | 58 _rotation_set(rhs._rotation_set) { |
| 60 _buffer = NULL; | 59 _buffer = NULL; |
| 61 _size = 0; | 60 _size = 0; |
| 62 _length = 0; | 61 _length = 0; |
| 63 if (rhs._buffer != NULL) | 62 if (rhs._buffer != NULL) { |
| 64 { | 63 VerifyAndAllocate(rhs._length); |
| 65 VerifyAndAllocate(rhs._length); | 64 memcpy(_buffer, rhs._buffer, rhs._length); |
| 66 memcpy(_buffer, rhs._buffer, rhs._length); | 65 _length = rhs._length; |
| 67 _length = rhs._length; | |
| 68 } | 66 } |
| 69 _fragmentation.CopyFrom(rhs._fragmentation); | 67 _fragmentation.CopyFrom(rhs._fragmentation); |
| 70 } | 68 } |
| 71 | 69 |
| 72 VCMEncodedFrame::~VCMEncodedFrame() | 70 VCMEncodedFrame::~VCMEncodedFrame() { |
| 73 { | 71 Free(); |
| 74 Free(); | |
| 75 } | 72 } |
| 76 | 73 |
| 77 void VCMEncodedFrame::Free() | 74 void VCMEncodedFrame::Free() { |
| 78 { | 75 Reset(); |
| 79 Reset(); | 76 if (_buffer != NULL) { |
| 80 if (_buffer != NULL) | 77 delete[] _buffer; |
| 81 { | 78 _buffer = NULL; |
| 82 delete [] _buffer; | 79 } |
| 83 _buffer = NULL; | |
| 84 } | |
| 85 } | 80 } |
| 86 | 81 |
| 87 void VCMEncodedFrame::Reset() | 82 void VCMEncodedFrame::Reset() { |
| 88 { | 83 _renderTimeMs = -1; |
| 89 _renderTimeMs = -1; | 84 _timeStamp = 0; |
| 90 _timeStamp = 0; | 85 _payloadType = 0; |
| 91 _payloadType = 0; | 86 _frameType = kVideoFrameDelta; |
| 92 _frameType = kVideoFrameDelta; | 87 _encodedWidth = 0; |
| 93 _encodedWidth = 0; | 88 _encodedHeight = 0; |
| 94 _encodedHeight = 0; | 89 _completeFrame = false; |
| 95 _completeFrame = false; | 90 _missingFrame = false; |
| 96 _missingFrame = false; | 91 _length = 0; |
| 97 _length = 0; | 92 _codecSpecificInfo.codecType = kVideoCodecUnknown; |
| 98 _codecSpecificInfo.codecType = kVideoCodecUnknown; | 93 _codec = kVideoCodecUnknown; |
| 99 _codec = kVideoCodecUnknown; | 94 _rotation = kVideoRotation_0; |
| 100 _rotation = kVideoRotation_0; | 95 _rotation_set = false; |
| 101 _rotation_set = false; | |
| 102 } | 96 } |
| 103 | 97 |
| 104 void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) | 98 void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) { |
| 105 { | |
| 106 if (header) { | 99 if (header) { |
| 107 switch (header->codec) { | 100 switch (header->codec) { |
| 108 case kRtpVideoVp8: { | 101 case kRtpVideoVp8: { |
| 109 if (_codecSpecificInfo.codecType != kVideoCodecVP8) { | 102 if (_codecSpecificInfo.codecType != kVideoCodecVP8) { |
| 110 // This is the first packet for this frame. | 103 // This is the first packet for this frame. |
| 111 _codecSpecificInfo.codecSpecific.VP8.pictureId = -1; | 104 _codecSpecificInfo.codecSpecific.VP8.pictureId = -1; |
| 112 _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0; | 105 _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0; |
| 113 _codecSpecificInfo.codecSpecific.VP8.layerSync = false; | 106 _codecSpecificInfo.codecSpecific.VP8.layerSync = false; |
| 114 _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1; | 107 _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1; |
| 115 _codecSpecificInfo.codecType = kVideoCodecVP8; | 108 _codecSpecificInfo.codecType = kVideoCodecVP8; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 break; | 201 break; |
| 209 } | 202 } |
| 210 } | 203 } |
| 211 } | 204 } |
| 212 } | 205 } |
| 213 | 206 |
| 214 const RTPFragmentationHeader* VCMEncodedFrame::FragmentationHeader() const { | 207 const RTPFragmentationHeader* VCMEncodedFrame::FragmentationHeader() const { |
| 215 return &_fragmentation; | 208 return &_fragmentation; |
| 216 } | 209 } |
| 217 | 210 |
| 218 void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) | 211 void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) { |
| 219 { | 212 if (minimumSize > _size) { |
| 220 if(minimumSize > _size) | 213 // create buffer of sufficient size |
| 221 { | 214 uint8_t* newBuffer = new uint8_t[minimumSize]; |
| 222 // create buffer of sufficient size | 215 if (_buffer) { |
| 223 uint8_t* newBuffer = new uint8_t[minimumSize]; | 216 // copy old data |
| 224 if(_buffer) | 217 memcpy(newBuffer, _buffer, _size); |
| 225 { | 218 delete[] _buffer; |
| 226 // copy old data | |
| 227 memcpy(newBuffer, _buffer, _size); | |
| 228 delete [] _buffer; | |
| 229 } | |
| 230 _buffer = newBuffer; | |
| 231 _size = minimumSize; | |
| 232 } | 219 } |
| 220 _buffer = newBuffer; |
| 221 _size = minimumSize; |
| 222 } |
| 233 } | 223 } |
| 234 | 224 |
| 235 } // namespace webrtc | 225 } // namespace webrtc |
| OLD | NEW |