[libav-devel] [PATCH] avresample: Introduce AVFrame-based API

2014-05-09 Thread Luca Barbato
---

Updated the documentation mostly, the function hadn't been exposed yet but it 
would, I can prepare examples
or let other do for me =)

 libavresample/avresample.h |  73 +
 libavresample/utils.c  | 130 +
 libavutil/error.h  |   2 +
 3 files changed, 205 insertions(+)

diff --git a/libavresample/avresample.h b/libavresample/avresample.h
index 0d42e88..7b29313 100644
--- a/libavresample/avresample.h
+++ b/libavresample/avresample.h
@@ -95,6 +95,7 @@
 #include "libavutil/avutil.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/dict.h"
+#include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/mathematics.h"

@@ -165,6 +166,10 @@ AVAudioResampleContext *avresample_alloc_context(void);

 /**
  * Initialize AVAudioResampleContext.
+ * @note The context must be configured using the AVOption api.
+ *
+ * @see av_opt_set_int()
+ * @see av_opt_set_dict()
  *
  * @param avr  audio resample context
  * @return 0 on success, negative AVERROR code on failure
@@ -424,6 +429,74 @@ int avresample_available(AVAudioResampleContext *avr);
  */
 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int 
nb_samples);

+
+
+/**
+ * Convert the samples in the input AVFrame and write them to the output 
AVFrame.
+ *
+ * Input and output AVFrames must have channel_layout, sample_rate and format 
set.
+ *
+ * The upper bound on the number of output samples is obtained through
+ * avresample_max_output_samples().
+ *
+ * If the output AVFrame does not have the data pointers allocated a the 
nb_samples
+ * will be set as described above and av_frame_get_buffer() will be called.
+ *
+ * The output AVFrame can be NULL or have fewer allocated samples than 
required.
+ *
+ * In this case, any remaining samples not written to the output will be added
+ * to an internal FIFO buffer, to be returned at the next call to this function
+ * or to avresample_convert() or to avresample_read().
+ *
+ * If converting sample rate, there may be data remaining in the internal
+ * resampling delay buffer. avresample_get_delay() tells the number of
+ * remaining samples. To get this data as output, call this function or
+ * avresample_convert() with NULL input.
+ *
+ * At the end of the conversion process, there may be data remaining in the
+ * internal FIFO buffer. avresample_available() tells the number of remaining
+ * samples. To get this data as output, either call this function or
+ * avresample_convert() with NULL input or call avresample_read().
+ *
+ * If the AVAudioResampleContext configuration does not match the output and
+ * input AVFrame settings the conversion does not take place and depending on
+ * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED
+ * or AVERROR_OUTPUT_CHANGED|AVERROR_INPUT_CHANGED is returned.
+ *
+ * @see avresample_max_output_samples()
+ * @see avresample_available()
+ * @see avresample_convert()
+ * @see avresample_read()
+ * @see avresample_get_delay()
+ *
+ * @param avr audio resample context
+ * @param output  output AVFrame
+ * @param input   input AVFrame
+ * @return0 on success, AVERROR on failure or nonmatching
+ *configuration.
+ */
+int avresample_convert_frame(AVAudioResampleContext *avr,
+ AVFrame *output, AVFrame *input);
+
+/**
+ * Configure or reconfigure the AVAudioResampleContext using the information
+ * provided by the AVFrames and an optional AVDictionary containing additional
+ * resampler options.
+ *
+ * The original resampling context is reset even on failure.
+ * The function calls internally avresample_open().
+ *
+ * @see avresample_open();
+ *
+ * @param avr audio resample context
+ * @param output  output AVFrame
+ * @param input   input AVFrame
+ * @param optsadditional options
+ * @return0 on success, AVERROR on failure.
+ */
+int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in,
+  AVDictionary **opts);
+
 /**
  * @}
  */
