OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 rotation == 270); | 93 rotation == 270); |
94 | 94 |
95 int adapted_width; | 95 int adapted_width; |
96 int adapted_height; | 96 int adapted_height; |
97 int crop_width; | 97 int crop_width; |
98 int crop_height; | 98 int crop_height; |
99 int crop_x; | 99 int crop_x; |
100 int crop_y; | 100 int crop_y; |
101 int64_t translated_camera_time_us; | 101 int64_t translated_camera_time_us; |
102 | 102 |
103 if (!AdaptFrame(width, height, timestamp_ns / rtc::kNumNanosecsPerMicrosec, | 103 if (!adapted_source_.AdaptFrame( |
104 &adapted_width, &adapted_height, &crop_width, &crop_height, | 104 width, height, timestamp_ns / rtc::kNumNanosecsPerMicrosec, |
105 &crop_x, &crop_y, &translated_camera_time_us)) { | 105 rtc::TimeMicros(), |
| 106 &adapted_width, &adapted_height, &crop_width, &crop_height, |
| 107 &crop_x, &crop_y, &translated_camera_time_us)) { |
106 return; | 108 return; |
107 } | 109 } |
108 | 110 |
109 int rotated_width = crop_width; | 111 int rotated_width = crop_width; |
110 int rotated_height = crop_height; | 112 int rotated_height = crop_height; |
111 | 113 |
112 rtc::CritScope lock(&apply_rotation_crit_); | 114 rtc::CritScope lock(&apply_rotation_crit_); |
113 if (apply_rotation_ && (rotation == 90 || rotation == 270)) { | 115 if (apply_rotation_ && (rotation == 90 || rotation == 270)) { |
114 std::swap(adapted_width, adapted_height); | 116 std::swap(adapted_width, adapted_height); |
115 std::swap(rotated_width, rotated_height); | 117 std::swap(rotated_width, rotated_height); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 rotation == 270); | 165 rotation == 270); |
164 | 166 |
165 int adapted_width; | 167 int adapted_width; |
166 int adapted_height; | 168 int adapted_height; |
167 int crop_width; | 169 int crop_width; |
168 int crop_height; | 170 int crop_height; |
169 int crop_x; | 171 int crop_x; |
170 int crop_y; | 172 int crop_y; |
171 int64_t translated_camera_time_us; | 173 int64_t translated_camera_time_us; |
172 | 174 |
173 if (!AdaptFrame(width, height, timestamp_ns / rtc::kNumNanosecsPerMicrosec, | 175 if (!adapted_source_.AdaptFrame( |
174 &adapted_width, &adapted_height, &crop_width, &crop_height, | 176 width, height, timestamp_ns / rtc::kNumNanosecsPerMicrosec, |
175 &crop_x, &crop_y, &translated_camera_time_us)) { | 177 &adapted_width, &adapted_height, &crop_width, &crop_height, |
| 178 &crop_x, &crop_y, &translated_camera_time_us)) { |
176 surface_texture_helper_->ReturnTextureFrame(); | 179 surface_texture_helper_->ReturnTextureFrame(); |
177 return; | 180 return; |
178 } | 181 } |
179 | 182 |
180 webrtc_jni::Matrix matrix = handle.sampling_matrix; | 183 webrtc_jni::Matrix matrix = handle.sampling_matrix; |
181 | 184 |
182 matrix.Crop(crop_width / static_cast<float>(width), | 185 matrix.Crop(crop_width / static_cast<float>(width), |
183 crop_height / static_cast<float>(height), | 186 crop_height / static_cast<float>(height), |
184 crop_x / static_cast<float>(width), | 187 crop_x / static_cast<float>(width), |
185 crop_y / static_cast<float>(height)); | 188 crop_y / static_cast<float>(height)); |
(...skipping 28 matching lines...) Expand all Loading... |
214 broadcaster_.OnFrame(frame); | 217 broadcaster_.OnFrame(frame); |
215 } | 218 } |
216 | 219 |
217 void AndroidVideoTrackSource::OnOutputFormatRequest(int width, | 220 void AndroidVideoTrackSource::OnOutputFormatRequest(int width, |
218 int height, | 221 int height, |
219 int fps) { | 222 int fps) { |
220 RTC_DCHECK(camera_thread_checker_.CalledOnValidThread()); | 223 RTC_DCHECK(camera_thread_checker_.CalledOnValidThread()); |
221 | 224 |
222 cricket::VideoFormat format(width, height, | 225 cricket::VideoFormat format(width, height, |
223 cricket::VideoFormat::FpsToInterval(fps), 0); | 226 cricket::VideoFormat::FpsToInterval(fps), 0); |
224 video_adapter_.OnOutputFormatRequest(format); | 227 adapted_source_.video_adapter()->OnOutputFormatRequest(format); |
225 } | |
226 | |
227 bool AndroidVideoTrackSource::AdaptFrame(int width, | |
228 int height, | |
229 int64_t camera_time_us, | |
230 int* out_width, | |
231 int* out_height, | |
232 int* crop_width, | |
233 int* crop_height, | |
234 int* crop_x, | |
235 int* crop_y, | |
236 int64_t* translated_camera_time_us) { | |
237 RTC_DCHECK(camera_thread_checker_.CalledOnValidThread()); | |
238 | |
239 int64_t system_time_us = rtc::TimeMicros(); | |
240 | |
241 int64_t offset_us = | |
242 timestamp_aligner_.UpdateOffset(camera_time_us, system_time_us); | |
243 | |
244 if (!broadcaster_.frame_wanted()) { | |
245 return false; | |
246 } | |
247 | |
248 if (!video_adapter_.AdaptFrameResolution( | |
249 width, height, camera_time_us * rtc::kNumNanosecsPerMicrosec, | |
250 crop_width, crop_height, out_width, out_height)) { | |
251 // VideoAdapter dropped the frame. | |
252 return false; | |
253 } | |
254 *crop_x = (width - *crop_width) / 2; | |
255 *crop_y = (height - *crop_height) / 2; | |
256 | |
257 *translated_camera_time_us = timestamp_aligner_.ClipTimestamp( | |
258 camera_time_us + offset_us, system_time_us); | |
259 return true; | |
260 } | 228 } |
261 | 229 |
262 } // namespace webrtc | 230 } // namespace webrtc |
OLD | NEW |