[FFmpeg-cvslog] lavf: move fifo test muxer into separate file
Josh de Kock
git at videolan.org
Tue Feb 6 20:57:47 EET 2018
ffmpeg | branch: master | Josh de Kock <josh at itanimul.li> | Tue Jan 2 13:36:05 2018 +0000| [598d5f8579b3a048a643486a5f20fc4d479a2017] | committer: Josh de Kock
lavf: move fifo test muxer into separate file
This fixes the fate-fifo-muxer test with the clarified
removal of registering external formats.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=598d5f8579b3a048a643486a5f20fc4d479a2017
---
libavformat/Makefile | 2 +-
libavformat/allformats.c | 1 +
libavformat/fifo_test.c | 151 +++++++++++++++++++++++++++++++++++++++++
libavformat/tests/fifo_muxer.c | 115 +------------------------------
4 files changed, 155 insertions(+), 114 deletions(-)
diff --git a/libavformat/Makefile b/libavformat/Makefile
index de0de921c2..e0bb8aef86 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -163,7 +163,7 @@ OBJS-$(CONFIG_EAC3_MUXER) += rawenc.o
OBJS-$(CONFIG_EPAF_DEMUXER) += epafdec.o pcm.o
OBJS-$(CONFIG_FFMETADATA_DEMUXER) += ffmetadec.o
OBJS-$(CONFIG_FFMETADATA_MUXER) += ffmetaenc.o
-OBJS-$(CONFIG_FIFO_MUXER) += fifo.o
+OBJS-$(CONFIG_FIFO_MUXER) += fifo.o fifo_test.o
OBJS-$(CONFIG_FILMSTRIP_DEMUXER) += filmstripdec.o
OBJS-$(CONFIG_FILMSTRIP_MUXER) += filmstripenc.o
OBJS-$(CONFIG_FITS_DEMUXER) += fitsdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 83ed766559..ce4f0d8c76 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -122,6 +122,7 @@ static void register_all(void)
REGISTER_MUXER (F4V, f4v);
REGISTER_MUXDEMUX(FFMETADATA, ffmetadata);
REGISTER_MUXER (FIFO, fifo);
+ REGISTER_MUXER (FIFO, fifo_test);
REGISTER_MUXDEMUX(FILMSTRIP, filmstrip);
REGISTER_MUXDEMUX(FITS, fits);
REGISTER_MUXDEMUX(FLAC, flac);
diff --git a/libavformat/fifo_test.c b/libavformat/fifo_test.c
new file mode 100644
index 0000000000..188e607855
--- /dev/null
+++ b/libavformat/fifo_test.c
@@ -0,0 +1,151 @@
+/*
+ * FIFO test pseudo-muxer
+ * Copyright (c) 2016 Jan Sebechlebsky
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include "libavutil/opt.h"
+#include "libavutil/time.h"
+#include "libavutil/avassert.h"
+#include "libavformat/avformat.h"
+#include "libavformat/url.h"
+#include "libavformat/network.h"
+
+/* Implementation of mock muxer to simulate real muxer failures */
+
+#define MAX_TST_PACKETS 128
+#define SLEEPTIME_50_MS 50000
+#define SLEEPTIME_10_MS 10000
+
+/* Implementation of mock muxer to simulate real muxer failures */
+
+/* This is structure of data sent in packets to
+ * failing muxer */
+typedef struct FailingMuxerPacketData {
+ int ret; /* return value of write_packet call*/
+ int recover_after; /* set ret to zero after this number of recovery attempts */
+ unsigned sleep_time; /* sleep for this long in write_packet to simulate long I/O operation */
+} FailingMuxerPacketData;
+
+
+typedef struct FailingMuxerContext {
+ AVClass *class;
+ int write_header_ret;
+ int write_trailer_ret;
+ /* If non-zero, summary of processed packets will be printed in deinit */
+ int print_deinit_summary;
+
+ int flush_count;
+ int pts_written[MAX_TST_PACKETS];
+ int pts_written_nr;
+} FailingMuxerContext;
+
+static int failing_write_header(AVFormatContext *avf)
+{
+ FailingMuxerContext *ctx = avf->priv_data;
+ return ctx->write_header_ret;
+}
+
+static int failing_write_packet(AVFormatContext *avf, AVPacket *pkt)
+{
+ FailingMuxerContext *ctx = avf->priv_data;
+ int ret = 0;
+ if (!pkt) {
+ ctx->flush_count++;
+ } else {
+ FailingMuxerPacketData *data = (FailingMuxerPacketData*) pkt->data;
+
+ if (!data->recover_after) {
+ data->ret = 0;
+ } else {
+ data->recover_after--;
+ }
+
+ ret = data->ret;
+
+ if (data->sleep_time) {
+ int64_t slept = 0;
+ while (slept < data->sleep_time) {
+ if (ff_check_interrupt(&avf->interrupt_callback))
+ return AVERROR_EXIT;
+ av_usleep(SLEEPTIME_10_MS);
+ slept += SLEEPTIME_10_MS;
+ }
+ }
+
+ if (!ret) {
+ ctx->pts_written[ctx->pts_written_nr++] = pkt->pts;
+ av_packet_unref(pkt);
+ }
+ }
+ return ret;
+}
+
+static int failing_write_trailer(AVFormatContext *avf)
+{
+ FailingMuxerContext *ctx = avf->priv_data;
+ return ctx->write_trailer_ret;
+}
+
+static void failing_deinit(AVFormatContext *avf)
+{
+ int i;
+ FailingMuxerContext *ctx = avf->priv_data;
+
+ if (!ctx->print_deinit_summary)
+ return;
+
+ printf("flush count: %d\n", ctx->flush_count);
+ printf("pts seen nr: %d\n", ctx->pts_written_nr);
+ printf("pts seen: ");
+ for (i = 0; i < ctx->pts_written_nr; ++i ) {
+ printf(i ? ",%d" : "%d", ctx->pts_written[i]);
+ }
+ printf("\n");
+}
+#define OFFSET(x) offsetof(FailingMuxerContext, x)
+static const AVOption options[] = {
+ {"write_header_ret", "write_header() return value", OFFSET(write_header_ret),
+ AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ {"write_trailer_ret", "write_trailer() return value", OFFSET(write_trailer_ret),
+ AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ {"print_deinit_summary", "print summary when deinitializing muxer", OFFSET(print_deinit_summary),
+ AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+ {NULL}
+ };
+
+static const AVClass failing_muxer_class = {
+ .class_name = "Fifo test muxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVOutputFormat ff_fifo_test_muxer = {
+ .name = "fifo_test",
+ .long_name = NULL_IF_CONFIG_SMALL("Fifo test muxer"),
+ .priv_data_size = sizeof(FailingMuxerContext),
+ .write_header = failing_write_header,
+ .write_packet = failing_write_packet,
+ .write_trailer = failing_write_trailer,
+ .deinit = failing_deinit,
+ .priv_class = &failing_muxer_class,
+ .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,
+};
+
diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c
index 4b63df085e..5127a8aadb 100644
--- a/libavformat/tests/fifo_muxer.c
+++ b/libavformat/tests/fifo_muxer.c
@@ -31,8 +31,6 @@
#define SLEEPTIME_50_MS 50000
#define SLEEPTIME_10_MS 10000
-/* Implementation of mock muxer to simulate real muxer failures */
-
/* This is structure of data sent in packets to
* failing muxer */
typedef struct FailingMuxerPacketData {
@@ -41,113 +39,7 @@ typedef struct FailingMuxerPacketData {
unsigned sleep_time; /* sleep for this long in write_packet to simulate long I/O operation */
} FailingMuxerPacketData;
-
-typedef struct FailingMuxerContext {
- AVClass *class;
- int write_header_ret;
- int write_trailer_ret;
- /* If non-zero, summary of processed packets will be printed in deinit */
- int print_deinit_summary;
-
- int flush_count;
- int pts_written[MAX_TST_PACKETS];
- int pts_written_nr;
-} FailingMuxerContext;
-
-static int failing_write_header(AVFormatContext *avf)
-{
- FailingMuxerContext *ctx = avf->priv_data;
- return ctx->write_header_ret;
-}
-
-static int failing_write_packet(AVFormatContext *avf, AVPacket *pkt)
-{
- FailingMuxerContext *ctx = avf->priv_data;
- int ret = 0;
- if (!pkt) {
- ctx->flush_count++;
- } else {
- FailingMuxerPacketData *data = (FailingMuxerPacketData*) pkt->data;
-
- if (!data->recover_after) {
- data->ret = 0;
- } else {
- data->recover_after--;
- }
-
- ret = data->ret;
-
- if (data->sleep_time) {
- int64_t slept = 0;
- while (slept < data->sleep_time) {
- if (ff_check_interrupt(&avf->interrupt_callback))
- return AVERROR_EXIT;
- av_usleep(SLEEPTIME_10_MS);
- slept += SLEEPTIME_10_MS;
- }
- }
-
- if (!ret) {
- ctx->pts_written[ctx->pts_written_nr++] = pkt->pts;
- av_packet_unref(pkt);
- }
- }
- return ret;
-}
-
-static int failing_write_trailer(AVFormatContext *avf)
-{
- FailingMuxerContext *ctx = avf->priv_data;
- return ctx->write_trailer_ret;
-}
-
-static void failing_deinit(AVFormatContext *avf)
-{
- int i;
- FailingMuxerContext *ctx = avf->priv_data;
-
- if (!ctx->print_deinit_summary)
- return;
-
- printf("flush count: %d\n", ctx->flush_count);
- printf("pts seen nr: %d\n", ctx->pts_written_nr);
- printf("pts seen: ");
- for (i = 0; i < ctx->pts_written_nr; ++i ) {
- printf(i ? ",%d" : "%d", ctx->pts_written[i]);
- }
- printf("\n");
-}
-#define OFFSET(x) offsetof(FailingMuxerContext, x)
-static const AVOption options[] = {
- {"write_header_ret", "write_header() return value", OFFSET(write_header_ret),
- AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
- {"write_trailer_ret", "write_trailer() return value", OFFSET(write_trailer_ret),
- AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
- {"print_deinit_summary", "print summary when deinitializing muxer", OFFSET(print_deinit_summary),
- AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
- {NULL}
- };
-
-static const AVClass failing_muxer_class = {
- .class_name = "Failing test muxer",
- .item_name = av_default_item_name,
- .option = options,
- .version = LIBAVUTIL_VERSION_INT,
-};
-
-AVOutputFormat tst_failing_muxer = {
- .name = "fail",
- .long_name = NULL_IF_CONFIG_SMALL("Failing test muxer"),
- .priv_data_size = sizeof(FailingMuxerContext),
- .write_header = failing_write_header,
- .write_packet = failing_write_packet,
- .write_trailer = failing_write_trailer,
- .deinit = failing_deinit,
- .priv_class = &failing_muxer_class,
- .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,
-};
-
-static int prepare_packet(AVPacket *pkt,const FailingMuxerPacketData *pkt_data, int64_t pts)
+static int prepare_packet(AVPacket *pkt, const FailingMuxerPacketData *pkt_data, int64_t pts)
{
int ret;
FailingMuxerPacketData *data = av_malloc(sizeof(*data));
@@ -333,7 +225,7 @@ static int run_test(const TestCase *test)
(int)test->print_summary_on_deinit, test->write_header_ret,
test->write_trailer_ret);
ret = av_dict_set(&opts, "format_opts", buffer, 0);
- ret1 = av_dict_set(&opts, "fifo_format", "fail", 0);
+ ret1 = av_dict_set(&opts, "fifo_format", "fifo_test", 0);
if (ret < 0 || ret1 < 0) {
fprintf(stderr, "Failed to set options for test muxer: %s\n",
av_err2str(ret));
@@ -382,9 +274,6 @@ int main(int argc, char *argv[])
{
int i, ret, ret_all = 0;
- av_register_all();
- av_register_output_format(&tst_failing_muxer);
-
for (i = 0; tests[i].test_func; i++) {
ret = run_test(&tests[i]);
if (!ret_all && ret < 0)
More information about the ffmpeg-cvslog
mailing list