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.

656 lines
20KB

  1. /*
  2. * FIFO pseudo-muxer
  3. * Copyright (c) 2016 Jan Sebechlebsky
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg 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
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/opt.h"
  23. #include "libavutil/time.h"
  24. #include "libavutil/thread.h"
  25. #include "libavutil/threadmessage.h"
  26. #include "avformat.h"
  27. #include "internal.h"
  28. #define FIFO_DEFAULT_QUEUE_SIZE 60
  29. #define FIFO_DEFAULT_MAX_RECOVERY_ATTEMPTS 0
  30. #define FIFO_DEFAULT_RECOVERY_WAIT_TIME_USEC 5000000 // 5 seconds
  31. typedef struct FifoContext {
  32. const AVClass *class;
  33. AVFormatContext *avf;
  34. char *format;
  35. AVDictionary *format_options;
  36. int queue_size;
  37. AVThreadMessageQueue *queue;
  38. pthread_t writer_thread;
  39. /* Return value of last write_trailer_call */
  40. int write_trailer_ret;
  41. /* Time to wait before next recovery attempt
  42. * This can refer to the time in processed stream,
  43. * or real time. */
  44. int64_t recovery_wait_time;
  45. /* Maximal number of unsuccessful successive recovery attempts */
  46. int max_recovery_attempts;
  47. /* Whether to attempt recovery from failure */
  48. int attempt_recovery;
  49. /* If >0 stream time will be used when waiting
  50. * for the recovery attempt instead of real time */
  51. int recovery_wait_streamtime;
  52. /* If >0 recovery will be attempted regardless of error code
  53. * (except AVERROR_EXIT, so exit request is never ignored) */
  54. int recover_any_error;
  55. /* Whether to drop packets in case the queue is full. */
  56. int drop_pkts_on_overflow;
  57. /* Whether to wait for keyframe when recovering
  58. * from failure or queue overflow */
  59. int restart_with_keyframe;
  60. pthread_mutex_t overflow_flag_lock;
  61. int overflow_flag_lock_initialized;
  62. /* Value > 0 signals queue overflow */
  63. volatile uint8_t overflow_flag;
  64. } FifoContext;
  65. typedef struct FifoThreadContext {
  66. AVFormatContext *avf;
  67. /* Timestamp of last failure.
  68. * This is either pts in case stream time is used,
  69. * or microseconds as returned by av_getttime_relative() */
  70. int64_t last_recovery_ts;
  71. /* Number of current recovery process
  72. * Value > 0 means we are in recovery process */
  73. int recovery_nr;
  74. /* If > 0 all frames will be dropped until keyframe is received */
  75. uint8_t drop_until_keyframe;
  76. /* Value > 0 means that the previous write_header call was successful
  77. * so finalization by calling write_trailer and ff_io_close must be done
  78. * before exiting / reinitialization of underlying muxer */
  79. uint8_t header_written;
  80. } FifoThreadContext;
  81. typedef enum FifoMessageType {
  82. FIFO_WRITE_HEADER,
  83. FIFO_WRITE_PACKET,
  84. FIFO_FLUSH_OUTPUT
  85. } FifoMessageType;
  86. typedef struct FifoMessage {
  87. FifoMessageType type;
  88. AVPacket pkt;
  89. } FifoMessage;
  90. static int fifo_thread_write_header(FifoThreadContext *ctx)
  91. {
  92. AVFormatContext *avf = ctx->avf;
  93. FifoContext *fifo = avf->priv_data;
  94. AVFormatContext *avf2 = fifo->avf;
  95. AVDictionary *format_options = NULL;
  96. int ret, i;
  97. ret = av_dict_copy(&format_options, fifo->format_options, 0);
  98. if (ret < 0)
  99. return ret;
  100. ret = ff_format_output_open(avf2, avf->url, &format_options);
  101. if (ret < 0) {
  102. av_log(avf, AV_LOG_ERROR, "Error opening %s: %s\n", avf->url,
  103. av_err2str(ret));
  104. goto end;
  105. }
  106. for (i = 0;i < avf2->nb_streams; i++)
  107. avf2->streams[i]->cur_dts = 0;
  108. ret = avformat_write_header(avf2, &format_options);
  109. if (!ret)
  110. ctx->header_written = 1;
  111. // Check for options unrecognized by underlying muxer
  112. if (format_options) {
  113. AVDictionaryEntry *entry = NULL;
  114. while ((entry = av_dict_get(format_options, "", entry, AV_DICT_IGNORE_SUFFIX)))
  115. av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
  116. ret = AVERROR(EINVAL);
  117. }
  118. end:
  119. av_dict_free(&format_options);
  120. return ret;
  121. }
  122. static int fifo_thread_flush_output(FifoThreadContext *ctx)
  123. {
  124. AVFormatContext *avf = ctx->avf;
  125. FifoContext *fifo = avf->priv_data;
  126. AVFormatContext *avf2 = fifo->avf;
  127. return av_write_frame(avf2, NULL);
  128. }
  129. static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt)
  130. {
  131. AVFormatContext *avf = ctx->avf;
  132. FifoContext *fifo = avf->priv_data;
  133. AVFormatContext *avf2 = fifo->avf;
  134. AVRational src_tb, dst_tb;
  135. int ret, s_idx;
  136. if (ctx->drop_until_keyframe) {
  137. if (pkt->flags & AV_PKT_FLAG_KEY) {
  138. ctx->drop_until_keyframe = 0;
  139. av_log(avf, AV_LOG_VERBOSE, "Keyframe received, recovering...\n");
  140. } else {
  141. av_log(avf, AV_LOG_VERBOSE, "Dropping non-keyframe packet\n");
  142. av_packet_unref(pkt);
  143. return 0;
  144. }
  145. }
  146. s_idx = pkt->stream_index;
  147. src_tb = avf->streams[s_idx]->time_base;
  148. dst_tb = avf2->streams[s_idx]->time_base;
  149. av_packet_rescale_ts(pkt, src_tb, dst_tb);
  150. ret = av_write_frame(avf2, pkt);
  151. if (ret >= 0)
  152. av_packet_unref(pkt);
  153. return ret;
  154. }
  155. static int fifo_thread_write_trailer(FifoThreadContext *ctx)
  156. {
  157. AVFormatContext *avf = ctx->avf;
  158. FifoContext *fifo = avf->priv_data;
  159. AVFormatContext *avf2 = fifo->avf;
  160. int ret;
  161. if (!ctx->header_written)
  162. return 0;
  163. ret = av_write_trailer(avf2);
  164. ff_format_io_close(avf2, &avf2->pb);
  165. return ret;
  166. }
  167. static int fifo_thread_dispatch_message(FifoThreadContext *ctx, FifoMessage *msg)
  168. {
  169. int ret = AVERROR(EINVAL);
  170. if (!ctx->header_written) {
  171. ret = fifo_thread_write_header(ctx);
  172. if (ret < 0)
  173. return ret;
  174. }
  175. switch(msg->type) {
  176. case FIFO_WRITE_HEADER:
  177. av_assert0(ret >= 0);
  178. return ret;
  179. case FIFO_WRITE_PACKET:
  180. return fifo_thread_write_packet(ctx, &msg->pkt);
  181. case FIFO_FLUSH_OUTPUT:
  182. return fifo_thread_flush_output(ctx);
  183. }
  184. av_assert0(0);
  185. return AVERROR(EINVAL);
  186. }
  187. static int is_recoverable(const FifoContext *fifo, int err_no) {
  188. if (!fifo->attempt_recovery)
  189. return 0;
  190. if (fifo->recover_any_error)
  191. return err_no != AVERROR_EXIT;
  192. switch (err_no) {
  193. case AVERROR(EINVAL):
  194. case AVERROR(ENOSYS):
  195. case AVERROR_EOF:
  196. case AVERROR_EXIT:
  197. case AVERROR_PATCHWELCOME:
  198. return 0;
  199. default:
  200. return 1;
  201. }
  202. }
  203. static void free_message(void *msg)
  204. {
  205. FifoMessage *fifo_msg = msg;
  206. if (fifo_msg->type == FIFO_WRITE_PACKET)
  207. av_packet_unref(&fifo_msg->pkt);
  208. }
  209. static int fifo_thread_process_recovery_failure(FifoThreadContext *ctx, AVPacket *pkt,
  210. int err_no)
  211. {
  212. AVFormatContext *avf = ctx->avf;
  213. FifoContext *fifo = avf->priv_data;
  214. int ret;
  215. av_log(avf, AV_LOG_INFO, "Recovery failed: %s\n",
  216. av_err2str(err_no));
  217. if (fifo->recovery_wait_streamtime) {
  218. if (pkt->pts == AV_NOPTS_VALUE)
  219. av_log(avf, AV_LOG_WARNING, "Packet does not contain presentation"
  220. " timestamp, recovery will be attempted immediately");
  221. ctx->last_recovery_ts = pkt->pts;
  222. } else {
  223. ctx->last_recovery_ts = av_gettime_relative();
  224. }
  225. if (fifo->max_recovery_attempts &&
  226. ctx->recovery_nr >= fifo->max_recovery_attempts) {
  227. av_log(avf, AV_LOG_ERROR,
  228. "Maximal number of %d recovery attempts reached.\n",
  229. fifo->max_recovery_attempts);
  230. ret = err_no;
  231. } else {
  232. ret = AVERROR(EAGAIN);
  233. }
  234. return ret;
  235. }
  236. static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg, int err_no)
  237. {
  238. AVFormatContext *avf = ctx->avf;
  239. FifoContext *fifo = avf->priv_data;
  240. AVPacket *pkt = &msg->pkt;
  241. int64_t time_since_recovery;
  242. int ret;
  243. if (!is_recoverable(fifo, err_no)) {
  244. ret = err_no;
  245. goto fail;
  246. }
  247. if (ctx->header_written) {
  248. fifo->write_trailer_ret = fifo_thread_write_trailer(ctx);
  249. ctx->header_written = 0;
  250. }
  251. if (!ctx->recovery_nr) {
  252. ctx->last_recovery_ts = fifo->recovery_wait_streamtime ?
  253. AV_NOPTS_VALUE : 0;
  254. } else {
  255. if (fifo->recovery_wait_streamtime) {
  256. if (ctx->last_recovery_ts == AV_NOPTS_VALUE) {
  257. AVRational tb = avf->streams[pkt->stream_index]->time_base;
  258. time_since_recovery = av_rescale_q(pkt->pts - ctx->last_recovery_ts,
  259. tb, AV_TIME_BASE_Q);
  260. } else {
  261. /* Enforce recovery immediately */
  262. time_since_recovery = fifo->recovery_wait_time;
  263. }
  264. } else {
  265. time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts;
  266. }
  267. if (time_since_recovery < fifo->recovery_wait_time)
  268. return AVERROR(EAGAIN);
  269. }
  270. ctx->recovery_nr++;
  271. if (fifo->max_recovery_attempts) {
  272. av_log(avf, AV_LOG_VERBOSE, "Recovery attempt #%d/%d\n",
  273. ctx->recovery_nr, fifo->max_recovery_attempts);
  274. } else {
  275. av_log(avf, AV_LOG_VERBOSE, "Recovery attempt #%d\n",
  276. ctx->recovery_nr);
  277. }
  278. if (fifo->restart_with_keyframe && fifo->drop_pkts_on_overflow)
  279. ctx->drop_until_keyframe = 1;
  280. ret = fifo_thread_dispatch_message(ctx, msg);
  281. if (ret < 0) {
  282. if (is_recoverable(fifo, ret)) {
  283. return fifo_thread_process_recovery_failure(ctx, pkt, ret);
  284. } else {
  285. goto fail;
  286. }
  287. } else {
  288. av_log(avf, AV_LOG_INFO, "Recovery successful\n");
  289. ctx->recovery_nr = 0;
  290. }
  291. return 0;
  292. fail:
  293. free_message(msg);
  294. return ret;
  295. }
  296. static int fifo_thread_recover(FifoThreadContext *ctx, FifoMessage *msg, int err_no)
  297. {
  298. AVFormatContext *avf = ctx->avf;
  299. FifoContext *fifo = avf->priv_data;
  300. int ret;
  301. do {
  302. if (!fifo->recovery_wait_streamtime && ctx->recovery_nr > 0) {
  303. int64_t time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts;
  304. int64_t time_to_wait = FFMAX(0, fifo->recovery_wait_time - time_since_recovery);
  305. if (time_to_wait)
  306. av_usleep(FFMIN(10000, time_to_wait));
  307. }
  308. ret = fifo_thread_attempt_recovery(ctx, msg, err_no);
  309. } while (ret == AVERROR(EAGAIN) && !fifo->drop_pkts_on_overflow);
  310. if (ret == AVERROR(EAGAIN) && fifo->drop_pkts_on_overflow) {
  311. if (msg->type == FIFO_WRITE_PACKET)
  312. av_packet_unref(&msg->pkt);
  313. ret = 0;
  314. }
  315. return ret;
  316. }
  317. static void *fifo_consumer_thread(void *data)
  318. {
  319. AVFormatContext *avf = data;
  320. FifoContext *fifo = avf->priv_data;
  321. AVThreadMessageQueue *queue = fifo->queue;
  322. FifoMessage msg = {FIFO_WRITE_HEADER, {0}};
  323. int ret;
  324. FifoThreadContext fifo_thread_ctx;
  325. memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
  326. fifo_thread_ctx.avf = avf;
  327. while (1) {
  328. uint8_t just_flushed = 0;
  329. if (!fifo_thread_ctx.recovery_nr)
  330. ret = fifo_thread_dispatch_message(&fifo_thread_ctx, &msg);
  331. if (ret < 0 || fifo_thread_ctx.recovery_nr > 0) {
  332. int rec_ret = fifo_thread_recover(&fifo_thread_ctx, &msg, ret);
  333. if (rec_ret < 0) {
  334. av_thread_message_queue_set_err_send(queue, rec_ret);
  335. break;
  336. }
  337. }
  338. /* If the queue is full at the moment when fifo_write_packet
  339. * attempts to insert new message (packet) to the queue,
  340. * it sets the fifo->overflow_flag to 1 and drops packet.
  341. * Here in consumer thread, the flag is checked and if it is
  342. * set, the queue is flushed and flag cleared. */
  343. pthread_mutex_lock(&fifo->overflow_flag_lock);
  344. if (fifo->overflow_flag) {
  345. av_thread_message_flush(queue);
  346. if (fifo->restart_with_keyframe)
  347. fifo_thread_ctx.drop_until_keyframe = 1;
  348. fifo->overflow_flag = 0;
  349. just_flushed = 1;
  350. }
  351. pthread_mutex_unlock(&fifo->overflow_flag_lock);
  352. if (just_flushed)
  353. av_log(avf, AV_LOG_INFO, "FIFO queue flushed\n");
  354. ret = av_thread_message_queue_recv(queue, &msg, 0);
  355. if (ret < 0) {
  356. av_thread_message_queue_set_err_send(queue, ret);
  357. break;
  358. }
  359. }
  360. fifo->write_trailer_ret = fifo_thread_write_trailer(&fifo_thread_ctx);
  361. return NULL;
  362. }
  363. static int fifo_mux_init(AVFormatContext *avf, ff_const59 AVOutputFormat *oformat,
  364. const char *filename)
  365. {
  366. FifoContext *fifo = avf->priv_data;
  367. AVFormatContext *avf2;
  368. int ret = 0, i;
  369. ret = avformat_alloc_output_context2(&avf2, oformat, NULL, filename);
  370. if (ret < 0)
  371. return ret;
  372. fifo->avf = avf2;
  373. avf2->interrupt_callback = avf->interrupt_callback;
  374. avf2->max_delay = avf->max_delay;
  375. ret = av_dict_copy(&avf2->metadata, avf->metadata, 0);
  376. if (ret < 0)
  377. return ret;
  378. avf2->opaque = avf->opaque;
  379. avf2->io_close = avf->io_close;
  380. avf2->io_open = avf->io_open;
  381. avf2->flags = avf->flags;
  382. for (i = 0; i < avf->nb_streams; ++i) {
  383. AVStream *st = avformat_new_stream(avf2, NULL);
  384. if (!st)
  385. return AVERROR(ENOMEM);
  386. ret = ff_stream_encode_params_copy(st, avf->streams[i]);
  387. if (ret < 0)
  388. return ret;
  389. }
  390. return 0;
  391. }
  392. static int fifo_init(AVFormatContext *avf)
  393. {
  394. FifoContext *fifo = avf->priv_data;
  395. ff_const59 AVOutputFormat *oformat;
  396. int ret = 0;
  397. if (fifo->recovery_wait_streamtime && !fifo->drop_pkts_on_overflow) {
  398. av_log(avf, AV_LOG_ERROR, "recovery_wait_streamtime can be turned on"
  399. " only when drop_pkts_on_overflow is also turned on\n");
  400. return AVERROR(EINVAL);
  401. }
  402. oformat = av_guess_format(fifo->format, avf->url, NULL);
  403. if (!oformat) {
  404. ret = AVERROR_MUXER_NOT_FOUND;
  405. return ret;
  406. }
  407. ret = fifo_mux_init(avf, oformat, avf->url);
  408. if (ret < 0)
  409. return ret;
  410. ret = av_thread_message_queue_alloc(&fifo->queue, (unsigned) fifo->queue_size,
  411. sizeof(FifoMessage));
  412. if (ret < 0)
  413. return ret;
  414. av_thread_message_queue_set_free_func(fifo->queue, free_message);
  415. ret = pthread_mutex_init(&fifo->overflow_flag_lock, NULL);
  416. if (ret < 0)
  417. return AVERROR(ret);
  418. fifo->overflow_flag_lock_initialized = 1;
  419. return 0;
  420. }
  421. static int fifo_write_header(AVFormatContext *avf)
  422. {
  423. FifoContext * fifo = avf->priv_data;
  424. int ret;
  425. ret = pthread_create(&fifo->writer_thread, NULL, fifo_consumer_thread, avf);
  426. if (ret) {
  427. av_log(avf, AV_LOG_ERROR, "Failed to start thread: %s\n",
  428. av_err2str(AVERROR(ret)));
  429. ret = AVERROR(ret);
  430. }
  431. return ret;
  432. }
  433. static int fifo_write_packet(AVFormatContext *avf, AVPacket *pkt)
  434. {
  435. FifoContext *fifo = avf->priv_data;
  436. FifoMessage msg = {.type = pkt ? FIFO_WRITE_PACKET : FIFO_FLUSH_OUTPUT};
  437. int ret;
  438. if (pkt) {
  439. av_init_packet(&msg.pkt);
  440. ret = av_packet_ref(&msg.pkt,pkt);
  441. if (ret < 0)
  442. return ret;
  443. }
  444. ret = av_thread_message_queue_send(fifo->queue, &msg,
  445. fifo->drop_pkts_on_overflow ?
  446. AV_THREAD_MESSAGE_NONBLOCK : 0);
  447. if (ret == AVERROR(EAGAIN)) {
  448. uint8_t overflow_set = 0;
  449. /* Queue is full, set fifo->overflow_flag to 1
  450. * to let consumer thread know the queue should
  451. * be flushed. */
  452. pthread_mutex_lock(&fifo->overflow_flag_lock);
  453. if (!fifo->overflow_flag)
  454. fifo->overflow_flag = overflow_set = 1;
  455. pthread_mutex_unlock(&fifo->overflow_flag_lock);
  456. if (overflow_set)
  457. av_log(avf, AV_LOG_WARNING, "FIFO queue full\n");
  458. ret = 0;
  459. goto fail;
  460. } else if (ret < 0) {
  461. goto fail;
  462. }
  463. return ret;
  464. fail:
  465. if (pkt)
  466. av_packet_unref(&msg.pkt);
  467. return ret;
  468. }
  469. static int fifo_write_trailer(AVFormatContext *avf)
  470. {
  471. FifoContext *fifo= avf->priv_data;
  472. int ret;
  473. av_thread_message_queue_set_err_recv(fifo->queue, AVERROR_EOF);
  474. ret = pthread_join(fifo->writer_thread, NULL);
  475. if (ret < 0) {
  476. av_log(avf, AV_LOG_ERROR, "pthread join error: %s\n",
  477. av_err2str(AVERROR(ret)));
  478. return AVERROR(ret);
  479. }
  480. ret = fifo->write_trailer_ret;
  481. return ret;
  482. }
  483. static void fifo_deinit(AVFormatContext *avf)
  484. {
  485. FifoContext *fifo = avf->priv_data;
  486. avformat_free_context(fifo->avf);
  487. av_thread_message_queue_free(&fifo->queue);
  488. if (fifo->overflow_flag_lock_initialized)
  489. pthread_mutex_destroy(&fifo->overflow_flag_lock);
  490. }
  491. #define OFFSET(x) offsetof(FifoContext, x)
  492. static const AVOption options[] = {
  493. {"fifo_format", "Target muxer", OFFSET(format),
  494. AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM},
  495. {"queue_size", "Size of fifo queue", OFFSET(queue_size),
  496. AV_OPT_TYPE_INT, {.i64 = FIFO_DEFAULT_QUEUE_SIZE}, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  497. {"format_opts", "Options to be passed to underlying muxer", OFFSET(format_options),
  498. AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM},
  499. {"drop_pkts_on_overflow", "Drop packets on fifo queue overflow not to block encoder", OFFSET(drop_pkts_on_overflow),
  500. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  501. {"restart_with_keyframe", "Wait for keyframe when restarting output", OFFSET(restart_with_keyframe),
  502. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  503. {"attempt_recovery", "Attempt recovery in case of failure", OFFSET(attempt_recovery),
  504. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  505. {"max_recovery_attempts", "Maximal number of recovery attempts", OFFSET(max_recovery_attempts),
  506. AV_OPT_TYPE_INT, {.i64 = FIFO_DEFAULT_MAX_RECOVERY_ATTEMPTS}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  507. {"recovery_wait_time", "Waiting time between recovery attempts", OFFSET(recovery_wait_time),
  508. AV_OPT_TYPE_DURATION, {.i64 = FIFO_DEFAULT_RECOVERY_WAIT_TIME_USEC}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  509. {"recovery_wait_streamtime", "Use stream time instead of real time while waiting for recovery",
  510. OFFSET(recovery_wait_streamtime), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  511. {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error),
  512. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  513. {NULL},
  514. };
  515. static const AVClass fifo_muxer_class = {
  516. .class_name = "Fifo muxer",
  517. .item_name = av_default_item_name,
  518. .option = options,
  519. .version = LIBAVUTIL_VERSION_INT,
  520. };
  521. AVOutputFormat ff_fifo_muxer = {
  522. .name = "fifo",
  523. .long_name = NULL_IF_CONFIG_SMALL("FIFO queue pseudo-muxer"),
  524. .priv_data_size = sizeof(FifoContext),
  525. .init = fifo_init,
  526. .write_header = fifo_write_header,
  527. .write_packet = fifo_write_packet,
  528. .write_trailer = fifo_write_trailer,
  529. .deinit = fifo_deinit,
  530. .priv_class = &fifo_muxer_class,
  531. .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE,
  532. };