Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 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 | |
nisse | ea3a798 | 2017-05-15 02:42:11 -0700 | [diff] [blame] | 11 | #include "webrtc/common_video/include/video_frame.h" |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
| 14 | |
| 15 | #include <algorithm> // swap |
| 16 | |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/bind.h" |
| 18 | #include "webrtc/rtc_base/checks.h" |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 22 | // FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due |
| 23 | // to optimized bitstream readers. See avcodec_decode_video2. |
| 24 | const size_t EncodedImage::kBufferPaddingBytesH264 = 8; |
hbos | d664836 | 2016-01-21 05:43:11 -0800 | [diff] [blame] | 25 | |
hbos | d664836 | 2016-01-21 05:43:11 -0800 | [diff] [blame] | 26 | size_t EncodedImage::GetBufferPaddingBytes(VideoCodecType codec_type) { |
| 27 | switch (codec_type) { |
| 28 | case kVideoCodecVP8: |
| 29 | case kVideoCodecVP9: |
| 30 | return 0; |
| 31 | case kVideoCodecH264: |
| 32 | return kBufferPaddingBytesH264; |
| 33 | case kVideoCodecI420: |
| 34 | case kVideoCodecRED: |
| 35 | case kVideoCodecULPFEC: |
brandtr | 87d7d77 | 2016-11-07 03:03:41 -0800 | [diff] [blame] | 36 | case kVideoCodecFlexfec: |
hbos | d664836 | 2016-01-21 05:43:11 -0800 | [diff] [blame] | 37 | case kVideoCodecGeneric: |
| 38 | case kVideoCodecUnknown: |
| 39 | return 0; |
| 40 | } |
| 41 | RTC_NOTREACHED(); |
| 42 | return 0; |
| 43 | } |
| 44 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 45 | EncodedImage::EncodedImage() : EncodedImage(nullptr, 0, 0) {} |
| 46 | |
| 47 | EncodedImage::EncodedImage(uint8_t* buffer, size_t length, size_t size) |
| 48 | : _buffer(buffer), _length(length), _size(size) {} |
| 49 | |
| 50 | void EncodedImage::SetEncodeTime(int64_t encode_start_ms, |
| 51 | int64_t encode_finish_ms) const { |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 52 | timing_.encode_start_ms = encode_start_ms; |
| 53 | timing_.encode_finish_ms = encode_finish_ms; |
| 54 | } |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 55 | } // namespace webrtc |