diff --git a/libavresample/utils.c b/libavresample/utils.c
index 04c4f46..e607dd9 100644
--- a/libavresample/utils.c
+++ b/libavresample/utils.c
@@ -21,6 +21,7 @@
 #include "libavutil/common.h"
 #include "libavutil/dict.h"
 #include "libavutil/error.h"
+#include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -506,6 +507,135 @@ int attribute_align_arg 
avresample_convert(AVAudioResampleContext *avr,
   current_buffer);
 }

+
+int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in,
+  AVDictionary **opts)
+{
+int ret;
+
+if (avresample_is_open(avr)) {
+avresample_close(avr);
+}
+
+if (in) {
+avr->in_channel_layout  = in->channel_layout;
+avr->in_sampl

Re: [libav-devel] [PATCH 2/2] avresample: Introduce AVFrame-based API

2014-05-09 Thread Justin Ruggles

On 05/05/2014 10:11 AM, Luca Barbato wrote:

+ * The upper bound on the number of output samples is given by
+ * avresample_available() + (avresample_get_delay() + number of input samples) 
*
+ * output sample rate / input sample rate.


Change this to avresample_max_output_samples()

-Justin

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] avresample: Introduce AVFrame-based API

2014-05-09 Thread Justin Ruggles

On 05/09/2014 04:18 AM, Luca Barbato wrote:

On 09/05/14 09:59, wm4 wrote:

On Mon,  5 May 2014 16:11:33 +0200
Luca Barbato  wrote:


---
  libavresample/avresample.h |  72 +
  libavresample/utils.c  | 128 +
  libavutil/error.h  |   2 +
  3 files changed, 202 insertions(+)

[...]
Should opts be allowed to be NULL?

Might be a good idea.


Definitely a good idea and would match the lavf and lavc APIs.


IMO there absolutely should be a public function that should check
whether two AVFrames have the same configuration, and/or a function
which checks whether an AVFrame is the same as the current configured
in/out format of the context (like the private config_changed).

The function can be exposed anytime, Justin wanted me to prepare a
commit with the least API increment so I kept it hidden.



I suppose allowing the user to be pro-active and check for changes 
separately would be fine to add at the same time. We could give both 
usage examples, checking separately or just handling the return codes.


-Justin


___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] Importing GIF encoder from ffmpeg

2014-05-09 Thread Alessandro Ghedini
On mer, mag 07, 2014 at 01:37:16 +0200, Luca Barbato wrote:
> On 07/05/14 00:37, Alessandro Ghedini wrote:
> > Hi,
> > 
> > I've been working on merging the GIF encoder from ffmpeg, since libav's 
> > doesn't
> > seem to work very well (in my tests anyway), and my initial approach has 
> > been to
> > simply copy/paste lavc/gif.{c,h} and lavf/gif.c, make them compile and see 
> > how
> > it goes (I'm using libav.git).
> > 
> > While I've been able to compile the whole thing (with a little bit of work, 
> > due
> > to missing av_copy_packet() and ff_alloc_packet2()),
> 
> av_copy_packet in a muxer sounds strange, in libav we do not have such
> function since avpackets are refcounted.

I've tried to replace av_copy_packet() with av_packet_ref() but it doesn't seem
to work (I get a whole bunch of "free(): invalid pointer" errors).

The packet copying was added in commit a7c5b7a6 to "correct the delay after the
first frame", which is needed for "low frame rate and large scene change". I
guess we could do without it, but those use cases won't work with libav.

> ff_alloc_packet2 from what I can recall keeps 1 packet cache in
> avcodeccontext, but then if you always copy/duplicate the avpacket
> produced it gets a little pointless having it, even worse if you have mt
> encoders.

I simply replaced it with ff_alloc_packet(). Not sure if that's ok though, and
maybe it has something to do with ffmpeg's gif encoder not working in libav.

Cheers


signature.asc
Description: Digital signature
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] mp3: enable packed main_data decoding in MP4

