1 /*
2 * RTP Depacketization of Opus, RFC 7587
3 * Copyright (c) 2025 Jonathan Baudanza <jon@jonb.org>
4 * Copyright (c) 2022 Erik Linge
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
28
30 {
31 unsigned nb_frames = 1;
32 unsigned toc =
src[0];
33 unsigned toc_config = toc >> 3;
34 unsigned toc_count = toc & 3;
35 unsigned frame_size = toc_config < 12 ?
FFMAX(480, 960 * (toc_config & 3)) :
36 toc_config < 16 ? 480 << (toc_config & 1) :
37 120 << (toc_config & 3);
38 if (toc_count == 3) {
41 nb_frames =
src[1] & 0x3F;
42 } else if (toc_count) {
43 nb_frames = 2;
44 }
45
47 }
48
50 {
51 uint8_t *bs;
53
54 /* This function writes an extradata with a channel mapping family of 0.
55 * This mapping family only supports mono and stereo layouts. And RFC7587
56 * specifies that the number of channels in the SDP must be 2.
57 */
60 }
61
65
67
68 /* Opus magic */
70 /* Version */
71 bytestream_put_byte (&bs, 0x1);
72 /* Channel count */
74 /* Pre skip */
75 bytestream_put_le16 (&bs, 0);
76 /* Input sample rate */
77 bytestream_put_le32 (&bs, 48000);
78 /* Output gain */
79 bytestream_put_le16 (&bs, 0x0);
80 /* Mapping family */
81 bytestream_put_byte (&bs, 0x0);
82
83 return 0;
84 }
85
87 {
89 }
90
93 const uint8_t *buf,
int len, uint16_t seq,
95 {
96 int rv;
98
100 return rv;
101
104
108 }
109
110 return 0;
111 }
112
115 const char *attr,
const char *
value)
116 {
117 if (!strcmp(attr, "sprop-maxcapturerate")) {
118 int rate = atoi(
value);
119 if (rate < 8000 || rate > 48000) {
121 "fmtp field 'sprop-maxcapturerate' must be between 8000 to 48000 (provided value: %s)",
124 }
125 stream->codecpar->sample_rate = rate;
126 }
127 return 0;
128 }
129
132 {
134
135 if (st_index < 0)
136 return 0;
137
140 }
141 return 0;
142 }
143
151 };