[FFmpeg-soc] [PATCH] lavfi audio framework

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Aug 2 12:24:36 CEST 2010


On date Monday 2010-08-02 01:57:57 -0700, S.N. Hemanth Meenakshisundaram encoded:
> lavfi audio fw using the generalized AVFilterBufferRef struct. Anonymous
> unions weren't allowed so I had to give the unions some names. Please
> review and comment.
> 
> ---
>  ffmpeg.c                     |    6 +-
>  ffplay.c                     |   12 ++--
>  libavfilter/avfilter.c       |   59 +++++++++++++++++++++-
>  libavfilter/avfilter.h       |  115 +++++++++++++++++++++++++++++++++++-------
>  libavfilter/defaults.c       |  105 ++++++++++++++++++++++++++++++++++++--
>  libavfilter/formats.c        |    3 +-
>  libavfilter/vf_aspect.c      |    2 +-
>  libavfilter/vf_crop.c        |    4 +-
>  libavfilter/vf_drawbox.c     |    6 +-
>  libavfilter/vf_fifo.c        |    2 +-
>  libavfilter/vf_fps.c         |    2 +-
>  libavfilter/vf_hflip.c       |    2 +-
>  libavfilter/vf_overlay.c     |    8 ++--
>  libavfilter/vf_pad.c         |    2 +-
>  libavfilter/vf_pixdesctest.c |    2 +-
>  libavfilter/vf_rotate.c      |   12 ++--
>  libavfilter/vf_scale.c       |    6 +-
>  libavfilter/vf_transpose.c   |   18 +++---
>  libavfilter/vsrc_buffer.c    |    8 ++--
>  19 files changed, 302 insertions(+), 72 deletions(-)

[...]
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 96fca21..c433c6c 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -99,21 +99,38 @@ typedef struct AVFilterBuffer
>  typedef struct AVFilterBufferRef
>  {
>      AVFilterBuffer *buf;        ///< the buffer that this is a reference to
> -    uint8_t *data[4];           ///< picture data for each plane
> -    int linesize[4];            ///< number of bytes per line
> -    int w;                      ///< image width
> -    int h;                      ///< image height
> +    uint8_t *data[8];           ///< picture/audio data for each plane/channel
> +    int linesize[8];            ///< number of bytes per line
>      int format;                 ///< media format
> +    int perms;                  ///< permissions, see the AV_PERM_* flags
>  
>      int64_t pts;                ///< presentation timestamp in units of 1/AV_TIME_BASE
>      int64_t pos;                ///< byte position in stream, -1 if unknown
>  
> -    AVRational pixel_aspect;    ///< pixel aspect ratio
> -
> -    int perms;                  ///< permissions, see the AV_PERM_* flags
> +    union {
> +        AVRational pixel_aspect; ///< pixel aspect ratio of video buffer
> +        int64_t channel_layout;  ///< channel layout of audio buffer
> +    } desc;
> +
> +    union {
> +        int w;                   ///< image width
> +        int samples_nb;          ///< number of audio samples
> +    } dim1;
> +    union {
> +        int h;                   ///< image height
> +        int size;                ///< audio buffer size
> +    } dim2;
> +
> +    union {
> +        int interlaced;          ///< is video frame interlaced
> +        uint32_t sample_rate;    ///< audio buffer sample rate
> +    } prop;
> +
> +    union {
> +        int top_field_first;     ///< video field order
> +        int planar;              ///< audio buffer - planar or packed
> +    } packing;
>  
> -    int interlaced;             ///< is frame interlaced
> -    int top_field_first;
>  } AVFilterBufferRef;

My idea was:

typedef struct AVFilterBufferRefAudioProps {
    enum SampleFormat format;
    int size;
    int samples_nb;          ///< number of audio samples
    int planar;              ///< audio buffer - planar or packed
    int64_t channel_layout;  ///< channel layout of audio buffer
} AVFilterBufferRefAudioProps;

typedef struct AVFilterBufferRefVideoProps {
    enum PixelFormat format;
    AVRational pixel_aspect; ///< pixel aspect ratio of video buffer
    int w, h;
    int interlaced;          ///< is video frame interlaced
    int top_field_first;     ///< video field order
} AVFilterBufferRefVideoProps;

typedef struct AVFilterBufferRef {
    AVFilterBuffer *buf;        ///< the buffer that this is a reference to
    uint8_t *data[8];           ///< picture/audio data for each plane/channel
    int linesize[8];            ///< number of bytes per line
    enum AVMediaType type;   

    int format;                 ///< media format, this can be eventually moved to the media props
    int perms;                  ///< permissions, see the AV_PERM_* flags
  
    int64_t pts;                ///< presentation timestamp in units of 1/AV_TIME_BASE
    int64_t pos;                ///< byte position in stream, -1 if unknown

    union {
        AVFilterBufferRefAudioProps audio;
        AVFilterBufferRefVideoProps video;
    } props;
} AVFilterBufferRef;

wxhere the semantics is:
"A filter buffer has a reference which has a media type and contains
some properties, which depends on the media type of the reference."

alternatively you may allocate the media props and reference them from
the AVFilterBufferRef through a void pointer:

void *props;  ///< media props, cast it to the right type

e.g.:

AVFilterBuffereRef *ref;
assert(ref->type == AVMEDIA_TYPE_AUDIO);
AVFilterBuffereRefAudioProps *props = ref->props;

This would be more robust (no ABI breaks at each media props field
addition), but may be potentially slower.

[...]

Regards.


More information about the FFmpeg-soc mailing list