2014-05-09 Thread Luca Barbato
On 09/05/14 16:59, nu774 wrote:
> Sample file for this:
> https://dl.dropboxusercontent.com/u/76042064/packed_maindata.mp3.mp4
> 
> (Had to create on my own since I have never seen such file in the wild).
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
> 


Thank you a lot! Providing patches plus samples is the best for us =)

lu
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/1] SQUASH: opus_celt: eliminate duplicate variable

2014-05-09 Thread Janne Grunau
---
 libavcodec/opus_celt.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index 3c86f66..1e7fadb 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -2105,7 +2105,6 @@ int ff_celt_decode_frame(CeltContext *s, OpusRangeCoder 
*rc,
 
 for (i = 0; i < 2; i++ ) {
 CeltFrame *frame = &s->frame[i];
-int j;
 
 if (!transient) {
 memcpy(frame->prev_energy[1], frame->prev_energy[0], 
sizeof(frame->prev_energy[0]));
-- 
1.9.2

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] mp3: enable packed main_data decoding in MP4

2014-05-09 Thread nu774
Sample file for this:
https://dl.dropboxusercontent.com/u/76042064/packed_maindata.mp3.mp4

(Had to create on my own since I have never seen such file in the wild).
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] mp3: enable packed main_data decoding in MP4

2014-05-09 Thread nu774
14496-3 suggests packing main_data of MP3 that is usually scatttered into
multiple frames due to bit reservoir.
However, after packing main_data into a access unit, bitrate index in the
MPEG audio frame header doesn't match with actual frame size.
In order to accept this, this patch removes unnecessary frame size checking
on mp3 decoder.
Also, mov demuxer was changed to use MP3 parser only on special cases
(QT MOV with specific sample description) to avoid re-packetizing.
---
 libavcodec/mpegaudiodec_template.c |7 ---
 libavformat/mov.c  |   10 +-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegaudiodec_template.c 
b/libavcodec/mpegaudiodec_template.c
index 9ce03ef..8f25c82 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1647,13 +1647,6 @@ static int decode_frame(AVCodecContext * avctx, void 
*data, int *got_frame_ptr,
 if (!avctx->bit_rate)
 avctx->bit_rate = s->bit_rate;
 
-if (s->frame_size <= 0 || s->frame_size > buf_size) {
-av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
-return AVERROR_INVALIDDATA;
-} else if (s->frame_size < buf_size) {
-buf_size= s->frame_size;
-}
-
 s->frame = data;
 
 ret = mp_decode_frame(s, NULL, buf, buf_size);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e3dc67b..0aacd0a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1256,6 +1256,15 @@ static void mov_parse_stsd_audio(MOVContext *c, 
AVIOContext *pb,
 ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample,
  flags);
 }
+if (version == 0 || (version == 1 && sc->audio_cid != -2)) {
+/* can't correctly handle variable sized packet as audio unit */
+switch (st->codec->codec_id) {
+case AV_CODEC_ID_MP2:
+case AV_CODEC_ID_MP3:
+st->need_parsing = AVSTREAM_PARSE_FULL;
+break;
+}
+}
 }
 
 switch (st->codec->codec_id) {
@@ -1424,7 +1433,6 @@ static int mov_finalize_stsd_codec(MOVContext *c, 
AVIOContext *pb,
 case AV_CODEC_ID_MP3:
 /* force type after stsd for m1a hdlr */
 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-st->need_parsing  = AVSTREAM_PARSE_FULL;
 break;
 case AV_CODEC_ID_GSM:
 case AV_CODEC_ID_ADPCM_MS:
-- 
1.7.9

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] pcm-dvd: fix 20bit decoding

2014-05-09 Thread nu774

Uploaded a sample:
https://dl.dropboxusercontent.com/u/76042064/pcm-20bit.VOB
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] pcm-dvd: fix 20bit decoding

2014-05-09 Thread Luca Barbato
On 09/05/14 14:47, nu774 wrote:
> Bug-ID: 592

