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

Michael Niedermayer michaelni
Thu Nov 12 19:29:40 CET 2009


On Thu, Nov 12, 2009 at 09:13:58AM +0100, Robert Kr?ger wrote:
> Hi,
>
> On 12.11.2009, at 01:42, Stefano Sabatini wrote:
>
>> On date Wednesday 2009-11-11 12:41:33 +0100, Robert Kr?ger encoded:
[...]
>>> +    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);
>>> +    	bitrate = bits_per_sample ? ctx->sample_rate * ctx->channels *
>>> bits_per_sample : ctx->bit_rate;
>>> +        break;
>>
>>> +    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;
>>> +}
>>> +
>>
>> VIDEO, DATA, SUBTITLE, ATTACHMENT and default cases can be factorized.
>>
>> Maybe it's simpler:
>> if (type == CODEC_AUDIO && (bits_per_sample = ...))
>>   bitrate = ...
>> else
>>   bitrate = ctx->bit_rate;
>>
> hmm, I tried not to change the behaviour of the code I extracted as I only 
> wanted to refactor and what you suggest would change the behaviour for 
> CODEC_TYPE_UNKNOWN ,  CODEC_TYPE_ATTACHMENT and CODEC_TYPE_NB as it would 
> no longer return 0 but return ctx->bit_rate. If that makes sense, I cannot 
> judge. I'll change it accordingly, if you say it does.

you could send 2 pathes
first to move the code, second to simplify it

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- 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/20091112/c2acd491/attachment.pgp>



More information about the ffmpeg-devel mailing list