mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Format *_jni.cc files
PiperOrigin-RevId: 374830877
This commit is contained in:
parent
9e4315f48d
commit
0de6bc861a
@ -13,9 +13,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include <android/log.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <android/log.h>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -33,8 +33,8 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_TAG "ffmpeg_jni"
|
#define LOG_TAG "ffmpeg_jni"
|
||||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
|
#define LOGE(...) \
|
||||||
__VA_ARGS__))
|
((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||||
|
|
||||||
#define LIBRARY_FUNC(RETURN_TYPE, NAME, ...) \
|
#define LIBRARY_FUNC(RETURN_TYPE, NAME, ...) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
@ -362,4 +362,3 @@ void releaseContext(AVCodecContext *context) {
|
|||||||
}
|
}
|
||||||
avcodec_free_context(&context);
|
avcodec_free_context(&context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,9 @@
|
|||||||
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_flac_FlacDecoderJni_##NAME( \
|
Java_com_google_android_exoplayer2_ext_flac_FlacDecoderJni_##NAME(JNIEnv *env, \
|
||||||
JNIEnv *env, jobject thiz, ##__VA_ARGS__); \
|
jobject thiz, \
|
||||||
|
##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_flac_FlacDecoderJni_##NAME( \
|
Java_com_google_android_exoplayer2_ext_flac_FlacDecoderJni_##NAME( \
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
@ -24,28 +23,28 @@
|
|||||||
#include "opus_multistream.h" // NOLINT
|
#include "opus_multistream.h" // NOLINT
|
||||||
|
|
||||||
#define LOG_TAG "opus_jni"
|
#define LOG_TAG "opus_jni"
|
||||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
|
#define LOGE(...) \
|
||||||
__VA_ARGS__))
|
((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||||
|
|
||||||
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_opus_OpusDecoder_ ## NAME \
|
Java_com_google_android_exoplayer2_ext_opus_OpusDecoder_##NAME( \
|
||||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__);\
|
JNIEnv* env, jobject thiz, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_opus_OpusDecoder_ ## NAME \
|
Java_com_google_android_exoplayer2_ext_opus_OpusDecoder_##NAME( \
|
||||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__)\
|
JNIEnv* env, jobject thiz, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define LIBRARY_FUNC(RETURN_TYPE, NAME, ...) \
|
#define LIBRARY_FUNC(RETURN_TYPE, NAME, ...) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_opus_OpusLibrary_ ## NAME \
|
Java_com_google_android_exoplayer2_ext_opus_OpusLibrary_##NAME( \
|
||||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__);\
|
JNIEnv* env, jobject thiz, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
JNIEXPORT RETURN_TYPE \
|
JNIEXPORT RETURN_TYPE \
|
||||||
Java_com_google_android_exoplayer2_ext_opus_OpusLibrary_ ## NAME \
|
Java_com_google_android_exoplayer2_ext_opus_OpusLibrary_##NAME( \
|
||||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__)\
|
JNIEnv* env, jobject thiz, ##__VA_ARGS__)
|
||||||
|
|
||||||
// JNI references for SimpleOutputBuffer class.
|
// JNI references for SimpleOutputBuffer class.
|
||||||
static jmethodID outputBufferInit;
|
static jmethodID outputBufferInit;
|
||||||
@ -66,7 +65,8 @@ static int errorCode;
|
|||||||
static bool outputFloat = false;
|
static bool outputFloat = false;
|
||||||
|
|
||||||
DECODER_FUNC(jlong, opusInit, jint sampleRate, jint channelCount,
|
DECODER_FUNC(jlong, opusInit, jint sampleRate, jint channelCount,
|
||||||
jint numStreams, jint numCoupled, jint gain, jbyteArray jStreamMap) {
|
jint numStreams, jint numCoupled, jint gain,
|
||||||
|
jbyteArray jStreamMap) {
|
||||||
int status = OPUS_INVALID_STATE;
|
int status = OPUS_INVALID_STATE;
|
||||||
::channelCount = channelCount;
|
::channelCount = channelCount;
|
||||||
errorCode = 0;
|
errorCode = 0;
|
||||||
@ -88,8 +88,8 @@ DECODER_FUNC(jlong, opusInit, jint sampleRate, jint channelCount,
|
|||||||
// Populate JNI References.
|
// Populate JNI References.
|
||||||
const jclass outputBufferClass = env->FindClass(
|
const jclass outputBufferClass = env->FindClass(
|
||||||
"com/google/android/exoplayer2/decoder/SimpleOutputBuffer");
|
"com/google/android/exoplayer2/decoder/SimpleOutputBuffer");
|
||||||
outputBufferInit = env->GetMethodID(outputBufferClass, "init",
|
outputBufferInit =
|
||||||
"(JI)Ljava/nio/ByteBuffer;");
|
env->GetMethodID(outputBufferClass, "init", "(JI)Ljava/nio/ByteBuffer;");
|
||||||
|
|
||||||
return reinterpret_cast<intptr_t>(decoder);
|
return reinterpret_cast<intptr_t>(decoder);
|
||||||
}
|
}
|
||||||
@ -97,12 +97,11 @@ DECODER_FUNC(jlong, opusInit, jint sampleRate, jint channelCount,
|
|||||||
DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
|
DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
|
||||||
jobject jInputBuffer, jint inputSize, jobject jOutputBuffer) {
|
jobject jInputBuffer, jint inputSize, jobject jOutputBuffer) {
|
||||||
OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
|
OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
|
||||||
const uint8_t* inputBuffer =
|
const uint8_t* inputBuffer = reinterpret_cast<const uint8_t*>(
|
||||||
reinterpret_cast<const uint8_t*>(
|
|
||||||
env->GetDirectBufferAddress(jInputBuffer));
|
env->GetDirectBufferAddress(jInputBuffer));
|
||||||
|
|
||||||
const int byteSizePerSample = outputFloat ?
|
const int byteSizePerSample =
|
||||||
kBytesPerFloatSample : kBytesPerIntPcmSample;
|
outputFloat ? kBytesPerFloatSample : kBytesPerIntPcmSample;
|
||||||
const jint outputSize =
|
const jint outputSize =
|
||||||
kMaxOpusOutputPacketSizeSamples * byteSizePerSample * channelCount;
|
kMaxOpusOutputPacketSizeSamples * byteSizePerSample * channelCount;
|
||||||
|
|
||||||
@ -111,8 +110,8 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
|
|||||||
// Exception is thrown in Java when returning from the native call.
|
// Exception is thrown in Java when returning from the native call.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
const jobject jOutputBufferData = env->CallObjectMethod(jOutputBuffer,
|
const jobject jOutputBufferData = env->CallObjectMethod(
|
||||||
outputBufferInit, jTimeUs, outputSize);
|
jOutputBuffer, outputBufferInit, jTimeUs, outputSize);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
// Exception is thrown in Java when returning from the native call.
|
// Exception is thrown in Java when returning from the native call.
|
||||||
return -1;
|
return -1;
|
||||||
@ -122,13 +121,15 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
|
|||||||
if (outputFloat) {
|
if (outputFloat) {
|
||||||
float* outputBufferData = reinterpret_cast<float*>(
|
float* outputBufferData = reinterpret_cast<float*>(
|
||||||
env->GetDirectBufferAddress(jOutputBufferData));
|
env->GetDirectBufferAddress(jOutputBufferData));
|
||||||
sampleCount = opus_multistream_decode_float(decoder, inputBuffer, inputSize,
|
sampleCount = opus_multistream_decode_float(
|
||||||
outputBufferData, kMaxOpusOutputPacketSizeSamples, 0);
|
decoder, inputBuffer, inputSize, outputBufferData,
|
||||||
|
kMaxOpusOutputPacketSizeSamples, 0);
|
||||||
} else {
|
} else {
|
||||||
int16_t* outputBufferData = reinterpret_cast<int16_t*>(
|
int16_t* outputBufferData = reinterpret_cast<int16_t*>(
|
||||||
env->GetDirectBufferAddress(jOutputBufferData));
|
env->GetDirectBufferAddress(jOutputBufferData));
|
||||||
sampleCount = opus_multistream_decode(decoder, inputBuffer, inputSize,
|
sampleCount = opus_multistream_decode(decoder, inputBuffer, inputSize,
|
||||||
outputBufferData, kMaxOpusOutputPacketSizeSamples, 0);
|
outputBufferData,
|
||||||
|
kMaxOpusOutputPacketSizeSamples, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// record error code
|
// record error code
|
||||||
@ -139,9 +140,9 @@ DECODER_FUNC(jint, opusDecode, jlong jDecoder, jlong jTimeUs,
|
|||||||
|
|
||||||
DECODER_FUNC(jint, opusSecureDecode, jlong jDecoder, jlong jTimeUs,
|
DECODER_FUNC(jint, opusSecureDecode, jlong jDecoder, jlong jTimeUs,
|
||||||
jobject jInputBuffer, jint inputSize, jobject jOutputBuffer,
|
jobject jInputBuffer, jint inputSize, jobject jOutputBuffer,
|
||||||
jint sampleRate, jobject mediaCrypto, jint inputMode, jbyteArray key,
|
jint sampleRate, jobject mediaCrypto, jint inputMode,
|
||||||
jbyteArray javaIv, jint inputNumSubSamples, jintArray numBytesOfClearData,
|
jbyteArray key, jbyteArray javaIv, jint inputNumSubSamples,
|
||||||
jintArray numBytesOfEncryptedData) {
|
jintArray numBytesOfClearData, jintArray numBytesOfEncryptedData) {
|
||||||
// Doesn't support
|
// Doesn't support
|
||||||
// Java client should have checked vpxSupportSecureDecode
|
// Java client should have checked vpxSupportSecureDecode
|
||||||
// and avoid calling this
|
// and avoid calling this
|
||||||
@ -163,13 +164,9 @@ DECODER_FUNC(jstring, opusGetErrorMessage, jlong jContext) {
|
|||||||
return env->NewStringUTF(opus_strerror(errorCode));
|
return env->NewStringUTF(opus_strerror(errorCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
DECODER_FUNC(jint, opusGetErrorCode, jlong jContext) {
|
DECODER_FUNC(jint, opusGetErrorCode, jlong jContext) { return errorCode; }
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
DECODER_FUNC(void, opusSetFloatOutput) {
|
DECODER_FUNC(void, opusSetFloatOutput) { outputFloat = true; }
|
||||||
outputFloat = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBRARY_FUNC(jstring, opusIsSecureDecodeSupported) {
|
LIBRARY_FUNC(jstring, opusIsSecureDecodeSupported) {
|
||||||
// Doesn't support
|
// Doesn't support
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
#ifdef __ARM_NEON__
|
#ifdef __ARM_NEON__
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#endif
|
#endif
|
||||||
#include <jni.h>
|
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android/native_window.h>
|
#include <android/native_window.h>
|
||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
|
#include <jni.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -31,12 +31,12 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#define VPX_CODEC_DISABLE_COMPAT 1
|
#define VPX_CODEC_DISABLE_COMPAT 1
|
||||||
#include "vpx/vpx_decoder.h"
|
|
||||||
#include "vpx/vp8dx.h"
|
#include "vpx/vp8dx.h"
|
||||||
|
#include "vpx/vpx_decoder.h"
|
||||||
|
|
||||||
#define LOG_TAG "vpx_jni"
|
#define LOG_TAG "vpx_jni"
|
||||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
|
#define LOGE(...) \
|
||||||
__VA_ARGS__))
|
((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||||
|
|
||||||
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
#define DECODER_FUNC(RETURN_TYPE, NAME, ...) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
@ -480,12 +480,12 @@ DECODER_FUNC(jlong, vpxInit, jboolean disableLoopFilter,
|
|||||||
// Populate JNI References.
|
// Populate JNI References.
|
||||||
const jclass outputBufferClass = env->FindClass(
|
const jclass outputBufferClass = env->FindClass(
|
||||||
"com/google/android/exoplayer2/video/VideoDecoderOutputBuffer");
|
"com/google/android/exoplayer2/video/VideoDecoderOutputBuffer");
|
||||||
initForYuvFrame = env->GetMethodID(outputBufferClass, "initForYuvFrame",
|
initForYuvFrame =
|
||||||
"(IIIII)Z");
|
env->GetMethodID(outputBufferClass, "initForYuvFrame", "(IIIII)Z");
|
||||||
initForPrivateFrame =
|
initForPrivateFrame =
|
||||||
env->GetMethodID(outputBufferClass, "initForPrivateFrame", "(II)V");
|
env->GetMethodID(outputBufferClass, "initForPrivateFrame", "(II)V");
|
||||||
dataField = env->GetFieldID(outputBufferClass, "data",
|
dataField =
|
||||||
"Ljava/nio/ByteBuffer;");
|
env->GetFieldID(outputBufferClass, "data", "Ljava/nio/ByteBuffer;");
|
||||||
outputModeField = env->GetFieldID(outputBufferClass, "mode", "I");
|
outputModeField = env->GetFieldID(outputBufferClass, "mode", "I");
|
||||||
decoderPrivateField =
|
decoderPrivateField =
|
||||||
env->GetFieldID(outputBufferClass, "decoderPrivate", "I");
|
env->GetFieldID(outputBufferClass, "decoderPrivate", "I");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user