[FFmpeg-soc] G723.1 Frame Parser

Ronald S. Bultje rsbultje at gmail.com
Mon Apr 5 22:42:19 CEST 2010


Hi,

On Mon, Apr 5, 2010 at 1:59 PM, Martin Storsjö <martin at martin.st> wrote:
> On Mon, 5 Apr 2010, Mohamed Naufal wrote:
>> +static const uint8_t frame_sizes[3] = {24, 20, 4};
>> +
>> +static int g723_1_handle_packet(AVFormatContext *ctx,
>> +                                PayloadContext *data,
>> +                                AVStream *st,
>> +                                AVPacket *pkt,
>> +                                uint32_t *timestamp,
>> +                                const uint8_t *buf,
>> +                                int len, int flags)
>> +{
>> +    int frames;
>> +    int pkt_size = len;
>> +
>> +    /* The frame size and codec type is determined from the HDR bits
>> +     * (buf[frames] & 3) in the first octet of a frame.
>> +     */
>> +    for (frames = 0; frames < len && (buf[frames] & 3) != 3;
>> +         frames += frame_sizes[buf[frames] & 3]);
>> +
>> +    if (frames > len) {
>> +        av_log(ctx, AV_LOG_WARNING, "Too little data in the RTP packet\n");
>> +    } else if (frames < len) {
>> +        /* This block is executed when the HDR bits are 0b11.
>> +         * But this is reserved for future use.
>> +         */
>> +        av_log(ctx, AV_LOG_WARNING, "Found an invalid frame!\n");
>> +        pkt_size = frames;
>> +    }
>> +
>> +    if (av_new_packet(pkt, pkt_size) < 0) {
>> +        av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
>> +        return AVERROR_NOMEM;
>> +    }
>> +
>> +    pkt->stream_index = st->index;
>> +    memcpy(pkt->data, buf, pkt_size);
>> +    return 0;
>> +}
>
> When you don't do any splitting of frames in the depacketizer, you're
> basically returning the whole packet payload unmodified, right? So this is
> basically only performing some sanity checks on the data, which will also
> be done implicitly by either a parser or ffplay/ffmpeg decoding from the
> same AVPacket multiple times until all data has been consumed. So I'm not
> sure if this really is necessary here, although there's no harm in
> keeping it either.

It's an extra file. If all this does is output into a packet, then
(see the default: case in rtpdec.c rtp_parse_packet()) we don't need
this file at all. Instead, just his change to the RTP payload table
should be sufficient, and the actual depacketizer can be removed.

Ronald


More information about the FFmpeg-soc mailing list