[FFmpeg-soc] [soc]: r310 - in qcelp: README doc doc/NOTES doc/TODO qcelp.h qcelp_glue.diff qcelpdec.c srcprepare.sh

Benjamin Larsson banan at ludd.ltu.se
Wed Jul 4 10:57:54 CEST 2007


Hi!

reynaldo skrev:
> Author: reynaldo
> Date: Tue Jul  3 22:16:49 2007
> New Revision: 310
>
> Log:
> Some structural code frame, only thing I would consider ready for initial peer review here is the parsing and reordering routine. feel free to destroy everything along with it thouhg ;)
> Added: qcelp/qcelp.h
>   

Please rename to qcelpdata.h.

> +#define QCELP_RATE_FULL_BITMAP \
>   

And make tables of these in the future.
> + *
> + * Oce frame is parsed all data gets stored in QCELPFrame.data acording
> + * to this structure:
>   

? Oce

> + *
> + *     QCELP_X0_POS
> + *           |
> + * CBSIGNs   0     1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
> + * CBGAINs  16    17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
> + * CINDEXs  32    33 34 35 36 37 38 39 40 41 43 43 44 45 46 47
> + * PLAGs    48    49 50 51
> + * PFRACs   52    53 54 55
> + * PGAINs   56    57 58 59
> + * LSPVs    60    61 62 63 64
> + * RSVD     65
> + * LSP      66    67 68 69 70 71 72 73 74 75
> + * CBSEED   76
> + *
> + *-------------------------------------------------------------------------*/
> +
> +typedef struct
> +{
> +    qcelp_packet_type type;
> +    uint8_t data[76];       /* holds all data from a frame (_once_ parsed) */
> +    uint8_t bits;
> +} QCELPFrame;
>   

Move this to the c file, and use simpler types(int). And rename 
qcelp_packet_type to qcelp_packet_rate.
> +
> +/*
> + * Position of the transmision codes inside the universal frame.
> + *
> + */
> +
> +#define QCELP_CBSIGN0_POS 0
> +#define QCELP_CBGAIN0_POS 16
> +#define QCELP_CINDEX0_POS 32
> +#define QCELP_PLAG0_POS   48
> +#define QCELP_PFRAC0_POS  52
> +#define QCELP_PGAIN0_POS  56
> +#define QCELP_LSPV0_POS   60
> +#define QCELP_RSRVD_POS   65    /* on all but rate 1/2 packets */
> +#define QCELP_LSP0_POS    66    /* only in rate 1/8 packets    */
> +#define QCELP_CBSEED_POS  76    /* only in rate 1/8 packets    */
>
> Added: qcelp/qcelpdec.c
> ==============================================================================
> --- (empty file)
> +++ qcelp/qcelpdec.c	Tue Jul  3 22:16:49 2007
> @@ -0,0 +1,235 @@
>   
[...]
> +
> +typedef struct {
> +    GetBitContext gb;
> +    QCELPFrame    *frame;
> +    uint8_t       erasure_count;
> +    uint8_t       ifq_count;
> +} QCELPContext;
>   

Use the int type and don't allocate frame.

> +
> +static int qcelp_decode_init(AVCodecContext *avctx);
> +static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
> +           int *data_size, uint8_t *buf, int buf_size);
> +static int qcelp_decode_close(AVCodecContext *avctx);
> +
>   

Remove the declarations and reorder the functions in the file if needed.

> +
> +static int qcelp_decode_init(AVCodecContext *avctx)
> +{
> +    QCELPContext *q = (QCELPContext *) avctx->priv_data;
> +
> +    avctx->sample_rate = 8000;
> +    avctx->channels = 1;
> +
> +    q->frame = av_mallocz(sizeof(QCELPFrame));
> +
>   

Remove this allocation.

> +
> +    if(q->frame == NULL)
> +        return -1;
> +
> +    return 0;
> +}
> +
> +static int qcelp_parse_pkt_full(uint8_t *buf, QCELPFrame *frame)
> +{
> +    return 0;
> +}
> +
> +static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
> +           int *data_size, uint8_t *buf, int buf_size)
> +{
> +    QCELPContext *q = avctx->priv_data;
> +    int16_t *outbuffer = data;
> +    int8_t samples;
> +    int8_t bitcount;
>   

Use int where you can.

> +    int16_t first16 = 0; /* needed for rate 1/8 particularities */
> +
> +    QCELPBitmap *order;
> +
> +    order = NULL;
> +
> +    init_get_bits(&q->gb, buf, buf_size*8);
> +
> +    /*
> +     * FIXME this comment should actually make some sence ..
> +     *
> +     * Here we try to identify each frame's rate by its byte size,
> +     * then, after setting a few utility vars we point 'order'
> +     * to start at the location of the rate's reference _slice_
> +     * inside the big REFERECE_FRAME array. We then proceed with
> +     * the bit reordering that will leave a full raw frame's data
> +     * ordered in our 'universal frame'
> +     */
> +
> +    switch(buf_size)
> +    {
> +        case 34:
>   
> +            q->frame->type = RATE_FULL;
> +            q->frame->bits = qcelp_bits_per_type[RATE_FULL];
>   

To not use the qcelp_bits_per_type table and just write the value here 
might be more clear if the table is only referenced once.

> +            order = QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS;
> +            break;
> +        case 16:
> +            q->frame->type = RATE_HALF;
> +            q->frame->bits = qcelp_bits_per_type[RATE_HALF];
> +            order = QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS;
> +            break;
> +        case 7:
> +            q->frame->type = RATE_QUARTER;
> +            q->frame->bits = qcelp_bits_per_type[RATE_QUARTER];
> +            order = QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS;
> +            break;
> +        case 3:
> +            q->frame->type = RATE_OCTAVE;
> +            q->frame->bits = qcelp_bits_per_type[RATE_OCTAVE];
> +            order = QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS;
> +            break;
> +        case 0: /* FIXME */
> +            q->frame->type = BLANK;
> +            q->frame->bits = 0;
> +            break;
> +        default:
> +            q->frame->type = RATE_UNKNOWN;
> +            q->frame->bits = 0;
> +            printf("UNKNOWN PACKET RATE\n");
>   

Use av_log.

> +            break;
> +    }
> +
> +    /*
> +     * reordering loop
> +     */
> +
> +    bitcount=0;
> +    while(bitcount < q->frame->bits)
>   

Can you use a for loop instead ? Should give more compact and 
understandable code.

> +    {
> +        /*
> +         * order[bitcount]->index holds the placement of this
> +         * input stream bit in the universal frame.
> +         *
> +         * order[bitcount]->pos holds the bit pos inside this value
> +         * byte.
> +         *
> +         */
> +
> +        q->frame->data[ order[bitcount].index ] |=
> +        get_bits1(&q->gb)>>(order[bitcount].bitpos);
> +
> +        /*
> +         * viral sample! :D
> +         *
> +         * just needed for rate 1/8 packets
> +         *
> +         */
> +
> +        if(bitcount<16)
> +        {
> +            first16 |= q->frame->data[ order[bitcount].index ]>>bitcount
> +        }
> +
> +        bitcount++;
> +    }
> +
>   

That's all for now, keep up the good work.

MvH
Benjamin Larsson





More information about the FFmpeg-soc mailing list