33#define FIFO_DEFAULT_QUEUE_SIZE 60
34#define FIFO_DEFAULT_MAX_RECOVERY_ATTEMPTS 0
35#define FIFO_DEFAULT_RECOVERY_WAIT_TIME_USEC 5000000
150 ctx->header_written = 1;
153 if (format_options) {
190 int64_t orig_pts, orig_dts, orig_duration;
196 if (
ctx->drop_until_keyframe) {
198 if (!
ctx->has_video_stream) {
199 ctx->drop_until_keyframe = 0;
203 ctx->drop_until_keyframe = 0;
220 orig_duration =
pkt->duration;
221 s_idx =
pkt->stream_index;
233 pkt->duration = orig_duration;
245 if (!
ctx->header_written)
261 if (!
ctx->header_written) {
321 " timestamp, recovery will be attempted immediately");
322 ctx->last_recovery_ts =
pkt->pts;
330 "Maximal number of %d recovery attempts reached.\n",
353 if (
ctx->header_written) {
355 ctx->header_written = 0;
358 if (!
ctx->recovery_nr) {
375 if (time_since_recovery < fifo->recovery_wait_time)
390 ctx->drop_until_keyframe = 1;
401 ctx->recovery_nr = 0;
447 fifo_thread_ctx.
avf = avf;
460 uint8_t just_flushed = 0;
465 if (ret < 0 || fifo_thread_ctx.recovery_nr > 0) {
508 const char *filename)
547 " only when drop_pkts_on_overflow is also turned on\n");
555 if (fifo->
format && !strcmp(fifo->
format,
"fifo_test")) {
616 uint8_t overflow_set = 0;
630 }
else if (ret < 0) {
668 }
while (ret >= 0 || ret ==
AVERROR(EAGAIN));
693#define OFFSET(x) offsetof(FifoContext, x)
695 {
"attempt_recovery",
"Attempt recovery in case of failure",
OFFSET(attempt_recovery),
698 {
"drop_pkts_on_overflow",
"Drop packets on fifo queue overflow not to block encoder",
OFFSET(drop_pkts_on_overflow),
704 {
"format_opts",
"Options to be passed to underlying muxer",
OFFSET(format_options),
707 {
"max_recovery_attempts",
"Maximal number of recovery attempts",
OFFSET(max_recovery_attempts),
710 {
"queue_size",
"Size of fifo queue",
OFFSET(queue_size),
713 {
"recovery_wait_streamtime",
"Use stream time instead of real time while waiting for recovery",
716 {
"recovery_wait_time",
"Waiting time between recovery attempts",
OFFSET(recovery_wait_time),
719 {
"recover_any_error",
"Attempt recovery regardless of type of the error",
OFFSET(recover_any_error),
722 {
"restart_with_keyframe",
"Wait for keyframe when restarting output",
OFFSET(restart_with_keyframe),
725 {
"timeshift",
"Delay fifo output",
OFFSET(timeshift),
732 .class_name =
"Fifo muxer",
static const char *const format[]
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
static void deinit(AVFormatContext *s)
int(* init)(AVBSFContext *ctx)
#define atomic_store(object, desired)
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_load_explicit(object, order)
intptr_t atomic_int_least64_t
#define atomic_init(obj, value)
#define atomic_fetch_sub_explicit(object, operand, order)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static void write_header(FFV1Context *f)
const FFOutputFormat ff_fifo_test_muxer
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int ff_thread_setname(const char *name)
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
Utility function to open IO stream of output format.
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Describe the class of an AVClass context structure.
enum AVMediaType codec_type
General type of the encoded data.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
AVIOContext * pb
I/O context.
AVDictionary * metadata
Metadata that applies to the whole file.
int flags
Flags modifying the (de)muxer behaviour.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char * url
input or output URL.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
volatile uint8_t overflow_flag
int overflow_flag_lock_initialized
atomic_int_least64_t queue_duration
int recovery_wait_streamtime
pthread_mutex_t overflow_flag_lock
int drop_pkts_on_overflow
int max_recovery_attempts
int restart_with_keyframe
int64_t recovery_wait_time
AVThreadMessageQueue * queue
AVDictionary * format_options
int64_t last_received_dts
uint8_t drop_until_keyframe
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, void(*free_func)(void *msg))
Set the optional free message callback function which will be called if an operation is removing mess...
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
void av_thread_message_flush(AVThreadMessageQueue *mq)
Flush the message queue.
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
@ AV_THREAD_MESSAGE_NONBLOCK
Perform non-blocking operation.
int av_usleep(unsigned usec)
Sleep for a period of time.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
static int write_trailer(AVFormatContext *s1)