Skip to content

Commit

Permalink
Merge pull request #2 from m-funky/feature/3_0_2_with_mediacodec_decoder
Browse files Browse the repository at this point in the history
Feature/3 0 2 with mediacodec decoder
  • Loading branch information
Takuma Okamoto authored Jul 20, 2016
2 parents 0e9dbf0 + 84d006c commit 509d8d5
Show file tree
Hide file tree
Showing 16 changed files with 1,243 additions and 402 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@
GPATH
GRTAGS
GTAGS

/output
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,7 @@ h264_d3d11va_hwaccel_deps="d3d11va"
h264_d3d11va_hwaccel_select="h264_decoder"
h264_dxva2_hwaccel_deps="dxva2"
h264_dxva2_hwaccel_select="h264_decoder"
h264_mediacodec_encoder_deps="mediacodec"
h264_mediacodec_decoder_deps="mediacodec"
h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
h264_mmal_decoder_deps="mmal"
Expand Down
13 changes: 13 additions & 0 deletions ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,19 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
ist->resample_height = decoded_frame->height;
ist->resample_pix_fmt = decoded_frame->format;

// hack for mediacodec
if (do_mediacodec && ist->st->codec->codec_id == AV_CODEC_ID_H264) {
for (i = 0; i < nb_input_streams; i++) {
if (input_streams[i] && input_streams[i]->st->codec->codec_id == AV_CODEC_ID_H264) {
av_log(NULL, AV_LOG_DEBUG, "Change decoder(%d) codec pixfmt(%s) from (%s).\n",
i, av_get_pix_fmt_name(decoded_frame->format),
av_get_pix_fmt_name(input_streams[i]->resample_pix_fmt));
input_streams[i]->resample_pix_fmt = decoded_frame->format;
}
}

}

for (i = 0; i < nb_filtergraphs; i++) {
if (ist_in_filtergraph(filtergraphs[i], ist) && ist->reinit_filters &&
configure_filtergraph(filtergraphs[i]) < 0) {
Expand Down
5 changes: 1 addition & 4 deletions ffmpeg_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,9 @@ static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *
if (codec_name) {
AVCodec *codec = find_codec_or_die(codec_name, st->codec->codec_type, 0);
st->codec->codec_id = codec->id;
av_log(NULL, AV_LOG_VERBOSE, "Choosed decoder name:(%s).\n", codec_name);
return codec;
} else {
av_log(NULL, AV_LOG_VERBOSE, "Choosed decoder codec id:(%d).\n", st->codec->codec_id);
} else
return avcodec_find_decoder(st->codec->codec_id);
}
}

/* Add all the streams from the given input file to the global
Expand Down
12 changes: 10 additions & 2 deletions libavcodec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ OBJS-$(CONFIG_LSP) += lsp.o
OBJS-$(CONFIG_LZF) += lzf.o
OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o mdct_fixed_32.o
OBJS-$(CONFIG_ME_CMP) += me_cmp.o
OBJS-$(CONFIG_MEDIACODEC) += mediacodecdec.o mediacodec_wrapper.o mediacodec_sw_buffer.o
OBJS-$(CONFIG_MEDIACODEC) += mediacodecdec.o \
mediacodecenc.o \
mediacodec_wrapper.o \
mediacodec_sw_buffer.o
OBJS-$(CONFIG_MPEG_ER) += mpeg_er.o
OBJS-$(CONFIG_MPEGAUDIO) += mpegaudio.o mpegaudiodata.o \
mpegaudiodecheader.o
Expand Down Expand Up @@ -306,6 +309,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o h264_cabac.o h264_cavlc.o \
h264_mb.o h264_picture.o h264_ps.o \
h264_refs.o h264_sei.o h264_slice.o
OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec_h264.o
OBJS-$(CONFIG_H264_MEDIACODEC_ENCODER) += mediacodecenc_h264.o
OBJS-$(CONFIG_H264_MMAL_DECODER) += mmaldec.o
OBJS-$(CONFIG_H264_VDA_DECODER) += vda_h264_dec.o
OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec_h2645.o
Expand Down Expand Up @@ -949,7 +953,11 @@ SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h
SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h
SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.h
SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec.h mediacodec_wrapper.h mediacodec_sw_buffer.h
SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec.h \
mediacodecenc.h \
mediacodec_wrapper.h \
mediacodec_sw_buffer.h \

SKIPHEADERS-$(CONFIG_QSV) += qsv.h qsv_internal.h
SKIPHEADERS-$(CONFIG_QSVDEC) += qsvdec.h
SKIPHEADERS-$(CONFIG_QSVENC) += qsvenc.h
Expand Down
1 change: 1 addition & 0 deletions libavcodec/allcodecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(H264, h264);
REGISTER_DECODER(H264_CRYSTALHD, h264_crystalhd);
REGISTER_DECODER(H264_MEDIACODEC, h264_mediacodec);
REGISTER_ENCODER(H264_MEDIACODEC, h264_mediacodec);
REGISTER_DECODER(H264_MMAL, h264_mmal);
REGISTER_DECODER(H264_QSV, h264_qsv);
REGISTER_DECODER(H264_VDA, h264_vda);
Expand Down
97 changes: 7 additions & 90 deletions libavcodec/ffjni.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <dlfcn.h>
#include <jni.h>
#include <pthread.h>
#include <stdlib.h>
Expand All @@ -35,80 +34,6 @@
static JavaVM *java_vm = NULL;
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

/**
* Check if JniInvocation has been initialized. Only available on
* Android >= 4.4.
*
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
static int check_jni_invocation(void *log_ctx)
{
int ret = AVERROR_EXTERNAL;
void *handle = NULL;
void **jni_invocation = NULL;

handle = dlopen(NULL, RTLD_LOCAL);
if (!handle) {
goto done;
}

jni_invocation = (void **)dlsym(handle, "_ZN13JniInvocation15jni_invocation_E");
if (!jni_invocation) {
av_log(log_ctx, AV_LOG_ERROR, "Could not find JniInvocation::jni_invocation_ symbol\n");
goto done;
}

ret = !(jni_invocation != NULL && *jni_invocation != NULL);

done:
if (handle) {
dlclose(handle);
}

return ret;
}

/**
* Return created Java virtual machine using private JNI_GetCreatedJavaVMs
* function from the specified library name.
*
* @param name library name used for symbol lookups, can be NULL
* @param log_ctx context used for logging, can be NULL
* @return the current Java virtual machine in use
*/
static JavaVM *get_java_vm(const char *name, void *log_ctx)
{
JavaVM *vm = NULL;
jsize nb_vm = 0;

void *handle = NULL;
jint (*get_created_java_vms) (JavaVM ** vmBuf, jsize bufLen, jsize *nVMs) = NULL;

handle = dlopen(name, RTLD_LOCAL);
if (!handle) {
return NULL;
}

get_created_java_vms = (jint (*)(JavaVM **, jsize, jsize *)) dlsym(handle, "JNI_GetCreatedJavaVMs");
if (!get_created_java_vms) {
av_log(log_ctx, AV_LOG_ERROR, "Could not find JNI_GetCreatedJavaVMs symbol in library '%s'\n", name);
goto done;
}

if (get_created_java_vms(&vm, 1, &nb_vm) != JNI_OK) {
av_log(log_ctx, AV_LOG_ERROR, "Could not get created Java virtual machines\n");
goto done;
}

done:
if (handle) {
dlclose(handle);
}

return vm;
}

