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