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/video_frame.h" | 11 #include "webrtc/api/video/video_frame.h" |
12 | 12 |
13 #include <string.h> | |
14 | |
15 #include <algorithm> // swap | |
16 | |
17 #include "webrtc/base/bind.h" | |
18 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/timeutils.h" |
19 | 15 |
20 namespace webrtc { | 16 namespace webrtc { |
21 | 17 |
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; | |
25 | |
26 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 18 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
27 webrtc::VideoRotation rotation, | 19 webrtc::VideoRotation rotation, |
28 int64_t timestamp_us) | 20 int64_t timestamp_us) |
29 : video_frame_buffer_(buffer), | 21 : video_frame_buffer_(buffer), |
30 timestamp_rtp_(0), | 22 timestamp_rtp_(0), |
31 ntp_time_ms_(0), | 23 ntp_time_ms_(0), |
32 timestamp_us_(timestamp_us), | 24 timestamp_us_(timestamp_us), |
33 rotation_(rotation) {} | 25 rotation_(rotation) {} |
34 | 26 |
35 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 27 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
36 uint32_t timestamp, | 28 uint32_t timestamp, |
37 int64_t render_time_ms, | 29 int64_t render_time_ms, |
38 VideoRotation rotation) | 30 VideoRotation rotation) |
39 : video_frame_buffer_(buffer), | 31 : video_frame_buffer_(buffer), |
40 timestamp_rtp_(timestamp), | 32 timestamp_rtp_(timestamp), |
41 ntp_time_ms_(0), | 33 ntp_time_ms_(0), |
42 timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), | 34 timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), |
43 rotation_(rotation) { | 35 rotation_(rotation) { |
44 RTC_DCHECK(buffer); | 36 RTC_DCHECK(buffer); |
45 } | 37 } |
46 | 38 |
| 39 VideoFrame::~VideoFrame() = default; |
| 40 |
| 41 VideoFrame::VideoFrame(const VideoFrame&) = default; |
| 42 VideoFrame::VideoFrame(VideoFrame&&) = default; |
| 43 VideoFrame& VideoFrame::operator=(const VideoFrame&) = default; |
| 44 VideoFrame& VideoFrame::operator=(VideoFrame&&) = default; |
| 45 |
47 int VideoFrame::width() const { | 46 int VideoFrame::width() const { |
48 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; | 47 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; |
49 } | 48 } |
50 | 49 |
51 int VideoFrame::height() const { | 50 int VideoFrame::height() const { |
52 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; | 51 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; |
53 } | 52 } |
54 | 53 |
55 rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { | 54 rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { |
56 return video_frame_buffer_; | 55 return video_frame_buffer_; |
57 } | 56 } |
58 | 57 |
59 size_t EncodedImage::GetBufferPaddingBytes(VideoCodecType codec_type) { | 58 void VideoFrame::set_render_time_ms(int64_t render_time_ms) { |
60 switch (codec_type) { | 59 set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec); |
61 case kVideoCodecVP8: | 60 } |
62 case kVideoCodecVP9: | 61 |
63 return 0; | 62 int64_t VideoFrame::render_time_ms() const { |
64 case kVideoCodecH264: | 63 return timestamp_us() / rtc::kNumMicrosecsPerMillisec; |
65 return kBufferPaddingBytesH264; | |
66 case kVideoCodecI420: | |
67 case kVideoCodecRED: | |
68 case kVideoCodecULPFEC: | |
69 case kVideoCodecFlexfec: | |
70 case kVideoCodecGeneric: | |
71 case kVideoCodecUnknown: | |
72 return 0; | |
73 } | |
74 RTC_NOTREACHED(); | |
75 return 0; | |
76 } | 64 } |
77 | 65 |
78 } // namespace webrtc | 66 } // namespace webrtc |
OLD | NEW |