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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Set up a new buffer. | 136 // Set up a new buffer. |
137 // TODO(fbarchard): Support lazy allocation. | 137 // TODO(fbarchard): Support lazy allocation. |
138 int new_width = dw; | 138 int new_width = dw; |
139 int new_height = dh; | 139 int new_height = dh; |
140 // If rotated swap width, height. | 140 // If rotated swap width, height. |
141 if (apply_rotation && (rotation == 90 || rotation == 270)) { | 141 if (apply_rotation && (rotation == 90 || rotation == 270)) { |
142 new_width = dh; | 142 new_width = dh; |
143 new_height = dw; | 143 new_height = dw; |
144 } | 144 } |
145 | 145 |
146 InitToEmptyBuffer(new_width, new_height); | 146 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 147 webrtc::I420Buffer::Create(new_width, new_height); |
| 148 video_frame_buffer_ = buffer; |
147 rotation_ = apply_rotation ? webrtc::kVideoRotation_0 : rotation; | 149 rotation_ = apply_rotation ? webrtc::kVideoRotation_0 : rotation; |
148 | 150 |
149 int horiz_crop = ((w - dw) / 2) & ~1; | 151 int horiz_crop = ((w - dw) / 2) & ~1; |
150 // ARGB on Windows has negative height. | 152 // ARGB on Windows has negative height. |
151 // The sample's layout in memory is normal, so just correct crop. | 153 // The sample's layout in memory is normal, so just correct crop. |
152 int vert_crop = ((abs(h) - dh) / 2) & ~1; | 154 int vert_crop = ((abs(h) - dh) / 2) & ~1; |
153 // Conversion functions expect negative height to flip the image. | 155 // Conversion functions expect negative height to flip the image. |
154 int idh = (h < 0) ? -dh : dh; | 156 int idh = (h < 0) ? -dh : dh; |
155 int r = libyuv::ConvertToI420( | 157 int r = libyuv::ConvertToI420( |
156 sample, sample_size, | 158 sample, sample_size, |
157 video_frame_buffer_->MutableDataY(), | 159 buffer->MutableDataY(), buffer->StrideY(), |
158 video_frame_buffer_->StrideY(), | 160 buffer->MutableDataU(), buffer->StrideU(), |
159 video_frame_buffer_->MutableDataU(), | 161 buffer->MutableDataV(), buffer->StrideV(), |
160 video_frame_buffer_->StrideU(), | 162 horiz_crop, vert_crop, w, h, dw, idh, |
161 video_frame_buffer_->MutableDataV(), | |
162 video_frame_buffer_->StrideV(), | |
163 horiz_crop, vert_crop, | |
164 w, h, | |
165 dw, idh, | |
166 static_cast<libyuv::RotationMode>( | 163 static_cast<libyuv::RotationMode>( |
167 apply_rotation ? rotation : webrtc::kVideoRotation_0), | 164 apply_rotation ? rotation : webrtc::kVideoRotation_0), |
168 format); | 165 format); |
169 if (r) { | 166 if (r) { |
170 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) | 167 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) |
171 << " return code : " << r; | 168 << " return code : " << r; |
172 return false; | 169 return false; |
173 } | 170 } |
174 timestamp_us_ = timestamp_us; | 171 timestamp_us_ = timestamp_us; |
175 return true; | 172 return true; |
176 } | 173 } |
177 | 174 |
178 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { | 175 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { |
179 video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); | 176 video_frame_buffer_ = webrtc::I420Buffer::Create(w, h); |
180 rotation_ = webrtc::kVideoRotation_0; | 177 rotation_ = webrtc::kVideoRotation_0; |
181 } | 178 } |
182 | 179 |
183 const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { | 180 const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { |
184 // If the frame is not rotated, the caller should reuse this frame instead of | 181 // If the frame is not rotated, the caller should reuse this frame instead of |
185 // making a redundant copy. | 182 // making a redundant copy. |
186 if (rotation() == webrtc::kVideoRotation_0) { | 183 if (rotation() == webrtc::kVideoRotation_0) { |
187 return this; | 184 return this; |
188 } | 185 } |
189 | 186 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 static_cast<libyuv::RotationMode>(rotation())); | 219 static_cast<libyuv::RotationMode>(rotation())); |
223 if (ret == 0) { | 220 if (ret == 0) { |
224 rotated_frame_.reset(new WebRtcVideoFrame( | 221 rotated_frame_.reset(new WebRtcVideoFrame( |
225 buffer, webrtc::kVideoRotation_0, timestamp_us_, transport_frame_id_)); | 222 buffer, webrtc::kVideoRotation_0, timestamp_us_, transport_frame_id_)); |
226 } | 223 } |
227 | 224 |
228 return rotated_frame_.get(); | 225 return rotated_frame_.get(); |
229 } | 226 } |
230 | 227 |
231 } // namespace cricket | 228 } // namespace cricket |
OLD | NEW |