[FFmpeg-devel] [PATCH] extract bit rate calculation into separate function

Michael Niedermayer michaelni
Wed Nov 11 15:23:17 CET 2009


On Wed, Nov 11, 2009 at 12:41:33PM +0100, Robert Kr?ger wrote:
> Hi,
>
> On 11.11.2009, at 11:23, Carl Eugen Hoyos wrote:
>
>> Hi!
>>
>> Robert Kr?ger <krueger <at> signal7.de> writes:
>>
>>>>> +/**
>>>>> + * Calculates the bit rate of a stream
>>>>> + *
>>>>> + * @ctx AVCodecContext of the stream
>>>>> + * @return bit rate in bits per second
>>>>> + */
>>>>
>>>> this belongs in a header
>>>>
>>> moved to header avformat.h and changed name to av_codec_get_bitrate
>>> because that seems to be the naming convention for exposed functions(?)
>>
>> You certainly cannot have a declaration in libavformat/avformat.h and the 
>> code
>> in libavcodec/utils.c (the different directories are a hint).
>>
>
> sorry, embarrassing mistake. Updated patch attached.
>
> Regards,
>
> Robert
>
> Index: libavcodec/avcodec.h
> ===================================================================
> --- libavcodec/avcodec.h	(revision 20511)
> +++ libavcodec/avcodec.h	(working copy)
> @@ -3444,6 +3444,14 @@
>   */
>  int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);
>
> +/**
> + * Calculates the bit rate of a stream
> + *
> + * @ctx AVCodecContext of the stream
> + * @return Bit rate in bits per second or 0 if it could not be determined
> + */
> +int av_get_bitrate(AVCodecContext *ctx);
> +
>  /* frame parsing */
>  typedef struct AVCodecParserContext {
>      void *priv_data;
> Index: libavcodec/utils.c
> ===================================================================
> --- libavcodec/utils.c	(revision 20511)
> +++ libavcodec/utils.c	(working copy)
> @@ -741,6 +741,34 @@
>      return NULL;
>  }
>
> +int av_get_bitrate(AVCodecContext *ctx)
> +{
> +    int bitrate;
> +    int bits_per_sample;
> +
> +    switch(ctx->codec_type) {
> +    case CODEC_TYPE_VIDEO:
> +  	    bitrate = ctx->bit_rate;
> +        break;
> +    case CODEC_TYPE_AUDIO:
> +    	bits_per_sample = av_get_bits_per_sample(ctx->codec_id);

tabs


> +    	bitrate = bits_per_sample ? ctx->sample_rate * ctx->channels * 
> bits_per_sample : ctx->bit_rate;
> +        break;

line break in the middle of a patch


> +    case CODEC_TYPE_DATA:
> +        bitrate = ctx->bit_rate;
> +        break;
> +    case CODEC_TYPE_SUBTITLE:
> +        bitrate = ctx->bit_rate;
> +        break;
> +    case CODEC_TYPE_ATTACHMENT:
> +        bitrate = ctx->bit_rate;
> +        break;
> +    default:
> +        break;
> +    }
> +    return bitrate;

returning an uninitalized value


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091111/48943747/attachment.pgp>



More information about the ffmpeg-devel mailing list