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 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 // Creating empty frame - reset all values. | 61 // Creating empty frame - reset all values. |
62 timestamp_ = 0; | 62 timestamp_ = 0; |
63 ntp_time_ms_ = 0; | 63 ntp_time_ms_ = 0; |
64 render_time_ms_ = 0; | 64 render_time_ms_ = 0; |
65 rotation_ = kVideoRotation_0; | 65 rotation_ = kVideoRotation_0; |
66 | 66 |
67 // Check if it's safe to reuse allocation. | 67 // Check if it's safe to reuse allocation. |
68 if (video_frame_buffer_ && video_frame_buffer_->IsMutable() && | 68 if (video_frame_buffer_ && video_frame_buffer_->IsMutable() && |
69 !video_frame_buffer_->native_handle() && | 69 !video_frame_buffer_->native_handle() && |
70 width == video_frame_buffer_->width() && | 70 width == video_frame_buffer_->width() && |
71 height == video_frame_buffer_->height() && stride_y == stride(kYPlane) && | 71 height == video_frame_buffer_->height() && |
72 stride_u == stride(kUPlane) && stride_v == stride(kVPlane)) { | 72 stride_y == video_frame_buffer_->StrideY() && |
73 stride_u == video_frame_buffer_->StrideU() && | |
74 stride_v == video_frame_buffer_->StrideV()) { | |
73 return; | 75 return; |
74 } | 76 } |
75 | 77 |
76 // Need to allocate new buffer. | 78 // Need to allocate new buffer. |
77 video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>( | 79 video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>( |
78 width, height, stride_y, stride_u, stride_v); | 80 width, height, stride_y, stride_u, stride_v); |
79 } | 81 } |
80 | 82 |
81 void VideoFrame::CreateFrame(const uint8_t* buffer_y, | 83 void VideoFrame::CreateFrame(const uint8_t* buffer_y, |
82 const uint8_t* buffer_u, | 84 const uint8_t* buffer_u, |
83 const uint8_t* buffer_v, | 85 const uint8_t* buffer_v, |
84 int width, | 86 int width, |
85 int height, | 87 int height, |
86 int stride_y, | 88 int stride_y, |
87 int stride_u, | 89 int stride_u, |
88 int stride_v, | 90 int stride_v, |
89 VideoRotation rotation) { | 91 VideoRotation rotation) { |
90 const int half_height = (height + 1) / 2; | 92 const int half_height = (height + 1) / 2; |
91 const int expected_size_y = height * stride_y; | 93 const int expected_size_y = height * stride_y; |
92 const int expected_size_u = half_height * stride_u; | 94 const int expected_size_u = half_height * stride_u; |
93 const int expected_size_v = half_height * stride_v; | 95 const int expected_size_v = half_height * stride_v; |
94 CreateEmptyFrame(width, height, stride_y, stride_u, stride_v); | 96 CreateEmptyFrame(width, height, stride_y, stride_u, stride_v); |
95 memcpy(buffer(kYPlane), buffer_y, expected_size_y); | 97 memcpy(video_frame_buffer_->MutableDataY(), buffer_y, expected_size_y); |
96 memcpy(buffer(kUPlane), buffer_u, expected_size_u); | 98 memcpy(video_frame_buffer_->MutableDataU(), buffer_u, expected_size_u); |
97 memcpy(buffer(kVPlane), buffer_v, expected_size_v); | 99 memcpy(video_frame_buffer_->MutableDataV(), buffer_v, expected_size_v); |
98 rotation_ = rotation; | 100 rotation_ = rotation; |
99 } | 101 } |
100 | 102 |
101 void VideoFrame::CreateFrame(const uint8_t* buffer, | 103 void VideoFrame::CreateFrame(const uint8_t* buffer, |
102 int width, | 104 int width, |
103 int height, | 105 int height, |
104 VideoRotation rotation) { | 106 VideoRotation rotation) { |
105 const int stride_y = width; | 107 const int stride_y = width; |
106 const int stride_uv = (width + 1) / 2; | 108 const int stride_uv = (width + 1) / 2; |
107 | 109 |
(...skipping 22 matching lines...) Expand all Loading... | |
130 } | 132 } |
131 | 133 |
132 void VideoFrame::Reset() { | 134 void VideoFrame::Reset() { |
133 video_frame_buffer_ = nullptr; | 135 video_frame_buffer_ = nullptr; |
134 timestamp_ = 0; | 136 timestamp_ = 0; |
135 ntp_time_ms_ = 0; | 137 ntp_time_ms_ = 0; |
136 render_time_ms_ = 0; | 138 render_time_ms_ = 0; |
137 rotation_ = kVideoRotation_0; | 139 rotation_ = kVideoRotation_0; |
138 } | 140 } |
139 | 141 |
140 uint8_t* VideoFrame::buffer(PlaneType type) { | 142 // TODO(nisse): Delete. Only one use, in |
141 return video_frame_buffer_ ? video_frame_buffer_->MutableData(type) | 143 // webrtcvideoengine2.cc:CreateBlackFrame. |
142 : nullptr; | |
143 } | |
144 | |
145 const uint8_t* VideoFrame::buffer(PlaneType type) const { | |
146 return video_frame_buffer_ ? video_frame_buffer_->data(type) : nullptr; | |
147 } | |
148 | |
149 int VideoFrame::allocated_size(PlaneType type) const { | 144 int VideoFrame::allocated_size(PlaneType type) const { |
150 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; | 145 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; |
151 return plane_height * stride(type); | 146 int stride; |
152 } | 147 switch (type) { |
153 | 148 case kYPlane: |
154 int VideoFrame::stride(PlaneType type) const { | 149 stride = video_frame_buffer_->StrideY(); |
155 return video_frame_buffer_ ? video_frame_buffer_->stride(type) : 0; | 150 break; |
151 case kUPlane: | |
152 stride = video_frame_buffer_->StrideU(); | |
153 break; | |
154 case kVPlane: | |
155 stride = video_frame_buffer_->StrideV(); | |
156 break; | |
157 default: | |
158 RTC_NOTREACHED(); | |
159 return 0; | |
160 } | |
161 return plane_height * stride; | |
156 } | 162 } |
157 | 163 |
158 int VideoFrame::width() const { | 164 int VideoFrame::width() const { |
159 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; | 165 return video_frame_buffer_ ? video_frame_buffer_->width() : 0; |
160 } | 166 } |
161 | 167 |
162 int VideoFrame::height() const { | 168 int VideoFrame::height() const { |
163 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; | 169 return video_frame_buffer_ ? video_frame_buffer_->height() : 0; |
164 } | 170 } |
165 | 171 |
166 bool VideoFrame::IsZeroSize() const { | 172 bool VideoFrame::IsZeroSize() const { |
167 return !video_frame_buffer_; | 173 return !video_frame_buffer_; |
168 } | 174 } |
169 | 175 |
170 rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { | 176 const rtc::scoped_refptr<VideoFrameBuffer>& VideoFrame::video_frame_buffer() |
perkj_webrtc
2016/04/19 12:28:13
have you run git cl format?
nisse-webrtc
2016/04/19 13:55:39
Not really. I've run git cl format --diff, and app
| |
177 const { | |
171 return video_frame_buffer_; | 178 return video_frame_buffer_; |
172 } | 179 } |
173 | 180 |
174 void VideoFrame::set_video_frame_buffer( | 181 void VideoFrame::set_video_frame_buffer( |
175 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer) { | 182 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer) { |
176 video_frame_buffer_ = buffer; | 183 video_frame_buffer_ = buffer; |
177 } | 184 } |
178 | 185 |
179 VideoFrame VideoFrame::ConvertNativeToI420Frame() const { | 186 VideoFrame VideoFrame::ConvertNativeToI420Frame() const { |
180 RTC_DCHECK(video_frame_buffer_->native_handle()); | 187 RTC_DCHECK(video_frame_buffer_->native_handle()); |
(...skipping 15 matching lines...) Expand all Loading... | |
196 case kVideoCodecULPFEC: | 203 case kVideoCodecULPFEC: |
197 case kVideoCodecGeneric: | 204 case kVideoCodecGeneric: |
198 case kVideoCodecUnknown: | 205 case kVideoCodecUnknown: |
199 return 0; | 206 return 0; |
200 } | 207 } |
201 RTC_NOTREACHED(); | 208 RTC_NOTREACHED(); |
202 return 0; | 209 return 0; |
203 } | 210 } |
204 | 211 |
205 } // namespace webrtc | 212 } // namespace webrtc |
OLD | NEW |