libavfilter/formats.c File Reference

#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
#include "libavutil/parseutils.h"
#include "libavutil/audioconvert.h"
#include "avfilter.h"
#include "internal.h"
#include "formats.h"
#include "all_channel_layouts.inc"

Go to the source code of this file.

Defines

#define MERGE_REF(ret, a, fmts, type, fail)
 Add all refs from a to ret and destroy a.
#define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail)
 Add all formats common for a and b to ret, copy the refs and destroy a and b.
#define COPY_INT_LIST(list_copy, list, type)
#define MAKE_FORMAT_LIST(type, field, count_field)
#define ADD_FORMAT(f, fmt, type, list, nb)
#define FORMATS_REF(f, ref)
#define FIND_REF_INDEX(ref, idx)
#define FORMATS_UNREF(ref, list)
#define FORMATS_CHANGEREF(oldref, newref)
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list)

Functions

AVFilterFormatsavfilter_merge_formats (AVFilterFormats *a, AVFilterFormats *b)
 Return a format list which contains the intersection of the formats of a and b.
AVFilterFormatsff_merge_samplerates (AVFilterFormats *a, AVFilterFormats *b)
AVFilterChannelLayoutsff_merge_channel_layouts (AVFilterChannelLayouts *a, AVFilterChannelLayouts *b)
 Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates of a and b.
int ff_fmt_is_in (int fmt, const int *fmts)
 Tell is a format is contained in the provided list terminated by -1.
int * ff_copy_int_list (const int *const list)
 Return a copy of a list of integers terminated by -1, or NULL in case of copy failure.
int64_t * ff_copy_int64_list (const int64_t *const list)
 Return a copy of a list of 64-bit integers, or NULL in case of copy failure.
AVFilterFormatsavfilter_make_format_list (const int *fmts)
 Create a list of supported formats.
AVFilterChannelLayoutsavfilter_make_format64_list (const int64_t *fmts)
int avfilter_add_format (AVFilterFormats **avff, int64_t fmt)
 Add fmt to the list of media formats contained in *avff.
int ff_add_channel_layout (AVFilterChannelLayouts **l, uint64_t channel_layout)
AVFilterFormatsavfilter_all_formats (enum AVMediaType type)
AVFilterFormatsavfilter_make_all_formats (enum AVMediaType type)
 Return a list of all formats supported by FFmpeg for the given media type.
AVFilterFormatsavfilter_make_all_packing_formats (void)
 Return a list of all audio packing formats.
AVFilterFormatsff_all_samplerates (void)
AVFilterChannelLayoutsff_all_channel_layouts (void)
 Construct an empty AVFilterChannelLayouts/AVFilterFormats struct -- representing any channel layout/sample rate.
