On Mon, 25 Aug 2014 12:50:40 +0200, Janne Grunau <[email protected]> wrote:
> On 2014-08-24 13:00:11 +0000, Anton Khirnov wrote:
> > ---
> >  libavcodec/avcodec.h | 145 
> > +++++++++++++++++++++++++++++++++++++++++++++++++++
> >  libavcodec/utils.c   | 144 
> > ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 289 insertions(+)
> > 
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index c7fbed9..2a9c5ec 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -3091,6 +3091,109 @@ typedef struct AVSubtitle {
> >  } AVSubtitle;
> >  
> >  /**
> > + * This struct describes the properties of an encoded stream.
> > + *
> > + * sizeof(AVCodecParameters) is not a part of the public ABI, this struct 
> > must
> > + * be allocated with avcodec_parameters_alloc() and freed with
> > + * avcodec_parameters_free().
> > + */
> > +typedef struct AVCodecParameters {
> > +    /**
> > +     * General type of the encoded data.
> > +     */
> > +    enum AVMediaType codec_type;
> > +    /**
> > +     * Specific type of the encoded data (the codec used).
> > +     */
> > +    enum AVCodecID   codec_id;
> > +    /**
> > +     * Additional information about the codec (corresponds to the AVI 
> > FOURCC).
> > +     */
> 
> or wav TWOCC I think
> 

Right, will fix.

> > +    uint32_t         codec_tag;
> > +
> > +    /**
> > +     * Extra binary data needed for initializing the decoder, 
> > codec-dependent.
> > +     *
> > +     * Must be allocated with av_malloc() and will be freed by
> > +     * avcodec_parameters_free(). The allocated size of extradata must be 
> > at
> > +     * least extradata_size + FF_MIN_BUFFER_SIZE, with the padding bytes 
> > zeroed.
> 
> FF_INPUT_BUFFER_PADDING_SIZE; 16kB padding would be ridiculous 
> 

Ditto.

> > +     */
> > +    uint8_t *extradata;
> > +    /**
> > +     * Size of the extradata content in bytes.
> > +     */
> > +    int      extradata_size;
> > +
> > +    /**
> > +     * - video: the pixel format, the value corresponds to enum 
> > AVPixelFormat.
> > +     * - audio: the sample format, the value corresponds to enum 
> > AVSampleFormat.
> > +     */
> > +    int format;
> > +    /**
> > +     * The average bitrate of the encoded data (in bits per second).
> > +     */
> > +    int bit_rate;
> > +    int bits_per_coded_sample;
> > +
> > +    /**
> > +     * Video only. The dimensions of the video frame in pixels.
> > +     */
> > +    int width;
> > +    int height;
> > +
> > +    /**
> > +     * Video only. The order of the fields in interlaced video.
> > +     */
> > +    enum AVFieldOrder                  field_order;
> > +
> > +    /**
> > +     * Video only. Additional colorspace characteristics.
> > +     */
> > +    enum AVColorRange                  color_range;
> > +    enum AVColorPrimaries              color_primaries;
> > +    enum AVColorTransferCharacteristic color_trc;
> > +    enum AVColorSpace                  color_space;
> > +    enum AVChromaLocation              chroma_location;
> > +
> > +    /**
> > +     * Audio only. The channel layout bitmask. May be 0 if the channel 
> > layout is
> > +     * unknown or unspecified, otherwise the number of bits set must be 
> > equal to
> > +     * the channels field.
> > +     */
> > +    uint64_t channel_layout;
> > +    /**
> > +     * Audio only. The number of audio channels.
> > +     */
> > +    int      channels;
> > +    /**
> > +     * Audio only. The number of audio samples per second.
> > +     */
> > +    int      sample_rate;
> > +    /**
> > +     * Audio only. The number of bytes per coded audio frame, required by 
> > some
> > +     * formats.
> > +     *
> > +     * Corresponds to nBlockAlign in WAVEFORMATEX.
> > +     */
> > +    int      block_align;
> > +
> > +    /**
> > +     * Audio only. The amount of padding (in samples) inserted by the 
> > encoder at
> > +     * the beginning of the audio. I.e. this number of leading decoded 
> > samples
> > +     * must be discarded by the caller to get the original audio without 
> > leading
> > +     * padding.
> > +     */
> > +    int initial_padding;
> > +    /**
> > +     * Audio only. The amount of padding (in samples) appended by the 
> > encoder to
> > +     * the end of the audio. I.e. this number of decoded samples must be
> > +     * discarded by the caller from the end of the stream to get the 
> > original
> > +     * audio without any trailing padding.
> > +     */
> > +    int trailing_padding;
> > +} AVCodecParameters;
> 
> I wonder if it make sense to encapsulate the audio/video specific values 
> in their own structs and embed an union of them. Probably too much 
> effort for little gain though.
> 

Considered it, but my conclusion was the same as yours.

