[Ffmpeg-devel] [PATCH] RTP payload format for AMR

Kite Flyer kiteflyer77
Thu Mar 8 13:51:34 CET 2007


Hi Michael,

Thanks for your review. I've attached a new patch with some changes
suggested: pls see below.

-Subrata

On 3/8/07, Michael Niedermayer <michaelni at gmx.at> wrote:
> Hi
>
> On Wed, Mar 07, 2007 at 09:00:11PM +0530, Kite Flyer wrote:
> > Hi,
> >
> > My work required to stream AMR audio. The attached patch implements
> > octet-aligned payload for AMR NB mono audio as per RFC 3267. It works well
> > with several media players e.g. real player, QuickTime player etc.
> >
> > I could very well change the bit rate with "-ab" option using older SVN
> > code. But current SVN code (ffmpeg.c) seems to break the option. Any idea
> > how to set the audio bit rate now?
>
> -ab 123 is now -ab 123k or kb

-ab Nkb works.

>
>
> [...]
>
> > +        //TODO: find a way to pack maximum number of frames based on max_payload_size
>
> yes
>

Keeping it as fixed no of frames as of now.

payload format requires that all speech data frames be written after
all frame headers i.e. ToC. If encoder always generates constant bit
rate frames then offset of data frames can be calculated and maximum
no of frames can be packed. But if encoder can generate variable bit
rate frames, then two memory areas can be taken: one for ToC and
another for data but the memcpy to concatenate the memories would be
expensive per send.

>
> [...]
> >      }
> >  }
> >
> > +/* Send AMR audio. Note: AMR_NB, single channel is supported now. */
> > +static void rtp_send_amr(AVFormatContext *s1,
> > +                               const uint8_t *buf1, int size)
> > +{
> > +    RTPDemuxContext *s = s1->priv_data;
> > +    AVStream *st = s1->streams[0];
> > +    const static uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
> > +    uint8_t toc, ft;
> > +    int dlen;
> > +
> > +    if (st->codec->codec_id != CODEC_ID_AMR_NB)
> > +        return; //FIXME: clean if reqd
> > +
> > +    if (size < 1)
> > +        return;
> > +
> > +    /* correct table of contents and add frames */
> > +    while (size > 0) {
>
> this function cannot receive more then 1 frame at a time, if it does then
> there is a bug somewhere, (if the amr encoder outputs several frames
> concatenated then it is buggy, if a demuxer outputs such mess a AVParser
> is needed to split it up, reimplementing such split up code everywhere
> will not be accepted)
>

True. Changed the comments though keeping the while like other codec
pack routines.

>
> [...]
> > +#ifdef DEBUG
> > +            printf("AMR: incomplete frame: frame type = %d, data len=%d, size = %d\n", ft, dlen, size);
> > +            //FIXME check if the data would come in next chunk
> > +#endif
>
> please use dprintf() insetad of printf under #ifdef DEBUG
>

Changed to dprintf.

>
> > +        }
> > +
> > +        /* flush if max number of frames added */
> > +        //TODO: find a way to pack maximum number of frames
> > +        if (s->frame_count == AMR_NB_MAX_FRAMES)
> > +        {
> > +            s->buf[s->frame_count] &= 0x7f; // set f = 0
> > +            rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
> > +            s->timestamp += 160 * s->frame_count;
> > +            s->buf[0] = 0xf0;
> > +            memset(s->buf + 1, 0x7c, AMR_NB_MAX_FRAMES);
>
> what does this memset do? isnt the area always overwritten again?
>

Right. Had something else in my mind. Removed now.

>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I am the wisest man alive, for I know one thing, and that is that I know
> nothing. -- Socrates
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: amr_rtp_payload1.patch
Type: application/octet-stream
Size: 3518 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070308/cc3e08d4/attachment.obj>



More information about the ffmpeg-devel mailing list