You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

701 lines
23KB

  1. /*
  2. * Ogg muxer
  3. * Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at free dot fr>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <stdint.h>
  22. #include "libavutil/crc.h"
  23. #include "libavutil/mathematics.h"
  24. #include "libavutil/opt.h"
  25. #include "libavutil/random_seed.h"
  26. #include "libavcodec/xiph.h"
  27. #include "libavcodec/bytestream.h"
  28. #include "libavcodec/flac.h"
  29. #include "avformat.h"
  30. #include "avio_internal.h"
  31. #include "internal.h"
  32. #include "vorbiscomment.h"
  33. #define MAX_PAGE_SIZE 65025
  34. typedef struct {
  35. int64_t start_granule;
  36. int64_t granule;
  37. int stream_index;
  38. uint8_t flags;
  39. uint8_t segments_count;
  40. uint8_t segments[255];
  41. uint8_t data[MAX_PAGE_SIZE];
  42. uint16_t size;
  43. } OGGPage;
  44. typedef struct {
  45. unsigned page_counter;
  46. uint8_t *header[3];
  47. int header_len[3];
  48. /** for theora granule */
  49. int kfgshift;
  50. int64_t last_kf_pts;
  51. int vrev;
  52. int eos;
  53. unsigned page_count; ///< number of page buffered
  54. OGGPage page; ///< current page
  55. unsigned serial_num; ///< serial number
  56. int64_t last_granule; ///< last packet granule
  57. } OGGStreamContext;
  58. typedef struct OGGPageList {
  59. OGGPage page;
  60. struct OGGPageList *next;
  61. } OGGPageList;
  62. typedef struct {
  63. const AVClass *class;
  64. OGGPageList *page_list;
  65. int pref_size; ///< preferred page size (0 => fill all segments)
  66. int64_t pref_duration; ///< preferred page duration (0 => fill all segments)
  67. } OGGContext;
  68. #define OFFSET(x) offsetof(OGGContext, x)
  69. #define PARAM AV_OPT_FLAG_ENCODING_PARAM
  70. static const AVOption options[] = {
  71. { "pagesize", "preferred page size in bytes (deprecated)",
  72. OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
  73. { "page_duration", "preferred page duration, in microseconds",
  74. OFFSET(pref_duration), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
  75. { NULL },
  76. };
  77. #define OGG_CLASS(flavor)\
  78. static const AVClass flavor ## _muxer_class = {\
  79. .class_name = #flavor " muxer",\
  80. .item_name = av_default_item_name,\
  81. .option = options,\
  82. .version = LIBAVUTIL_VERSION_INT,\
  83. };
  84. static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
  85. {
  86. int64_t pos = avio_tell(pb);
  87. uint32_t checksum = ffio_get_checksum(pb);
  88. avio_seek(pb, crc_offset, SEEK_SET);
  89. avio_wb32(pb, checksum);
  90. avio_seek(pb, pos, SEEK_SET);
  91. }
  92. static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
  93. {
  94. OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
  95. AVIOContext *pb;
  96. int64_t crc_offset;
  97. int ret, size;
  98. uint8_t *buf;
  99. ret = avio_open_dyn_buf(&pb);
  100. if (ret < 0)
  101. return ret;
  102. ffio_init_checksum(pb, ff_crc04C11DB7_update, 0);
  103. ffio_wfourcc(pb, "OggS");
  104. avio_w8(pb, 0);
  105. avio_w8(pb, page->flags | extra_flags);
  106. avio_wl64(pb, page->granule);
  107. avio_wl32(pb, oggstream->serial_num);
  108. avio_wl32(pb, oggstream->page_counter++);
  109. crc_offset = avio_tell(pb);
  110. avio_wl32(pb, 0); // crc
  111. avio_w8(pb, page->segments_count);
  112. avio_write(pb, page->segments, page->segments_count);
  113. avio_write(pb, page->data, page->size);
  114. ogg_update_checksum(s, pb, crc_offset);
  115. avio_flush(pb);
  116. size = avio_close_dyn_buf(pb, &buf);
  117. if (size < 0)
  118. return size;
  119. avio_write(s->pb, buf, size);
  120. avio_flush(s->pb);
  121. av_free(buf);
  122. oggstream->page_count--;
  123. return 0;
  124. }
  125. static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
  126. {
  127. if (oggstream->kfgshift)
  128. return (granule>>oggstream->kfgshift) +
  129. (granule & ((1<<oggstream->kfgshift)-1));
  130. else
  131. return granule;
  132. }
  133. static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
  134. {
  135. AVStream *st2 = s->streams[next->stream_index];
  136. AVStream *st = s->streams[page->stream_index];
  137. int64_t next_granule, cur_granule;
  138. if (next->granule == -1 || page->granule == -1)
  139. return 0;
  140. next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
  141. st2->time_base, AV_TIME_BASE_Q);
  142. cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
  143. st ->time_base, AV_TIME_BASE_Q);
  144. return next_granule > cur_granule;
  145. }
  146. static int ogg_reset_cur_page(OGGStreamContext *oggstream)
  147. {
  148. oggstream->page.granule = -1;
  149. oggstream->page.flags = 0;
  150. oggstream->page.segments_count = 0;
  151. oggstream->page.size = 0;
  152. return 0;
  153. }
  154. static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
  155. {
  156. OGGContext *ogg = s->priv_data;
  157. OGGPageList **p = &ogg->page_list;
  158. OGGPageList *l = av_mallocz(sizeof(*l));
  159. if (!l)
  160. return AVERROR(ENOMEM);
  161. l->page = oggstream->page;
  162. oggstream->page.start_granule = oggstream->page.granule;
  163. oggstream->page_count++;
  164. ogg_reset_cur_page(oggstream);
  165. while (*p) {
  166. if (ogg_compare_granule(s, &(*p)->page, &l->page))
  167. break;
  168. p = &(*p)->next;
  169. }
  170. l->next = *p;
  171. *p = l;
  172. return 0;
  173. }
  174. static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
  175. uint8_t *data, unsigned size, int64_t granule,
  176. int header)
  177. {
  178. OGGStreamContext *oggstream = st->priv_data;
  179. OGGContext *ogg = s->priv_data;
  180. int total_segments = size / 255 + 1;
  181. uint8_t *p = data;
  182. int i, segments, len, flush = 0;
  183. // Handles VFR by flushing page because this frame needs to have a timestamp
  184. if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header &&
  185. ogg_granule_to_timestamp(oggstream, granule) >
  186. ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) {
  187. if (oggstream->page.granule != -1)
  188. ogg_buffer_page(s, oggstream);
  189. flush = 1;
  190. }
  191. // avoid a continued page
  192. if (!header && oggstream->page.size > 0 &&
  193. MAX_PAGE_SIZE - oggstream->page.size < size) {
  194. ogg_buffer_page(s, oggstream);
  195. }
  196. for (i = 0; i < total_segments; ) {
  197. OGGPage *page = &oggstream->page;
  198. segments = FFMIN(total_segments - i, 255 - page->segments_count);
  199. if (i && !page->segments_count)
  200. page->flags |= 1; // continued packet
  201. memset(page->segments+page->segments_count, 255, segments - 1);
  202. page->segments_count += segments - 1;
  203. len = FFMIN(size, segments*255);
  204. page->segments[page->segments_count++] = len - (segments-1)*255;
  205. memcpy(page->data+page->size, p, len);
  206. p += len;
  207. size -= len;
  208. i += segments;
  209. page->size += len;
  210. if (i == total_segments)
  211. page->granule = granule;
  212. if (!header) {
  213. AVStream *st = s->streams[page->stream_index];
  214. int64_t start = av_rescale_q(page->start_granule, st->time_base,
  215. AV_TIME_BASE_Q);
  216. int64_t next = av_rescale_q(page->granule, st->time_base,
  217. AV_TIME_BASE_Q);
  218. if (page->segments_count == 255 ||
  219. (ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
  220. (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
  221. ogg_buffer_page(s, oggstream);
  222. }
  223. }
  224. }
  225. if (flush && oggstream->page.granule != -1)
  226. ogg_buffer_page(s, oggstream);
  227. return 0;
  228. }
  229. static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
  230. int *header_len, AVDictionary **m, int framing_bit)
  231. {
  232. const char *vendor = bitexact ? "Libav" : LIBAVFORMAT_IDENT;
  233. int size;
  234. uint8_t *p, *p0;
  235. ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
  236. size = offset + ff_vorbiscomment_length(*m, vendor) + framing_bit;
  237. p = av_mallocz(size);
  238. if (!p)
  239. return NULL;
  240. p0 = p;
  241. p += offset;
  242. ff_vorbiscomment_write(&p, m, vendor);
  243. if (framing_bit)
  244. bytestream_put_byte(&p, 1);
  245. *header_len = size;
  246. return p0;
  247. }
  248. static int ogg_build_flac_headers(AVCodecContext *avctx,
  249. OGGStreamContext *oggstream, int bitexact,
  250. AVDictionary **m)
  251. {
  252. uint8_t *p;
  253. if (avctx->extradata_size < FLAC_STREAMINFO_SIZE)
  254. return AVERROR(EINVAL);
  255. // first packet: STREAMINFO
  256. oggstream->header_len[0] = 51;
  257. oggstream->header[0] = av_mallocz(51); // per ogg flac specs
  258. p = oggstream->header[0];
  259. if (!p)
  260. return AVERROR(ENOMEM);
  261. bytestream_put_byte(&p, 0x7F);
  262. bytestream_put_buffer(&p, "FLAC", 4);
  263. bytestream_put_byte(&p, 1); // major version
  264. bytestream_put_byte(&p, 0); // minor version
  265. bytestream_put_be16(&p, 1); // headers packets without this one
  266. bytestream_put_buffer(&p, "fLaC", 4);
  267. bytestream_put_byte(&p, 0x00); // streaminfo
  268. bytestream_put_be24(&p, 34);
  269. bytestream_put_buffer(&p, avctx->extradata, FLAC_STREAMINFO_SIZE);
  270. // second packet: VorbisComment
  271. p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
  272. if (!p)
  273. return AVERROR(ENOMEM);
  274. oggstream->header[1] = p;
  275. bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
  276. bytestream_put_be24(&p, oggstream->header_len[1] - 4);
  277. return 0;
  278. }
  279. #define SPEEX_HEADER_SIZE 80
  280. static int ogg_build_speex_headers(AVCodecContext *avctx,
  281. OGGStreamContext *oggstream, int bitexact,
  282. AVDictionary **m)
  283. {
  284. uint8_t *p;
  285. if (avctx->extradata_size < SPEEX_HEADER_SIZE)
  286. return -1;
  287. // first packet: Speex header
  288. p = av_mallocz(SPEEX_HEADER_SIZE);
  289. if (!p)
  290. return AVERROR(ENOMEM);
  291. oggstream->header[0] = p;
  292. oggstream->header_len[0] = SPEEX_HEADER_SIZE;
  293. bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE);
  294. AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
  295. // second packet: VorbisComment
  296. p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
  297. if (!p)
  298. return AVERROR(ENOMEM);
  299. oggstream->header[1] = p;
  300. return 0;
  301. }
  302. #define OPUS_HEADER_SIZE 19
  303. static int ogg_build_opus_headers(AVCodecContext *avctx,
  304. OGGStreamContext *oggstream, int bitexact,
  305. AVDictionary **m)
  306. {
  307. uint8_t *p;
  308. if (avctx->extradata_size < OPUS_HEADER_SIZE)
  309. return -1;
  310. /* first packet: Opus header */
  311. p = av_mallocz(avctx->extradata_size);
  312. if (!p)
  313. return AVERROR(ENOMEM);
  314. oggstream->header[0] = p;
  315. oggstream->header_len[0] = avctx->extradata_size;
  316. bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size);
  317. /* second packet: VorbisComment */
  318. p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
  319. if (!p)
  320. return AVERROR(ENOMEM);
  321. oggstream->header[1] = p;
  322. bytestream_put_buffer(&p, "OpusTags", 8);
  323. return 0;
  324. }
  325. static void ogg_write_pages(AVFormatContext *s, int flush)
  326. {
  327. OGGContext *ogg = s->priv_data;
  328. OGGPageList *next, *p;
  329. if (!ogg->page_list)
  330. return;
  331. for (p = ogg->page_list; p; ) {
  332. OGGStreamContext *oggstream =
  333. s->streams[p->page.stream_index]->priv_data;
  334. if (oggstream->page_count < 2 && !flush)
  335. break;
  336. ogg_write_page(s, &p->page,
  337. flush == 1 && oggstream->page_count == 1 ? 4 : 0); // eos
  338. next = p->next;
  339. av_freep(&p);
  340. p = next;
  341. }
  342. ogg->page_list = p;
  343. }
  344. static int ogg_write_header(AVFormatContext *s)
  345. {
  346. OGGContext *ogg = s->priv_data;
  347. OGGStreamContext *oggstream;
  348. int i, j;
  349. if (ogg->pref_size)
  350. av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
  351. for (i = 0; i < s->nb_streams; i++) {
  352. AVStream *st = s->streams[i];
  353. unsigned serial_num = i;
  354. if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
  355. if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  356. /* Opus requires a fixed 48kHz clock */
  357. avpriv_set_pts_info(st, 64, 1, 48000);
  358. else
  359. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  360. if (st->codec->codec_id != AV_CODEC_ID_VORBIS &&
  361. st->codec->codec_id != AV_CODEC_ID_THEORA &&
  362. st->codec->codec_id != AV_CODEC_ID_SPEEX &&
  363. st->codec->codec_id != AV_CODEC_ID_FLAC &&
  364. st->codec->codec_id != AV_CODEC_ID_OPUS) {
  365. av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
  366. return -1;
  367. }
  368. if (!st->codec->extradata || !st->codec->extradata_size) {
  369. av_log(s, AV_LOG_ERROR, "No extradata present\n");
  370. return -1;
  371. }
  372. oggstream = av_mallocz(sizeof(*oggstream));
  373. oggstream->page.stream_index = i;
  374. if (!(s->flags & AVFMT_FLAG_BITEXACT))
  375. do {
  376. serial_num = av_get_random_seed();
  377. for (j = 0; j < i; j++) {
  378. OGGStreamContext *sc = s->streams[j]->priv_data;
  379. if (serial_num == sc->serial_num)
  380. break;
  381. }
  382. } while (j < i);
  383. oggstream->serial_num = serial_num;
  384. st->priv_data = oggstream;
  385. if (st->codec->codec_id == AV_CODEC_ID_FLAC) {
  386. int err = ogg_build_flac_headers(st->codec, oggstream,
  387. s->flags & AVFMT_FLAG_BITEXACT,
  388. &s->metadata);
  389. if (err) {
  390. av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
  391. av_freep(&st->priv_data);
  392. return err;
  393. }
  394. } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) {
  395. int err = ogg_build_speex_headers(st->codec, oggstream,
  396. s->flags & AVFMT_FLAG_BITEXACT,
  397. &s->metadata);
  398. if (err) {
  399. av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
  400. av_freep(&st->priv_data);
  401. return err;
  402. }
  403. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) {
  404. int err = ogg_build_opus_headers(st->codec, oggstream,
  405. s->flags & AVFMT_FLAG_BITEXACT,
  406. &s->metadata);
  407. if (err) {
  408. av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
  409. av_freep(&st->priv_data);
  410. return err;
  411. }
  412. } else {
  413. uint8_t *p;
  414. const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
  415. int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
  416. int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
  417. if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
  418. st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
  419. oggstream->header, oggstream->header_len) < 0) {
  420. av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
  421. av_freep(&st->priv_data);
  422. return -1;
  423. }
  424. p = ogg_write_vorbiscomment(7, s->flags & AVFMT_FLAG_BITEXACT,
  425. &oggstream->header_len[1], &s->metadata,
  426. framing_bit);
  427. oggstream->header[1] = p;
  428. if (!p)
  429. return AVERROR(ENOMEM);
  430. bytestream_put_byte(&p, header_type);
  431. bytestream_put_buffer(&p, cstr, 6);
  432. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  433. /** KFGSHIFT is the width of the less significant section of the granule position
  434. The less significant section is the frame count since the last keyframe */
  435. oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
  436. oggstream->vrev = oggstream->header[0][9];
  437. av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
  438. oggstream->kfgshift, oggstream->vrev);
  439. }
  440. }
  441. }
  442. for (j = 0; j < s->nb_streams; j++) {
  443. OGGStreamContext *oggstream = s->streams[j]->priv_data;
  444. ogg_buffer_data(s, s->streams[j], oggstream->header[0],
  445. oggstream->header_len[0], 0, 1);
  446. oggstream->page.flags |= 2; // bos
  447. ogg_buffer_page(s, oggstream);
  448. }
  449. for (j = 0; j < s->nb_streams; j++) {
  450. AVStream *st = s->streams[j];
  451. OGGStreamContext *oggstream = st->priv_data;
  452. for (i = 1; i < 3; i++) {
  453. if (oggstream->header_len[i])
  454. ogg_buffer_data(s, st, oggstream->header[i],
  455. oggstream->header_len[i], 0, 1);
  456. }
  457. ogg_buffer_page(s, oggstream);
  458. }
  459. oggstream->page.start_granule = AV_NOPTS_VALUE;
  460. ogg_write_pages(s, 2);
  461. return 0;
  462. }
  463. static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
  464. {
  465. AVStream *st = s->streams[pkt->stream_index];
  466. OGGStreamContext *oggstream = st->priv_data;
  467. int ret;
  468. int64_t granule;
  469. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  470. int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
  471. int pframe_count;
  472. if (pkt->flags & AV_PKT_FLAG_KEY)
  473. oggstream->last_kf_pts = pts;
  474. pframe_count = pts - oggstream->last_kf_pts;
  475. // prevent frame count from overflow if key frame flag is not set
  476. if (pframe_count >= (1<<oggstream->kfgshift)) {
  477. oggstream->last_kf_pts += pframe_count;
  478. pframe_count = 0;
  479. }
  480. granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
  481. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  482. granule = pkt->pts + pkt->duration +
  483. av_rescale_q(st->codec->initial_padding,
  484. (AVRational){ 1, st->codec->sample_rate },
  485. st->time_base);
  486. else
  487. granule = pkt->pts + pkt->duration;
  488. if (oggstream->page.start_granule == AV_NOPTS_VALUE)
  489. oggstream->page.start_granule = pkt->pts;
  490. ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
  491. if (ret < 0)
  492. return ret;
  493. ogg_write_pages(s, 0);
  494. oggstream->last_granule = granule;
  495. return 0;
  496. }
  497. static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
  498. {
  499. int i;
  500. if (pkt)
  501. return ogg_write_packet_internal(s, pkt);
  502. for (i = 0; i < s->nb_streams; i++) {
  503. OGGStreamContext *oggstream = s->streams[i]->priv_data;
  504. if (oggstream->page.segments_count)
  505. ogg_buffer_page(s, oggstream);
  506. }
  507. ogg_write_pages(s, 2);
  508. return 0;
  509. }
  510. static int ogg_write_trailer(AVFormatContext *s)
  511. {
  512. int i;
  513. /* flush current page if needed */
  514. for (i = 0; i < s->nb_streams; i++) {
  515. OGGStreamContext *oggstream = s->streams[i]->priv_data;
  516. if (oggstream->page.size > 0)
  517. ogg_buffer_page(s, oggstream);
  518. }
  519. ogg_write_pages(s, 1);
  520. for (i = 0; i < s->nb_streams; i++) {
  521. AVStream *st = s->streams[i];
  522. OGGStreamContext *oggstream = st->priv_data;
  523. if (st->codec->codec_id == AV_CODEC_ID_FLAC ||
  524. st->codec->codec_id == AV_CODEC_ID_SPEEX ||
  525. st->codec->codec_id == AV_CODEC_ID_OPUS) {
  526. av_free(oggstream->header[0]);
  527. }
  528. av_freep(&oggstream->header[1]);
  529. av_freep(&st->priv_data);
  530. }
  531. return 0;
  532. }
  533. #if CONFIG_OGG_MUXER
  534. OGG_CLASS(ogg)
  535. AVOutputFormat ff_ogg_muxer = {
  536. .name = "ogg",
  537. .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
  538. .mime_type = "application/ogg",
  539. .extensions = "ogg,ogv",
  540. .priv_data_size = sizeof(OGGContext),
  541. .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
  542. AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
  543. .video_codec = AV_CODEC_ID_THEORA,
  544. .write_header = ogg_write_header,
  545. .write_packet = ogg_write_packet,
  546. .write_trailer = ogg_write_trailer,
  547. .flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
  548. .priv_class = &ogg_muxer_class,
  549. };
  550. #endif
  551. #if CONFIG_OGA_MUXER
  552. OGG_CLASS(oga)
  553. AVOutputFormat ff_oga_muxer = {
  554. .name = "oga",
  555. .long_name = NULL_IF_CONFIG_SMALL("Ogg Audio"),
  556. .mime_type = "audio/ogg",
  557. .extensions = "oga",
  558. .priv_data_size = sizeof(OGGContext),
  559. .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
  560. AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
  561. .write_header = ogg_write_header,
  562. .write_packet = ogg_write_packet,
  563. .write_trailer = ogg_write_trailer,
  564. .flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
  565. .priv_class = &oga_muxer_class,
  566. };
  567. #endif
  568. #if CONFIG_SPX_MUXER
  569. OGG_CLASS(spx)
  570. AVOutputFormat ff_spx_muxer = {
  571. .name = "spx",
  572. .long_name = NULL_IF_CONFIG_SMALL("Ogg Speex"),
  573. .mime_type = "audio/ogg",
  574. .extensions = "spx",
  575. .priv_data_size = sizeof(OGGContext),
  576. .audio_codec = AV_CODEC_ID_SPEEX,
  577. .write_header = ogg_write_header,
  578. .write_packet = ogg_write_packet,
  579. .write_trailer = ogg_write_trailer,
  580. .flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
  581. .priv_class = &spx_muxer_class,
  582. };
  583. #endif
  584. #if CONFIG_OPUS_MUXER
  585. OGG_CLASS(opus)
  586. AVOutputFormat ff_opus_muxer = {
  587. .name = "opus",
  588. .long_name = NULL_IF_CONFIG_SMALL("Ogg Opus"),
  589. .mime_type = "audio/ogg",
  590. .extensions = "opus",
  591. .priv_data_size = sizeof(OGGContext),
  592. .audio_codec = AV_CODEC_ID_OPUS,
  593. .write_header = ogg_write_header,
  594. .write_packet = ogg_write_packet,
  595. .write_trailer = ogg_write_trailer,
  596. .flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
  597. .priv_class = &opus_muxer_class,
  598. };
  599. #endif