void ff_channel_layouts_ref (AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
 Add *ref as a new reference to f.
void avfilter_formats_ref (AVFilterFormats *f, AVFilterFormats **ref)
 Add *ref as a new reference to formats.
void avfilter_formats_unref (AVFilterFormats **ref)
 If *ref is non-NULL, remove *ref as a reference to the format list it currently points to, deallocates that list if this was the last reference, and sets *ref to NULL.
void ff_channel_layouts_unref (AVFilterChannelLayouts **ref)
 Remove a reference to a channel layouts list.
void ff_channel_layouts_changeref (AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
void avfilter_formats_changeref (AVFilterFormats **oldref, AVFilterFormats **newref)
 Before After ________ ________ |formats |<---------.
void ff_set_common_channel_layouts (AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
 A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
void ff_set_common_samplerates (AVFilterContext *ctx, AVFilterFormats *samplerates)
void avfilter_set_common_formats (AVFilterContext *ctx, AVFilterFormats *formats)
 A helper for query_formats() which sets all links to the same list of formats.
int ff_default_query_formats (AVFilterContext *ctx)
int ff_parse_pixel_format (enum PixelFormat *ret, const char *arg, void *log_ctx)
 Parse a pixel format.
int ff_parse_sample_format (int *ret, const char *arg, void *log_ctx)
 Parse a sample format name or a corresponding integer representation.
int ff_parse_time_base (AVRational *ret, const char *arg, void *log_ctx)
 Parse a time base.
int ff_parse_sample_rate (int *ret, const char *arg, void *log_ctx)
 Parse a sample rate.
int ff_parse_channel_layout (int64_t *ret, const char *arg, void *log_ctx)
 Parse a channel layout or a corresponding integer representation.
int avfilter_default_query_formats (AVFilterContext *ctx)
 Default handler for query_formats().

Variables

const int64_t avfilter_all_channel_layouts []
 A list of all channel layouts supported by libavfilter.


Define Documentation

#define ADD_FORMAT ( f,
fmt,
type,
list,
nb   ) 

Value:

do {                                                        \
    type *fmts;                                             \
                                                            \
    if (!(*f) && !(*f = av_mallocz(sizeof(**f))))           \
        return AVERROR(ENOMEM);                             \
                                                            \
    fmts = av_realloc((*f)->list,                           \
                      sizeof(*(*f)->list) * ((*f)->nb + 1));\
    if (!fmts)                                              \
        return AVERROR(ENOMEM);                             \
                                                            \
    (*f)->list = fmts;                                      \
    (*f)->list[(*f)->nb++] = fmt;                           \
    return 0;                                               \
} while (0)

Definition at line 236 of file formats.c.

Referenced by avfilter_add_format(), and ff_add_channel_layout().

#define COPY_INT_LIST ( list_copy,
list,
type   ) 

Value:

{                          \
    int count = 0;                                                      \
    if (list)                                                           \
        for (count = 0; list[count] != -1; count++)                     \
            ;                                                           \
    list_copy = av_calloc(count+1, sizeof(type));                       \
    if (list_copy) {                                                    \
        memcpy(list_copy, list, sizeof(type) * count);                  \
        list_copy[count] = -1;                                          \
    }                                                                   \
}

Definition at line 173 of file formats.c.

Referenced by ff_copy_int64_list(), and ff_copy_int_list().

#define FIND_REF_INDEX ( ref,
idx   ) 

Value:

do {                                        \
    int i;                                  \
    for (i = 0; i < (*ref)->refcount; i ++) \
        if((*ref)->refs[i] == ref) {        \
            idx = i;                        \
            break;                          \
        }                                   \
} while (0)

Definition at line 337 of file formats.c.

#define FORMATS_CHANGEREF ( oldref,
newref   ) 

Value:

do {                                            \
    int idx = -1;                               \
                                                \
    FIND_REF_INDEX(oldref, idx);                \
                                                \
    if (idx >= 0) {                             \
        (*oldref)->refs[idx] = newref;          \
        *newref = *oldref;                      \
        *oldref = NULL;                         \
    }                                           \
} while (0)

Definition at line 378 of file formats.c.

Referenced by avfilter_formats_changeref(), and ff_channel_layouts_changeref().

#define FORMATS_REF ( f,
ref   ) 

Value:

do {                                                                 \
    *ref = f;                                                        \
    f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
    f->refs[f->refcount-1] = ref;                                    \
} while (0)

Definition at line 320 of file formats.c.

Referenced by avfilter_formats_ref(), and ff_channel_layouts_ref().

#define FORMATS_UNREF ( ref,
list   ) 

Value:

do {                                                               \
    int idx = -1;                                                  \
                                                                   \
    if (!*ref)                                                     \
        return;                                                    \
                                                                   \
    FIND_REF_INDEX(ref, idx);                                      \
                                                                   \
    if (idx >= 0)                                                  \
        memmove((*ref)->refs + idx, (*ref)->refs + idx + 1,        \
            sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
                                                                   \
    if(!--(*ref)->refcount) {                                      \
        av_free((*ref)->list);                                     \
        av_free((*ref)->refs);                                     \
        av_free(*ref);                                             \
    }                                                              \
    *ref = NULL;                                                   \
} while (0)

Definition at line 347 of file formats.c.

Referenced by avfilter_formats_unref(), and ff_channel_layouts_unref().

#define MAKE_FORMAT_LIST ( type,
field,
count_field   ) 

Value:

type *formats;                                                      \
    int count = 0;                                                      \
    if (fmts)                                                           \
        for (count = 0; fmts[count] != -1; count++)                     \
            ;                                                           \
    formats = av_mallocz(sizeof(*formats));                             \
    if (!formats) return NULL;                                          \
    formats->count_field = count;                                       \
    if (count) {                                                        \
        formats->field = av_malloc(sizeof(*formats->field)*count);      \
        if (!formats->field) {                                          \
            av_free(formats);                                           \
            return NULL;                                                \
        }                                                               \
    }

Definition at line 199 of file formats.c.

