From patchwork Fri Feb 2 19:44:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 7487 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp783372jai; Fri, 2 Feb 2018 11:45:03 -0800 (PST) X-Google-Smtp-Source: AH8x226rfzlH2JKlzaPOpEDuQLCzxo3EjdDLQW8MS5eA8Ihx4JTUG8XyK59iUzFTYCKac4Bv7xrg X-Received: by 10.28.144.20 with SMTP id s20mr31499243wmd.149.1517600703481; Fri, 02 Feb 2018 11:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517600703; cv=none; d=google.com; s=arc-20160816; b=twjvcHR55/V6RaM9XYlPLX+whs1FVtapzpCJmNPL1twG6b6hs9iUPt14KegGCMgVa3 yzWzbZq+tgkchVFXQMwHt9fzryEy5tbyqEEbt/xHu05ZGvxp2yMSm7agnYfkRdZqAoN4 D8AbPWUa0bolIACPT0D5giyKkD7RCj9yqRSOTMbGnHH92xeFz0YLg3HImleacJzhvvyg XqHEnSAC/rIcBmLAt8q2hBh7pQQbk2382FQ/sMWmHQ8W5qrcYt2MdezqG3oOAi3dZA6U FVMp+f+yBroXW1MORQAfWJR/yPVpFhyyIO7rjZIZ0lxJXbPGCI0W3aUavLsfQm7kFQ+W HVvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-signature:delivered-to :arc-authentication-results; bh=JVzTR45zzjVk9wzh7lMtFgBjtlzDrxGY8ZqdB4giu+8=; b=oWJm/wPWHr4rUn9M9UuaHSapHBL29BNWjQhizi1xUgDlaowaB8cVxCFtrI3ODrXPpw iH6zWv3ggxtVCMjY+i5wnJpzP178Q24tD2+YHzKNCdoP7g4IXJasQ4pu1Cz/IpEP2u8q wItVKdRYRea1bWKyCATfHKqqF/iIaBT5KBb7mFSqS+QVNvymoItkb0e4ukh8gw/Vvbku 5FGTb1gk9pnWmQ+1kCfxg9BSNjMfFfhL7hvnALupiRoVw55Hh0pjGk/r//U3Mvuwl2SV 6z5s+MjbgSTb6npJZ0/tlpAO4SwpegcH5oDJkmJiLBH1BaU5DVnvo7wJJYsIcm6+Mr50 N98A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=MA5GKe1g; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm1 header.b=nrPpiHoo; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s15si2181224wrg.348.2018.02.02.11.45.03; Fri, 02 Feb 2018 11:45:03 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@itanimul.li header.s=fm1 header.b=MA5GKe1g; dkim=neutral (body hash did not verify) header.i=@messagingengine.com header.s=fm1 header.b=nrPpiHoo; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 63BE6689B55; Fri, 2 Feb 2018 21:44:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A95F6883CA for ; Fri, 2 Feb 2018 21:44:19 +0200 (EET) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D84AA224CB for ; Fri, 2 Feb 2018 14:44:24 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Fri, 02 Feb 2018 14:44:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itanimul.li; h= date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=S7x2Gc4b8iyc/XNgT Sj9JgzMb34yWvrv4YaRK/D2P3c=; b=MA5GKe1gmfOiWrhoBrfrX6n5BhWvlB+Le eGsH/njjca4IoZw0EWaFUvr2wHQnTh484HFvtxlt0u4IFkJUQTBbZLUybwRmOI8U 4X/P06MvjNIe5g4ApY0c0vNDgjLhhkueZHpwVlrdCHMxiIrgYfX5pIBUbPeoEhcd PYf6y15LVub+s8djqYldGNJ3K3mCCcnNeCXQpe+N/HY1NLr86D8N896ZAIgx5taW H/83FYLd6DDz85AoDj3m7xnPYnlb7Wi4QhUBPWQvlKxdmn4qWJ1O5o7cEbl78UVq MksooAMn2Yqnilus2wg3UA4VRNDCVQU97F4lfsm6e6RxIUS20tDTA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=S7x2Gc4b8iyc/XNgTSj9JgzMb34yWvrv4YaRK/D2P3c=; b=nrPpiHoo bvEes6z63akMwlgvfhPiR5/6EXM3Z2iKrJH9fv/M2M3tFYbBl4PqjJ740mXnSZTX +bN7jH5/XQ/SQYjgo2+PC+pHXoVBdtqP3gsCufOlbdfzUTLOYlpuIeFG9w40yG4v p0x2lmDbETS5PymrNr/GrR6ypfaAILPVpXHdrGcBRtNJprjAkFj1TyOqRrOFBmkB 4bSGQFMduR6dFYVL9zbtaWDUTeCKs+gHVsC10Y958Go/FMg78xaCLvWwq7T93iUR q5Bd1/3AwkJusuhCc0eoidp674HHibzc68H7arKWZAUrjoVwVSsS5VwebuS626ku xOMZS4JCTtUj8Q== X-ME-Sender: Received: from DESKTOP-AFAL1BE.localdomain (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net [82.22.8.169]) by mail.messagingengine.com (Postfix) with ESMTPA id 4A7D77E795 for ; Fri, 2 Feb 2018 14:44:24 -0500 (EST) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Feb 2018 19:44:15 +0000 Message-Id: <1517600658-32681-4-git-send-email-josh@itanimul.li> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517600658-32681-1-git-send-email-josh@itanimul.li> References: <1517600658-32681-1-git-send-email-josh@itanimul.li> Subject: [FFmpeg-devel] [PATCH v4 4/7] lavf: move fifo test muxer into separate file X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This fixes the fate-fifo-muxer test. --- libavformat/Makefile | 2 +- libavformat/allformats.c | 1 + libavformat/fifo_test.c | 150 +++++++++++++++++++++++++++++++++++++++++ libavformat/tests/fifo_muxer.c | 115 +------------------------------ 4 files changed, 154 insertions(+), 114 deletions(-) create mode 100644 libavformat/fifo_test.c diff --git a/libavformat/Makefile b/libavformat/Makefile index de0de92..e0bb8ae 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 0f198d5..09c4213 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -125,6 +125,7 @@ extern AVOutputFormat ff_f4v_muxer; extern AVInputFormat ff_ffmetadata_demuxer; extern AVOutputFormat ff_ffmetadata_muxer; extern AVOutputFormat ff_fifo_muxer; +extern AVOutputFormat ff_fifo_test_muxer; extern AVInputFormat ff_filmstrip_demuxer; extern AVOutputFormat ff_filmstrip_muxer; extern AVInputFormat ff_fits_demuxer; diff --git a/libavformat/fifo_test.c b/libavformat/fifo_test.c new file mode 100644 index 0000000..b86195b --- /dev/null +++ b/libavformat/fifo_test.c @@ -0,0 +1,150 @@ +/* + * 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 +#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, +}; \ No newline at end of file diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c index 4b63df0..5127a8a 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)