History

Merge commit '998e1b8f521b73e1ed3a13caaabcf79eb401cf0d'

* commit '998e1b8f521b73e1ed3a13caaabcf79eb401cf0d': lavc: add codec parameters API Fixes added in: - bit_rate has been made int64_t to match. - profile and level are properly initialize.

Derek Buitenhuis committed 10 years ago

Commit f9b1cf12 parents 6de58b4 998e1b84 files · +319 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavcodec/avcodec.h +163 −0
  3. libavcodec/utils.c +152 −0
  4. libavcodec/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182016-xx-xx - lavc 57.33.0 - avcodec.h
19 xxxxxxx - Add AVCodecParameters and its related API.
20
182016-03-11 - xxxxxxx - lavf/lavc 57.28.101212016-03-11 - xxxxxxx - lavf/lavc 57.28.101
19 Add requirement to bitstream filtering API that returned packets with22 Add requirement to bitstream filtering API that returned packets with
20 size == 0 and side_data_elems == 0 are to be skipped by the caller.23 size == 0 and side_data_elems == 0 are to be skipped by the caller.
libavcodec/avcodec.h+163−0
@@ -3785,6 +3785,127 @@ typedef struct AVSubtitle { · 3784 unmodified lines
3785 int64_t pts; ///< Same as packet pts, in AV_TIME_BASE3785 int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
3786} AVSubtitle;3786} AVSubtitle;
3787 3787
3788/**
3789 * This struct describes the properties of an encoded stream.
3790 *
3791 * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
3792 * be allocated with avcodec_parameters_alloc() and freed with
3793 * avcodec_parameters_free().
3794 */
3795typedef struct AVCodecParameters {
3796 /**
3797 * General type of the encoded data.
3798 */
3799 enum AVMediaType codec_type;
3800 /**
3801 * Specific type of the encoded data (the codec used).
3802 */
3803 enum AVCodecID codec_id;
3804 /**
3805 * Additional information about the codec (corresponds to the AVI FOURCC).
3806 */
3807 uint32_t codec_tag;
3808
3809 /**
3810 * Extra binary data needed for initializing the decoder, codec-dependent.
3811 *
3812 * Must be allocated with av_malloc() and will be freed by
3813 * avcodec_parameters_free(). The allocated size of extradata must be at
3814 * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
3815 * bytes zeroed.
3816 */
3817 uint8_t *extradata;
3818 /**
3819 * Size of the extradata content in bytes.
3820 */
3821 int extradata_size;
3822
3823 /**
3824 * - video: the pixel format, the value corresponds to enum AVPixelFormat.
3825 * - audio: the sample format, the value corresponds to enum AVSampleFormat.
3826 */
3827 int format;
3828
3829 /**
3830 * The average bitrate of the encoded data (in bits per second).
3831 */
3832 int64_t bit_rate;
3833
3834 int bits_per_coded_sample;
3835
3836 /**
3837 * Codec-specific bitstream restrictions that the stream conforms to.
3838 */
3839 int profile;
3840 int level;
3841
3842 /**
3843 * Video only. The dimensions of the video frame in pixels.
3844 */
3845 int width;
3846 int height;
3847
3848 /**
3849 * Video only. The aspect ratio (width / height) which a single pixel
3850 * should have when displayed.
3851 *
3852 * When the aspect ratio is unknown / undefined, the numerator should be
3853 * set to 0 (the denominator may have any value).
3854 */
3855 AVRational sample_aspect_ratio;
3856
3857 /**
3858 * Video only. The order of the fields in interlaced video.
3859 */
3860 enum AVFieldOrder field_order;
3861
3862 /**
3863 * Video only. Additional colorspace characteristics.
3864 */
3865 enum AVColorRange color_range;
3866 enum AVColorPrimaries color_primaries;
3867 enum AVColorTransferCharacteristic color_trc;
3868 enum AVColorSpace color_space;
3869 enum AVChromaLocation chroma_location;
3870
3871 /**
3872 * Audio only. The channel layout bitmask. May be 0 if the channel layout is
3873 * unknown or unspecified, otherwise the number of bits set must be equal to
3874 * the channels field.
3875 */
3876 uint64_t channel_layout;
3877 /**
3878 * Audio only. The number of audio channels.
3879 */
3880 int channels;
3881 /**
3882 * Audio only. The number of audio samples per second.
3883 */
3884 int sample_rate;
3885 /**
3886 * Audio only. The number of bytes per coded audio frame, required by some
3887 * formats.
3888 *
3889 * Corresponds to nBlockAlign in WAVEFORMATEX.
3890 */
3891 int block_align;
3892
3893 /**
3894 * Audio only. The amount of padding (in samples) inserted by the encoder at
3895 * the beginning of the audio. I.e. this number of leading decoded samples
3896 * must be discarded by the caller to get the original audio without leading
3897 * padding.
3898 */
3899 int initial_padding;
3900 /**
3901 * Audio only. The amount of padding (in samples) appended by the encoder to
3902 * the end of the audio. I.e. this number of decoded samples must be
3903 * discarded by the caller from the end of the stream to get the original
3904 * audio without any trailing padding.
3905 */
3906 int trailing_padding;
3907} AVCodecParameters;
3908
3788/**3909/**
3789 * If c is NULL, returns the first registered codec,3910 * If c is NULL, returns the first registered codec,
3790 * if c is non-NULL, returns the next registered codec after c,3911 * if c is non-NULL, returns the next registered codec after c,
@@ -3899,6 +4020,48 @@ const AVClass *avcodec_get_subtitle_rect_class(void); · 108 unmodified lines
3899 */4020 */
3900int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);4021int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
3901 4022
4023/**
4024 * Allocate a new AVCodecParameters and set its fields to default values
4025 * (unknown/invalid/0). The returned struct must be freed with
4026 * avcodec_parameters_free().
4027 */
4028AVCodecParameters *avcodec_parameters_alloc(void);
4029
4030/**
4031 * Free an AVCodecParameters instance and everything associated with it and
4032 * write NULL to the supplied pointer.
4033 */
4034void avcodec_parameters_free(AVCodecParameters **par);
4035
4036/**
4037 * Copy the contents of src to dst. Any allocated fields in dst are freed and
4038 * replaced with newly allocated duplicates of the corresponding fields in src.
4039 *
4040 * @return >= 0 on success, a negative AVERROR code on failure.
4041 */
4042int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
4043
4044/**
4045 * Fill the parameters struct based on the values from the supplied codec
4046 * context. Any allocated fields in par are freed and replaced with duplicates
4047 * of the corresponding fields in codec.
4048 *
4049 * @return >= 0 on success, a negative AVERROR code on failure
4050 */
4051int avcodec_parameters_from_context(AVCodecParameters *par,
4052 const AVCodecContext *codec);
4053
4054/**
4055 * Fill the codec context based on the values from the supplied codec
4056 * parameters. Any allocated fields in codec that have a corresponding field in
4057 * par are freed and replaced with duplicates of the corresponding field in par.
4058 * Fields in codec that do not have a counterpart in par are not touched.
4059 *
4060 * @return >= 0 on success, a negative AVERROR code on failure.
4061 */
4062int avcodec_parameters_to_context(AVCodecContext *codec,
4063 const AVCodecParameters *par);
4064
3902/**4065/**
3903 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this4066 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3904 * function the context has to be allocated with avcodec_alloc_context3().4067 * function the context has to be allocated with avcodec_alloc_context3().
libavcodec/utils.c+152−0
@@ -3680,6 +3680,158 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx) · 3679 unmodified lines
3680 return props;3680 return props;
3681}3681}
3682 3682
3683static void codec_parameters_reset(AVCodecParameters *par)
3684{
3685 av_freep(&par->extradata);
3686
3687 memset(par, 0, sizeof(*par));
3688
3689 par->codec_type = AVMEDIA_TYPE_UNKNOWN;
3690 par->codec_id = AV_CODEC_ID_NONE;
3691 par->format = -1;
3692 par->field_order = AV_FIELD_UNKNOWN;
3693 par->color_range = AVCOL_RANGE_UNSPECIFIED;
3694 par->color_primaries = AVCOL_PRI_UNSPECIFIED;
3695 par->color_trc = AVCOL_TRC_UNSPECIFIED;
3696 par->color_space = AVCOL_SPC_UNSPECIFIED;
3697 par->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
3698 par->sample_aspect_ratio = (AVRational){ 0, 1 };
3699}
3700
3701AVCodecParameters *avcodec_parameters_alloc(void)
3702{
3703 AVCodecParameters *par = av_mallocz(sizeof(*par));
3704
3705 if (!par)
3706 return NULL;
3707 codec_parameters_reset(par);
3708 return par;
3709}
3710
3711void avcodec_parameters_free(AVCodecParameters **ppar)
3712{
3713 AVCodecParameters *par = *ppar;
3714
3715 if (!par)
3716 return;
3717 codec_parameters_reset(par);
3718
3719 av_freep(ppar);
3720}
3721
3722int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
3723{
3724 codec_parameters_reset(dst);
3725 memcpy(dst, src, sizeof(*dst));
3726
3727 dst->extradata = NULL;
3728 dst->extradata_size = 0;
3729 if (src->extradata) {
3730 dst->extradata = av_mallocz(src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
3731 if (!dst->extradata)
3732 return AVERROR(ENOMEM);
3733 memcpy(dst->extradata, src->extradata, src->extradata_size);
3734 dst->extradata_size = src->extradata_size;
3735 }
3736
3737 return 0;
3738}
3739
3740int avcodec_parameters_from_context(AVCodecParameters *par,
3741 const AVCodecContext *codec)
3742{
3743 codec_parameters_reset(par);
3744
3745 par->codec_type = codec->codec_type;
3746 par->codec_id = codec->codec_id;
3747 par->codec_tag = codec->codec_tag;
3748
3749 par->bit_rate = codec->bit_rate;
3750 par->bits_per_coded_sample = codec->bits_per_coded_sample;
3751 par->profile = codec->profile;
3752 par->level = codec->level;
3753
3754 switch (par->codec_type) {
3755 case AVMEDIA_TYPE_VIDEO:
3756 par->format = codec->pix_fmt;
3757 par->width = codec->width;
3758 par->height = codec->height;
3759 par->field_order = codec->field_order;
3760 par->color_range = codec->color_range;
3761 par->color_primaries = codec->color_primaries;
3762 par->color_trc = codec->color_trc;
3763 par->color_space = codec->colorspace;
3764 par->chroma_location = codec->chroma_sample_location;
3765 par->sample_aspect_ratio = codec->sample_aspect_ratio;
3766 break;
3767 case AVMEDIA_TYPE_AUDIO:
3768 par->format = codec->sample_fmt;
3769 par->channel_layout = codec->channel_layout;
3770 par->channels = codec->channels;
3771 par->sample_rate = codec->sample_rate;
3772 par->block_align = codec->block_align;
3773 par->initial_padding = codec->initial_padding;
3774 break;
3775 }
3776
3777 if (codec->extradata) {
3778 par->extradata = av_mallocz(codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
3779 if (!par->extradata)
3780 return AVERROR(ENOMEM);
3781 memcpy(par->extradata, codec->extradata, codec->extradata_size);
3782 par->extradata_size = codec->extradata_size;
3783 }
3784
3785 return 0;
3786}
3787
3788int avcodec_parameters_to_context(AVCodecContext *codec,
3789 const AVCodecParameters *par)
3790{
3791 codec->codec_type = par->codec_type;
3792 codec->codec_id = par->codec_id;
3793 codec->codec_tag = par->codec_tag;
3794
3795 codec->bit_rate = par->bit_rate;
3796 codec->bits_per_coded_sample = par->bits_per_coded_sample;
3797 codec->profile = par->profile;
3798 codec->level = par->level;
3799
3800 switch (par->codec_type) {
3801 case AVMEDIA_TYPE_VIDEO:
3802 codec->pix_fmt = par->format;
3803 codec->width = par->width;
3804 codec->height = par->height;
3805 codec->field_order = par->field_order;
3806 codec->color_range = par->color_range;
3807 codec->color_primaries = par->color_primaries;
3808 codec->color_trc = par->color_trc;
3809 codec->colorspace = par->color_space;
3810 codec->chroma_sample_location = par->chroma_location;
3811 codec->sample_aspect_ratio = par->sample_aspect_ratio;
3812 break;
3813 case AVMEDIA_TYPE_AUDIO:
3814 codec->sample_fmt = par->format;
3815 codec->channel_layout = par->channel_layout;
3816 codec->channels = par->channels;
3817 codec->sample_rate = par->sample_rate;
3818 codec->block_align = par->block_align;
3819 codec->initial_padding = par->initial_padding;
3820 break;
3821 }
3822
3823 if (par->extradata) {
3824 av_freep(&codec->extradata);
3825 codec->extradata = av_mallocz(par->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
3826 if (!codec->extradata)
3827 return AVERROR(ENOMEM);
3828 memcpy(codec->extradata, par->extradata, par->extradata_size);
3829 codec->extradata_size = par->extradata_size;
3830 }
3831
3832 return 0;
3833}
3834
3683#ifdef TEST3835#ifdef TEST
3684int main(void){3836int main(void){
3685 AVCodec *codec = NULL;3837 AVCodec *codec = NULL;
libavcodec/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
28#include "libavutil/version.h"28#include "libavutil/version.h"
29 29
30#define LIBAVCODEC_VERSION_MAJOR 5730#define LIBAVCODEC_VERSION_MAJOR 57
31#define LIBAVCODEC_VERSION_MINOR 3231#define LIBAVCODEC_VERSION_MINOR 33
32#define LIBAVCODEC_VERSION_MICRO 10032#define LIBAVCODEC_VERSION_MICRO 100
33 33
34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t