Referenced by avfilter_make_format64_list(), and avfilter_make_format_list().

#define MERGE_FORMATS ( ret,
a,
b,
fmts,
nb,
type,
fail   ) 

Value:

do {                                                                            \
    int i, j, k = 0, count = FFMIN(a->nb, b->nb);                               \
                                                                                \
    if (!(ret = av_mallocz(sizeof(*ret))))                                      \
        goto fail;                                                              \
                                                                                \
    if (count) {                                                                \
        if (!(ret->fmts = av_malloc(sizeof(*ret->fmts) * count)))               \
            goto fail;                                                          \
        for (i = 0; i < a->nb; i++)                                             \
            for (j = 0; j < b->nb; j++)                                         \
                if (a->fmts[i] == b->fmts[j]) {                                 \
                    if(k >= FFMIN(a->nb, b->nb)){                               \
                        av_log(0, AV_LOG_ERROR, "Duplicate formats in avfilter_merge_formats() detected\n"); \
                        av_free(ret->fmts);                                     \
                        av_free(ret);                                           \
                        return NULL;                                            \
                    }                                                           \
                    ret->fmts[k++] = a->fmts[i];                                \
                }                                                               \
    }                                                                           \
    ret->nb = k;                                                                \
    /* check that there was at least one common format */                       \
    if (!ret->nb)                                                               \
        goto fail;                                                              \
                                                                                \
    MERGE_REF(ret, a, fmts, type, fail);                                        \
    MERGE_REF(ret, b, fmts, type, fail);                                        \
} while (0)
Add all formats common for a and b to ret, copy the refs and destroy a and b.

Definition at line 57 of file formats.c.

Referenced by avfilter_merge_formats(), ff_merge_channel_layouts(), and ff_merge_samplerates().

#define MERGE_REF ( ret,
a,
fmts,
type,
fail   ) 

Value:

do {                                                                       \
    type ***tmp;                                                           \
    int i;                                                                 \
                                                                           \
    if (!(tmp = av_realloc(ret->refs,                                      \
                           sizeof(*tmp) * (ret->refcount + a->refcount)))) \
        goto fail;                                                         \
    ret->refs = tmp;                                                       \
                                                                           \
    for (i = 0; i < a->refcount; i ++) {                                   \
        ret->refs[ret->refcount] = a->refs[i];                             \
        *ret->refs[ret->refcount++] = ret;                                 \
    }                                                                      \
                                                                           \
    av_freep(&a->refs);                                                    \
    av_freep(&a->fmts);                                                    \
    av_freep(&a);                                                          \
} while (0)
Add all refs from a to ret and destroy a.

Definition at line 33 of file formats.c.

Referenced by ff_merge_channel_layouts(), and ff_merge_samplerates().

#define SET_COMMON_FORMATS ( ctx,
fmts,
in_fmts,
out_fmts,
ref,
list   ) 

Value:

{                                                                   \
    int count = 0, i;                                               \
                                                                    \
    for (i = 0; i < ctx->input_count; i++) {                        \
        if (ctx->inputs[i]) {                                       \
            ref(fmts, &ctx->inputs[i]->out_fmts);                   \
            count++;                                                \
        }                                                           \
    }                                                               \
    for (i = 0; i < ctx->output_count; i++) {                       \
        if (ctx->outputs[i]) {                                      \
            ref(fmts, &ctx->outputs[i]->in_fmts);                   \
            count++;                                                \
        }                                                           \
    }                                                               \
                                                                    \
    if (!count) {                                                   \
        av_freep(&fmts->list);                                      \
        av_freep(&fmts->refs);                                      \
        av_freep(&fmts);                                            \
    }                                                               \
}

Definition at line 403 of file formats.c.

Referenced by avfilter_set_common_formats(), ff_set_common_channel_layouts(), and ff_set_common_samplerates().


Function Documentation

int avfilter_add_format ( AVFilterFormats **  avff,
int64_t  fmt 
)

Add fmt to the list of media formats contained in *avff.

If *avff is NULL the function allocates the filter formats struct and puts its pointer in *avff.

Returns:
a non negative value in case of success, or a negative value corresponding to an AVERROR code in case of error

Definition at line 253 of file formats.c.

Referenced by avfilter_make_all_formats(), init(), query_formats(), and reduce_formats_on_filter().

AVFilterFormats* avfilter_all_formats ( enum AVMediaType  type  ) 

