OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 format); | 142 format); |
143 if (r) { | 143 if (r) { |
144 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) | 144 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) |
145 << " return code : " << r; | 145 << " return code : " << r; |
146 return false; | 146 return false; |
147 } | 147 } |
148 timestamp_us_ = timestamp_us; | 148 timestamp_us_ = timestamp_us; |
149 return true; | 149 return true; |
150 } | 150 } |
151 | 151 |
152 VideoFrame* WebRtcVideoFrame::CreateEmptyFrame(int w, | |
153 int h, | |
154 int64_t timestamp_us) const { | |
155 WebRtcVideoFrame* frame = new WebRtcVideoFrame(); | |
156 frame->InitToEmptyBuffer(w, h, rtc::kNumNanosecsPerMicrosec * timestamp_us); | |
157 return frame; | |
158 } | |
159 | |
160 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { | 152 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { |
161 video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); | 153 video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); |
162 rotation_ = webrtc::kVideoRotation_0; | 154 rotation_ = webrtc::kVideoRotation_0; |
163 } | 155 } |
164 | 156 |
165 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h, | |
166 int64_t time_stamp_ns) { | |
167 video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); | |
168 SetTimeStamp(time_stamp_ns); | |
169 rotation_ = webrtc::kVideoRotation_0; | |
170 } | |
171 | |
172 const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { | 157 const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { |
173 // If the frame is not rotated, the caller should reuse this frame instead of | 158 // If the frame is not rotated, the caller should reuse this frame instead of |
174 // making a redundant copy. | 159 // making a redundant copy. |
175 if (rotation() == webrtc::kVideoRotation_0) { | 160 if (rotation() == webrtc::kVideoRotation_0) { |
176 return this; | 161 return this; |
177 } | 162 } |
178 | 163 |
179 // If the video frame is backed up by a native handle, it resides in the GPU | 164 // If the video frame is backed up by a native handle, it resides in the GPU |
180 // memory which we can't rotate here. The assumption is that the renderers | 165 // memory which we can't rotate here. The assumption is that the renderers |
181 // which uses GPU to render should be able to rotate themselves. | 166 // which uses GPU to render should be able to rotate themselves. |
182 RTC_DCHECK(!video_frame_buffer()->native_handle()); | 167 RTC_DCHECK(!video_frame_buffer()->native_handle()); |
183 | 168 |
184 if (rotated_frame_) { | 169 if (rotated_frame_) { |
185 return rotated_frame_.get(); | 170 return rotated_frame_.get(); |
186 } | 171 } |
187 | 172 |
188 int orig_width = width(); | 173 int current_width = width(); |
189 int orig_height = height(); | 174 int current_height = height(); |
190 | 175 |
191 int rotated_width = orig_width; | 176 int rotated_width = current_width; |
192 int rotated_height = orig_height; | 177 int rotated_height = current_height; |
193 if (rotation() == webrtc::kVideoRotation_90 || | 178 if (rotation() == webrtc::kVideoRotation_90 || |
194 rotation() == webrtc::kVideoRotation_270) { | 179 rotation() == webrtc::kVideoRotation_270) { |
195 rotated_width = orig_height; | 180 std::swap(rotated_width, rotated_height); |
196 rotated_height = orig_width; | |
197 } | 181 } |
198 | 182 |
199 rotated_frame_.reset( | 183 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
200 CreateEmptyFrame(rotated_width, rotated_height, timestamp_us_)); | 184 new rtc::RefCountedObject<webrtc::I420Buffer>(rotated_width, |
| 185 rotated_height); |
201 | 186 |
202 // TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from | 187 // TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from |
203 // VideoRotation to libyuv::RotationMode. | 188 // VideoRotation to libyuv::RotationMode. |
204 int ret = libyuv::I420Rotate( | 189 int ret = libyuv::I420Rotate( |
205 video_frame_buffer_->DataY(), video_frame_buffer_->StrideY(), | 190 video_frame_buffer_->DataY(), video_frame_buffer_->StrideY(), |
206 video_frame_buffer_->DataU(), video_frame_buffer_->StrideU(), | 191 video_frame_buffer_->DataU(), video_frame_buffer_->StrideU(), |
207 video_frame_buffer_->DataV(), video_frame_buffer_->StrideV(), | 192 video_frame_buffer_->DataV(), video_frame_buffer_->StrideV(), |
208 rotated_frame_->video_frame_buffer()->MutableDataY(), | 193 buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), |
209 rotated_frame_->video_frame_buffer()->StrideY(), | 194 buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), |
210 rotated_frame_->video_frame_buffer()->MutableDataU(), | 195 current_width, current_height, |
211 rotated_frame_->video_frame_buffer()->StrideU(), | |
212 rotated_frame_->video_frame_buffer()->MutableDataV(), | |
213 rotated_frame_->video_frame_buffer()->StrideV(), | |
214 orig_width, orig_height, | |
215 static_cast<libyuv::RotationMode>(rotation())); | 196 static_cast<libyuv::RotationMode>(rotation())); |
216 if (ret == 0) { | 197 if (ret == 0) { |
217 return rotated_frame_.get(); | 198 rotated_frame_.reset( |
| 199 new WebRtcVideoFrame(buffer, webrtc::kVideoRotation_0, timestamp_us_)); |
218 } | 200 } |
219 return nullptr; | 201 |
| 202 return rotated_frame_.get(); |
220 } | 203 } |
221 | 204 |
222 } // namespace cricket | 205 } // namespace cricket |
OLD | NEW |