> > +
> > +/**
> >   * If c is NULL, returns the first registered codec,
> >   * if c is non-NULL, returns the next registered codec after c,
> >   * or NULL if c is the last one.
> > @@ -3188,6 +3291,48 @@ const AVClass *avcodec_get_class(void);
> >   */
> >  int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
> >  
> > +/**
> > + * Allocate a new AVCodecParameters and set its fields to default values
> > + * (unknown/invalid/0). The returned struct must be freed with
> > + * avcodec_parameters_free().
> > + */
> > +AVCodecParameters *avcodec_parameters_alloc(void);
> > +
> > +/**
> > + * Free an AVCodecParameters instance and everything associated with it and
> > + * write NULL to the supplied pointer.
> > + */
> > +void avcodec_parameters_free(AVCodecParameters **par);
> > +
> > +/**
> > + * Copy the contents of src to dst. Any allocated fields in dst are freed 
> > and
> > + * replaced with newly allocated duplicates of the corresponding fields in 
> > src.
> > + *
> > + * @return >= 0 on success, a negative AVERROR code on failure.
> > + */
> > +int avcodec_parameters_copy(AVCodecParameters *dst, const 
> > AVCodecParameters *src);
> > +
> > +/**
> > + * Fill the parameters struct based on the values from the supplied codec
> > + * context. Any allocated fields in par are freed and replaced with 
> > duplicates
> > + * of the corresponding fields in codec.
> > + *
> > + * @return >= 0 on success, a negative AVERROR code on failure
> > + */
> > +int avcodec_parameters_from_context(AVCodecParameters *par,
> > +                                    const AVCodecContext *codec);
> > +
> > +/**
> > + * Fill the codec context based on the values from the supplied codec
> > + * parameters. Any allocated fields in codec that have a corresponding 
> > field in
> > + * par are freed and replaced with duplicates of the corresponding field 
> > in par.
> > + * Fields in codec that do not have a counterpart in par are not touched.
> > + *
> > + * @return >= 0 on success, a negative AVERROR code on failure.
> > + */
> > +int avcodec_parameters_to_context(AVCodecContext *codec,
> > +                                  const AVCodecParameters *par);
> > +
> >  #if FF_API_AVFRAME_LAVC
> >  /**
> >   * @deprecated use av_frame_alloc()
> > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > index e0f11d3..baa25eb 100644
> > --- a/libavcodec/utils.c
> > +++ b/libavcodec/utils.c
> > @@ -2418,3 +2418,147 @@ const uint8_t *avpriv_find_start_code(const uint8_t 
> > *restrict p,
> >  
> >      return p + 4;
> >  }
> > +
> > +static void codec_parameters_reset(AVCodecParameters *par)
> > +{
> > +    av_freep(&par->extradata);
> > +
> > +    memset(par, 0, sizeof(*par));
> > +
> > +    par->codec_type      = AVMEDIA_TYPE_UNKNOWN;
> > +    par->codec_id        = AV_CODEC_ID_NONE;
> > +    par->format          = -1;
> > +    par->field_order     = AV_FIELD_UNKNOWN;
> > +    par->color_range     = AVCOL_RANGE_UNSPECIFIED;
> > +    par->color_primaries = AVCOL_PRI_UNSPECIFIED;
> > +    par->color_trc       = AVCOL_TRC_UNSPECIFIED;
> > +    par->color_space     = AVCOL_SPC_UNSPECIFIED;
> > +    par->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
> > +}
> > +
> > +AVCodecParameters *avcodec_parameters_alloc(void)
> > +{
> > +    AVCodecParameters *par = av_mallocz(sizeof(*par));
> > +
> > +    if (!par)
> > +        return NULL;
> > +    codec_parameters_reset(par);
> > +    return par;
> > +}
> > +
> > +void avcodec_parameters_free(AVCodecParameters **ppar)
> > +{
> > +    AVCodecParameters *par = *ppar;
> > +
> > +    if (!par)
> > +        return;
> > +    codec_parameters_reset(par);
> > +
> > +    av_freep(ppar);
> > +}
> > +
> > +int avcodec_parameters_copy(AVCodecParameters *dst, const 
> > AVCodecParameters *src)
> > +{
> > +    codec_parameters_reset(dst);
> > +    memcpy(dst, src, sizeof(*dst));
> > +
> > +    dst->extradata      = NULL;
> > +    dst->extradata_size = 0;
> > +    if (src->extradata) {
> > +        dst->extradata = av_mallocz(src->extradata_size + 
> > FF_INPUT_BUFFER_PADDING_SIZE);
> > +        if (!dst->extradata)
> > +            return AVERROR(ENOMEM);
> > +        memcpy(dst->extradata, src->extradata, src->extradata_size);
> > +        dst->extradata_size = src->extradata_size;
> > +    }
> > +
> > +    return 0;
> > +}
> > +
> > +int avcodec_parameters_from_context(AVCodecParameters *par,
> > +                                    const AVCodecContext *codec)
> > +{
> > +    codec_parameters_reset(par);
> > +
> > +    par->codec_type = codec->codec_type;
> > +    par->codec_id   = codec->codec_id;
> > +    par->codec_tag  = codec->codec_tag;
> > +
> > +    par->bit_rate              = codec->bit_rate;
> > +    par->bits_per_coded_sample = codec->bits_per_coded_sample;
> > +
> > +    switch (par->codec_type) {
> > +    case AVMEDIA_TYPE_VIDEO:
> > +        par->format          = codec->pix_fmt;
> > +        par->width           = codec->width;
> > +        par->height          = codec->height;
> > +        par->field_order     = codec->field_order;
> > +        par->color_range     = codec->color_range;
> > +        par->color_primaries = codec->color_primaries;
> > +        par->color_trc       = codec->color_trc;
> > +        par->color_space     = codec->colorspace;
> > +        par->chroma_location = codec->chroma_sample_location;
> > +        break;
> > +    case AVMEDIA_TYPE_AUDIO:
> > +        par->format          = codec->sample_fmt;
> > +        par->channel_layout  = codec->channel_layout;
> > +        par->channels        = codec->channels;
> > +        par->sample_rate     = codec->sample_rate;
> > +        par->block_align     = codec->block_align;
> > +        par->initial_padding = codec->initial_padding;
> 
> AVCodecContext has no field initial_padding here, same problem in 
> avcodec_parameters_to_context()

There's a patch on the ML adding it.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to