42#define MAX_TST_PACKETS 128
43#define SLEEPTIME_50_MS 50000
44#define SLEEPTIME_10_MS 10000
69 return ctx->write_header_ret;
81 if (!
data->recover_after) {
84 data->recover_after--;
89 if (
data->sleep_time) {
91 while (slept < data->sleep_time) {
100 ctx->pts_written[
ctx->pts_written_nr++] =
pkt->pts;
110 return ctx->write_trailer_ret;
118 if (!
ctx->print_deinit_summary)
121 printf(
"flush count: %d\n",
ctx->flush_count);
122 printf(
"pts seen nr: %d\n",
ctx->pts_written_nr);
124 for (
i = 0;
i <
ctx->pts_written_nr; ++
i ) {
130#define OFF(x) offsetof(FifoTestMuxerContext, x)
132 {
"write_header_ret",
"write_header() return value",
OFF(write_header_ret),
134 {
"write_trailer_ret",
"write_trailer() return value",
OFF(write_trailer_ret),
136 {
"print_deinit_summary",
"print summary when deinitializing muxer",
OFF(print_deinit_summary),
142 .class_name =
"Fifo test muxer",
149 .p.name =
"fifo_test",
167 memcpy(
pkt->data, pkt_data,
sizeof(*pkt_data));
182 fprintf(stderr,
"Failed to create format context: %s\n",
189 fprintf(stderr,
"Failed to create stream: %s\n",
208 fprintf(stderr,
"Unexpected write_header failure: %s\n",
213 for (
i = 0;
i < 15;
i++ ) {
216 fprintf(stderr,
"Failed to prepare test packet: %s\n",
218 goto write_trailer_and_fail;
223 fprintf(stderr,
"Unexpected write_frame error: %s\n",
225 goto write_trailer_and_fail;
231 fprintf(stderr,
"Unexpected write_frame error during flushing: %s\n",
233 goto write_trailer_and_fail;
238 fprintf(stderr,
"Unexpected write_trailer error during flushing: %s\n",
244write_trailer_and_fail:
258 fprintf(stderr,
"Unexpected write_header failure: %s\n",
264 for (
i = 0;
i < 6;
i++ ) {
267 fprintf(stderr,
"Failed to prepare test packet: %s\n",
279 duration = write_pkt_end - write_pkt_start;
281 fprintf(stderr,
"Writing packets to fifo muxer took too much time while testing"
282 "buffer overflow with drop_pkts_on_overflow was on.\n");
288 fprintf(stderr,
"Unexpected write_packet error: %s\n",
av_err2str(ret));
294 fprintf(stderr,
"Unexpected write_trailer error: %s\n",
av_err2str(ret));
316#define BUFFER_SIZE 64
328 fprintf(stderr,
"Muxer initialization failed: %s\n",
av_err2str(ret));
335 fprintf(stderr,
"Failed to parse options: %s\n",
av_err2str(ret));
341 "print_deinit_summary=%d:write_header_ret=%d:write_trailer_ret=%d",
342 (
int)
test->print_summary_on_deinit,
test->write_header_ret,
343 test->write_trailer_ret);
346 if (ret < 0 || ret1 < 0) {
347 fprintf(stderr,
"Failed to set options for test muxer: %s\n",
355 printf(
"%s: %s\n",
test->test_name, ret < 0 ?
"fail" :
"ok");
370 {
fifo_basic_test,
"recovery test",
"attempt_recovery=1:recovery_wait_time=0",
371 0, 0, 0, {
AVERROR(ETIMEDOUT), 3, 0}},
391int main(
int argc,
char *argv[])
393 int i, ret, ret_all = 0;
395 for (
i = 0;
tests[
i].test_func;
i++) {
397 if (!ret_all && ret < 0)
static AVFormatContext * ctx
static AVDictionary * opts
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
#define i(width, name, range_min, range_max)
static void deinit(AVFormatContext *s)
__device__ int printf(const char *,...)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static void write_header(FFV1Context *f)
static int fifo_test_trailer(AVFormatContext *avf)
static int prepare_packet(AVPacket *pkt, const FailingMuxerPacketData *pkt_data, int64_t pts)
static const AVClass failing_muxer_class
static int initialize_fifo_tst_muxer_chain(AVFormatContext **oc, AVPacket **pkt)
static int fifo_test_header(AVFormatContext *avf)
static int run_test(const TestCase *test)
static int fifo_overflow_drop_test(AVFormatContext *oc, AVDictionary **opts, AVPacket *pkt, const FailingMuxerPacketData *data)
static void failing_deinit(AVFormatContext *avf)
static int fifo_test_packet(AVFormatContext *avf, AVPacket *pkt)
const FFOutputFormat ff_fifo_test_muxer
static const AVOption fifo_test_options[]
static int fifo_basic_test(AVFormatContext *oc, AVDictionary **opts, AVPacket *pkt, const FailingMuxerPacketData *pkt_data)
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
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.
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.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
Describe the class of an AVClass context structure.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
void * priv_data
Format private data.
This structure stores compressed data.
int pts_written[MAX_TST_PACKETS]
uint8_t print_summary_on_deinit
int(* test_func)(AVFormatContext *, AVDictionary **, AVPacket *, const FailingMuxerPacketData *pkt_data)
FailingMuxerPacketData pkt_data
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.
unbuffered private I/O API
static int write_trailer(AVFormatContext *s1)