OLD | NEW |
| (Empty) |
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 WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_ | |
12 #define WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_ | |
13 | |
14 #include <android/log.h> | |
15 #include <string> | |
16 | |
17 #include "webrtc/base/thread.h" | |
18 #include "webrtc/api/android/jni/classreferenceholder.h" | |
19 #include "webrtc/api/android/jni/jni_helpers.h" | |
20 #include "webrtc/base/logging.h" | |
21 #include "webrtc/base/thread.h" | |
22 | |
23 namespace webrtc_jni { | |
24 | |
25 // Uncomment this define to enable verbose logging for every encoded/decoded | |
26 // video frame. | |
27 //#define TRACK_BUFFER_TIMING | |
28 | |
29 #define TAG_COMMON "MediaCodecVideo" | |
30 | |
31 // Color formats supported by encoder - should mirror supportedColorList | |
32 // from MediaCodecVideoEncoder.java | |
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_FORMATYUV420PackedSemiPlanar32m = 0x7FA30C04 | |
42 }; | |
43 | |
44 // Arbitrary interval to poll the codec for new outputs. | |
45 enum { kMediaCodecPollMs = 10 }; | |
46 // Arbitrary interval to poll at when there should be no more frames. | |
47 enum { kMediaCodecPollNoFramesMs = 100 }; | |
48 // Media codec maximum output buffer ready timeout. | |
49 enum { kMediaCodecTimeoutMs = 1000 }; | |
50 // Interval to print codec statistics (bitrate, fps, encoding/decoding time). | |
51 enum { kMediaCodecStatisticsIntervalMs = 3000 }; | |
52 // Maximum amount of pending frames for VP8 decoder. | |
53 enum { kMaxPendingFramesVp8 = 1 }; | |
54 // Maximum amount of pending frames for VP9 decoder. | |
55 enum { kMaxPendingFramesVp9 = 1 }; | |
56 // Maximum amount of pending frames for H.264 decoder. | |
57 enum { kMaxPendingFramesH264 = 3 }; | |
58 // Maximum amount of decoded frames for which per-frame logging is enabled. | |
59 enum { kMaxDecodedLogFrames = 10 }; | |
60 // Maximum amount of encoded frames for which per-frame logging is enabled. | |
61 enum { kMaxEncodedLogFrames = 10 }; | |
62 | |
63 static inline void AllowBlockingCalls() { | |
64 rtc::Thread* current_thread = rtc::Thread::Current(); | |
65 if (current_thread != NULL) | |
66 current_thread->SetAllowBlockingCalls(true); | |
67 } | |
68 | |
69 // Return the (singleton) Java Enum object corresponding to |index|; | |
70 // |state_class_fragment| is something like "MediaSource$State". | |
71 static inline jobject JavaEnumFromIndexAndClassName( | |
72 JNIEnv* jni, const std::string& state_class_fragment, int index) { | |
73 const std::string state_class = "org/webrtc/" + state_class_fragment; | |
74 return JavaEnumFromIndex(jni, FindClass(jni, state_class.c_str()), | |
75 state_class, index); | |
76 } | |
77 | |
78 // Checks for any Java exception, prints stack backtrace and clears | |
79 // currently thrown exception. | |
80 static inline bool CheckException(JNIEnv* jni) { | |
81 if (jni->ExceptionCheck()) { | |
82 LOG_TAG(rtc::LS_ERROR, TAG_COMMON) << "Java JNI exception."; | |
83 jni->ExceptionDescribe(); | |
84 jni->ExceptionClear(); | |
85 return true; | |
86 } | |
87 return false; | |
88 } | |
89 | |
90 } // namespace webrtc_jni | |
91 | |
92 #endif // WEBRTC_API_JAVA_JNI_ANDROIDMEDIACODECCOMMON_H_ | |
OLD | NEW |