| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 GetScaledBufferOnEncode(frame.video_frame_buffer())); | 300 GetScaledBufferOnEncode(frame.video_frame_buffer())); |
| 301 | 301 |
| 302 if (input_image->width() != width_ || input_image->height() != height_) { | 302 if (input_image->width() != width_ || input_image->height() != height_) { |
| 303 width_ = input_image->width(); | 303 width_ = input_image->width(); |
| 304 height_ = input_image->height(); | 304 height_ = input_image->height(); |
| 305 int ret = ResetCompressionSession(); | 305 int ret = ResetCompressionSession(); |
| 306 if (ret < 0) | 306 if (ret < 0) |
| 307 return ret; | 307 return ret; |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Get a pixel buffer from the pool and copy frame data over. |
| 311 CVPixelBufferPoolRef pixel_buffer_pool = |
| 312 VTCompressionSessionGetPixelBufferPool(compression_session_); |
| 313 #if defined(WEBRTC_IOS) |
| 314 if (!pixel_buffer_pool) { |
| 315 // Kind of a hack. On backgrounding, the compression session seems to get |
| 316 // invalidated, which causes this pool call to fail when the application |
| 317 // is foregrounded and frames are being sent for encoding again. |
| 318 // Resetting the session when this happens fixes the issue. |
| 319 // In addition we request a keyframe so video can recover quickly. |
| 320 ResetCompressionSession(); |
| 321 pixel_buffer_pool = |
| 322 VTCompressionSessionGetPixelBufferPool(compression_session_); |
| 323 is_keyframe_required = true; |
| 324 LOG(LS_INFO) << "Resetting compression session due to invalid pool."; |
| 325 } |
| 326 #endif |
| 327 |
| 310 CVPixelBufferRef pixel_buffer = | 328 CVPixelBufferRef pixel_buffer = |
| 311 static_cast<CVPixelBufferRef>(input_image->native_handle()); | 329 static_cast<CVPixelBufferRef>(input_image->native_handle()); |
| 312 if (pixel_buffer) { | 330 if (pixel_buffer) { |
| 313 CVBufferRetain(pixel_buffer); | 331 CVBufferRetain(pixel_buffer); |
| 332 pixel_buffer_pool = nullptr; |
| 314 } else { | 333 } else { |
| 315 // Get a pixel buffer from the pool and copy frame data over. | |
| 316 CVPixelBufferPoolRef pixel_buffer_pool = | |
| 317 VTCompressionSessionGetPixelBufferPool(compression_session_); | |
| 318 #if defined(WEBRTC_IOS) | |
| 319 if (!pixel_buffer_pool) { | |
| 320 // Kind of a hack. On backgrounding, the compression session seems to get | |
| 321 // invalidated, which causes this pool call to fail when the application | |
| 322 // is foregrounded and frames are being sent for encoding again. | |
| 323 // Resetting the session when this happens fixes the issue. | |
| 324 // In addition we request a keyframe so video can recover quickly. | |
| 325 ResetCompressionSession(); | |
| 326 pixel_buffer_pool = | |
| 327 VTCompressionSessionGetPixelBufferPool(compression_session_); | |
| 328 is_keyframe_required = true; | |
| 329 } | |
| 330 #endif | |
| 331 if (!pixel_buffer_pool) { | 334 if (!pixel_buffer_pool) { |
| 332 LOG(LS_ERROR) << "Failed to get pixel buffer pool."; | 335 LOG(LS_ERROR) << "Failed to get pixel buffer pool."; |
| 333 return WEBRTC_VIDEO_CODEC_ERROR; | 336 return WEBRTC_VIDEO_CODEC_ERROR; |
| 334 } | 337 } |
| 335 CVReturn ret = CVPixelBufferPoolCreatePixelBuffer( | 338 CVReturn ret = CVPixelBufferPoolCreatePixelBuffer( |
| 336 nullptr, pixel_buffer_pool, &pixel_buffer); | 339 nullptr, pixel_buffer_pool, &pixel_buffer); |
| 337 if (ret != kCVReturnSuccess) { | 340 if (ret != kCVReturnSuccess) { |
| 338 LOG(LS_ERROR) << "Failed to create pixel buffer: " << ret; | 341 LOG(LS_ERROR) << "Failed to create pixel buffer: " << ret; |
| 339 // We probably want to drop frames here, since failure probably means | 342 // We probably want to drop frames here, since failure probably means |
| 340 // that the pool is empty. | 343 // that the pool is empty. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 if (result != 0) { | 644 if (result != 0) { |
| 642 LOG(LS_ERROR) << "Encode callback failed: " << result; | 645 LOG(LS_ERROR) << "Encode callback failed: " << result; |
| 643 return; | 646 return; |
| 644 } | 647 } |
| 645 bitrate_adjuster_.Update(frame._size); | 648 bitrate_adjuster_.Update(frame._size); |
| 646 } | 649 } |
| 647 | 650 |
| 648 } // namespace webrtc | 651 } // namespace webrtc |
| 649 | 652 |
| 650 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 653 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
| OLD | NEW |