blob: 518bac0e4d24d39554d3f7b33f22dc648edd79df [file] [log] [blame]
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "common_video/include/video_frame.h"
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070012
13#include <string.h>
14
15#include <algorithm> // swap
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/bind.h"
18#include "rtc_base/checks.h"
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070019
20namespace webrtc {
21
hbosbab934b2016-01-27 01:36:03 -080022// FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due
23// to optimized bitstream readers. See avcodec_decode_video2.
24const size_t EncodedImage::kBufferPaddingBytesH264 = 8;
hbosd6648362016-01-21 05:43:11 -080025
hbosd6648362016-01-21 05:43:11 -080026size_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:
hbosd6648362016-01-21 05:43:11 -080034 case kVideoCodecGeneric:
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080035 case kVideoCodecMultiplex:
hbosd6648362016-01-21 05:43:11 -080036 case kVideoCodecUnknown:
37 return 0;
38 }
39 RTC_NOTREACHED();
40 return 0;
41}
42
mflodman351424e2017-08-10 02:43:14 -070043EncodedImage::EncodedImage() : EncodedImage(nullptr, 0, 0) {}
44
Paulina Hensmana680a6a2018-04-05 11:42:24 +020045EncodedImage::EncodedImage(const EncodedImage&) = default;
46
mflodman351424e2017-08-10 02:43:14 -070047EncodedImage::EncodedImage(uint8_t* buffer, size_t length, size_t size)
48 : _buffer(buffer), _length(length), _size(size) {}
49
50void EncodedImage::SetEncodeTime(int64_t encode_start_ms,
Ilya Nikolaevskiy76f2a852017-11-16 14:33:53 +010051 int64_t encode_finish_ms) {
52 timing_.encode_start_ms = encode_start_ms;
53 timing_.encode_finish_ms = encode_finish_ms;
mflodman351424e2017-08-10 02:43:14 -070054}
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070055} // namespace webrtc