[FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-22 Thread Matthieu Bouron
From: Matthieu Bouron 

---
 configure   |5 +
 libavcodec/Makefile |3 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/mediacodec_wrapper.c | 1521 +++
 libavcodec/mediacodec_wrapper.h |  123 
 libavcodec/mediacodecdec.c  |  862 ++
 libavcodec/mediacodecdec.h  |   82 +++
 libavcodec/mediacodecdec_h264.c |  356 +
 8 files changed, 2953 insertions(+)
 create mode 100644 libavcodec/mediacodec_wrapper.c
 create mode 100644 libavcodec/mediacodec_wrapper.h
 create mode 100644 libavcodec/mediacodecdec.c
 create mode 100644 libavcodec/mediacodecdec.h
 create mode 100644 libavcodec/mediacodecdec_h264.c

diff --git a/configure b/configure
index b107a38..4fadaea 100755
--- a/configure
+++ b/configure
@@ -275,6 +275,7 @@ External library support:
   --enable-libzvbi enable teletext support via libzvbi [no]
   --disable-lzma   disable lzma [autodetect]
   --enable-decklinkenable Blackmagic DeckLink I/O support [no]
+  --enable-mediacodec  enable Android MediaCodec support [no]
   --enable-mmalenable decoding via MMAL [no]
   --enable-netcdf  enable NetCDF, needed for sofalizer filter [no]
   --enable-nvenc   enable NVIDIA NVENC support [no]
@@ -1497,6 +1498,7 @@ EXTERNAL_LIBRARY_LIST="
 libzmq
 libzvbi
 lzma
+mediacodec
 mmal
 netcdf
 nvenc
@@ -2491,6 +2493,8 @@ h264_d3d11va_hwaccel_deps="d3d11va"
 h264_d3d11va_hwaccel_select="h264_decoder"
 h264_dxva2_hwaccel_deps="dxva2"
 h264_dxva2_hwaccel_select="h264_decoder"
+h264_mediacodec_decoder_deps="mediacodec"
+h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
 h264_mmal_decoder_deps="mmal"
 h264_mmal_decoder_select="mmal"
 h264_mmal_hwaccel_deps="mmal"
@@ -5570,6 +5574,7 @@ enabled libzmq&& require_pkg_config libzmq 
zmq.h zmq_ctx_new
 enabled libzvbi   && require libzvbi libzvbi.h vbi_decoder_new -lzvbi 
&&
  { check_cpp_condition libzvbi.h 
"VBI_VERSION_MAJOR > 0 || VBI_VERSION_MINOR > 2 || VBI_VERSION_MINOR == 2 && 
VBI_VERSION_MICRO >= 28" ||
enabled gpl || die "ERROR: libzvbi requires 
version 0.2.28 or --enable-gpl."; }
+enabled mediacodec&& { enabled jni || die "ERROR: mediacodec requires 
--enable-jni"; }
 enabled mmal  && { check_lib interface/mmal/mmal.h 
mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host ||
 { ! enabled cross_compile && {
 add_cflags -isystem/opt/vc/include/ 
-isystem/opt/vc/include/interface/vmcs_host/linux 
-isystem/opt/vc/include/interface/vcos/pthreads -fgnu89-inline ;
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ced700a..e14a55b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -88,6 +88,7 @@ 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
 OBJS-$(CONFIG_MPEG_ER) += mpeg_er.o
 OBJS-$(CONFIG_MPEGAUDIO)   += mpegaudio.o mpegaudiodata.o   \
   mpegaudiodecheader.o
@@ -302,6 +303,7 @@ OBJS-$(CONFIG_H264_DECODER)+= h264.o 
h264_cabac.o h264_cavlc.o \
   h264_direct.o h264_loopfilter.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_MMAL_DECODER)   += mmaldec.o
 OBJS-$(CONFIG_H264_VDA_DECODER)+= vda_h264_dec.o
 OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
@@ -945,6 +947,7 @@ 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
 SKIPHEADERS-$(CONFIG_QSV)  += qsv.h qsv_internal.h
 SKIPHEADERS-$(CONFIG_QSVDEC)   += qsvdec.h
 SKIPHEADERS-$(CONFIG_QSVENC)   += qsvenc.h
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2097db0..58bcb24 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -196,6 +196,7 @@ void avcodec_register_all(void)
 REGISTER_ENCDEC (H263P, h263p);
 REGISTER_DECODER(H264,  h264);
 REGISTER_DECODER(H264_CRYSTALHD,h264_crystalhd);
+REGISTER_DECODER(H264_MEDIACODEC,   h264_mediacodec);
 REGISTER_DECODER(H264_MMAL, h264_mmal);
 REGISTER_DE

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-26 Thread Matthieu Bouron
On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> On Tue, 23 Feb 2016 09:53:43 +0100
> Matthieu Bouron  wrote:
> 
> > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > > From: Matthieu Bouron   
> > > [...]  
> > > > +codec = (*env)->NewObject(env, jfields.mediacodec_list_class, 
> > > > jfields.init_id, 0);
> > > > +if (!codec) {
> > > > +av_log(NULL, AV_LOG_ERROR, "Could not create media codec 
> > > > list\n");
> > > > +goto done;
> > > > +}
> > > > +
> > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > jfields.find_decoder_for_format_id, format);
> > > > +if (!tmp) {
> > > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in 
> > > > media codec list\n");
> > > > +goto done;
> > > > +}
> > > > +
> > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > +if (!name) {  
> > >   
> > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring to 
> > > > utf chars\n");  
> > > 
> > > some non NULL context would be better, if possible, so the user knows
> > > where an error came from  
> > 
> > It would require to pass the log_ctx (avctx) as an argument of
> > ff_AMediaCodecList_getCodecByName.
> > 
> > All the functions of this wrapper does not take a log_ctx as argument
> > to be as close as possible to the original NDK MediaCodec API. The
> > NDK MediaCodec API does not provide any wrapper around MediaCodecList.
> > 
> > I would like the whole wrapper API to be consistent but also as close as
> > possible to original one.
> > If you think it's mandatory I can add a log_ctx argument to every
> > functions of the wrapper API (so it will be used directly by av_log and
> > ff_jni_exception_check).
> > 
> > On another note, I fixed locally this part of the code by adding missing 
> > calls
> > to ff_jni_exception_check.
> > 
> > [...]
> 
> Is it possible to store the log_ctx somewhere in the JNI?
> 
> We might at some point in the future forbid av_log(NULL, ...) calls, and
> then it'd get complicated.

Patch updated with the following differences:
  * All logging arguments in mediacodec_wrapper functions are now non
  NULL
  * The mediacodec buffer copy functions has been moved to a separate file
  * The Mediacodec enum codec flags are properly retrieved from JNI

The codec extradata conversion to annex b simplification has not been
addressed in this update. The bitstream filter api does not seem to
provide a way to do the extradata conversion without feeding an actual
packet to the api (av_bitstream_filter_filter) and i would like to keep
the codec initialization in the init function.

The patchset has been pushed to a new branch:
https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3

Matthieu
>From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
From: Matthieu Bouron 
Date: Thu, 21 Jan 2016 09:29:39 +0100
Subject: [PATCH 2/2] lavc: add h264 mediacodec decoder

---
 configure |5 +
 libavcodec/Makefile   |3 +
 libavcodec/allcodecs.c|1 +
 libavcodec/mediacodec_sw_buffer.c |  339 
 libavcodec/mediacodec_sw_buffer.h |   62 ++
 libavcodec/mediacodec_wrapper.c   | 1674 +
 libavcodec/mediacodec_wrapper.h   |  122 +++
 libavcodec/mediacodecdec.c|  563 +
 libavcodec/mediacodecdec.h|   82 ++
 libavcodec/mediacodecdec_h264.c   |  356 
 10 files changed, 3207 insertions(+)
 create mode 100644 libavcodec/mediacodec_sw_buffer.c
 create mode 100644 libavcodec/mediacodec_sw_buffer.h
 create mode 100644 libavcodec/mediacodec_wrapper.c
 create mode 100644 libavcodec/mediacodec_wrapper.h
 create mode 100644 libavcodec/mediacodecdec.c
 create mode 100644 libavcodec/mediacodecdec.h
 create mode 100644 libavcodec/mediacodecdec_h264.c

diff --git a/configure b/configure
index 3ee9376..2dbd9e4 100755
--- a/configure
+++ b/configure
@@ -276,6 +276,7 @@ External library support:
   --enable-libzvbi enable teletext support via libzvbi [no]
   --disable-lzma   disable lzma [autodetect]
   --enable-decklinkenable Blackmagic DeckLink I/O support [no]
+  --enable-mediacodec  enable Android MediaCodec support [no]
   --enable-mmalenable decoding via MMAL [no]
   --enable-netcdf  enable NetCDF, needed for sofalizer filter [no]
   --enable-nvenc   enable NVIDIA NVENC support [no]
@@ -1499,6 +1500,7 @@ EXTERNAL_LIBRARY_LIST="
 libzmq
 libzvbi
 lzma
+mediacodec
 mmal
 netcdf
 nvenc
@@ -2499,6 +2501,8 @@ h264_d3d11va_hwaccel_deps="d3d11va"
 h264_d3d11va_hwaccel_select="h264_decoder"
 h264_dxva2_hwaccel_deps="dxva2"
 h264_dxva2_hwaccel_select="h264_decoder"
+h264_mediacodec_decoder_deps="mediacodec"
+h264_mediacodec_decoder_select="h264_mp4toannexb

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-26 Thread Carl Eugen Hoyos
Matthieu Bouron  gmail.com> writes:

> Patch updated

> +  --enable-mediacodec  enable Android MediaCodec support [no]

> +enabled mediacodec&& { enabled jni || die

Sorry if you have already explained:
Why are two separate enable-options necessary?
How is jni useful without mediacodec?

Thank you, Carl Eugen

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-26 Thread Matthieu Bouron
On Fri, Feb 26, 2016 at 5:02 PM, Carl Eugen Hoyos  wrote:

> Matthieu Bouron  gmail.com> writes:
>
> > Patch updated
>
> > +  --enable-mediacodec  enable Android MediaCodec support [no]
>
> > +enabled mediacodec&& { enabled jni || die
>
> Sorry if you have already explained:
> Why are two separate enable-options necessary?
> How is jni useful without mediacodec?
>

My original patchset also included support for android content uri in lavf
(which also requires jni)
. I dropped this patch for now since it is subject to discussions and not
mandatory for mediacodec but i'm likely to submit another version of it
after the initial mediacodec work is done.

Matthieu
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-27 Thread Michael Niedermayer
On Fri, Feb 26, 2016 at 04:54:47PM +0100, Matthieu Bouron wrote:
> On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> > On Tue, 23 Feb 2016 09:53:43 +0100
> > Matthieu Bouron  wrote:
> > 
> > > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > > > From: Matthieu Bouron   
> > > > [...]  
> > > > > +codec = (*env)->NewObject(env, 
> > > > > jfields.mediacodec_list_class, jfields.init_id, 0);
> > > > > +if (!codec) {
> > > > > +av_log(NULL, AV_LOG_ERROR, "Could not create media codec 
> > > > > list\n");
> > > > > +goto done;
> > > > > +}
> > > > > +
> > > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > > jfields.find_decoder_for_format_id, format);
> > > > > +if (!tmp) {
> > > > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in 
> > > > > media codec list\n");
> > > > > +goto done;
> > > > > +}
> > > > > +
> > > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > > +if (!name) {  
> > > >   
> > > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring to 
> > > > > utf chars\n");  
> > > > 
> > > > some non NULL context would be better, if possible, so the user knows
> > > > where an error came from  
> > > 
> > > It would require to pass the log_ctx (avctx) as an argument of
> > > ff_AMediaCodecList_getCodecByName.
> > > 
> > > All the functions of this wrapper does not take a log_ctx as argument
> > > to be as close as possible to the original NDK MediaCodec API. The
> > > NDK MediaCodec API does not provide any wrapper around MediaCodecList.
> > > 
> > > I would like the whole wrapper API to be consistent but also as close as
> > > possible to original one.
> > > If you think it's mandatory I can add a log_ctx argument to every
> > > functions of the wrapper API (so it will be used directly by av_log and
> > > ff_jni_exception_check).
> > > 
> > > On another note, I fixed locally this part of the code by adding missing 
> > > calls
> > > to ff_jni_exception_check.
> > > 
> > > [...]
> > 
> > Is it possible to store the log_ctx somewhere in the JNI?
> > 
> > We might at some point in the future forbid av_log(NULL, ...) calls, and
> > then it'd get complicated.
> 
> Patch updated with the following differences:
>   * All logging arguments in mediacodec_wrapper functions are now non
>   NULL
>   * The mediacodec buffer copy functions has been moved to a separate file
>   * The Mediacodec enum codec flags are properly retrieved from JNI
> 
> The codec extradata conversion to annex b simplification has not been
> addressed in this update. The bitstream filter api does not seem to
> provide a way to do the extradata conversion without feeding an actual
> packet to the api (av_bitstream_filter_filter) and i would like to keep
> the codec initialization in the init function.
> 
> The patchset has been pushed to a new branch:
> https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3
> 
> Matthieu

>  configure |5 
>  libavcodec/Makefile   |3 
>  libavcodec/allcodecs.c|1 
>  libavcodec/mediacodec_sw_buffer.c |  339 +++
>  libavcodec/mediacodec_sw_buffer.h |   62 +
>  libavcodec/mediacodec_wrapper.c   | 1674 
> ++
>  libavcodec/mediacodec_wrapper.h   |  122 ++
>  libavcodec/mediacodecdec.c|  563 
>  libavcodec/mediacodecdec.h|   82 +
>  libavcodec/mediacodecdec_h264.c   |  356 
>  10 files changed, 3207 insertions(+)
> f545068afece74d27cc04a365d9de7dcf5586a7d  
> 0002-lavc-add-h264-mediacodec-decoder.patch
> From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
> From: Matthieu Bouron 
> Date: Thu, 21 Jan 2016 09:29:39 +0100
> Subject: [PATCH 2/2] lavc: add h264 mediacodec decoder

breaks fate
swr-resample_lin-fltp-48000-44100
TESTswr-resample_lin-dblp-8000-44100
TESTswr-resample_lin-dblp-8000-48000
--- ./tests/ref/fate/source 2016-02-24 22:42:26.379879152 +0100
+++ tests/data/fate/source  2016-02-27 14:44:09.176735216 +0100
@@ -27,3 +27,4 @@
 compat/avisynth/windowsPorts/windows2linux.h
 compat/float/float.h
 compat/float/limits.h
+libavcodec/mediacodec_sw_buffer.h
Test source failed. Look at tests/data/fate/source.err for details.
make: *** [fate-source] Error 1
make: *** Waiting for unfinished jobs


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ff

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-03-01 Thread Matthieu Bouron
On Sat, Feb 27, 2016 at 04:28:43PM +0100, Michael Niedermayer wrote:
> On Fri, Feb 26, 2016 at 04:54:47PM +0100, Matthieu Bouron wrote:
> > On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> > > On Tue, 23 Feb 2016 09:53:43 +0100
> > > Matthieu Bouron  wrote:
> > > 
> > > > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > > > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > > > > From: Matthieu Bouron   
> > > > > [...]  
> > > > > > +codec = (*env)->NewObject(env, 
> > > > > > jfields.mediacodec_list_class, jfields.init_id, 0);
> > > > > > +if (!codec) {
> > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not create media 
> > > > > > codec list\n");
> > > > > > +goto done;
> > > > > > +}
> > > > > > +
> > > > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > > > jfields.find_decoder_for_format_id, format);
> > > > > > +if (!tmp) {
> > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in 
> > > > > > media codec list\n");
> > > > > > +goto done;
> > > > > > +}
> > > > > > +
> > > > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > > > +if (!name) {  
> > > > >   
> > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring 
> > > > > > to utf chars\n");  
> > > > > 
> > > > > some non NULL context would be better, if possible, so the user knows
> > > > > where an error came from  
> > > > 
> > > > It would require to pass the log_ctx (avctx) as an argument of
> > > > ff_AMediaCodecList_getCodecByName.
> > > > 
> > > > All the functions of this wrapper does not take a log_ctx as argument
> > > > to be as close as possible to the original NDK MediaCodec API. The
> > > > NDK MediaCodec API does not provide any wrapper around MediaCodecList.
> > > > 
> > > > I would like the whole wrapper API to be consistent but also as close as
> > > > possible to original one.
> > > > If you think it's mandatory I can add a log_ctx argument to every
> > > > functions of the wrapper API (so it will be used directly by av_log and
> > > > ff_jni_exception_check).
> > > > 
> > > > On another note, I fixed locally this part of the code by adding 
> > > > missing calls
> > > > to ff_jni_exception_check.
> > > > 
> > > > [...]
> > > 
> > > Is it possible to store the log_ctx somewhere in the JNI?
> > > 
> > > We might at some point in the future forbid av_log(NULL, ...) calls, and
> > > then it'd get complicated.
> > 
> > Patch updated with the following differences:
> >   * All logging arguments in mediacodec_wrapper functions are now non
> >   NULL
> >   * The mediacodec buffer copy functions has been moved to a separate file
> >   * The Mediacodec enum codec flags are properly retrieved from JNI
> > 
> > The codec extradata conversion to annex b simplification has not been
> > addressed in this update. The bitstream filter api does not seem to
> > provide a way to do the extradata conversion without feeding an actual
> > packet to the api (av_bitstream_filter_filter) and i would like to keep
> > the codec initialization in the init function.
> > 
> > The patchset has been pushed to a new branch:
> > https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3
> > 
> > Matthieu
> 
> >  configure |5 
> >  libavcodec/Makefile   |3 
> >  libavcodec/allcodecs.c|1 
> >  libavcodec/mediacodec_sw_buffer.c |  339 +++
> >  libavcodec/mediacodec_sw_buffer.h |   62 +
> >  libavcodec/mediacodec_wrapper.c   | 1674 
> > ++
> >  libavcodec/mediacodec_wrapper.h   |  122 ++
> >  libavcodec/mediacodecdec.c|  563 
> >  libavcodec/mediacodecdec.h|   82 +
> >  libavcodec/mediacodecdec_h264.c   |  356 
> >  10 files changed, 3207 insertions(+)
> > f545068afece74d27cc04a365d9de7dcf5586a7d  
> > 0002-lavc-add-h264-mediacodec-decoder.patch
> > From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
> > From: Matthieu Bouron 
> > Date: Thu, 21 Jan 2016 09:29:39 +0100
> > Subject: [PATCH 2/2] lavc: add h264 mediacodec decoder
> 
> breaks fate
> swr-resample_lin-fltp-48000-44100
> TESTswr-resample_lin-dblp-8000-44100
> TESTswr-resample_lin-dblp-8000-48000
> --- ./tests/ref/fate/source 2016-02-24 22:42:26.379879152 +0100
> +++ tests/data/fate/source  2016-02-27 14:44:09.176735216 +0100
> @@ -27,3 +27,4 @@
>  compat/avisynth/windowsPorts/windows2linux.h
>  compat/float/float.h
>  compat/float/limits.h
> +libavcodec/mediacodec_sw_buffer.h
> Test source failed. Look at tests/data/fate/source.err for details.
> make: *** [fate-source] Error 1
> make: *** Waiting for unfinished jobs

New patch attached fixing the issue. It also fixes an issue while the
binding was trying to access the field MediaCodec.BUFFER_FLAG_KEY_FRAME
which is only available in android >= 5 causing the JNI 

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-03-01 Thread Michael Niedermayer
On Tue, Mar 01, 2016 at 08:01:45PM +0100, Matthieu Bouron wrote:
> On Sat, Feb 27, 2016 at 04:28:43PM +0100, Michael Niedermayer wrote:
> > On Fri, Feb 26, 2016 at 04:54:47PM +0100, Matthieu Bouron wrote:
> > > On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> > > > On Tue, 23 Feb 2016 09:53:43 +0100
> > > > Matthieu Bouron  wrote:
> > > > 
> > > > > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > > > > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > > > > > From: Matthieu Bouron   
> > > > > > [...]  
> > > > > > > +codec = (*env)->NewObject(env, 
> > > > > > > jfields.mediacodec_list_class, jfields.init_id, 0);
> > > > > > > +if (!codec) {
> > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not create media 
> > > > > > > codec list\n");
> > > > > > > +goto done;
> > > > > > > +}
> > > > > > > +
> > > > > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > > > > jfields.find_decoder_for_format_id, format);
> > > > > > > +if (!tmp) {
> > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder 
> > > > > > > in media codec list\n");
> > > > > > > +goto done;
> > > > > > > +}
> > > > > > > +
> > > > > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > > > > +if (!name) {  
> > > > > >   
> > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert 
> > > > > > > jstring to utf chars\n");  
> > > > > > 
> > > > > > some non NULL context would be better, if possible, so the user 
> > > > > > knows
> > > > > > where an error came from  
> > > > > 
> > > > > It would require to pass the log_ctx (avctx) as an argument of
> > > > > ff_AMediaCodecList_getCodecByName.
> > > > > 
> > > > > All the functions of this wrapper does not take a log_ctx as argument
> > > > > to be as close as possible to the original NDK MediaCodec API. The
> > > > > NDK MediaCodec API does not provide any wrapper around MediaCodecList.
> > > > > 
> > > > > I would like the whole wrapper API to be consistent but also as close 
> > > > > as
> > > > > possible to original one.
> > > > > If you think it's mandatory I can add a log_ctx argument to every
> > > > > functions of the wrapper API (so it will be used directly by av_log 
> > > > > and
> > > > > ff_jni_exception_check).
> > > > > 
> > > > > On another note, I fixed locally this part of the code by adding 
> > > > > missing calls
> > > > > to ff_jni_exception_check.
> > > > > 
> > > > > [...]
> > > > 
> > > > Is it possible to store the log_ctx somewhere in the JNI?
> > > > 
> > > > We might at some point in the future forbid av_log(NULL, ...) calls, and
> > > > then it'd get complicated.
> > > 
> > > Patch updated with the following differences:
> > >   * All logging arguments in mediacodec_wrapper functions are now non
> > >   NULL
> > >   * The mediacodec buffer copy functions has been moved to a separate file
> > >   * The Mediacodec enum codec flags are properly retrieved from JNI
> > > 
> > > The codec extradata conversion to annex b simplification has not been
> > > addressed in this update. The bitstream filter api does not seem to
> > > provide a way to do the extradata conversion without feeding an actual
> > > packet to the api (av_bitstream_filter_filter) and i would like to keep
> > > the codec initialization in the init function.
> > > 
> > > The patchset has been pushed to a new branch:
> > > https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3
> > > 
> > > Matthieu
> > 
> > >  configure |5 
> > >  libavcodec/Makefile   |3 
> > >  libavcodec/allcodecs.c|1 
> > >  libavcodec/mediacodec_sw_buffer.c |  339 +++
> > >  libavcodec/mediacodec_sw_buffer.h |   62 +
> > >  libavcodec/mediacodec_wrapper.c   | 1674 
> > > ++
> > >  libavcodec/mediacodec_wrapper.h   |  122 ++
> > >  libavcodec/mediacodecdec.c|  563 
> > >  libavcodec/mediacodecdec.h|   82 +
> > >  libavcodec/mediacodecdec_h264.c   |  356 
> > >  10 files changed, 3207 insertions(+)
> > > f545068afece74d27cc04a365d9de7dcf5586a7d  
> > > 0002-lavc-add-h264-mediacodec-decoder.patch
> > > From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
> > > From: Matthieu Bouron 
> > > Date: Thu, 21 Jan 2016 09:29:39 +0100
> > > Subject: [PATCH 2/2] lavc: add h264 mediacodec decoder
> > 
> > breaks fate
> > swr-resample_lin-fltp-48000-44100
> > TESTswr-resample_lin-dblp-8000-44100
> > TESTswr-resample_lin-dblp-8000-48000
> > --- ./tests/ref/fate/source 2016-02-24 22:42:26.379879152 +0100
> > +++ tests/data/fate/source  2016-02-27 14:44:09.176735216 +0100
> > @@ -27,3 +27,4 @@
> >  compat/avisynth/windowsPorts/windows2linux.h
> >  compat/float/float.h
> >  compat/float/limits.h
> > +libavcodec/mediacodec_sw_buffer.h
> > Test source failed. Look at tes

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-03-02 Thread Matthieu Bouron
On Tue, Mar 01, 2016 at 11:26:45PM +0100, Michael Niedermayer wrote:
> On Tue, Mar 01, 2016 at 08:01:45PM +0100, Matthieu Bouron wrote:
> > On Sat, Feb 27, 2016 at 04:28:43PM +0100, Michael Niedermayer wrote:
> > > On Fri, Feb 26, 2016 at 04:54:47PM +0100, Matthieu Bouron wrote:
> > > > On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> > > > > On Tue, 23 Feb 2016 09:53:43 +0100
> > > > > Matthieu Bouron  wrote:
> > > > > 
> > > > > > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > > > > > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > > > > > > From: Matthieu Bouron   
> > > > > > > [...]  
> > > > > > > > +codec = (*env)->NewObject(env, 
> > > > > > > > jfields.mediacodec_list_class, jfields.init_id, 0);
> > > > > > > > +if (!codec) {
> > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not create media 
> > > > > > > > codec list\n");
> > > > > > > > +goto done;
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > > > > > jfields.find_decoder_for_format_id, format);
> > > > > > > > +if (!tmp) {
> > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder 
> > > > > > > > in media codec list\n");
> > > > > > > > +goto done;
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > > > > > +if (!name) {  
> > > > > > >   
> > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert 
> > > > > > > > jstring to utf chars\n");  
> > > > > > > 
> > > > > > > some non NULL context would be better, if possible, so the user 
> > > > > > > knows
> > > > > > > where an error came from  
> > > > > > 
> > > > > > It would require to pass the log_ctx (avctx) as an argument of
> > > > > > ff_AMediaCodecList_getCodecByName.
> > > > > > 
> > > > > > All the functions of this wrapper does not take a log_ctx as 
> > > > > > argument
> > > > > > to be as close as possible to the original NDK MediaCodec API. The
> > > > > > NDK MediaCodec API does not provide any wrapper around 
> > > > > > MediaCodecList.
> > > > > > 
> > > > > > I would like the whole wrapper API to be consistent but also as 
> > > > > > close as
> > > > > > possible to original one.
> > > > > > If you think it's mandatory I can add a log_ctx argument to every
> > > > > > functions of the wrapper API (so it will be used directly by av_log 
> > > > > > and
> > > > > > ff_jni_exception_check).
> > > > > > 
> > > > > > On another note, I fixed locally this part of the code by adding 
> > > > > > missing calls
> > > > > > to ff_jni_exception_check.
> > > > > > 
> > > > > > [...]
> > > > > 
> > > > > Is it possible to store the log_ctx somewhere in the JNI?
> > > > > 
> > > > > We might at some point in the future forbid av_log(NULL, ...) calls, 
> > > > > and
> > > > > then it'd get complicated.
> > > > 
> > > > Patch updated with the following differences:
> > > >   * All logging arguments in mediacodec_wrapper functions are now non
> > > >   NULL
> > > >   * The mediacodec buffer copy functions has been moved to a separate 
> > > > file
> > > >   * The Mediacodec enum codec flags are properly retrieved from JNI
> > > > 
> > > > The codec extradata conversion to annex b simplification has not been
> > > > addressed in this update. The bitstream filter api does not seem to
> > > > provide a way to do the extradata conversion without feeding an actual
> > > > packet to the api (av_bitstream_filter_filter) and i would like to keep
> > > > the codec initialization in the init function.
> > > > 
> > > > The patchset has been pushed to a new branch:
> > > > https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3
> > > > 
> > > > Matthieu
> > > 
> > > >  configure |5 
> > > >  libavcodec/Makefile   |3 
> > > >  libavcodec/allcodecs.c|1 
> > > >  libavcodec/mediacodec_sw_buffer.c |  339 +++
> > > >  libavcodec/mediacodec_sw_buffer.h |   62 +
> > > >  libavcodec/mediacodec_wrapper.c   | 1674 
> > > > ++
> > > >  libavcodec/mediacodec_wrapper.h   |  122 ++
> > > >  libavcodec/mediacodecdec.c|  563 
> > > >  libavcodec/mediacodecdec.h|   82 +
> > > >  libavcodec/mediacodecdec_h264.c   |  356 
> > > >  10 files changed, 3207 insertions(+)
> > > > f545068afece74d27cc04a365d9de7dcf5586a7d  
> > > > 0002-lavc-add-h264-mediacodec-decoder.patch
> > > > From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
> > > > From: Matthieu Bouron 
> > > > Date: Thu, 21 Jan 2016 09:29:39 +0100
> > > > Subject: [PATCH 2/2] lavc: add h264 mediacodec decoder
> > > 
> > > breaks fate
> > > swr-resample_lin-fltp-48000-44100
> > > TESTswr-resample_lin-dblp-8000-44100
> > > TESTswr-resample_lin-dblp-8000-48000
> > > --- ./tests/ref/

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-03-03 Thread Matthieu Bouron
On Wed, Mar 02, 2016 at 03:34:09PM +0100, Matthieu Bouron wrote:
> On Tue, Mar 01, 2016 at 11:26:45PM +0100, Michael Niedermayer wrote:
> > On Tue, Mar 01, 2016 at 08:01:45PM +0100, Matthieu Bouron wrote:
> > > On Sat, Feb 27, 2016 at 04:28:43PM +0100, Michael Niedermayer wrote:
> > > > On Fri, Feb 26, 2016 at 04:54:47PM +0100, Matthieu Bouron wrote:
> > > > > On Tue, Feb 23, 2016 at 11:28:01AM +0100, wm4 wrote:
> > > > > > On Tue, 23 Feb 2016 09:53:43 +0100
> > > > > > Matthieu Bouron  wrote:
> > > > > > 
> > > > > > > On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer 
> > > > > > > wrote:
> > > > > > > > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron 
> > > > > > > > wrote:  
> > > > > > > > > From: Matthieu Bouron   
> > > > > > > > [...]  
> > > > > > > > > +codec = (*env)->NewObject(env, 
> > > > > > > > > jfields.mediacodec_list_class, jfields.init_id, 0);
> > > > > > > > > +if (!codec) {
> > > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not create 
> > > > > > > > > media codec list\n");
> > > > > > > > > +goto done;
> > > > > > > > > +}
> > > > > > > > > +
> > > > > > > > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > > > > > > > jfields.find_decoder_for_format_id, format);
> > > > > > > > > +if (!tmp) {
> > > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not find 
> > > > > > > > > decoder in media codec list\n");
> > > > > > > > > +goto done;
> > > > > > > > > +}
> > > > > > > > > +
> > > > > > > > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > > > > > > > +if (!name) {  
> > > > > > > >   
> > > > > > > > > +av_log(NULL, AV_LOG_ERROR, "Could not convert 
> > > > > > > > > jstring to utf chars\n");  
> > > > > > > > 
> > > > > > > > some non NULL context would be better, if possible, so the user 
> > > > > > > > knows
> > > > > > > > where an error came from  
> > > > > > > 
> > > > > > > It would require to pass the log_ctx (avctx) as an argument of
> > > > > > > ff_AMediaCodecList_getCodecByName.
> > > > > > > 
> > > > > > > All the functions of this wrapper does not take a log_ctx as 
> > > > > > > argument
> > > > > > > to be as close as possible to the original NDK MediaCodec API. The
> > > > > > > NDK MediaCodec API does not provide any wrapper around 
> > > > > > > MediaCodecList.
> > > > > > > 
> > > > > > > I would like the whole wrapper API to be consistent but also as 
> > > > > > > close as
> > > > > > > possible to original one.
> > > > > > > If you think it's mandatory I can add a log_ctx argument to every
> > > > > > > functions of the wrapper API (so it will be used directly by 
> > > > > > > av_log and
> > > > > > > ff_jni_exception_check).
> > > > > > > 
> > > > > > > On another note, I fixed locally this part of the code by adding 
> > > > > > > missing calls
> > > > > > > to ff_jni_exception_check.
> > > > > > > 
> > > > > > > [...]
> > > > > > 
> > > > > > Is it possible to store the log_ctx somewhere in the JNI?
> > > > > > 
> > > > > > We might at some point in the future forbid av_log(NULL, ...) 
> > > > > > calls, and
> > > > > > then it'd get complicated.
> > > > > 
> > > > > Patch updated with the following differences:
> > > > >   * All logging arguments in mediacodec_wrapper functions are now non
> > > > >   NULL
> > > > >   * The mediacodec buffer copy functions has been moved to a separate 
> > > > > file
> > > > >   * The Mediacodec enum codec flags are properly retrieved from JNI
> > > > > 
> > > > > The codec extradata conversion to annex b simplification has not been
> > > > > addressed in this update. The bitstream filter api does not seem to
> > > > > provide a way to do the extradata conversion without feeding an actual
> > > > > packet to the api (av_bitstream_filter_filter) and i would like to 
> > > > > keep
> > > > > the codec initialization in the init function.
> > > > > 
> > > > > The patchset has been pushed to a new branch:
> > > > > https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v3
> > > > > 
> > > > > Matthieu
> > > > 
> > > > >  configure |5 
> > > > >  libavcodec/Makefile   |3 
> > > > >  libavcodec/allcodecs.c|1 
> > > > >  libavcodec/mediacodec_sw_buffer.c |  339 +++
> > > > >  libavcodec/mediacodec_sw_buffer.h |   62 +
> > > > >  libavcodec/mediacodec_wrapper.c   | 1674 
> > > > > ++
> > > > >  libavcodec/mediacodec_wrapper.h   |  122 ++
> > > > >  libavcodec/mediacodecdec.c|  563 
> > > > >  libavcodec/mediacodecdec.h|   82 +
> > > > >  libavcodec/mediacodecdec_h264.c   |  356 
> > > > >  10 files changed, 3207 insertions(+)
> > > > > f545068afece74d27cc04a365d9de7dcf5586a7d  
> > > > > 0002-lavc-add-h264-mediacodec-decoder.patch
> > > > > From 805c7b95433f1bfbbc5d47fd59a1bbb755edb112 Mon Sep 17 00:00:00 2001
> > > > > Fro

Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-03-07 Thread Matthieu Bouron
On Thu, Mar 03, 2016 at 02:03:01PM +0100, Matthieu Bouron wrote:

[...]

> 
> Patch updated with the following differences:
>   * ff_set_dimensions return code is now used
>   * add missing exception when trying to call the MediaCodec object 
> constructor
>   * remove leftover avctx_internal field from MediaCodecH264DecContext
>   * add ff_AMediaCodec_getName function
> 
> The dev branch can be found here:
> https://github.com/mbouron/FFmpeg/tree/feature/mediacodec-support-v7
> 
> If nobody objects I would like to push the patchset in 3 days.
> 

Pushed.

[...]
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-22 Thread Michael Niedermayer
On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:
> From: Matthieu Bouron 
[...]
> +codec = (*env)->NewObject(env, jfields.mediacodec_list_class, 
> jfields.init_id, 0);
> +if (!codec) {
> +av_log(NULL, AV_LOG_ERROR, "Could not create media codec 
> list\n");
> +goto done;
> +}
> +
> +tmp = (*env)->CallObjectMethod(env, codec, 
> jfields.find_decoder_for_format_id, format);
> +if (!tmp) {
> +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in media 
> codec list\n");
> +goto done;
> +}
> +
> +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> +if (!name) {

> +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring to utf 
> chars\n");

some non NULL context would be better, if possible, so the user knows
where an error came from



[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-22 Thread wm4
On Mon, 22 Feb 2016 12:20:36 +0100
Matthieu Bouron  wrote:

> From: Matthieu Bouron 
> 
> ---
> ...

Some remarks:

- The qcom stuff should probably be moved into its own source file,
  because it's a lot of code, but self-contained.

- Do you really need h264_extradata_to_annexb_sps_pps? The BSF already
  creates mp4-style extradata, which MediaCodec apparently can take
  directly.

- There are several timeouts to avoid deadlocks in the dataflow,
  apparently. Is this inherently needed, or only because of the
  libavcodec API, which requires returning 0 or 1 output frames per
  input packet?

- The JNI code uses braces in case labels: "case (FF_JNI_FIELD): {"
  (Seems unusual coding style.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-23 Thread Matthieu Bouron
On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:
> > From: Matthieu Bouron 
> [...]
> > +codec = (*env)->NewObject(env, jfields.mediacodec_list_class, 
> > jfields.init_id, 0);
> > +if (!codec) {
> > +av_log(NULL, AV_LOG_ERROR, "Could not create media codec 
> > list\n");
> > +goto done;
> > +}
> > +
> > +tmp = (*env)->CallObjectMethod(env, codec, 
> > jfields.find_decoder_for_format_id, format);
> > +if (!tmp) {
> > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in media 
> > codec list\n");
> > +goto done;
> > +}
> > +
> > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > +if (!name) {
> 
> > +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring to utf 
> > chars\n");
> 
> some non NULL context would be better, if possible, so the user knows
> where an error came from

It would require to pass the log_ctx (avctx) as an argument of
ff_AMediaCodecList_getCodecByName.

All the functions of this wrapper does not take a log_ctx as argument
to be as close as possible to the original NDK MediaCodec API. The
NDK MediaCodec API does not provide any wrapper around MediaCodecList.

I would like the whole wrapper API to be consistent but also as close as
possible to original one.
If you think it's mandatory I can add a log_ctx argument to every
functions of the wrapper API (so it will be used directly by av_log and
ff_jni_exception_check).

On another note, I fixed locally this part of the code by adding missing calls
to ff_jni_exception_check.

[...]
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-23 Thread Matthieu Bouron
On Mon, Feb 22, 2016 at 02:55:06PM +0100, wm4 wrote:
> On Mon, 22 Feb 2016 12:20:36 +0100
> Matthieu Bouron  wrote:
> 
> > From: Matthieu Bouron 
> > 
> > ---
> > ...
> 
> Some remarks:
> 
> - The qcom stuff should probably be moved into its own source file,
>   because it's a lot of code, but self-contained.

I'll move the copy / conversion routines to another file. Would you be OK
with that ? Or do you want only the qcom stuff in a separate file
(probably named mediacodec_buffer.c,h) ?

> 
> - Do you really need h264_extradata_to_annexb_sps_pps? The BSF already
>   creates mp4-style extradata, which MediaCodec apparently can take
>   directly.

I will do more testing and remove it if possible in the next revision of
the patch. The original idea behind it was to comply with the
documentation that states that for the h264 codec csd-0 should contain pps
and csd-1 sps (those values are also set this way by the MediaExtractor
(SDK MP4 demuxer).

> 
> - There are several timeouts to avoid deadlocks in the dataflow,
>   apparently. Is this inherently needed, or only because of the
>   libavcodec API, which requires returning 0 or 1 output frames per
>   input packet?

It is needed for different reasons:
  * The MediaCodec API does not guarantee 1 input - 1 output,

  * The MediaCodec API needs to be fed with enough buffers before
  it outputs its first buffer. And you want to do that as fast as
  possible (this is why in this case, I make the API returns immediately
  when I try to dequeue the output buffers when it hasn't returned any
  frames yet).

  * You also don't want to wait forever for an input buffer or an output
  buffer to be available because if the internal queue of the codec is
  full, you'll never get an input buffer available and if the codec hasn't
  consumed enough packets, you'll never get an output buffer.

  * Also in theory, you would be able to block forever when the codec is
  flushing its remaining frames. I preferred to not block forever but
  for a fair amount of time so if it happens that there is bug in the
  codec implementation or something else, it won't deadlock the whole
  process.

> 
> - The JNI code uses braces in case labels: "case (FF_JNI_FIELD): {"
>   (Seems unusual coding style.)

The reason for this is to declare and scope local variables to the
case block. If this style is not allowed in FFmpeg, I will removed the
braces.

Matthieu
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-23 Thread wm4
On Tue, 23 Feb 2016 09:53:43 +0100
Matthieu Bouron  wrote:

> On Mon, Feb 22, 2016 at 01:08:49PM +0100, Michael Niedermayer wrote:
> > On Mon, Feb 22, 2016 at 12:20:36PM +0100, Matthieu Bouron wrote:  
> > > From: Matthieu Bouron   
> > [...]  
> > > +codec = (*env)->NewObject(env, jfields.mediacodec_list_class, 
> > > jfields.init_id, 0);
> > > +if (!codec) {
> > > +av_log(NULL, AV_LOG_ERROR, "Could not create media codec 
> > > list\n");
> > > +goto done;
> > > +}
> > > +
> > > +tmp = (*env)->CallObjectMethod(env, codec, 
> > > jfields.find_decoder_for_format_id, format);
> > > +if (!tmp) {
> > > +av_log(NULL, AV_LOG_ERROR, "Could not find decoder in media 
> > > codec list\n");
> > > +goto done;
> > > +}
> > > +
> > > +name = ff_jni_jstring_to_utf_chars(env, tmp, NULL);
> > > +if (!name) {  
> >   
> > > +av_log(NULL, AV_LOG_ERROR, "Could not convert jstring to utf 
> > > chars\n");  
> > 
> > some non NULL context would be better, if possible, so the user knows
> > where an error came from  
> 
> It would require to pass the log_ctx (avctx) as an argument of
> ff_AMediaCodecList_getCodecByName.
> 
> All the functions of this wrapper does not take a log_ctx as argument
> to be as close as possible to the original NDK MediaCodec API. The
> NDK MediaCodec API does not provide any wrapper around MediaCodecList.
> 
> I would like the whole wrapper API to be consistent but also as close as
> possible to original one.
> If you think it's mandatory I can add a log_ctx argument to every
> functions of the wrapper API (so it will be used directly by av_log and
> ff_jni_exception_check).
> 
> On another note, I fixed locally this part of the code by adding missing calls
> to ff_jni_exception_check.
> 
> [...]

Is it possible to store the log_ctx somewhere in the JNI?

We might at some point in the future forbid av_log(NULL, ...) calls, and
then it'd get complicated.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-23 Thread wm4
On Mon, 22 Feb 2016 12:20:36 +0100
Matthieu Bouron  wrote:

> From: Matthieu Bouron 
> 
> ---


> +FFAMediaFormat *ff_AMediaFormat_new()
> +{
> +int attached = 0;

That's C++, not C. In C it needs to be *ff_AMediaFormat_new(void). An
empty argument list means that the argument list is unknown and
arbitrary.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavc: add h264 mediacodec decoder

2016-02-23 Thread wm4
On Tue, 23 Feb 2016 10:21:10 +0100
Matthieu Bouron  wrote:

> On Mon, Feb 22, 2016 at 02:55:06PM +0100, wm4 wrote:
> > On Mon, 22 Feb 2016 12:20:36 +0100
> > Matthieu Bouron  wrote:
> >   
> > > From: Matthieu Bouron 
> > > 
> > > ---
> > > ...  
> > 
> > Some remarks:
> > 
> > - The qcom stuff should probably be moved into its own source file,
> >   because it's a lot of code, but self-contained.  
> 
> I'll move the copy / conversion routines to another file. Would you be OK
> with that ? Or do you want only the qcom stuff in a separate file
> (probably named mediacodec_buffer.c,h) ?

Well, I just thought that the qcom code looks relatively
self-contained, so it'd be a good candidate to move away.

> > 
> > - Do you really need h264_extradata_to_annexb_sps_pps? The BSF already
> >   creates mp4-style extradata, which MediaCodec apparently can take
> >   directly.  
> 
> I will do more testing and remove it if possible in the next revision of
> the patch. The original idea behind it was to comply with the
> documentation that states that for the h264 codec csd-0 should contain pps
> and csd-1 sps (those values are also set this way by the MediaExtractor
> (SDK MP4 demuxer).

Yeah, but in the non-Annex-B if branch you set csd-0 to the whole
extradata, without bothering to split it by pps and sps.

> > 
> > - There are several timeouts to avoid deadlocks in the dataflow,
> >   apparently. Is this inherently needed, or only because of the
> >   libavcodec API, which requires returning 0 or 1 output frames per
> >   input packet?  
> 
> It is needed for different reasons:
>   * The MediaCodec API does not guarantee 1 input - 1 output,
> 
>   * The MediaCodec API needs to be fed with enough buffers before
>   it outputs its first buffer. And you want to do that as fast as
>   possible (this is why in this case, I make the API returns immediately
>   when I try to dequeue the output buffers when it hasn't returned any
>   frames yet).
> 
>   * You also don't want to wait forever for an input buffer or an output
>   buffer to be available because if the internal queue of the codec is
>   full, you'll never get an input buffer available and if the codec hasn't
>   consumed enough packets, you'll never get an output buffer.
> 
>   * Also in theory, you would be able to block forever when the codec is
>   flushing its remaining frames. I preferred to not block forever but
>   for a fair amount of time so if it happens that there is bug in the
>   codec implementation or something else, it won't deadlock the whole
>   process.

All these problems sound pretty similar to the problems I had in MMAL
(an API relatively similar to OMX), which is asynchronous and has
decoupled input/output. It's very fragile and can't do without
timeouts, but I didn't find a better way to handle it either. I'm
thinking about proposing a new decode API for libavcodec, which would
make interacting with this type of API much simpler.

> > 
> > - The JNI code uses braces in case labels: "case (FF_JNI_FIELD): {"
> >   (Seems unusual coding style.)  
> 
> The reason for this is to declare and scope local variables to the
> case block. If this style is not allowed in FFmpeg, I will removed the
> braces.

That's fine. I mean why isn't it "case FF_JNI_FIELD: {"?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel