[FFmpeg-devel] [PATCH] G.729 parameters decoding
Vladimir Voroshilov
voroshil
Fri Jun 12 20:21:24 CEST 2009
2009/6/11 Michael Niedermayer <michaelni at gmx.at>:
> On Thu, Jun 11, 2009 at 01:35:48AM +0700, Vladimir Voroshilov wrote:
>> 2009/6/11 Diego Biurrun <diego at biurrun.de>:
>> > On Thu, Jun 11, 2009 at 01:22:35AM +0700, Vladimir Voroshilov wrote:
>> >> Patch adds routine, which decodes one G.729 frame into vector of
>> >> decoding parameters.
>> >> Both G.729 and G.729D are supported.
>> >>
>> >> --- ffmpeg-r19127.orig/libavcodec/g729dec.c
>> >> +++ ffmpeg-r19127.mod/libavcodec/g729dec.c
>> >> @@ -162,12 +203,43 @@ static av_cold int decoder_init(AVCodecContext * avctx)
>> >> +static void g729_bytes2parm(G729FormatDescription *format, const uint8_t *buf, int buf_size, G729Parameters *parm)
>> >
>> > Is the prefix needed?
>> >
>> > And extra good karma for breaking long lines.
>> >
>>
>> Deeper night is the only time i can code :(
>> Both fixed.
>>
>> --
>> Regards,
>> Vladimir Voroshilov ? ? mailto:voroshil at gmail.com
>> JID: voroshil at gmail.com, voroshil at jabber.ru
>> ICQ: 95587719
>
>> ?g729dec.c | ? 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
>> ?1 file changed, 82 insertions(+), 7 deletions(-)
>> 88ce1485be321b60e87b9104600d01ffd05e0d1d ?0004-Parameters-decoding-routine.131.patch
>> From 95ebdd0e7d4bbcaa146de7d4bc539ccc015151c4 Mon Sep 17 00:00:00 2001
>> From: Vladimir Voroshilov <voroshil at gmail.com>
>> Date: Wed, 10 Jun 2009 10:44:57 +0700
>> Subject: [PATCH] Parameters decoding routine
>>
>>
>> diff --git ffmpeg-r19127.orig/libavcodec/g729dec.c ffmpeg-r19127.mod/libavcodec/g729dec.c
>> index fcebcdb..4670ff4 100644
>> --- ffmpeg-r19127.orig/libavcodec/g729dec.c
>> +++ ffmpeg-r19127.mod/libavcodec/g729dec.c
>> @@ -72,19 +72,59 @@
>> ?#define SHARP_MAX ? ? ? ? ? ? ? ? ?13017
>>
>> ?typedef struct {
>> - ? ?int sample_rate;
>> - ? ?uint8_t packed_frame_size; ?///< input frame size(in bytes)
>> - ? ?uint8_t unpacked_frame_size;///< output frame size (in bytes)
>> - ? ?uint8_t fc_indexes_bits; ? ?///< size (in bits) of fixed-codebook index entry
>> + ? ?uint8_t ma_predictor; ? ? ///< switched MA predictor of LSP quantizer
>> + ? ?uint8_t quantizer_1st; ? ?///< first stage vector of quantizer
>> + ? ?uint8_t quantizer_2nd_lo; ///< second stage lower vector of quantizer (size in bits)
>> + ? ?uint8_t quantizer_2nd_hi; ///< second stage higher vector of quantizer (size in bits)
>> + ? ?uint8_t parity[2]; ? ? ? ?///< parity bit for pitch delay (size in bits)
>> + ? ?uint8_t ac_index[2]; ? ? ?///< adaptive codebook index
>> + ? ?uint8_t pulses_signs[2]; ?///< fixed-codebook vector pulse signs
>> + ? ?int fc_indexes[2]; ? ? ? ?///< fixed-codebook indexes
>> + ? ?uint8_t gc_1st_index[2]; ?///< gain codebook (first stage) index
>> + ? ?uint8_t gc_2nd_index[2]; ?///< gain codebook (second stage) index
>> +} G729Parameters;
>>
>> - ? ?/// mr_energy = mean_energy + 10 * log10(2^26 ?* subframe_size) in (7.13)
>> - ? ?int mr_energy;
>> +typedef struct {
>> + ? ?uint8_t ac_index_bits[2]; ? ///< adaptive codebook index for second subframe (size in bits)
>> + ? ?uint8_t parity_bits[2]; ? ? ///< parity bit for pitch delay (size in bits)
>> + ? ?uint8_t gc_1st_index_bits; ?///< gain codebook (first stage) index (size in bits)
>> + ? ?uint8_t gc_2nd_index_bits; ?///< gain codebook (second stage) index (size in bits)
>> + ? ?uint8_t fc_signs_bits; ? ? ?///< number of pulses in fixed-codebook vector
>> + ? ?uint8_t fc_indexes_bits; ? ?///< size (in bits) of fixed-codebook index entry
>> ?} G729FormatDescription;
>>
>
>> +typedef enum {
>> + ? ?FORMAT_G729_8K = 0,
>> + ? ?FORMAT_G729D_6K4,
>> + ? ?FORMAT_COUNT,
>> +} G729Formats;
>
> useless
Removed from current patch. Will be added later, if needed.
>
>
>> +
>> ?typedef struct {
>> + ? ?const G729FormatDescription *format; ? ? ? ? ///< format index from formats array
>
> this requires an extra dereference, aka speed loss
>
>
> [...]
>> @@ -115,8 +155,10 @@ static av_cold int decoder_init(AVCodecContext * avctx)
>>
>> ? ? ?if (avctx->bit_rate == 8000) {
>> ? ? ? ? ?ctx->bytes_per_frame = 10;
>> + ? ? ? ?ctx->format = &formats[FORMAT_G729_8K];
>
> ctx->format = format_g729_8k
Done.
>
>
>> ? ? ?} else if (avctx->bit_rate == 6400) {
>> ? ? ? ? ?ctx->bytes_per_frame = 8;
>> + ? ? ? ?ctx->format = &formats[FORMAT_G729D_6K4];
>> ? ? ?} else {
>> ? ? ? ? ?av_log(avctx, AV_LOG_ERROR, "Bitrate %d is not supported.\n", avctx->sample_rate);
>> ? ? ? ? ?return AVERROR_NOFMT;
>
>> @@ -134,7 +176,6 @@ static av_cold int decoder_init(AVCodecContext * avctx)
>>
>> ? ? ?/* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */
>> ? ? ?avctx->frame_size = SUBFRAME_SIZE << 1;
>> -
>> ? ? ?return 0;
>> ?}
>>
>
> cosmetics
Fixed.
>
>
>> @@ -162,12 +203,44 @@ static av_cold int decoder_init(AVCodecContext * avctx)
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ( voicing && ctx->frame_erasure) ? 0 : ctx->gain_code,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 << 13, 14, SUBFRAME_SIZE);
>>
>> +/**
>> + * Decodes one G.729 frame (10 bytes long) into parameter vector.
>> + * @param format used format (8k/4.4k/etc)
>> + * @param buf 10 bytes of decoder parameters
>> + * @param buf_size size of input buffer
>> + * @param parm [out] decoded codec parameters
>> + */
>> +static void bytes2parm(G729FormatDescription *format, const uint8_t *buf,
>> + ? ? ? ? ? ? ? ? ? ? ? int buf_size, G729Parameters *parm)
>> +{
>> + ? ?GetBitContext gb;
>> + ? ?int i;
>> +
>> + ? ?init_get_bits(&gb, buf, buf_size);
>> +
>> + ? ?parm->ma_predictor ? ? = get_bits(&gb, 1);
>> + ? ?parm->quantizer_1st ? ?= get_bits(&gb, VQ_1ST_BITS);
>> + ? ?parm->quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS);
>> + ? ?parm->quantizer_2nd_hi = get_bits(&gb, VQ_2ND_BITS);
>> +
>> + ? ?for (i = 0; i < 2; i++) {
>> + ? ? ? ?parm->ac_index[i] ? ? ?= get_bits(&gb, format->ac_index_bits[i]);
>> + ? ? ? ?parm->parity[i] ? ? ? ?= get_bits(&gb, format->parity_bits[i]);
>> + ? ? ? ?parm->fc_indexes[i] ? ?= get_bits(&gb, format->fc_indexes_bits);
>> + ? ? ? ?parm->pulses_signs[i] ?= get_bits(&gb, format->fc_signs_bits);
>> + ? ? ? ?parm->gc_1st_index[i] ?= get_bits(&gb, format->gc_1st_index_bits);
>> + ? ? ? ?parm->gc_2nd_index[i] ?= get_bits(&gb, format->gc_2nd_index_bits);
>> + ? ?}
>> +}
>
> iam not convinced that this loading into the struct is needed
Structure removed in favor of local variables.
decode_frame, bytes2parm,decode_frame_internal were merged into one routine.
formats array splitted into two structures.
parameters structure were removed.
Updated patch is attached.
>
> [...]
> --
> Michael ? ? GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The educated differ from the uneducated as much as the living from the
> dead. -- Aristotle
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iD8DBQFKMNonYR7HhwQLD6sRArq0AJ9PAG/ddG6OWbI8Caxqjzd0ZEtTLwCgmG61
> s5JbyNixbMeJ+yjpaQzIxiI=
> =dE8N
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>
--
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
JID: voroshil at gmail.com, voroshil at jabber.ru
ICQ: 95587719
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Decoding-routine-skeleton.142.patch
Type: text/x-diff
Size: 6809 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090613/bf31585a/attachment.patch>
More information about the ffmpeg-devel
mailing list