annotate rtpenc_amr.c @ 6170:224077f3c564 libavformat

Correctly return EOF for smacker videos Patch by Alexei Svitkine, alexei dot svitkine at gmail
author mstorsjo
date Thu, 24 Jun 2010 06:55:53 +0000
parents e09092917f7e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4836
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
1 /*
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
2 * RTP packetization for AMR audio
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
3 * Copyright (c) 2007 Luca Abeni
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
4 * Copyright (c) 2009 Martin Storsjo
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
5 *
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
6 * This file is part of FFmpeg.
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
7 *
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
12 *
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
16 * Lesser General Public License for more details.
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
17 *
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
21 */
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
22
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
23 #include "avformat.h"
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
24 #include "rtpenc.h"
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
25
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
26 /**
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
27 * Packetize AMR frames into RTP packets according to RFC 3267,
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
28 * in octet-aligned mode.
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
29 */
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
30 void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
31 {
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
32 RTPMuxContext *s = s1->priv_data;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
33 int max_header_toc_size = 1 + s->max_frames_per_packet;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
34 uint8_t *p;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
35 int len;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
36
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
37 /* Test if the packet must be sent. */
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
38 len = s->buf_ptr - s->buf;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
39 if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
40 int header_size = s->num_frames + 1;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
41 p = s->buf + max_header_toc_size - header_size;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
42 if (p != s->buf)
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
43 memmove(p, s->buf, header_size);
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
44
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
45 ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
46
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
47 s->num_frames = 0;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
48 }
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
49
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
50 if (!s->num_frames) {
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
51 s->buf[0] = 0xf0;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
52 s->buf_ptr = s->buf + max_header_toc_size;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
53 s->timestamp = s->cur_timestamp;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
54 } else {
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
55 /* Mark the previous TOC entry as having more entries following. */
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
56 s->buf[1 + s->num_frames - 1] |= 0x80;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
57 }
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
58
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
59 /* Copy the frame type and quality bits. */
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
60 s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
61 buff++;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
62 size--;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
63 memcpy(s->buf_ptr, buff, size);
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
64 s->buf_ptr += size;
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
65 }
bf87d9ffb3ae Add support for AMR audio in the RTP muxer
lucabe
parents:
diff changeset
66