Whoever that pushes "Bug-Id: 592

The patch looks correct, do you happen to have sample we could check as
well?

Thanks a lot!

lu
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] pcm-dvd: fix 20bit decoding

2014-05-09 Thread nu774
Bug-ID: 592
---
 libavcodec/pcm-dvd.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
index 172e93a..0872d29 100644
--- a/libavcodec/pcm-dvd.c
+++ b/libavcodec/pcm-dvd.c
@@ -177,11 +177,11 @@ static void *pcm_dvd_decode_samples(AVCodecContext 
*avctx, const uint8_t *src,
 dst32[2] = bytestream2_get_be16u(&gb) << 16;
 dst32[3] = bytestream2_get_be16u(&gb) << 16;
 t = bytestream2_get_byteu(&gb);
-*dst32 += (t & 0xf0) << 8;
-*dst32 += (t & 0x0f) << 12;
+*dst32++ += (t & 0xf0) << 8;
+*dst32++ += (t & 0x0f) << 12;
 t = bytestream2_get_byteu(&gb);
-*dst32 += (t & 0xf0) << 8;
-*dst32 += (t & 0x0f) << 12;
+*dst32++ += (t & 0xf0) << 8;
+*dst32++ += (t & 0x0f) << 12;
 }
 } while (--blocks);
 return dst32;
-- 
1.7.9

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] configure: check for recent dxva2api headers with fixed COBJMACROS defines

2014-05-09 Thread Tim Walker
On 09 May 2014, at 13:54, Hendrik Leppkes  wrote:

> This fixes build failures on older mingw chains (before 2012).
> ---
> configure | 13 -
> 1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 47fd690..bdf4f66 100755
> --- a/configure
> +++ b/configure
> @@ -4016,6 +4017,16 @@ disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion 
> -lbz2 || disable bzlib
> check_lib math.h sin -lm && LIBM="-lm"
> enabled vaapi && require vaapi va/va.h vaInitialize -lva
> 
> +enabled dxva2api_h &&
> +check_cc < +#define _WIN32_WINNT 0x0600

Nit: maybe add a comment explaining the value is _WIN32_WINNT_VISTA?

Tim
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] configure: check for recent dxva2api headers with fixed COBJMACROS defines

2014-05-09 Thread Hendrik Leppkes
On Fri, May 9, 2014 at 1:54 PM, Hendrik Leppkes  wrote:
> This fixes build failures on older mingw chains (before 2012).
> ---
>  configure | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 47fd690..bdf4f66 100755
> --- a/configure
> +++ b/configure
> @@ -1505,6 +1505,7 @@ HAVE_LIST="
>  $TYPES_LIST
>  atomics_native
>  dos_paths
> +dxva2api_cobj
>  dxva2_lib
>  libc_msvcrt
>  libdc1394_1
> @@ -4016,6 +4017,16 @@ disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion 
> -lbz2 || disable bzlib
>  check_lib math.h sin -lm && LIBM="-lm"
>  enabled vaapi && require vaapi va/va.h vaInitialize -lva
>
> +enabled dxva2api_h &&
> +check_cc < +#define _WIN32_WINNT 0x0600
> +#define COBJMACROS
> +#include 
> +#include 
> +#include 
> +int main(void) { IDirectXVideoDecoder *o = NULL; 
> IDirectXVideoDecoder_Release(o); return 0; }
> +EOF
> +

Sadly there didn't seem to be a finished macro to make testing this
easier, to I had to use check_cc which makes it look kinda bloated -
but its tested to work.
Better ideas welcome.

- Hendrik
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/1] SQUASH: opus: imdct: factor scale multiplication out

2014-05-09 Thread Janne Grunau
---
 libavcodec/opus_imdct.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/opus_imdct.c b/libavcodec/opus_imdct.c
