| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #define MAX_NALUS_PERFRAME 32 | 55 #define MAX_NALUS_PERFRAME 32 |
| 56 // Maximum supported HW video encoder resolution. | 56 // Maximum supported HW video encoder resolution. |
| 57 #define MAX_VIDEO_WIDTH 1280 | 57 #define MAX_VIDEO_WIDTH 1280 |
| 58 #define MAX_VIDEO_HEIGHT 1280 | 58 #define MAX_VIDEO_HEIGHT 1280 |
| 59 // Maximum supported HW video encoder fps. | 59 // Maximum supported HW video encoder fps. |
| 60 #define MAX_VIDEO_FPS 30 | 60 #define MAX_VIDEO_FPS 30 |
| 61 // Maximum allowed fps value in SetRates() call. | 61 // Maximum allowed fps value in SetRates() call. |
| 62 #define MAX_ALLOWED_VIDEO_FPS 60 | 62 #define MAX_ALLOWED_VIDEO_FPS 60 |
| 63 // Maximum allowed frames in encoder input queue. | 63 // Maximum allowed frames in encoder input queue. |
| 64 #define MAX_ENCODER_Q_SIZE 2 | 64 #define MAX_ENCODER_Q_SIZE 2 |
| 65 // Maximum allowed latency in ms. | |
| 66 #define MAX_ENCODER_LATENCY_MS 70 | |
| 67 // Maximum amount of dropped frames caused by full encoder queue - exceeding | 65 // Maximum amount of dropped frames caused by full encoder queue - exceeding |
| 68 // this threshold means that encoder probably got stuck and need to be reset. | 66 // this threshold means that encoder probably got stuck and need to be reset. |
| 69 #define ENCODER_STALL_FRAMEDROP_THRESHOLD 60 | 67 #define ENCODER_STALL_FRAMEDROP_THRESHOLD 60 |
| 70 | 68 |
| 71 // Logging macros. | 69 // Logging macros. |
| 72 #define TAG_ENCODER "MediaCodecVideoEncoder" | 70 #define TAG_ENCODER "MediaCodecVideoEncoder" |
| 73 #ifdef TRACK_BUFFER_TIMING | 71 #ifdef TRACK_BUFFER_TIMING |
| 74 #define ALOGV(...) | 72 #define ALOGV(...) |
| 75 __android_log_print(ANDROID_LOG_VERBOSE, TAG_ENCODER, __VA_ARGS__) | 73 __android_log_print(ANDROID_LOG_VERBOSE, TAG_ENCODER, __VA_ARGS__) |
| 76 #else | 74 #else |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 ALOGW << "Encoder drop frame - failed callback."; | 633 ALOGW << "Encoder drop frame - failed callback."; |
| 636 drop_next_input_frame_ = false; | 634 drop_next_input_frame_ = false; |
| 637 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; | 635 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; |
| 638 frames_dropped_media_encoder_++; | 636 frames_dropped_media_encoder_++; |
| 639 OnDroppedFrame(); | 637 OnDroppedFrame(); |
| 640 return WEBRTC_VIDEO_CODEC_OK; | 638 return WEBRTC_VIDEO_CODEC_OK; |
| 641 } | 639 } |
| 642 | 640 |
| 643 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; | 641 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; |
| 644 | 642 |
| 645 // Check if we accumulated too many frames in encoder input buffers | 643 // Check if we accumulated too many frames in encoder input buffers and drop |
| 646 // or the encoder latency exceeds 70 ms and drop frame if so. | 644 // frame if so. |
| 647 if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) { | 645 if (frames_in_queue_ > MAX_ENCODER_Q_SIZE) { |
| 648 int encoder_latency_ms = last_input_timestamp_ms_ - | 646 ALOGD << "Already " << frames_in_queue_ << " frames in the queue, dropping" |
| 649 last_output_timestamp_ms_; | 647 << ". TS: " << (int)(current_timestamp_us_ / 1000) |
| 650 if (frames_in_queue_ > MAX_ENCODER_Q_SIZE || | 648 << ". Fps: " << last_set_fps_ |
| 651 encoder_latency_ms > MAX_ENCODER_LATENCY_MS) { | 649 << ". Consecutive drops: " << consecutive_full_queue_frame_drops_; |
| 652 ALOGD << "Drop frame - encoder is behind by " << encoder_latency_ms << | 650 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; |
| 653 " ms. Q size: " << frames_in_queue_ << ". TS: " << | 651 consecutive_full_queue_frame_drops_++; |
| 654 (int)(current_timestamp_us_ / 1000) << ". Fps: " << last_set_fps_ << | 652 if (consecutive_full_queue_frame_drops_ >= |
| 655 ". Consecutive drops: " << consecutive_full_queue_frame_drops_ ; | 653 ENCODER_STALL_FRAMEDROP_THRESHOLD) { |
| 656 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; | 654 ALOGE << "Encoder got stuck. Reset."; |
| 657 consecutive_full_queue_frame_drops_++; | 655 ResetCodecOnCodecThread(); |
| 658 if (consecutive_full_queue_frame_drops_ >= | 656 return WEBRTC_VIDEO_CODEC_ERROR; |
| 659 ENCODER_STALL_FRAMEDROP_THRESHOLD) { | |
| 660 ALOGE << "Encoder got stuck. Reset."; | |
| 661 ResetCodecOnCodecThread(); | |
| 662 return WEBRTC_VIDEO_CODEC_ERROR; | |
| 663 } | |
| 664 frames_dropped_media_encoder_++; | |
| 665 OnDroppedFrame(); | |
| 666 return WEBRTC_VIDEO_CODEC_OK; | |
| 667 } | 657 } |
| 658 frames_dropped_media_encoder_++; |
| 659 OnDroppedFrame(); |
| 660 return WEBRTC_VIDEO_CODEC_OK; |
| 668 } | 661 } |
| 669 consecutive_full_queue_frame_drops_ = 0; | 662 consecutive_full_queue_frame_drops_ = 0; |
| 670 | 663 |
| 671 VideoFrame input_frame = frame; | 664 VideoFrame input_frame = frame; |
| 672 if (scale_) { | 665 if (scale_) { |
| 673 // Check framerate before spatial resolution change. | 666 // Check framerate before spatial resolution change. |
| 674 quality_scaler_.OnEncodeFrame(frame); | 667 quality_scaler_.OnEncodeFrame(frame); |
| 675 const webrtc::QualityScaler::Resolution scaled_resolution = | 668 const webrtc::QualityScaler::Resolution scaled_resolution = |
| 676 quality_scaler_.GetScaledResolution(); | 669 quality_scaler_.GetScaledResolution(); |
| 677 if (scaled_resolution.width != frame.width() || | 670 if (scaled_resolution.width != frame.width() || |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 } | 1253 } |
| 1261 | 1254 |
| 1262 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1255 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
| 1263 webrtc::VideoEncoder* encoder) { | 1256 webrtc::VideoEncoder* encoder) { |
| 1264 ALOGD << "Destroy video encoder."; | 1257 ALOGD << "Destroy video encoder."; |
| 1265 delete encoder; | 1258 delete encoder; |
| 1266 } | 1259 } |
| 1267 | 1260 |
| 1268 } // namespace webrtc_jni | 1261 } // namespace webrtc_jni |
| 1269 | 1262 |
| OLD | NEW |