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