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 14 matching lines...) Expand all Loading... |
25 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" | 25 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" |
26 #include "webrtc/base/bind.h" | 26 #include "webrtc/base/bind.h" |
27 #include "webrtc/base/checks.h" | 27 #include "webrtc/base/checks.h" |
28 #include "webrtc/base/logging.h" | 28 #include "webrtc/base/logging.h" |
29 #include "webrtc/base/scoped_ref_ptr.h" | 29 #include "webrtc/base/scoped_ref_ptr.h" |
30 #include "webrtc/base/thread.h" | 30 #include "webrtc/base/thread.h" |
31 #include "webrtc/base/timeutils.h" | 31 #include "webrtc/base/timeutils.h" |
32 #include "webrtc/common_video/include/i420_buffer_pool.h" | 32 #include "webrtc/common_video/include/i420_buffer_pool.h" |
33 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 33 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
34 #include "webrtc/system_wrappers/include/logcat_trace_context.h" | 34 #include "webrtc/system_wrappers/include/logcat_trace_context.h" |
35 #include "webrtc/system_wrappers/include/tick_util.h" | |
36 | 35 |
37 using rtc::Bind; | 36 using rtc::Bind; |
38 using rtc::Thread; | 37 using rtc::Thread; |
39 using rtc::ThreadManager; | 38 using rtc::ThreadManager; |
40 | 39 |
41 using webrtc::CodecSpecificInfo; | 40 using webrtc::CodecSpecificInfo; |
42 using webrtc::DecodedImageCallback; | 41 using webrtc::DecodedImageCallback; |
43 using webrtc::EncodedImage; | 42 using webrtc::EncodedImage; |
44 using webrtc::VideoFrame; | 43 using webrtc::VideoFrame; |
45 using webrtc::RTPFragmentationHeader; | 44 using webrtc::RTPFragmentationHeader; |
46 using webrtc::TickTime; | |
47 using webrtc::VideoCodec; | 45 using webrtc::VideoCodec; |
48 using webrtc::VideoCodecType; | 46 using webrtc::VideoCodecType; |
49 using webrtc::kVideoCodecH264; | 47 using webrtc::kVideoCodecH264; |
50 using webrtc::kVideoCodecVP8; | 48 using webrtc::kVideoCodecVP8; |
51 using webrtc::kVideoCodecVP9; | 49 using webrtc::kVideoCodecVP9; |
52 | 50 |
53 namespace webrtc_jni { | 51 namespace webrtc_jni { |
54 | 52 |
55 // Logging macros. | 53 // Logging macros. |
56 #define TAG_DECODER "MediaCodecVideoDecoder" | 54 #define TAG_DECODER "MediaCodecVideoDecoder" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 Bind(&MediaCodecVideoDecoder::InitDecodeOnCodecThread, this)); | 310 Bind(&MediaCodecVideoDecoder::InitDecodeOnCodecThread, this)); |
313 } | 311 } |
314 | 312 |
315 void MediaCodecVideoDecoder::ResetVariables() { | 313 void MediaCodecVideoDecoder::ResetVariables() { |
316 CheckOnCodecThread(); | 314 CheckOnCodecThread(); |
317 | 315 |
318 key_frame_required_ = true; | 316 key_frame_required_ = true; |
319 frames_received_ = 0; | 317 frames_received_ = 0; |
320 frames_decoded_ = 0; | 318 frames_decoded_ = 0; |
321 frames_decoded_logged_ = kMaxDecodedLogFrames; | 319 frames_decoded_logged_ = kMaxDecodedLogFrames; |
322 start_time_ms_ = GetCurrentTimeMs(); | 320 start_time_ms_ = rtc::TimeMillis(); |
323 current_frames_ = 0; | 321 current_frames_ = 0; |
324 current_bytes_ = 0; | 322 current_bytes_ = 0; |
325 current_decoding_time_ms_ = 0; | 323 current_decoding_time_ms_ = 0; |
326 current_delay_time_ms_ = 0; | 324 current_delay_time_ms_ = 0; |
327 } | 325 } |
328 | 326 |
329 int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() { | 327 int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() { |
330 CheckOnCodecThread(); | 328 CheckOnCodecThread(); |
331 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 329 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
332 ScopedLocalRefFrame local_ref_frame(jni); | 330 ScopedLocalRefFrame local_ref_frame(jni); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 580 |
583 // Try to drain the decoder and wait until output is not too | 581 // Try to drain the decoder and wait until output is not too |
584 // much behind the input. | 582 // much behind the input. |
585 if (codecType_ == kVideoCodecH264 && | 583 if (codecType_ == kVideoCodecH264 && |
586 frames_received_ > frames_decoded_ + max_pending_frames_) { | 584 frames_received_ > frames_decoded_ + max_pending_frames_) { |
587 // Print warning for H.264 only - for VP8/VP9 one frame delay is ok. | 585 // Print warning for H.264 only - for VP8/VP9 one frame delay is ok. |
588 ALOGW << "Decoder is too far behind. Try to drain. Received: " << | 586 ALOGW << "Decoder is too far behind. Try to drain. Received: " << |
589 frames_received_ << ". Decoded: " << frames_decoded_; | 587 frames_received_ << ". Decoded: " << frames_decoded_; |
590 EnableFrameLogOnWarning(); | 588 EnableFrameLogOnWarning(); |
591 } | 589 } |
592 const int64 drain_start = GetCurrentTimeMs(); | 590 const int64 drain_start = rtc::TimeMillis(); |
593 while ((frames_received_ > frames_decoded_ + max_pending_frames_) && | 591 while ((frames_received_ > frames_decoded_ + max_pending_frames_) && |
594 (GetCurrentTimeMs() - drain_start) < kMediaCodecTimeoutMs) { | 592 (rtc::TimeMillis() - drain_start) < kMediaCodecTimeoutMs) { |
595 if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) { | 593 if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) { |
596 ALOGE << "DeliverPendingOutputs error. Frames received: " << | 594 ALOGE << "DeliverPendingOutputs error. Frames received: " << |
597 frames_received_ << ". Frames decoded: " << frames_decoded_; | 595 frames_received_ << ". Frames decoded: " << frames_decoded_; |
598 return ProcessHWErrorOnCodecThread(); | 596 return ProcessHWErrorOnCodecThread(); |
599 } | 597 } |
600 } | 598 } |
601 if (frames_received_ > frames_decoded_ + max_pending_frames_) { | 599 if (frames_received_ > frames_decoded_ + max_pending_frames_) { |
602 ALOGE << "Output buffer dequeue timeout. Frames received: " << | 600 ALOGE << "Output buffer dequeue timeout. Frames received: " << |
603 frames_received_ << ". Frames decoded: " << frames_decoded_; | 601 frames_received_ << ". Frames decoded: " << frames_decoded_; |
604 return ProcessHWErrorOnCodecThread(); | 602 return ProcessHWErrorOnCodecThread(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 ". TS: " << presentation_timestamps_ms << | 835 ". TS: " << presentation_timestamps_ms << |
838 ". DecTime: " << (int)decode_time_ms << | 836 ". DecTime: " << (int)decode_time_ms << |
839 ". DelayTime: " << (int)frame_delayed_ms; | 837 ". DelayTime: " << (int)frame_delayed_ms; |
840 } | 838 } |
841 | 839 |
842 // Calculate and print decoding statistics - every 3 seconds. | 840 // Calculate and print decoding statistics - every 3 seconds. |
843 frames_decoded_++; | 841 frames_decoded_++; |
844 current_frames_++; | 842 current_frames_++; |
845 current_decoding_time_ms_ += decode_time_ms; | 843 current_decoding_time_ms_ += decode_time_ms; |
846 current_delay_time_ms_ += frame_delayed_ms; | 844 current_delay_time_ms_ += frame_delayed_ms; |
847 int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; | 845 int statistic_time_ms = rtc::TimeMillis() - start_time_ms_; |
848 if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs && | 846 if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs && |
849 current_frames_ > 0) { | 847 current_frames_ > 0) { |
850 int current_bitrate = current_bytes_ * 8 / statistic_time_ms; | 848 int current_bitrate = current_bytes_ * 8 / statistic_time_ms; |
851 int current_fps = | 849 int current_fps = |
852 (current_frames_ * 1000 + statistic_time_ms / 2) / statistic_time_ms; | 850 (current_frames_ * 1000 + statistic_time_ms / 2) / statistic_time_ms; |
853 ALOGD << "Frames decoded: " << frames_decoded_ << | 851 ALOGD << "Frames decoded: " << frames_decoded_ << |
854 ". Received: " << frames_received_ << | 852 ". Received: " << frames_received_ << |
855 ". Bitrate: " << current_bitrate << " kbps" << | 853 ". Bitrate: " << current_bitrate << " kbps" << |
856 ". Fps: " << current_fps << | 854 ". Fps: " << current_fps << |
857 ". DecTime: " << (current_decoding_time_ms_ / current_frames_) << | 855 ". DecTime: " << (current_decoding_time_ms_ / current_frames_) << |
858 ". DelayTime: " << (current_delay_time_ms_ / current_frames_) << | 856 ". DelayTime: " << (current_delay_time_ms_ / current_frames_) << |
859 " for last " << statistic_time_ms << " ms."; | 857 " for last " << statistic_time_ms << " ms."; |
860 start_time_ms_ = GetCurrentTimeMs(); | 858 start_time_ms_ = rtc::TimeMillis(); |
861 current_frames_ = 0; | 859 current_frames_ = 0; |
862 current_bytes_ = 0; | 860 current_bytes_ = 0; |
863 current_decoding_time_ms_ = 0; | 861 current_decoding_time_ms_ = 0; |
864 current_delay_time_ms_ = 0; | 862 current_delay_time_ms_ = 0; |
865 } | 863 } |
866 | 864 |
867 // |.IsZeroSize())| returns true when a frame has been dropped. | 865 // |.IsZeroSize())| returns true when a frame has been dropped. |
868 if (!decoded_frame.IsZeroSize()) { | 866 if (!decoded_frame.IsZeroSize()) { |
869 // Callback - output decoded frame. | 867 // Callback - output decoded frame. |
870 const int32_t callback_status = | 868 const int32_t callback_status = |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 webrtc::VideoDecoder* decoder) { | 984 webrtc::VideoDecoder* decoder) { |
987 ALOGD << "Destroy video decoder."; | 985 ALOGD << "Destroy video decoder."; |
988 delete decoder; | 986 delete decoder; |
989 } | 987 } |
990 | 988 |
991 const char* MediaCodecVideoDecoder::ImplementationName() const { | 989 const char* MediaCodecVideoDecoder::ImplementationName() const { |
992 return "MediaCodec"; | 990 return "MediaCodec"; |
993 } | 991 } |
994 | 992 |
995 } // namespace webrtc_jni | 993 } // namespace webrtc_jni |
996 | |
OLD | NEW |