index aa1b0d6..09037da 100644
--- a/libavcodec/opus_imdct.c
+++ b/libavcodec/opus_imdct.c
@@ -262,11 +262,11 @@ static void celt_imdct_half(CeltIMDCTContext *s, float 
*dst, const float *src,
 for (i = 0; i < len8; i++) {
 float r0, i0, r1, i1;
 
-CMUL3(r0, i1, scale * z[len8 - i - 1].im, scale * z[len8 - i - 1].re,  
s->twiddle_exptab[len8 - i - 1].im, s->twiddle_exptab[len8 - i - 1].re);
-CMUL3(r1, i0, scale * z[len8 + i].im, scale * z[len8 + i].re,  
s->twiddle_exptab[len8 + i].im, s->twiddle_exptab[len8 + i].re);
-z[len8 - i - 1].re = r0;
-z[len8 - i - 1].im = i0;
-z[len8 + i].re = r1;
-z[len8 + i].im = i1;
+CMUL3(r0, i1, z[len8 - i - 1].im, z[len8 - i - 1].re,  
s->twiddle_exptab[len8 - i - 1].im, s->twiddle_exptab[len8 - i - 1].re);
+CMUL3(r1, i0, z[len8 + i].im, z[len8 + i].re,  
s->twiddle_exptab[len8 + i].im, s->twiddle_exptab[len8 + i].re);
+z[len8 - i - 1].re = scale * r0;
+z[len8 - i - 1].im = scale * i0;
+z[len8 + i].re = scale * r1;
+z[len8 + i].im = scale * i1;
 }
 }
-- 
1.9.2

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] configure: check for recent dxva2api headers with fixed COBJMACROS defines

2014-05-09 Thread Hendrik Leppkes
This fixes build failures on older mingw chains (before 2012).
---
 configure | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 47fd690..bdf4f66 100755
--- a/configure
+++ b/configure
@@ -1505,6 +1505,7 @@ HAVE_LIST="
 $TYPES_LIST
 atomics_native
 dos_paths
+dxva2api_cobj
 dxva2_lib
 libc_msvcrt
 libdc1394_1
@@ -4016,6 +4017,16 @@ disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion 
-lbz2 || disable bzlib
 check_lib math.h sin -lm && LIBM="-lm"
 enabled vaapi && require vaapi va/va.h vaInitialize -lva
 
+enabled dxva2api_h &&
+check_cc <
+#include 
+#include 
+int main(void) { IDirectXVideoDecoder *o = NULL; 
IDirectXVideoDecoder_Release(o); return 0; }
+EOF
+
 atan2f_args=2
 ldexpf_args=2
 powf_args=2
@@ -4356,7 +4367,7 @@ check_deps $CONFIG_LIST   \
$HAVE_LIST \
$ALL_COMPONENTS\
 
-enabled_all dxva2 CoTaskMemFree &&
+enabled_all dxva2 dxva2api_cobj CoTaskMemFree &&
 prepend avconv_libs $($ldflags_filter "-lole32") &&
 enable dxva2_lib
 
-- 
1.9.2.msysgit.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] avresample: Introduce AVFrame-based API