Deprecated:
Use avfilter_make_all_formats() instead.

Definition at line 264 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

int avfilter_default_query_formats ( AVFilterContext ctx  ) 

Default handler for query_formats().

Definition at line 538 of file formats.c.

void avfilter_formats_changeref ( AVFilterFormats **  oldref,
AVFilterFormats **  newref 
)

Before After ________ ________ |formats |<---------.

|formats |<---------. | ____ | ___|___ | ____ | ___|___ | |refs| | | | | | |refs| | | | | NULL | |* *--------->|*oldref| | |* *--------->|*newref| ^ | |* * | | |_______| | |* * | | |_______| ___|___ | |____| | | |____| | | | | |________| |________| |*oldref| |_______|

Definition at line 397 of file formats.c.

Referenced by avfilter_insert_filter().

void avfilter_formats_ref ( AVFilterFormats formats,
AVFilterFormats **  ref 
)

Add *ref as a new reference to formats.

That is the pointers will point like in the ASCII art below: ________ |formats |<--------. | ____ | ____|___________________ | |refs| | | __|_ | |* * | | | | | | AVFilterLink | |* *--------->|*ref| | |____| | | |____| |________| |________________________

Definition at line 332 of file formats.c.

Referenced by avfilter_set_common_formats(), ff_set_common_samplerates(), query_formats(), and set_common_formats().

void avfilter_formats_unref ( AVFilterFormats **  ref  ) 

If *ref is non-NULL, remove *ref as a reference to the format list it currently points to, deallocates that list if this was the last reference, and sets *ref to NULL.

Before After ________ ________ NULL |formats |<--------. |formats | ^ | ____ | ____|________________ | ____ | ____|________________ | |refs| | | __|_ | |refs| | | __|_ | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink | |* *--------->|*ref| | |* | | | |*ref| | |____| | | |____| | |____| | | |____| |________| |_____________________ |________| |_____________________

Definition at line 368 of file formats.c.

Referenced by avfilter_free(), pick_format(), and query_formats().

AVFilterFormats* avfilter_make_all_formats ( enum AVMediaType  type  ) 

Return a list of all formats supported by FFmpeg for the given media type.

Definition at line 270 of file formats.c.

Referenced by avfilter_all_formats(), and query_formats().

AVFilterFormats* avfilter_make_all_packing_formats ( void   ) 

Return a list of all audio packing formats.

Definition at line 296 of file formats.c.

AVFilterChannelLayouts* avfilter_make_format64_list ( const int64_t *  fmts  ) 

Definition at line 225 of file formats.c.

Referenced by query_formats().

AVFilterFormats* avfilter_make_format_list ( const int *  fmts  ) 

Create a list of supported formats.

This is intended for use in AVFilter->query_formats().

Parameters:
fmts list of media formats, terminated by -1. If NULL an empty list is created.
Returns:
the format list, with no existing references

Definition at line 216 of file formats.c.

Referenced by avfilter_make_all_packing_formats(), ff_draw_supported_pixel_formats(), and query_formats().

AVFilterFormats* avfilter_merge_formats ( AVFilterFormats a,
AVFilterFormats b 
)

Return a format list which contains the intersection of the formats of a and b.

Also, all the references of a, all the references of b, and a and b themselves will be deallocated.

If a and b do not share any common formats, neither is modified, and NULL is returned.

Definition at line 88 of file formats.c.

Referenced by insert_conv_filter(), and query_formats().

void avfilter_set_common_formats ( AVFilterContext ctx,
AVFilterFormats formats 
)

A helper for query_formats() which sets all links to the same list of formats.

Helpers for query_formats() which set all links to the same list of formats/layouts.

If there are no links hooked to this filter, the list of formats is freed.

Definition at line 446 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

int ff_add_channel_layout ( AVFilterChannelLayouts **  l,
uint64_t  channel_layout 
)

Definition at line 258 of file formats.c.

Referenced by init(), query_formats(), and reduce_formats_on_filter().

AVFilterChannelLayouts* ff_all_channel_layouts ( void   ) 

Construct an empty AVFilterChannelLayouts/AVFilterFormats struct -- representing any channel layout/sample rate.

Definition at line 314 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

AVFilterFormats* ff_all_samplerates ( void   ) 

Definition at line 308 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

void ff_channel_layouts_changeref ( AVFilterChannelLayouts **  oldref,
AVFilterChannelLayouts **  newref 
)

