blob: 62d48626157981b127c40da06438f3ff5bfd9811 [file] [log] [blame]
glaznev@webrtc.org18c92472015-02-18 18:42:55 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
glaznev@webrtc.org18c92472015-02-18 18:42:55 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org18c92472015-02-18 18:42:55 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_
12#define SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000013
14#include <android/log.h>
Perec2922f2016-01-27 15:25:46 +010015#include <string>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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.org18c92472015-02-18 18:42:55 +000021
magjeda3d4f682017-08-28 16:24:06 -070022namespace webrtc {
23namespace jni {
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000024
25// Uncomment this define to enable verbose logging for every encoded/decoded
26// video frame.
glaznev@webrtc.orgb28474c2015-02-23 17:44:27 +000027//#define TRACK_BUFFER_TIMING
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000028
glaznevf4decb52016-01-15 13:49:22 -080029#define TAG_COMMON "MediaCodecVideo"
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000030
glaznev893a7ee2016-09-22 10:44:30 -070031// 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.org18c92472015-02-18 18:42:55 +000035enum 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.
glaznev893a7ee2016-09-22 10:44:30 -070043 COLOR_QCOM_FORMATYVU420PackedSemiPlanar32m4ka = 0x7FA30C01,
44 COLOR_QCOM_FORMATYVU420PackedSemiPlanar16m4ka = 0x7FA30C02,
45 COLOR_QCOM_FORMATYVU420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03,
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000046 COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m = 0x7FA30C04
47};
48
49// Arbitrary interval to poll the codec for new outputs.
50enum { kMediaCodecPollMs = 10 };
sakal1fc48102016-06-14 01:53:39 -070051// Arbitrary interval to poll at when there should be no more frames.
52enum { kMediaCodecPollNoFramesMs = 100 };
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000053// Media codec maximum output buffer ready timeout.
glaznev@webrtc.orga4623d22015-02-25 00:02:50 +000054enum { kMediaCodecTimeoutMs = 1000 };
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000055// Interval to print codec statistics (bitrate, fps, encoding/decoding time).
56enum { kMediaCodecStatisticsIntervalMs = 3000 };
glaznev@webrtc.orga4623d22015-02-25 00:02:50 +000057// Maximum amount of pending frames for VP8 decoder.
58enum { kMaxPendingFramesVp8 = 1 };
Alex Glaznev69a7fd52015-11-10 10:25:40 -080059// Maximum amount of pending frames for VP9 decoder.
60enum { kMaxPendingFramesVp9 = 1 };
glaznev@webrtc.orga4623d22015-02-25 00:02:50 +000061// Maximum amount of pending frames for H.264 decoder.
sakal65b42c22016-10-03 08:07:02 -070062enum { kMaxPendingFramesH264 = 4 };
glazneve55c42c2015-10-28 10:30:32 -070063// Maximum amount of decoded frames for which per-frame logging is enabled.
glaznevae95ff32016-02-04 11:47:12 -080064enum { kMaxDecodedLogFrames = 10 };
glaznevf4decb52016-01-15 13:49:22 -080065// Maximum amount of encoded frames for which per-frame logging is enabled.
glaznevae95ff32016-02-04 11:47:12 -080066enum { kMaxEncodedLogFrames = 10 };
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000067
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000068static inline void AllowBlockingCalls() {
69 rtc::Thread* current_thread = rtc::Thread::Current();
70 if (current_thread != NULL)
71 current_thread->SetAllowBlockingCalls(true);
72}
73
Alex Glaznev782671f2015-06-12 16:40:44 -070074// Checks for any Java exception, prints stack backtrace and clears
75// currently thrown exception.
76static inline bool CheckException(JNIEnv* jni) {
77 if (jni->ExceptionCheck()) {
glaznevf4decb52016-01-15 13:49:22 -080078 LOG_TAG(rtc::LS_ERROR, TAG_COMMON) << "Java JNI exception.";
Alex Glaznev782671f2015-06-12 16:40:44 -070079 jni->ExceptionDescribe();
80 jni->ExceptionClear();
81 return true;
82 }
83 return false;
84}
85
magjeda3d4f682017-08-28 16:24:06 -070086} // namespace jni
87} // namespace webrtc
glaznev@webrtc.org18c92472015-02-18 18:42:55 +000088
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#endif // SDK_ANDROID_SRC_JNI_ANDROIDMEDIACODECCOMMON_H_