[FFmpeg-devel] [PATCH] RTP depacketizer for AMR

Martin Storsjö martin
Wed Jan 27 20:55:16 CET 2010


On Wed, 27 Jan 2010, Ronald S. Bultje wrote:

> On Wed, Jan 27, 2010 at 7:50 AM, Martin Storsj? <martin at martin.st> wrote:
> > Here's the first shot at an RTP depacketizer for AMR. It has been tested
> > with libavformat's RTP AMR packetizer, QuickTime Broadcaster and samples
> > from Darwin Streaming Server.
> 
> Does it work with Colin & Vitor's AMR decoder?

I've only tested it with libopencore-amr, but I assume it does, especially 
as long as the frames are split within the depacketizer.

> > I also tried returning all frames at once, but ffmpeg.c gives the
> > "Multiple frames in a packet from stream" error message (but works fine
> > except for that).
> 
> CODEC_CAP_SUBFRAMES in the decoder fixes that.

If I understood Michael correctly, that's the incorrect solution, either 
we should split the packets or create a parser to do that.

> > +static const uint8_t frame_sizes_nb[16] = {
> > +    12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0
> > +};
> 
> Can this be shared with the AMR decoder that is in Vitor's patch? (I
> didn't see it on quick look.)

Probably, yes. Similar arrays are found in both libavformat/amr.c and 
libavcodec/libopencore-amr.c, and some roughly similar data (but counted 
differently) in the SoC AMR decoder.

> > +        /* Make sure we've got a local buffer for storing the packet
> > +         * while returning one frame at a time. */
> > +        if (!data->buf || data->buf_size < len) {
> > +            av_freep(&data->buf);
> > +            data->buf_size = len;
> > +            data->buf = av_malloc(data->buf_size);
> > +            if (!data->buf) {
> > +                av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
> > +                return AVERROR_NOMEM;
> > +            }
> > +        }
> 
> *_dyn_pkt_buf.

Will have a look at that.

> > +static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
> > +                              PayloadContext *data, const char *line)
> [..]
> > +    if (av_strstart(line, "fmtp:", &p)) {
> [..]
> > +        while (*p && *p == ' ') p++; /* strip spaces */
> > +        while (*p && *p != ' ') p++; /* eat protocol identifier */
> > +        while (*p && *p == ' ') p++; /* strip trailing spaces */
> > +
> > +        while (rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) {
> > +            if (!strcmp(attr, "octet-align"))
> > +                octet_align = atoi(value);
> > +            else if (!strcmp(attr, "crc"))
> > +                crc = atoi(value);
> > +            else if (!strcmp(attr, "interleaving"))
> > +                interleaving = atoi(value);
> > +            else if (!strcmp(attr, "channels"))
> > +                channels = atoi(value);
> > +        }
> 
> Can you document what format it's looking for here?

Do you mean what the fmtp line looks like? It's something like this:

a=fmtp:97 octet-align=1; interleaving=0; channels=1

That is, normal semicolon & space separated key/value pairs, as most fmtp 
lines, since it uses the generic parser routine, too.

If this was what you meant, I'll add a comment about it.

// Martin



More information about the ffmpeg-devel mailing list