1 /*
2  *  Copyright 2015 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10 
11 #ifndef SDK_ANDROID_SRC_JNI_ANDROID_MEDIA_CODEC_COMMON_H_
12 #define SDK_ANDROID_SRC_JNI_ANDROID_MEDIA_CODEC_COMMON_H_
13 
14 #include <string>
15 
16 #include "rtc_base/logging.h"
17 #include "rtc_base/thread.h"
18 #include "sdk/android/src/jni/jni_helpers.h"
19 
20 namespace webrtc {
21 namespace jni {
22 
23 // Uncomment this define to enable verbose logging for every encoded/decoded
24 // video frame.
25 //#define TRACK_BUFFER_TIMING
26 
27 #define TAG_COMMON "MediaCodecVideo"
28 
29 // Color formats supported by encoder or decoder - should include all
30 // colors from supportedColorList in MediaCodecVideoEncoder.java and
31 // MediaCodecVideoDecoder.java. Supported color format set in encoder
32 // and decoder could be different.
33 enum COLOR_FORMATTYPE {
34   COLOR_FormatYUV420Planar = 0x13,
35   COLOR_FormatYUV420SemiPlanar = 0x15,
36   COLOR_QCOM_FormatYUV420SemiPlanar = 0x7FA30C00,
37   // NV12 color format supported by QCOM codec, but not declared in MediaCodec -
38   // see /hardware/qcom/media/mm-core/inc/OMX_QCOMExtns.h
39   // This format is presumably similar to COLOR_FormatYUV420SemiPlanar,
40   // but requires some (16, 32?) byte alignment.
41   COLOR_QCOM_FORMATYVU420PackedSemiPlanar32m4ka = 0x7FA30C01,
42   COLOR_QCOM_FORMATYVU420PackedSemiPlanar16m4ka = 0x7FA30C02,
43   COLOR_QCOM_FORMATYVU420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03,
44   COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m = 0x7FA30C04
45 };
46 
47 // Arbitrary interval to poll the codec for new outputs.
48 enum { kMediaCodecPollMs = 10 };
49 // Arbitrary interval to poll at when there should be no more frames.
50 enum { kMediaCodecPollNoFramesMs = 100 };
51 // Media codec maximum output buffer ready timeout.
52 enum { kMediaCodecTimeoutMs = 1000 };
53 // Interval to print codec statistics (bitrate, fps, encoding/decoding time).
54 enum { kMediaCodecStatisticsIntervalMs = 3000 };
55 // Maximum amount of pending frames for VP8 decoder.
56 enum { kMaxPendingFramesVp8 = 1 };
57 // Maximum amount of pending frames for VP9 decoder.
58 enum { kMaxPendingFramesVp9 = 1 };
59 // Maximum amount of pending frames for H.264 decoder.
60 enum { kMaxPendingFramesH264 = 4 };
61 // Maximum amount of decoded frames for which per-frame logging is enabled.
62 enum { kMaxDecodedLogFrames = 10 };
63 // Maximum amount of encoded frames for which per-frame logging is enabled.
64 enum { kMaxEncodedLogFrames = 10 };
65 
AllowBlockingCalls()66 static inline void AllowBlockingCalls() {
67   rtc::Thread* current_thread = rtc::Thread::Current();
68   if (current_thread != NULL)
69     current_thread->DEPRECATED_AllowBlockingCalls();
70 }
71 
72 // Checks for any Java exception, prints stack backtrace and clears
73 // currently thrown exception.
CheckException(JNIEnv * jni)74 static inline bool CheckException(JNIEnv* jni) {
75   if (jni->ExceptionCheck()) {
76     RTC_LOG_TAG(rtc::LS_ERROR, TAG_COMMON) << "Java JNI exception.";
77     jni->ExceptionDescribe();
78     jni->ExceptionClear();
79     return true;
80   }
81   return false;
82 }
83 
84 }  // namespace jni
85 }  // namespace webrtc
86 
87 #endif  // SDK_ANDROID_SRC_JNI_ANDROID_MEDIA_CODEC_COMMON_H_
88