OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" | 31 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" |
32 #include "talk/app/webrtc/java/jni/androidmediacodeccommon.h" | 32 #include "talk/app/webrtc/java/jni/androidmediacodeccommon.h" |
33 #include "talk/app/webrtc/java/jni/classreferenceholder.h" | 33 #include "talk/app/webrtc/java/jni/classreferenceholder.h" |
34 #include "talk/app/webrtc/java/jni/native_handle_impl.h" | 34 #include "talk/app/webrtc/java/jni/native_handle_impl.h" |
35 #include "webrtc/base/bind.h" | 35 #include "webrtc/base/bind.h" |
36 #include "webrtc/base/checks.h" | 36 #include "webrtc/base/checks.h" |
37 #include "webrtc/base/logging.h" | 37 #include "webrtc/base/logging.h" |
38 #include "webrtc/base/scoped_ref_ptr.h" | 38 #include "webrtc/base/scoped_ref_ptr.h" |
39 #include "webrtc/base/thread.h" | 39 #include "webrtc/base/thread.h" |
| 40 #include "webrtc/base/timeutils.h" |
40 #include "webrtc/common_video/interface/i420_buffer_pool.h" | 41 #include "webrtc/common_video/interface/i420_buffer_pool.h" |
41 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" | 42 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" |
42 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" | 43 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" |
43 #include "webrtc/system_wrappers/interface/tick_util.h" | 44 #include "webrtc/system_wrappers/interface/tick_util.h" |
44 #include "third_party/libyuv/include/libyuv/convert.h" | 45 #include "third_party/libyuv/include/libyuv/convert.h" |
45 #include "third_party/libyuv/include/libyuv/convert_from.h" | 46 #include "third_party/libyuv/include/libyuv/convert_from.h" |
46 #include "third_party/libyuv/include/libyuv/video_common.h" | 47 #include "third_party/libyuv/include/libyuv/video_common.h" |
47 | 48 |
48 using rtc::Bind; | 49 using rtc::Bind; |
49 using rtc::Thread; | 50 using rtc::Thread; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 j_release_method_ = | 192 j_release_method_ = |
192 GetMethodID(jni, *j_media_codec_video_decoder_class_, "release", "()V"); | 193 GetMethodID(jni, *j_media_codec_video_decoder_class_, "release", "()V"); |
193 j_dequeue_input_buffer_method_ = GetMethodID( | 194 j_dequeue_input_buffer_method_ = GetMethodID( |
194 jni, *j_media_codec_video_decoder_class_, "dequeueInputBuffer", "()I"); | 195 jni, *j_media_codec_video_decoder_class_, "dequeueInputBuffer", "()I"); |
195 j_queue_input_buffer_method_ = GetMethodID( | 196 j_queue_input_buffer_method_ = GetMethodID( |
196 jni, *j_media_codec_video_decoder_class_, "queueInputBuffer", "(IIJ)Z"); | 197 jni, *j_media_codec_video_decoder_class_, "queueInputBuffer", "(IIJ)Z"); |
197 j_dequeue_output_buffer_method_ = GetMethodID( | 198 j_dequeue_output_buffer_method_ = GetMethodID( |
198 jni, *j_media_codec_video_decoder_class_, "dequeueOutputBuffer", | 199 jni, *j_media_codec_video_decoder_class_, "dequeueOutputBuffer", |
199 "(I)Lorg/webrtc/MediaCodecVideoDecoder$DecoderOutputBufferInfo;"); | 200 "(I)Lorg/webrtc/MediaCodecVideoDecoder$DecoderOutputBufferInfo;"); |
200 j_release_output_buffer_method_ = GetMethodID( | 201 j_release_output_buffer_method_ = GetMethodID( |
201 jni, *j_media_codec_video_decoder_class_, "releaseOutputBuffer", "(I)Z"); | 202 jni, *j_media_codec_video_decoder_class_, "releaseOutputBuffer", "(I)V"); |
202 | 203 |
203 j_input_buffers_field_ = GetFieldID( | 204 j_input_buffers_field_ = GetFieldID( |
204 jni, *j_media_codec_video_decoder_class_, | 205 jni, *j_media_codec_video_decoder_class_, |
205 "inputBuffers", "[Ljava/nio/ByteBuffer;"); | 206 "inputBuffers", "[Ljava/nio/ByteBuffer;"); |
206 j_output_buffers_field_ = GetFieldID( | 207 j_output_buffers_field_ = GetFieldID( |
207 jni, *j_media_codec_video_decoder_class_, | 208 jni, *j_media_codec_video_decoder_class_, |
208 "outputBuffers", "[Ljava/nio/ByteBuffer;"); | 209 "outputBuffers", "[Ljava/nio/ByteBuffer;"); |
209 j_color_format_field_ = GetFieldID( | 210 j_color_format_field_ = GetFieldID( |
210 jni, *j_media_codec_video_decoder_class_, "colorFormat", "I"); | 211 jni, *j_media_codec_video_decoder_class_, "colorFormat", "I"); |
211 j_width_field_ = GetFieldID( | 212 j_width_field_ = GetFieldID( |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 if (CheckException(jni)) { | 566 if (CheckException(jni)) { |
566 return false; | 567 return false; |
567 } | 568 } |
568 if (IsNull(jni, j_decoder_output_buffer_info)) { | 569 if (IsNull(jni, j_decoder_output_buffer_info)) { |
569 return true; | 570 return true; |
570 } | 571 } |
571 | 572 |
572 // Extract output buffer info from Java DecoderOutputBufferInfo. | 573 // Extract output buffer info from Java DecoderOutputBufferInfo. |
573 int output_buffer_index = | 574 int output_buffer_index = |
574 GetIntField(jni, j_decoder_output_buffer_info, j_info_index_field_); | 575 GetIntField(jni, j_decoder_output_buffer_info, j_info_index_field_); |
575 if (output_buffer_index < 0) { | 576 RTC_CHECK_GE(output_buffer_index, 0); |
576 ALOGE("dequeueOutputBuffer error : %d", output_buffer_index); | |
577 return false; | |
578 } | |
579 int output_buffer_offset = | 577 int output_buffer_offset = |
580 GetIntField(jni, j_decoder_output_buffer_info, j_info_offset_field_); | 578 GetIntField(jni, j_decoder_output_buffer_info, j_info_offset_field_); |
581 int output_buffer_size = | 579 int output_buffer_size = |
582 GetIntField(jni, j_decoder_output_buffer_info, j_info_size_field_); | 580 GetIntField(jni, j_decoder_output_buffer_info, j_info_size_field_); |
583 long output_timestamps_ms = GetLongField(jni, j_decoder_output_buffer_info, | 581 long output_timestamps_ms = GetLongField(jni, j_decoder_output_buffer_info, |
584 j_info_presentation_timestamp_us_field_) / 1000; | 582 j_info_presentation_timestamp_us_field_) / rtc::kNumMicrosecsPerMillisec; |
585 if (CheckException(jni)) { | 583 if (CheckException(jni)) { |
586 return false; | 584 return false; |
587 } | 585 } |
588 | 586 |
589 // Get decoded video frame properties. | 587 // Get decoded video frame properties. |
590 int color_format = GetIntField(jni, *j_media_codec_video_decoder_, | 588 int color_format = GetIntField(jni, *j_media_codec_video_decoder_, |
591 j_color_format_field_); | 589 j_color_format_field_); |
592 int width = GetIntField(jni, *j_media_codec_video_decoder_, j_width_field_); | 590 int width = GetIntField(jni, *j_media_codec_video_decoder_, j_width_field_); |
593 int height = GetIntField(jni, *j_media_codec_video_decoder_, j_height_field_); | 591 int height = GetIntField(jni, *j_media_codec_video_decoder_, j_height_field_); |
594 int stride = GetIntField(jni, *j_media_codec_video_decoder_, j_stride_field_); | 592 int stride = GetIntField(jni, *j_media_codec_video_decoder_, j_stride_field_); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 int64_t frame_decoding_time_ms = 0; | 668 int64_t frame_decoding_time_ms = 0; |
671 if (frame_rtc_times_ms_.size() > 0) { | 669 if (frame_rtc_times_ms_.size() > 0) { |
672 frame_decoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); | 670 frame_decoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); |
673 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); | 671 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); |
674 } | 672 } |
675 ALOGV("Decoder frame out # %d. %d x %d. %d x %d. Color: 0x%x. TS: %ld." | 673 ALOGV("Decoder frame out # %d. %d x %d. %d x %d. Color: 0x%x. TS: %ld." |
676 " DecTime: %lld", frames_decoded_, width, height, stride, slice_height, | 674 " DecTime: %lld", frames_decoded_, width, height, stride, slice_height, |
677 color_format, output_timestamps_ms, frame_decoding_time_ms); | 675 color_format, output_timestamps_ms, frame_decoding_time_ms); |
678 | 676 |
679 // Return output buffer back to codec. | 677 // Return output buffer back to codec. |
680 bool success = jni->CallBooleanMethod( | 678 jni->CallVoidMethod( |
681 *j_media_codec_video_decoder_, | 679 *j_media_codec_video_decoder_, |
682 j_release_output_buffer_method_, | 680 j_release_output_buffer_method_, |
683 output_buffer_index); | 681 output_buffer_index); |
684 if (CheckException(jni) || !success) { | 682 if (CheckException(jni)) { |
685 ALOGE("releaseOutputBuffer error"); | 683 ALOGE("releaseOutputBuffer error"); |
686 return false; | 684 return false; |
687 } | 685 } |
688 | 686 |
689 // Calculate and print decoding statistics - every 3 seconds. | 687 // Calculate and print decoding statistics - every 3 seconds. |
690 frames_decoded_++; | 688 frames_decoded_++; |
691 current_frames_++; | 689 current_frames_++; |
692 current_decoding_time_ms_ += frame_decoding_time_ms; | 690 current_decoding_time_ms_ += frame_decoding_time_ms; |
693 int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; | 691 int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; |
694 if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs && | 692 if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs && |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 return NULL; | 827 return NULL; |
830 } | 828 } |
831 | 829 |
832 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( | 830 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( |
833 webrtc::VideoDecoder* decoder) { | 831 webrtc::VideoDecoder* decoder) { |
834 delete decoder; | 832 delete decoder; |
835 } | 833 } |
836 | 834 |
837 } // namespace webrtc_jni | 835 } // namespace webrtc_jni |
838 | 836 |
OLD | NEW |