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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // Set up a new buffer. | 122 // Set up a new buffer. |
123 // TODO(fbarchard): Support lazy allocation. | 123 // TODO(fbarchard): Support lazy allocation. |
124 int new_width = dw; | 124 int new_width = dw; |
125 int new_height = dh; | 125 int new_height = dh; |
126 // If rotated swap width, height. | 126 // If rotated swap width, height. |
127 if (apply_rotation && (rotation == 90 || rotation == 270)) { | 127 if (apply_rotation && (rotation == 90 || rotation == 270)) { |
128 new_width = dh; | 128 new_width = dh; |
129 new_height = dw; | 129 new_height = dw; |
130 } | 130 } |
131 | 131 |
132 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 132 InitToEmptyBuffer(new_width, new_height); |
133 webrtc::I420Buffer::Create(new_width, new_height); | |
134 video_frame_buffer_ = buffer; | |
135 rotation_ = apply_rotation ? webrtc::kVideoRotation_0 : rotation; | 133 rotation_ = apply_rotation ? webrtc::kVideoRotation_0 : rotation; |
136 | 134 |
137 int horiz_crop = ((w - dw) / 2) & ~1; | 135 int horiz_crop = ((w - dw) / 2) & ~1; |
138 // ARGB on Windows has negative height. | 136 // ARGB on Windows has negative height. |
139 // The sample's layout in memory is normal, so just correct crop. | 137 // The sample's layout in memory is normal, so just correct crop. |
140 int vert_crop = ((abs(h) - dh) / 2) & ~1; | 138 int vert_crop = ((abs(h) - dh) / 2) & ~1; |
141 // Conversion functions expect negative height to flip the image. | 139 // Conversion functions expect negative height to flip the image. |
142 int idh = (h < 0) ? -dh : dh; | 140 int idh = (h < 0) ? -dh : dh; |
143 int r = libyuv::ConvertToI420( | 141 int r = libyuv::ConvertToI420( |
144 sample, sample_size, | 142 sample, sample_size, |
145 buffer->MutableDataY(), buffer->StrideY(), | 143 video_frame_buffer_->MutableDataY(), |
146 buffer->MutableDataU(), buffer->StrideU(), | 144 video_frame_buffer_->StrideY(), |
147 buffer->MutableDataV(), buffer->StrideV(), | 145 video_frame_buffer_->MutableDataU(), |
148 horiz_crop, vert_crop, w, h, dw, idh, | 146 video_frame_buffer_->StrideU(), |
| 147 video_frame_buffer_->MutableDataV(), |
| 148 video_frame_buffer_->StrideV(), |
| 149 horiz_crop, vert_crop, |
| 150 w, h, |
| 151 dw, idh, |
149 static_cast<libyuv::RotationMode>( | 152 static_cast<libyuv::RotationMode>( |
150 apply_rotation ? rotation : webrtc::kVideoRotation_0), | 153 apply_rotation ? rotation : webrtc::kVideoRotation_0), |
151 format); | 154 format); |
152 if (r) { | 155 if (r) { |
153 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) | 156 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) |
154 << " return code : " << r; | 157 << " return code : " << r; |
155 return false; | 158 return false; |
156 } | 159 } |
157 timestamp_us_ = timestamp_us; | 160 timestamp_us_ = timestamp_us; |
158 return true; | 161 return true; |
159 } | 162 } |
160 | 163 |
161 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { | 164 void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { |
162 video_frame_buffer_ = webrtc::I420Buffer::Create(w, h); | 165 video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); |
163 rotation_ = webrtc::kVideoRotation_0; | 166 rotation_ = webrtc::kVideoRotation_0; |
164 } | 167 } |
165 | 168 |
166 } // namespace cricket | 169 } // namespace cricket |
OLD | NEW |