JNIEnv *ff_jni_attach_env(int *attached, void *log_ctx)
{
int ret = 0;
Expand All @@ -117,21 +42,13 @@ JNIEnv *ff_jni_attach_env(int *attached, void *log_ctx)
*attached = 0;

pthread_mutex_lock(&lock);
if (java_vm == NULL && (java_vm = av_jni_get_java_vm(log_ctx)) == NULL) {

av_log(log_ctx, AV_LOG_INFO, "Retrieving current Java virtual machine using Android JniInvocation wrapper\n");
if (check_jni_invocation(log_ctx) == 0) {
if ((java_vm = get_java_vm(NULL, log_ctx)) != NULL ||
(java_vm = get_java_vm("libdvm.so", log_ctx)) != NULL ||
(java_vm = get_java_vm("libart.so", log_ctx)) != NULL) {
av_log(log_ctx, AV_LOG_INFO, "Found Java virtual machine using Android JniInvocation wrapper\n");
}
}
if (java_vm == NULL) {
java_vm = av_jni_get_java_vm(log_ctx);
}
pthread_mutex_unlock(&lock);

if (!java_vm) {
av_log(log_ctx, AV_LOG_ERROR, "Could not retrieve a Java virtual machine\n");
av_log(log_ctx, AV_LOG_ERROR, "No Java virtual machine has been registered\n");
return NULL;
}

Expand Down Expand Up @@ -192,7 +109,7 @@ char *ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx)
if ((*env)->ExceptionCheck(env)) {
(*env)->ExceptionClear(env);
av_log(log_ctx, AV_LOG_ERROR, "String.releaseStringUTFChars() threw an exception\n");
return NULL;;
return NULL;
}

return ret;
Expand Down Expand Up @@ -227,7 +144,7 @@ int ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error
jclass exception_class = NULL;
jmethodID get_message_id = NULL;

jstring string;
jstring string = NULL;

av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);

Expand Down Expand Up @@ -294,12 +211,12 @@ int ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error
if (name && message) {
av_bprintf(&bp, "%s: %s", name, message);
} else if (name && !message) {
av_bprintf(&bp, "%s occured", name);
av_bprintf(&bp, "%s occurred", name);
} else if (!name && message) {
av_bprintf(&bp, "Exception: %s", message);
} else {
av_log(log_ctx, AV_LOG_WARNING, "Could not retreive exception name and message\n");
av_bprintf(&bp, "Exception occured");
av_bprintf(&bp, "Exception occurred");
}

ret = av_bprint_finalize(&bp, error);
Expand Down
2 changes: 0 additions & 2 deletions libavcodec/mediacodec_sw_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ void ff_mediacodec_sw_buffer_copy_yuv420_semi_planar(AVCodecContext *avctx,
}
}



void ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar(AVCodecContext *avctx,
MediaCodecDecContext *s,
uint8_t *data,
Expand Down
Loading

0 comments on commit 509d8d5

Please sign in to comment.