Definition at line 391 of file formats.c.

Referenced by avfilter_insert_filter().

void ff_channel_layouts_ref ( AVFilterChannelLayouts f,
AVFilterChannelLayouts **  ref 
)

Add *ref as a new reference to f.

Definition at line 327 of file formats.c.

Referenced by ff_set_common_channel_layouts(), and query_formats().

void ff_channel_layouts_unref ( AVFilterChannelLayouts **  ref  ) 

Remove a reference to a channel layouts list.

Definition at line 373 of file formats.c.

Referenced by avfilter_free(), and pick_format().

int64_t* ff_copy_int64_list ( const int64_t *const   list  ) 

Return a copy of a list of 64-bit integers, or NULL in case of copy failure.

Definition at line 192 of file formats.c.

int* ff_copy_int_list ( const int *const   list  ) 

Return a copy of a list of integers terminated by -1, or NULL in case of copy failure.

Definition at line 185 of file formats.c.

int ff_default_query_formats ( AVFilterContext ctx  ) 

Definition at line 452 of file formats.c.

Referenced by avfilter_default_query_formats(), main(), and query_formats().

int ff_fmt_is_in ( int  fmt,
const int *  fmts 
)

Tell is a format is contained in the provided list terminated by -1.

Definition at line 162 of file formats.c.

Referenced by config_input(), config_input_main(), config_input_overlay(), config_out_props(), and config_props().

AVFilterChannelLayouts* ff_merge_channel_layouts ( AVFilterChannelLayouts a,
AVFilterChannelLayouts b 
)

Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates of a and b.

Also, all the references of a, all the references of b, and a and b themselves will be deallocated.

If a and b do not share any common elements, neither is modified, and NULL is returned.

Definition at line 134 of file formats.c.

Referenced by insert_conv_filter(), and query_formats().

AVFilterFormats* ff_merge_samplerates ( AVFilterFormats a,
AVFilterFormats b 
)

Definition at line 107 of file formats.c.

Referenced by query_formats().

int ff_parse_channel_layout ( int64_t *  ret,
const char *  arg,
void *  log_ctx 
)

Parse a channel layout or a corresponding integer representation.

Parameters:
ret 64bit integer pointer to where the value should be written.
arg string to parse
log_ctx log context
Returns:
0 in case of success, a negative AVERROR code on error

Definition at line 522 of file formats.c.

Referenced by init().

int ff_parse_pixel_format ( enum PixelFormat ret,
const char *  arg,
void *  log_ctx 
)

Parse a pixel format.

Parameters:
ret pixel format pointer to where the value should be written
arg string to parse
log_ctx log context
Returns:
0 in case of success, a negative AVERROR code on error

Definition at line 469 of file formats.c.

Referenced by init(), and init_video().

int ff_parse_sample_format ( int *  ret,
const char *  arg,
void *  log_ctx 
)

Parse a sample format name or a corresponding integer representation.

Parameters:
ret integer pointer to where the value should be written
arg string to parse
log_ctx log context
Returns:
0 in case of success, a negative AVERROR code on error

Definition at line 484 of file formats.c.

Referenced by init().

int ff_parse_sample_rate ( int *  ret,
const char *  arg,
void *  log_ctx 
)

Parse a sample rate.

Parameters:
ret unsigned integer pointer to where the value should be written
arg string to parse
log_ctx log context
Returns:
0 in case of success, a negative AVERROR code on error

Definition at line 510 of file formats.c.

Referenced by init().

int ff_parse_time_base ( AVRational ret,
const char *  arg,
void *  log_ctx 
)

Parse a time base.

Parameters:
ret unsigned AVRational pointer to where the value should be written
arg string to parse
log_ctx log context
Returns:
0 in case of success, a negative AVERROR code on error

Definition at line 499 of file formats.c.

void ff_set_common_channel_layouts ( AVFilterContext ctx,
AVFilterChannelLayouts layouts 
)

A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.

If there are no links hooked to this filter, the list is freed.

Definition at line 427 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

void ff_set_common_samplerates ( AVFilterContext ctx,
AVFilterFormats samplerates 
)

Definition at line 434 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().


Variable Documentation

A list of all channel layouts supported by libavfilter.

Definition at line 285 of file formats.c.

Referenced by init_filters(), and lavfi_read_header().


Generated on Fri Oct 26 02:48:00 2012 for FFmpeg by  doxygen 1.5.8