+static int opus_write_extradata(AVCodecParameters *codecpar)
+{
+ uint8_t *bs;
+ int ret;
+
+ /* This function writes an extradata with a channel mapping family of 0.
+ * This mapping family only supports mono and stereo layouts. And RFC7587
+ * specifies that the number of channels in the SDP must be 2.
+ */
+ if (codecpar->channels > 2) {
+ return AVERROR_INVALIDDATA;
+ }
+
+ ret = ff_alloc_extradata(codecpar, 19);
+ if (ret < 0)
+ return ret;
+
+ bs = (uint8_t *)codecpar->extradata;
+
+ /* Opus magic */
+ bytestream_put_buffer(&bs, "OpusHead", 8);
+ /* Version */
+ bytestream_put_byte (&bs, 0x1);
+ /* Channel count */
+ bytestream_put_byte (&bs, codecpar->channels);
+ /* Pre skip */
+ bytestream_put_le16 (&bs, 0);
+ /* Input sample rate */
+ bytestream_put_le32 (&bs, 48000);
+ /* Output gain */
+ bytestream_put_le16 (&bs, 0x0);
+ /* Mapping family */
+ bytestream_put_byte (&bs, 0x0);
+
+ return 0;
+}
+