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/video_frame.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <algorithm> // swap | 15 #include <algorithm> // swap |
16 | 16 |
17 #include "webrtc/base/bind.h" | 17 #include "webrtc/base/bind.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 // FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due | 22 // FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due |
23 // to optimized bitstream readers. See avcodec_decode_video2. | 23 // to optimized bitstream readers. See avcodec_decode_video2. |
24 const size_t EncodedImage::kBufferPaddingBytesH264 = 8; | 24 const size_t EncodedImage::kBufferPaddingBytesH264 = 8; |
25 | 25 |
26 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | |
danilchap
2016/08/26 13:19:30
order constructor same as in header file, i.e. thi
| |
27 webrtc::VideoRotation rotation, | |
28 int64_t timestamp_us) | |
29 : video_frame_buffer_(buffer), | |
30 timestamp_(0), | |
31 ntp_time_ms_(0), | |
32 timestamp_us_(timestamp_us), | |
33 rotation_(rotation) {} | |
34 | |
35 | |
26 VideoFrame::VideoFrame() | 36 VideoFrame::VideoFrame() |
27 : video_frame_buffer_(nullptr), | 37 : video_frame_buffer_(nullptr), |
28 timestamp_(0), | 38 timestamp_(0), |
29 ntp_time_ms_(0), | 39 ntp_time_ms_(0), |
30 render_time_ms_(0), | 40 timestamp_us_(0), |
31 rotation_(kVideoRotation_0) {} | 41 rotation_(kVideoRotation_0) {} |
32 | 42 |
33 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 43 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
34 uint32_t timestamp, | 44 uint32_t timestamp, |
35 int64_t render_time_ms, | 45 int64_t render_time_ms, |
36 VideoRotation rotation) | 46 VideoRotation rotation) |
37 : video_frame_buffer_(buffer), | 47 : video_frame_buffer_(buffer), |
38 timestamp_(timestamp), | 48 timestamp_(timestamp), |
39 ntp_time_ms_(0), | 49 ntp_time_ms_(0), |
40 render_time_ms_(render_time_ms), | 50 timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), |
41 rotation_(rotation) { | 51 rotation_(rotation) { |
42 RTC_DCHECK(buffer); | 52 RTC_DCHECK(buffer); |
43 } | 53 } |
44 | 54 |
45 void VideoFrame::CreateEmptyFrame(int width, | 55 void VideoFrame::CreateEmptyFrame(int width, |
46 int height, | 56 int height, |
47 int stride_y, | 57 int stride_y, |
48 int stride_u, | 58 int stride_u, |
49 int stride_v) { | 59 int stride_v) { |
50 const int half_width = (width + 1) / 2; | 60 const int half_width = (width + 1) / 2; |
51 RTC_DCHECK_GT(width, 0); | 61 RTC_DCHECK_GT(width, 0); |
52 RTC_DCHECK_GT(height, 0); | 62 RTC_DCHECK_GT(height, 0); |
53 RTC_DCHECK_GE(stride_y, width); | 63 RTC_DCHECK_GE(stride_y, width); |
54 RTC_DCHECK_GE(stride_u, half_width); | 64 RTC_DCHECK_GE(stride_u, half_width); |
55 RTC_DCHECK_GE(stride_v, half_width); | 65 RTC_DCHECK_GE(stride_v, half_width); |
56 | 66 |
57 // Creating empty frame - reset all values. | 67 // Creating empty frame - reset all values. |
58 timestamp_ = 0; | 68 timestamp_ = 0; |
59 ntp_time_ms_ = 0; | 69 ntp_time_ms_ = 0; |
60 render_time_ms_ = 0; | 70 timestamp_us_ = 0; |
61 rotation_ = kVideoRotation_0; | 71 rotation_ = kVideoRotation_0; |
62 | 72 |
63 // Allocate a new buffer. | 73 // Allocate a new buffer. |
64 video_frame_buffer_ = I420Buffer::Create( | 74 video_frame_buffer_ = I420Buffer::Create( |
65 width, height, stride_y, stride_u, stride_v); | 75 width, height, stride_y, stride_u, stride_v); |
66 } | 76 } |
67 | 77 |
68 void VideoFrame::CreateFrame(const uint8_t* buffer_y, | 78 void VideoFrame::CreateFrame(const uint8_t* buffer_y, |
69 const uint8_t* buffer_u, | 79 const uint8_t* buffer_u, |
70 const uint8_t* buffer_v, | 80 const uint8_t* buffer_v, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 // If backed by a plain memory buffer, create a new, non-shared, copy. | 115 // If backed by a plain memory buffer, create a new, non-shared, copy. |
106 if (video_frame_buffer_ && !video_frame_buffer_->native_handle()) { | 116 if (video_frame_buffer_ && !video_frame_buffer_->native_handle()) { |
107 video_frame_buffer_ = I420Buffer::Copy(video_frame_buffer_); | 117 video_frame_buffer_ = I420Buffer::Copy(video_frame_buffer_); |
108 } | 118 } |
109 } | 119 } |
110 | 120 |
111 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) { | 121 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) { |
112 video_frame_buffer_ = videoFrame.video_frame_buffer(); | 122 video_frame_buffer_ = videoFrame.video_frame_buffer(); |
113 timestamp_ = videoFrame.timestamp_; | 123 timestamp_ = videoFrame.timestamp_; |
114 ntp_time_ms_ = videoFrame.ntp_time_ms_; | 124 ntp_time_ms_ = videoFrame.ntp_time_ms_; |
115 render_time_ms_ = videoFrame.render_time_ms_; | 125 timestamp_us_ = videoFrame.timestamp_us_; |
116 rotation_ = videoFrame.rotation_; | 126 rotation_ = videoFrame.rotation_; |
117 } | 127 } |
118 | 128 |
119 // TODO(nisse): Delete. Besides test code, only one use, in | 129 // TODO(nisse): Delete. Besides test code, only one use, in |
120 // webrtcvideoengine2.cc:CreateBlackFrame. | 130 // webrtcvideoengine2.cc:CreateBlackFrame. |
121 int VideoFrame::allocated_size(PlaneType type) const { | 131 int VideoFrame::allocated_size(PlaneType type) const { |
122 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; | 132 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; |
123 int stride; | 133 int stride; |
124 switch (type) { | 134 switch (type) { |
125 case kYPlane: | 135 case kYPlane: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 case kVideoCodecULPFEC: | 177 case kVideoCodecULPFEC: |
168 case kVideoCodecGeneric: | 178 case kVideoCodecGeneric: |
169 case kVideoCodecUnknown: | 179 case kVideoCodecUnknown: |
170 return 0; | 180 return 0; |
171 } | 181 } |
172 RTC_NOTREACHED(); | 182 RTC_NOTREACHED(); |
173 return 0; | 183 return 0; |
174 } | 184 } |
175 | 185 |
176 } // namespace webrtc | 186 } // namespace webrtc |
OLD | NEW |