2014-05-09 Thread Luca Barbato
On 09/05/14 09:59, wm4 wrote:
> On Mon,  5 May 2014 16:11:33 +0200
> Luca Barbato  wrote:
> 
>> ---
>>  libavresample/avresample.h |  72 +
>>  libavresample/utils.c  | 128 
>> +
>>  libavutil/error.h  |   2 +
>>  3 files changed, 202 insertions(+)
>>
>> diff --git a/libavresample/avresample.h b/libavresample/avresample.h
>> index 0d42e88..37b92d3 100644
>> --- a/libavresample/avresample.h
>> +++ b/libavresample/avresample.h
>> @@ -95,6 +95,7 @@
>>  #include "libavutil/avutil.h"
>>  #include "libavutil/channel_layout.h"
>>  #include "libavutil/dict.h"
>> +#include "libavutil/frame.h"
>>  #include "libavutil/log.h"
>>  #include "libavutil/mathematics.h"
>>  
>> @@ -165,6 +166,10 @@ AVAudioResampleContext *avresample_alloc_context(void);
>>  
>>  /**
>>   * Initialize AVAudioResampleContext.
>> + * @note The context must be configured using the AVOption api.
>> + *
>> + * @see av_opt_set_int()
>> + * @see av_opt_set_dict()
>>   *
>>   * @param avr  audio resample context
>>   * @return 0 on success, negative AVERROR code on failure
>> @@ -424,6 +429,73 @@ int avresample_available(AVAudioResampleContext *avr);
>>   */
>>  int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int 
>> nb_samples);
>>  
>> +
>> +
>> +/**
>> + * Convert the samples in the input AVFrame and write them to the output 
>> AVFrame.
>> + *
>> + * Input and output AVFrames must have channel_layout, sample_rate and 
>> format set.
> 
> What about other things. Will side-data be used? Both
> AV_FRAME_DATA_MATRIXENCODING and AV_FRAME_DATA_DOWNMIX_INFO
> seem relevant.
> 
> (I know the patch currently doesn't implement them. But should they in
> the future? If so, should that be reflected in the documentation? There
> needs to be forward-compatibility too.)

I'd mention them when they are supported, having that information
missing won't make the conversion fail.

> You should also mention avresample_max_output_samples().

Good catch! Thank you.

> Annoying corner cases: what if the format is planar and only some
> pointers are allocated? I guess this should be considered invalid.

Not sure that is the right place to check it, but yes, it would be invalid.

> IMO this absolutely should provide a example how to convert a stream of
> input AVFrame (in any format). The code fragment should fully handle
> format changes. It's best to provide this right in the docs, instead of
> requiring every API user to reinvent it badly.

I do agree, I'd put the snippet in the code and have a working example
in the docs/examples.

>> + * @param avr audio resample context
>> + * @param output  output AVFrame
>> + * @param input   input AVFrame
>> + * @return0 on success, AVERROR on failure or nonmatching
>> + *configuration.
>> + */
>> +int avresample_convert_frame(AVAudioResampleContext *avr,
>> + AVFrame *output, AVFrame *input);
>> +
>> +/**
>> + * Configure or reconfigure the AVAudioResampleContext using the information
>> + * provided by the AVFrames and an optional AVDictionary containing 
>> additional
>> + * resampler options.
>> + *
>> + * The original resampling context is reset even on failure.
>> + * The function calls internally avresample_open().
>> + *
>> + * @see avresample_open();
>> + *
>> + * @param avr audio resample context
>> + * @param output  output AVFrame
>> + * @param input   input AVFrame
> 
> Forgets opts.
> 
> Should opts be allowed to be NULL?

Might be a good idea.

> IMO there absolutely should be a public function that should check
> whether two AVFrames have the same configuration, and/or a function
> which checks whether an AVFrame is the same as the current configured
> in/out format of the context (like the private config_changed).

The function can be exposed anytime, Justin wanted me to prepare a
commit with the least API increment so I kept it hidden.

lu


___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] avresample: Introduce AVFrame-based API

2014-05-09 Thread wm4
On Mon,  5 May 2014 16:11:33 +0200
Luca Barbato  wrote:

> ---
>  libavresample/avresample.h |  72 +
>  libavresample/utils.c  | 128 
> +
>  libavutil/error.h  |   2 +
>  3 files changed, 202 insertions(+)
> 
> diff --git a/libavresample/avresample.h b/libavresample/avresample.h
> index 0d42e88..37b92d3 100644
> --- a/libavresample/avresample.h
> +++ b/libavresample/avresample.h
> @@ -95,6 +95,7 @@
>  #include "libavutil/avutil.h"
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/dict.h"
> +#include "libavutil/frame.h"
>  #include "libavutil/log.h"
>  #include "libavutil/mathematics.h"
>  
> @@ -165,6 +166,10 @@ AVAudioResampleContext *avresample_alloc_context(void);
>  
>  /**
>   * Initialize AVAudioResampleContext.
> + * @note The context must be configured using the AVOption api.
> + *
> + * @see av_opt_set_int()
> + * @see av_opt_set_dict()
>   *
>   * @param avr  audio resample context
>   * @return 0 on success, negative AVERROR code on failure
> @@ -424,6 +429,73 @@ int avresample_available(AVAudioResampleContext *avr);
>   */
>  int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int 
> nb_samples);
>  
> +
> +
> +/**
> + * Convert the samples in the input AVFrame and write them to the output 
> AVFrame.
> + *
> + * Input and output AVFrames must have channel_layout, sample_rate and 
> format set.

What about other things. Will side-data be used? Both
AV_FRAME_DATA_MATRIXENCODING and AV_FRAME_DATA_DOWNMIX_INFO
seem relevant.

(I know the patch currently doesn't implement them. But should they in
the future? If so, should that be reflected in the documentation? There
needs to be forward-compatibility too.)

> + *
> + * The upper bound on the number of output samples is given by
> + * avresample_available() + (avresample_get_delay() + number of input 
> samples) *
> + * output sample rate / input sample rate.
> + *

You should also mention avresample_max_output_samples().

> + * If the output AVFrame does not have the data pointers allocated a the 
> nb_samples
> + * will be set as described above and av_frame_get_buffer() will be called.
> + *

Annoying corner cases: what if the format is planar and only some
pointers are allocated? I guess this should be considered invalid.

> + * The output AVFrame can be NULL or have fewer allocated samples than 
> required.
> + *
> + * In this case, any remaining samples not written to the output will be 
> added
> + * to an internal FIFO buffer, to be returned at the next call to this 
> function
> + * or to avresample_convert() or to avresample_read().
> + *
> + * If converting sample rate, there may be data remaining in the internal
> + * resampling delay buffer. avresample_get_delay() tells the number of
> + * remaining samples. To get this data as output, call this function or
> + * avresample_convert() with NULL input.
> + *
> + * At the end of the conversion process, there may be data remaining in the
> + * internal FIFO buffer. avresample_available() tells the number of remaining
> + * samples. To get this data as output, either call this function or
> + * avresample_convert() with NULL input or call avresample_read().
> + *
> + * If the AVAudioResampleContext configuration does not match the output and
> + * input AVFrame settings the conversion does not take place and depending on
> + * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, 
> AVERROR_INPUT_CHANGED
> + * or AVERROR_OUTPUT_CHANGED|AVERROR_INPUT_CHANGED is returned.
> + *
> + * @see avresample_available()
> + * @see avresample_convert()
> + * @see avresample_read()
> + * @see avresample_get_delay()
> + *

IMO this absolutely should provide a example how to convert a stream of
input AVFrame (in any format). The code fragment should fully handle
format changes. It's best to provide this right in the docs, instead of
requiring every API user to reinvent it badly.

> + * @param avr audio resample context
> + * @param output  output AVFrame
> + * @param input   input AVFrame
> + * @return0 on success, AVERROR on failure or nonmatching
> + *configuration.
> + */
> +int avresample_convert_frame(AVAudioResampleContext *avr,
> + AVFrame *output, AVFrame *input);
> +
> +/**
> + * Configure or reconfigure the AVAudioResampleContext using the information
> + * provided by the AVFrames and an optional AVDictionary containing 
> additional
> + * resampler options.
> + *
> + * The original resampling context is reset even on failure.
> + * The function calls internally avresample_open().
> + *
> + * @see avresample_open();
> + *
> + * @param avr audio resample context
> + * @param output  output AVFrame
> + * @param input   input AVFrame

Forgets opts.

Should opts be allowed to be NULL?

> + * @return0 on success, AVERROR on failure.
> + */
> +int avres