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.

664 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/opt.h"
  22. #include "libavutil/time.h"
  23. #include "libavutil/thread.h"
  24. #include "libavutil/threadmessage.h"
  25. #include "avformat.h"
  26. #include "internal.h"
  27. #define FIFO_DEFAULT_QUEUE_SIZE 60
  28. #define FIFO_DEFAULT_MAX_RECOVERY_ATTEMPTS 0
  29. #define FIFO_DEFAULT_RECOVERY_WAIT_TIME_USEC 5000000 // 5 seconds
  30. typedef struct FifoContext {
  31. const AVClass *class;
  32. AVFormatContext *avf;
  33. char *format;
  34. char *format_options_str;
  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->filename, &format_options);
  101. if (ret < 0) {
  102. av_log(avf, AV_LOG_ERROR, "Error opening %s: %s\n", avf->filename,
  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;
  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. return ret;
  178. case FIFO_WRITE_PACKET:
  179. return fifo_thread_write_packet(ctx, &msg->pkt);
  180. case FIFO_FLUSH_OUTPUT:
  181. return fifo_thread_flush_output(ctx);
  182. }
  183. return AVERROR(EINVAL);
  184. }
  185. static int is_recoverable(const FifoContext *fifo, int err_no) {
  186. if (!fifo->attempt_recovery)
  187. return 0;
  188. if (fifo->recover_any_error)
  189. return err_no != AVERROR_EXIT;
  190. switch (err_no) {
  191. case AVERROR(EINVAL):
  192. case AVERROR(ENOSYS):
  193. case AVERROR_EOF:
  194. case AVERROR_EXIT:
  195. case AVERROR_PATCHWELCOME:
  196. return 0;
  197. default:
  198. return 1;
  199. }
  200. }
  201. static void free_message(void *msg)
  202. {
  203. FifoMessage *fifo_msg = msg;
  204. if (fifo_msg->type == FIFO_WRITE_PACKET)
  205. av_packet_unref(&fifo_msg->pkt);
  206. }
  207. static int fifo_thread_process_recovery_failure(FifoThreadContext *ctx, AVPacket *pkt,
  208. int err_no)
  209. {
  210. AVFormatContext *avf = ctx->avf;
  211. FifoContext *fifo = avf->priv_data;
  212. int ret;
  213. av_log(avf, AV_LOG_INFO, "Recovery failed: %s\n",
  214. av_err2str(err_no));
  215. if (fifo->recovery_wait_streamtime) {
  216. if (pkt->pts == AV_NOPTS_VALUE)
  217. av_log(avf, AV_LOG_WARNING, "Packet does not contain presentation"
  218. " timestamp, recovery will be attempted immediately");
  219. ctx->last_recovery_ts = pkt->pts;
  220. } else {
  221. ctx->last_recovery_ts = av_gettime_relative();
  222. }
  223. if (fifo->max_recovery_attempts &&
  224. ctx->recovery_nr >= fifo->max_recovery_attempts) {
  225. av_log(avf, AV_LOG_ERROR,
  226. "Maximal number of %d recovery attempts reached.\n",
  227. fifo->max_recovery_attempts);
  228. ret = err_no;
  229. } else {
  230. ret = AVERROR(EAGAIN);
  231. }
  232. return ret;
  233. }
  234. static int fifo_thread_attempt_recovery(FifoThreadContext *ctx, FifoMessage *msg, int err_no)
  235. {
  236. AVFormatContext *avf = ctx->avf;
  237. FifoContext *fifo = avf->priv_data;
  238. AVPacket *pkt = &msg->pkt;
  239. int64_t time_since_recovery;
  240. int ret;
  241. if (!is_recoverable(fifo, err_no)) {
  242. ret = err_no;
  243. goto fail;
  244. }
  245. if (ctx->header_written) {
  246. fifo->write_trailer_ret = fifo_thread_write_trailer(ctx);
  247. ctx->header_written = 0;
  248. }
  249. if (!ctx->recovery_nr) {
  250. ctx->last_recovery_ts = fifo->recovery_wait_streamtime ?
  251. AV_NOPTS_VALUE : 0;
  252. } else {
  253. if (fifo->recovery_wait_streamtime) {
  254. if (ctx->last_recovery_ts == AV_NOPTS_VALUE) {
  255. AVRational tb = avf->streams[pkt->stream_index]->time_base;
  256. time_since_recovery = av_rescale_q(pkt->pts - ctx->last_recovery_ts,
  257. tb, AV_TIME_BASE_Q);
  258. } else {
  259. /* Enforce recovery immediately */
  260. time_since_recovery = fifo->recovery_wait_time;
  261. }
  262. } else {
  263. time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts;
  264. }
  265. if (time_since_recovery < fifo->recovery_wait_time)
  266. return AVERROR(EAGAIN);
  267. }
  268. ctx->recovery_nr++;
  269. if (fifo->max_recovery_attempts) {
  270. av_log(avf, AV_LOG_VERBOSE, "Recovery attempt #%d/%d\n",
  271. ctx->recovery_nr, fifo->max_recovery_attempts);
  272. } else {
  273. av_log(avf, AV_LOG_VERBOSE, "Recovery attempt #%d\n",
  274. ctx->recovery_nr);
  275. }
  276. if (fifo->restart_with_keyframe && fifo->drop_pkts_on_overflow)
  277. ctx->drop_until_keyframe = 1;
  278. ret = fifo_thread_dispatch_message(ctx, msg);
  279. if (ret < 0) {
  280. if (is_recoverable(fifo, ret)) {
  281. return fifo_thread_process_recovery_failure(ctx, pkt, ret);
  282. } else {
  283. goto fail;
  284. }
  285. } else {
  286. av_log(avf, AV_LOG_INFO, "Recovery successful\n");
  287. ctx->recovery_nr = 0;
  288. }
  289. return 0;
  290. fail:
  291. free_message(msg);
  292. return ret;
  293. }
  294. static int fifo_thread_recover(FifoThreadContext *ctx, FifoMessage *msg, int err_no)
  295. {
  296. AVFormatContext *avf = ctx->avf;
  297. FifoContext *fifo = avf->priv_data;
  298. int ret;
  299. do {
  300. if (!fifo->recovery_wait_streamtime && ctx->recovery_nr > 0) {
  301. int64_t time_since_recovery = av_gettime_relative() - ctx->last_recovery_ts;
  302. int64_t time_to_wait = FFMAX(0, fifo->recovery_wait_time - time_since_recovery);
  303. if (time_to_wait)
  304. av_usleep(FFMIN(10000, time_to_wait));
  305. }
  306. ret = fifo_thread_attempt_recovery(ctx, msg, err_no);
  307. } while (ret == AVERROR(EAGAIN) && !fifo->drop_pkts_on_overflow);
  308. if (ret == AVERROR(EAGAIN) && fifo->drop_pkts_on_overflow) {
  309. if (msg->type == FIFO_WRITE_PACKET)
  310. av_packet_unref(&msg->pkt);
  311. ret = 0;
  312. }
  313. return ret;
  314. }
  315. static void *fifo_consumer_thread(void *data)
  316. {
  317. AVFormatContext *avf = data;
  318. FifoContext *fifo = avf->priv_data;
  319. AVThreadMessageQueue *queue = fifo->queue;
  320. FifoMessage msg = {FIFO_WRITE_HEADER, {0}};
  321. int ret;
  322. FifoThreadContext fifo_thread_ctx;
  323. memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
  324. fifo_thread_ctx.avf = avf;
  325. while (1) {
  326. uint8_t just_flushed = 0;
  327. if (!fifo_thread_ctx.recovery_nr)
  328. ret = fifo_thread_dispatch_message(&fifo_thread_ctx, &msg);
  329. if (ret < 0 || fifo_thread_ctx.recovery_nr > 0) {
  330. int rec_ret = fifo_thread_recover(&fifo_thread_ctx, &msg, ret);
  331. if (rec_ret < 0) {
  332. av_thread_message_queue_set_err_send(queue, rec_ret);
  333. break;
  334. }
  335. }
  336. /* If the queue is full at the moment when fifo_write_packet
  337. * attempts to insert new message (packet) to the queue,
  338. * it sets the fifo->overflow_flag to 1 and drops packet.
  339. * Here in consumer thread, the flag is checked and if it is
  340. * set, the queue is flushed and flag cleared. */
  341. pthread_mutex_lock(&fifo->overflow_flag_lock);
  342. if (fifo->overflow_flag) {
  343. av_thread_message_flush(queue);
  344. if (fifo->restart_with_keyframe)
  345. fifo_thread_ctx.drop_until_keyframe = 1;
  346. fifo->overflow_flag = 0;
  347. just_flushed = 1;
  348. }
  349. pthread_mutex_unlock(&fifo->overflow_flag_lock);
  350. if (just_flushed)
  351. av_log(avf, AV_LOG_INFO, "FIFO queue flushed\n");
  352. ret = av_thread_message_queue_recv(queue, &msg, 0);
  353. if (ret < 0) {
  354. av_thread_message_queue_set_err_send(queue, ret);
  355. break;
  356. }
  357. }
  358. fifo->write_trailer_ret = fifo_thread_write_trailer(&fifo_thread_ctx);
  359. return NULL;
  360. }
  361. static int fifo_mux_init(AVFormatContext *avf, AVOutputFormat *oformat)
  362. {
  363. FifoContext *fifo = avf->priv_data;
  364. AVFormatContext *avf2;
  365. int ret = 0, i;
  366. ret = avformat_alloc_output_context2(&avf2, oformat, NULL, NULL);
  367. if (ret < 0)
  368. return ret;
  369. fifo->avf = avf2;
  370. avf2->interrupt_callback = avf->interrupt_callback;
  371. avf2->max_delay = avf->max_delay;
  372. ret = av_dict_copy(&avf2->metadata, avf->metadata, 0);
  373. if (ret < 0)
  374. return ret;
  375. avf2->opaque = avf->opaque;
  376. avf2->io_close = avf->io_close;
  377. avf2->io_open = avf->io_open;
  378. avf2->flags = avf->flags;
  379. for (i = 0; i < avf->nb_streams; ++i) {
  380. AVStream *st = avformat_new_stream(avf2, NULL);
  381. if (!st)
  382. return AVERROR(ENOMEM);
  383. ret = ff_stream_encode_params_copy(st, avf->streams[i]);
  384. if (ret < 0)
  385. return ret;
  386. }
  387. return 0;
  388. }
  389. static int fifo_init(AVFormatContext *avf)
  390. {
  391. FifoContext *fifo = avf->priv_data;
  392. AVOutputFormat *oformat;
  393. int ret = 0;
  394. if (fifo->recovery_wait_streamtime && !fifo->drop_pkts_on_overflow) {
  395. av_log(avf, AV_LOG_ERROR, "recovery_wait_streamtime can be turned on"
  396. " only when drop_pkts_on_overflow is also turned on\n");
  397. return AVERROR(EINVAL);
  398. }
  399. if (fifo->format_options_str) {
  400. ret = av_dict_parse_string(&fifo->format_options, fifo->format_options_str,
  401. "=", ":", 0);
  402. if (ret < 0) {
  403. av_log(avf, AV_LOG_ERROR, "Could not parse format options list '%s'\n",
  404. fifo->format_options_str);
  405. return ret;
  406. }
  407. }
  408. oformat = av_guess_format(fifo->format, avf->filename, NULL);
  409. if (!oformat) {
  410. ret = AVERROR_MUXER_NOT_FOUND;
  411. return ret;
  412. }
  413. ret = fifo_mux_init(avf, oformat);
  414. if (ret < 0)
  415. return ret;
  416. ret = av_thread_message_queue_alloc(&fifo->queue, (unsigned) fifo->queue_size,
  417. sizeof(FifoMessage));
  418. if (ret < 0)
  419. return ret;
  420. av_thread_message_queue_set_free_func(fifo->queue, free_message);
  421. ret = pthread_mutex_init(&fifo->overflow_flag_lock, NULL);
  422. if (ret < 0)
  423. return AVERROR(ret);
  424. fifo->overflow_flag_lock_initialized = 1;
  425. return 0;
  426. }
  427. static int fifo_write_header(AVFormatContext *avf)
  428. {
  429. FifoContext * fifo = avf->priv_data;
  430. int ret;
  431. ret = pthread_create(&fifo->writer_thread, NULL, fifo_consumer_thread, avf);
  432. if (ret) {
  433. av_log(avf, AV_LOG_ERROR, "Failed to start thread: %s\n",
  434. av_err2str(AVERROR(ret)));
  435. ret = AVERROR(ret);
  436. }
  437. return ret;
  438. }
  439. static int fifo_write_packet(AVFormatContext *avf, AVPacket *pkt)
  440. {
  441. FifoContext *fifo = avf->priv_data;
  442. FifoMessage msg = {.type = pkt ? FIFO_WRITE_PACKET : FIFO_FLUSH_OUTPUT};
  443. int ret;
  444. if (pkt) {
  445. av_init_packet(&msg.pkt);
  446. ret = av_packet_ref(&msg.pkt,pkt);
  447. if (ret < 0)
  448. return ret;
  449. }
  450. ret = av_thread_message_queue_send(fifo->queue, &msg,
  451. fifo->drop_pkts_on_overflow ?
  452. AV_THREAD_MESSAGE_NONBLOCK : 0);
  453. if (ret == AVERROR(EAGAIN)) {
  454. uint8_t overflow_set = 0;
  455. /* Queue is full, set fifo->overflow_flag to 1
  456. * to let consumer thread know the queue should
  457. * be flushed. */
  458. pthread_mutex_lock(&fifo->overflow_flag_lock);
  459. if (!fifo->overflow_flag)
  460. fifo->overflow_flag = overflow_set = 1;
  461. pthread_mutex_unlock(&fifo->overflow_flag_lock);
  462. if (overflow_set)
  463. av_log(avf, AV_LOG_WARNING, "FIFO queue full\n");
  464. ret = 0;
  465. goto fail;
  466. } else if (ret < 0) {
  467. goto fail;
  468. }
  469. return ret;
  470. fail:
  471. if (pkt)
  472. av_packet_unref(&msg.pkt);
  473. return ret;
  474. }
  475. static int fifo_write_trailer(AVFormatContext *avf)
  476. {
  477. FifoContext *fifo= avf->priv_data;
  478. int ret;
  479. av_thread_message_queue_set_err_recv(fifo->queue, AVERROR_EOF);
  480. ret = pthread_join(fifo->writer_thread, NULL);
  481. if (ret < 0) {
  482. av_log(avf, AV_LOG_ERROR, "pthread join error: %s\n",
  483. av_err2str(AVERROR(ret)));
  484. return AVERROR(ret);
  485. }
  486. ret = fifo->write_trailer_ret;
  487. return ret;
  488. }
  489. static void fifo_deinit(AVFormatContext *avf)
  490. {
  491. FifoContext *fifo = avf->priv_data;
  492. av_dict_free(&fifo->format_options);
  493. avformat_free_context(fifo->avf);
  494. av_thread_message_queue_free(&fifo->queue);
  495. if (fifo->overflow_flag_lock_initialized)
  496. pthread_mutex_destroy(&fifo->overflow_flag_lock);
  497. }
  498. #define OFFSET(x) offsetof(FifoContext, x)
  499. static const AVOption options[] = {
  500. {"fifo_format", "Target muxer", OFFSET(format),
  501. AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM},
  502. {"queue_size", "Size of fifo queue", OFFSET(queue_size),
  503. AV_OPT_TYPE_INT, {.i64 = FIFO_DEFAULT_QUEUE_SIZE}, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  504. {"format_opts", "Options to be passed to underlying muxer", OFFSET(format_options_str),
  505. AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM},
  506. {"drop_pkts_on_overflow", "Drop packets on fifo queue overflow not to block encoder", OFFSET(drop_pkts_on_overflow),
  507. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  508. {"restart_with_keyframe", "Wait for keyframe when restarting output", OFFSET(restart_with_keyframe),
  509. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  510. {"attempt_recovery", "Attempt recovery in case of failure", OFFSET(attempt_recovery),
  511. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  512. {"max_recovery_attempts", "Maximal number of recovery attempts", OFFSET(max_recovery_attempts),
  513. AV_OPT_TYPE_INT, {.i64 = FIFO_DEFAULT_MAX_RECOVERY_ATTEMPTS}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  514. {"recovery_wait_time", "Waiting time between recovery attempts", OFFSET(recovery_wait_time),
  515. AV_OPT_TYPE_DURATION, {.i64 = FIFO_DEFAULT_RECOVERY_WAIT_TIME_USEC}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM},
  516. {"recovery_wait_streamtime", "Use stream time instead of real time while waiting for recovery",
  517. OFFSET(recovery_wait_streamtime), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  518. {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error),
  519. AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
  520. {NULL},
  521. };
  522. static const AVClass fifo_muxer_class = {
  523. .class_name = "Fifo muxer",
  524. .item_name = av_default_item_name,
  525. .option = options,
  526. .version = LIBAVUTIL_VERSION_INT,
  527. };
  528. AVOutputFormat ff_fifo_muxer = {
  529. .name = "fifo",
  530. .long_name = NULL_IF_CONFIG_SMALL("FIFO queue pseudo-muxer"),
  531. .priv_data_size = sizeof(FifoContext),
  532. .init = fifo_init,
  533. .write_header = fifo_write_header,
  534. .write_packet = fifo_write_packet,
  535. .write_trailer = fifo_write_trailer,
  536. .deinit = fifo_deinit,
  537. .priv_class = &fifo_muxer_class,
  538. .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE,
  539. };