glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_ |
| 12 | #define SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_ |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 13 | |
| 14 | #include <android/log.h> |
Per | ec2922f | 2016-01-27 15:25:46 +0100 | [diff] [blame] | 15 | #include <string> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 17 | #include "rtc_base/logging.h" |
| 18 | #include "rtc_base/thread.h" |
| 19 | #include "sdk/android/src/jni/classreferenceholder.h" |
| 20 | #include "sdk/android/src/jni/jni_helpers.h" |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 21 | |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | namespace jni { |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 24 | |
| 25 | // Uncomment this define to enable verbose logging for every encoded/decoded |
| 26 | // video frame. |
glaznev@webrtc.org | b28474c | 2015-02-23 17:44:27 +0000 | [diff] [blame] | 27 | //#define TRACK_BUFFER_TIMING |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 28 | |
glaznev | f4decb5 | 2016-01-15 13:49:22 -0800 | [diff] [blame] | 29 | #define TAG_COMMON "MediaCodecVideo" |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 30 | |
glaznev | 893a7ee | 2016-09-22 10:44:30 -0700 | [diff] [blame] | 31 | // Color formats supported by encoder or decoder - should include all |
| 32 | // colors from supportedColorList in MediaCodecVideoEncoder.java and |
| 33 | // MediaCodecVideoDecoder.java. Supported color format set in encoder |
| 34 | // and decoder could be different. |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 35 | enum COLOR_FORMATTYPE { |
| 36 | COLOR_FormatYUV420Planar = 0x13, |
| 37 | COLOR_FormatYUV420SemiPlanar = 0x15, |
| 38 | COLOR_QCOM_FormatYUV420SemiPlanar = 0x7FA30C00, |
| 39 | // NV12 color format supported by QCOM codec, but not declared in MediaCodec - |
| 40 | // see /hardware/qcom/media/mm-core/inc/OMX_QCOMExtns.h |
| 41 | // This format is presumably similar to COLOR_FormatYUV420SemiPlanar, |
| 42 | // but requires some (16, 32?) byte alignment. |
glaznev | 893a7ee | 2016-09-22 10:44:30 -0700 | [diff] [blame] | 43 | COLOR_QCOM_FORMATYVU420PackedSemiPlanar32m4ka = 0x7FA30C01, |
| 44 | COLOR_QCOM_FORMATYVU420PackedSemiPlanar16m4ka = 0x7FA30C02, |
| 45 | COLOR_QCOM_FORMATYVU420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03, |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 46 | COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m = 0x7FA30C04 |
| 47 | }; |
| 48 | |
| 49 | // Arbitrary interval to poll the codec for new outputs. |
| 50 | enum { kMediaCodecPollMs = 10 }; |
sakal | 1fc4810 | 2016-06-14 01:53:39 -0700 | [diff] [blame] | 51 | // Arbitrary interval to poll at when there should be no more frames. |
| 52 | enum { kMediaCodecPollNoFramesMs = 100 }; |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 53 | // Media codec maximum output buffer ready timeout. |
glaznev@webrtc.org | a4623d2 | 2015-02-25 00:02:50 +0000 | [diff] [blame] | 54 | enum { kMediaCodecTimeoutMs = 1000 }; |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 55 | // Interval to print codec statistics (bitrate, fps, encoding/decoding time). |
| 56 | enum { kMediaCodecStatisticsIntervalMs = 3000 }; |
glaznev@webrtc.org | a4623d2 | 2015-02-25 00:02:50 +0000 | [diff] [blame] | 57 | // Maximum amount of pending frames for VP8 decoder. |
| 58 | enum { kMaxPendingFramesVp8 = 1 }; |
Alex Glaznev | 69a7fd5 | 2015-11-10 10:25:40 -0800 | [diff] [blame] | 59 | // Maximum amount of pending frames for VP9 decoder. |
| 60 | enum { kMaxPendingFramesVp9 = 1 }; |
glaznev@webrtc.org | a4623d2 | 2015-02-25 00:02:50 +0000 | [diff] [blame] | 61 | // Maximum amount of pending frames for H.264 decoder. |
sakal | 65b42c2 | 2016-10-03 08:07:02 -0700 | [diff] [blame] | 62 | enum { kMaxPendingFramesH264 = 4 }; |
glaznev | e55c42c | 2015-10-28 10:30:32 -0700 | [diff] [blame] | 63 | // Maximum amount of decoded frames for which per-frame logging is enabled. |
glaznev | ae95ff3 | 2016-02-04 11:47:12 -0800 | [diff] [blame] | 64 | enum { kMaxDecodedLogFrames = 10 }; |
glaznev | f4decb5 | 2016-01-15 13:49:22 -0800 | [diff] [blame] | 65 | // Maximum amount of encoded frames for which per-frame logging is enabled. |
glaznev | ae95ff3 | 2016-02-04 11:47:12 -0800 | [diff] [blame] | 66 | enum { kMaxEncodedLogFrames = 10 }; |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 67 | |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 68 | static inline void AllowBlockingCalls() { |
| 69 | rtc::Thread* current_thread = rtc::Thread::Current(); |
| 70 | if (current_thread != NULL) |
| 71 | current_thread->SetAllowBlockingCalls(true); |
| 72 | } |
| 73 | |
Alex Glaznev | 782671f | 2015-06-12 16:40:44 -0700 | [diff] [blame] | 74 | // Checks for any Java exception, prints stack backtrace and clears |
| 75 | // currently thrown exception. |
| 76 | static inline bool CheckException(JNIEnv* jni) { |
| 77 | if (jni->ExceptionCheck()) { |
glaznev | f4decb5 | 2016-01-15 13:49:22 -0800 | [diff] [blame] | 78 | LOG_TAG(rtc::LS_ERROR, TAG_COMMON) << "Java JNI exception."; |
Alex Glaznev | 782671f | 2015-06-12 16:40:44 -0700 | [diff] [blame] | 79 | jni->ExceptionDescribe(); |
| 80 | jni->ExceptionClear(); |
| 81 | return true; |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 86 | } // namespace jni |
| 87 | } // namespace webrtc |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 88 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 89 | #endif // SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_ |