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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 *j_media_codec_video_decoder_class_, | 181 *j_media_codec_video_decoder_class_, |
182 "<init>", | 182 "<init>", |
183 "()V"))) { | 183 "()V"))) { |
184 ScopedLocalRefFrame local_ref_frame(jni); | 184 ScopedLocalRefFrame local_ref_frame(jni); |
185 codec_thread_->SetName("MediaCodecVideoDecoder", NULL); | 185 codec_thread_->SetName("MediaCodecVideoDecoder", NULL); |
186 CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder"; | 186 CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder"; |
187 | 187 |
188 j_init_decode_method_ = GetMethodID( | 188 j_init_decode_method_ = GetMethodID( |
189 jni, *j_media_codec_video_decoder_class_, "initDecode", | 189 jni, *j_media_codec_video_decoder_class_, "initDecode", |
190 "(Lorg/webrtc/MediaCodecVideoDecoder$VideoCodecType;" | 190 "(Lorg/webrtc/MediaCodecVideoDecoder$VideoCodecType;" |
191 "IIZLandroid/opengl/EGLContext;)Z"); | 191 "IILandroid/opengl/EGLContext;)Z"); |
192 j_release_method_ = | 192 j_release_method_ = |
193 GetMethodID(jni, *j_media_codec_video_decoder_class_, "release", "()V"); | 193 GetMethodID(jni, *j_media_codec_video_decoder_class_, "release", "()V"); |
194 j_dequeue_input_buffer_method_ = GetMethodID( | 194 j_dequeue_input_buffer_method_ = GetMethodID( |
195 jni, *j_media_codec_video_decoder_class_, "dequeueInputBuffer", "()I"); | 195 jni, *j_media_codec_video_decoder_class_, "dequeueInputBuffer", "()I"); |
196 j_queue_input_buffer_method_ = GetMethodID( | 196 j_queue_input_buffer_method_ = GetMethodID( |
197 jni, *j_media_codec_video_decoder_class_, "queueInputBuffer", "(IIJ)Z"); | 197 jni, *j_media_codec_video_decoder_class_, "queueInputBuffer", "(IIJ)Z"); |
198 j_dequeue_output_buffer_method_ = GetMethodID( | 198 j_dequeue_output_buffer_method_ = GetMethodID( |
199 jni, *j_media_codec_video_decoder_class_, "dequeueOutputBuffer", | 199 jni, *j_media_codec_video_decoder_class_, "dequeueOutputBuffer", |
200 "(I)Lorg/webrtc/MediaCodecVideoDecoder$DecoderOutputBufferInfo;"); | 200 "(I)Lorg/webrtc/MediaCodecVideoDecoder$DecoderOutputBufferInfo;"); |
201 j_release_output_buffer_method_ = GetMethodID( | 201 j_release_output_buffer_method_ = GetMethodID( |
202 jni, *j_media_codec_video_decoder_class_, "releaseOutputBuffer", "(IZ)Z"); | 202 jni, *j_media_codec_video_decoder_class_, "releaseOutputBuffer", "(I)Z"); |
203 | 203 |
204 j_input_buffers_field_ = GetFieldID( | 204 j_input_buffers_field_ = GetFieldID( |
205 jni, *j_media_codec_video_decoder_class_, | 205 jni, *j_media_codec_video_decoder_class_, |
206 "inputBuffers", "[Ljava/nio/ByteBuffer;"); | 206 "inputBuffers", "[Ljava/nio/ByteBuffer;"); |
207 j_output_buffers_field_ = GetFieldID( | 207 j_output_buffers_field_ = GetFieldID( |
208 jni, *j_media_codec_video_decoder_class_, | 208 jni, *j_media_codec_video_decoder_class_, |
209 "outputBuffers", "[Ljava/nio/ByteBuffer;"); | 209 "outputBuffers", "[Ljava/nio/ByteBuffer;"); |
210 j_color_format_field_ = GetFieldID( | 210 j_color_format_field_ = GetFieldID( |
211 jni, *j_media_codec_video_decoder_class_, "colorFormat", "I"); | 211 jni, *j_media_codec_video_decoder_class_, "colorFormat", "I"); |
212 j_width_field_ = GetFieldID( | 212 j_width_field_ = GetFieldID( |
(...skipping 15 matching lines...) Expand all Loading... |
228 j_info_index_field_ = GetFieldID( | 228 j_info_index_field_ = GetFieldID( |
229 jni, j_decoder_output_buffer_info_class, "index", "I"); | 229 jni, j_decoder_output_buffer_info_class, "index", "I"); |
230 j_info_offset_field_ = GetFieldID( | 230 j_info_offset_field_ = GetFieldID( |
231 jni, j_decoder_output_buffer_info_class, "offset", "I"); | 231 jni, j_decoder_output_buffer_info_class, "offset", "I"); |
232 j_info_size_field_ = GetFieldID( | 232 j_info_size_field_ = GetFieldID( |
233 jni, j_decoder_output_buffer_info_class, "size", "I"); | 233 jni, j_decoder_output_buffer_info_class, "size", "I"); |
234 j_info_presentation_timestamp_us_field_ = GetFieldID( | 234 j_info_presentation_timestamp_us_field_ = GetFieldID( |
235 jni, j_decoder_output_buffer_info_class, "presentationTimestampUs", "J"); | 235 jni, j_decoder_output_buffer_info_class, "presentationTimestampUs", "J"); |
236 | 236 |
237 CHECK_EXCEPTION(jni) << "MediaCodecVideoDecoder ctor failed"; | 237 CHECK_EXCEPTION(jni) << "MediaCodecVideoDecoder ctor failed"; |
238 use_surface_ = (render_egl_context_ != NULL) ? true : false; | 238 use_surface_ = (render_egl_context_ != NULL); |
239 ALOGD("MediaCodecVideoDecoder ctor. Use surface: %d", use_surface_); | 239 ALOGD("MediaCodecVideoDecoder ctor. Use surface: %d", use_surface_); |
240 memset(&codec_, 0, sizeof(codec_)); | 240 memset(&codec_, 0, sizeof(codec_)); |
241 AllowBlockingCalls(); | 241 AllowBlockingCalls(); |
242 } | 242 } |
243 | 243 |
244 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { | 244 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { |
245 // Call Release() to ensure no more callbacks to us after we are deleted. | 245 // Call Release() to ensure no more callbacks to us after we are deleted. |
246 Release(); | 246 Release(); |
247 // Delete global references. | 247 // Delete global references. |
248 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 248 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 frames_decoded_ = 0; | 302 frames_decoded_ = 0; |
303 | 303 |
304 jobject j_video_codec_enum = JavaEnumFromIndex( | 304 jobject j_video_codec_enum = JavaEnumFromIndex( |
305 jni, "MediaCodecVideoDecoder$VideoCodecType", codecType_); | 305 jni, "MediaCodecVideoDecoder$VideoCodecType", codecType_); |
306 bool success = jni->CallBooleanMethod( | 306 bool success = jni->CallBooleanMethod( |
307 *j_media_codec_video_decoder_, | 307 *j_media_codec_video_decoder_, |
308 j_init_decode_method_, | 308 j_init_decode_method_, |
309 j_video_codec_enum, | 309 j_video_codec_enum, |
310 codec_.width, | 310 codec_.width, |
311 codec_.height, | 311 codec_.height, |
312 use_surface_, | 312 use_surface_ ? render_egl_context_ : nullptr); |
313 render_egl_context_); | |
314 if (CheckException(jni) || !success) { | 313 if (CheckException(jni) || !success) { |
315 ALOGE("Codec initialization error - fallback to SW codec."); | 314 ALOGE("Codec initialization error - fallback to SW codec."); |
316 sw_fallback_required_ = true; | 315 sw_fallback_required_ = true; |
317 return WEBRTC_VIDEO_CODEC_ERROR; | 316 return WEBRTC_VIDEO_CODEC_ERROR; |
318 } | 317 } |
319 inited_ = true; | 318 inited_ = true; |
320 | 319 |
321 switch (codecType_) { | 320 switch (codecType_) { |
322 case kVideoCodecVP8: | 321 case kVideoCodecVP8: |
323 max_pending_frames_ = kMaxPendingFramesVp8; | 322 max_pending_frames_ = kMaxPendingFramesVp8; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); | 658 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); |
660 } | 659 } |
661 ALOGV("Decoder frame out # %d. %d x %d. %d x %d. Color: 0x%x. TS: %ld." | 660 ALOGV("Decoder frame out # %d. %d x %d. %d x %d. Color: 0x%x. TS: %ld." |
662 " DecTime: %lld", frames_decoded_, width, height, stride, slice_height, | 661 " DecTime: %lld", frames_decoded_, width, height, stride, slice_height, |
663 color_format, output_timestamps_ms, frame_decoding_time_ms); | 662 color_format, output_timestamps_ms, frame_decoding_time_ms); |
664 | 663 |
665 // Return output buffer back to codec. | 664 // Return output buffer back to codec. |
666 bool success = jni->CallBooleanMethod( | 665 bool success = jni->CallBooleanMethod( |
667 *j_media_codec_video_decoder_, | 666 *j_media_codec_video_decoder_, |
668 j_release_output_buffer_method_, | 667 j_release_output_buffer_method_, |
669 output_buffer_index, | 668 output_buffer_index); |
670 use_surface_); | |
671 if (CheckException(jni) || !success) { | 669 if (CheckException(jni) || !success) { |
672 ALOGE("releaseOutputBuffer error"); | 670 ALOGE("releaseOutputBuffer error"); |
673 return false; | 671 return false; |
674 } | 672 } |
675 | 673 |
676 // Calculate and print decoding statistics - every 3 seconds. | 674 // Calculate and print decoding statistics - every 3 seconds. |
677 frames_decoded_++; | 675 frames_decoded_++; |
678 current_frames_++; | 676 current_frames_++; |
679 current_decoding_time_ms_ += frame_decoding_time_ms; | 677 current_decoding_time_ms_ += frame_decoding_time_ms; |
680 int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; | 678 int statistic_time_ms = GetCurrentTimeMs() - start_time_ms_; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 return NULL; | 826 return NULL; |
829 } | 827 } |
830 | 828 |
831 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( | 829 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( |
832 webrtc::VideoDecoder* decoder) { | 830 webrtc::VideoDecoder* decoder) { |
833 delete decoder; | 831 delete decoder; |
834 } | 832 } |
835 | 833 |
836 } // namespace webrtc_jni | 834 } // namespace webrtc_jni |
837 | 835 |
OLD | NEW |