From patchwork Fri Aug 5 13:45:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sebechlebskyjan@gmail.com X-Patchwork-Id: 100 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp1730729vsd; Fri, 5 Aug 2016 06:46:25 -0700 (PDT) X-Received: by 10.194.168.197 with SMTP id zy5mr82233150wjb.112.1470404785692; Fri, 05 Aug 2016 06:46:25 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x8si8941822wme.6.2016.08.05.06.46.24; Fri, 05 Aug 2016 06:46:25 -0700 (PDT) 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=@gmail.com; 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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A74D468A677; Fri, 5 Aug 2016 16:46:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9853868A63A for ; Fri, 5 Aug 2016 16:46:04 +0300 (EEST) Received: by mail-wm0-f67.google.com with SMTP id o80so3863851wme.0 for ; Fri, 05 Aug 2016 06:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=IeW0xtAHmJoJPmSlLmks7gsbKuamG5sNCKfLOklBYsg=; b=sEh8idz21WssSO8yDAhjVEQU8QpsnYRWOtF4db/5F1PAjU+SQZbldD4p2p9hfONOPm fDsk+TioDa3cvFLIp9kSgb2NvGHlBH9yvjmxwigv6H6BJI9N7PosXVlo7xCj5NfH3eLb FFN3l/YcuFYD2RUQqhImRqvT3+opsrHp5JpOrvoKnTpBSqV0HpseOpXWf8F/pwkFhqAC DmLeOpsikNB9dEU9/Q9EQvIS4dMdc2qxBZaLHQvKWEQStngQo+d7fL+4gchAHcSOja8G VweN/p3cVaffyT1ngzpIdeL54h4IsiKSbF/jJJ/6H/M/WHljJxVC4mLSJucf8O/kBr+K WAeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=IeW0xtAHmJoJPmSlLmks7gsbKuamG5sNCKfLOklBYsg=; b=hCG4OECmhTgTY6vVsAAUPnXevLlXqIbQF6Ur86RbhT4G7MBs7qqNw8rf6a1zCqE8tB HOiWC5lXIF08wVWAg3jLUowJ5XGzOA8zmDMvFq8yAnrh3jDLZ+4xOhizT/xlt8oclF+g 477D8b8kik6mZzw+ZIoAYfg5TExSuQ1GVqhL3bYH9AZe+lnKVGheyPW2EZTBNoTE+WAl e3d0z5q7Nwb1XaPp/KUa5mxiyNqU8ub4Q1fQ9GOOuLrrfUC9GAuj+SBLgVYsuMX1OsBE 6DRw8ajZ6KZSVlH1EEr6wQ/l2K9fXIWzXmbo7vx+UBU4PCNHSHL9ormDvB1gUpeZnzTv CL2g== X-Gm-Message-State: AEkoouvp/Xjf1r4ztecj3SR5GV21GpRnvaBuvo4ALCXDlpBuVzFB8PsedLThd4GvK6sBsQ== X-Received: by 10.194.172.165 with SMTP id bd5mr12111229wjc.33.1470404771202; Fri, 05 Aug 2016 06:46:11 -0700 (PDT) Received: from localhost.localdomain (157.174.broadband3.iol.cz. [85.70.174.157]) by smtp.gmail.com with ESMTPSA id al10sm17936279wjc.12.2016.08.05.06.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Aug 2016 06:46:10 -0700 (PDT) From: sebechlebskyjan@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Aug 2016 15:45:54 +0200 Message-Id: <1470404754-16334-1-git-send-email-sebechlebskyjan@gmail.com> X-Mailer: git-send-email 1.9.1 Subject: [FFmpeg-devel] [PATCH v2 5/5] avformat/tee: Use BSF list API 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 Cc: Jan Sebechlebsky MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Sebechlebsky Signed-off-by: Jan Sebechlebsky --- No changes from the last version, just rebased after Michael's commit. libavformat/tee.c | 80 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/libavformat/tee.c b/libavformat/tee.c index 5689ca3..179ad2d 100644 --- a/libavformat/tee.c +++ b/libavformat/tee.c @@ -37,7 +37,7 @@ typedef enum { typedef struct { AVFormatContext *avf; - AVBitStreamFilterContext **bsfs; ///< bitstream filters per stream + AVBSFContext **bsfs; ///< bitstream filters per stream SlaveFailurePolicy on_fail; @@ -135,14 +135,8 @@ static int close_slave(TeeSlave *tee_slave) ret = av_write_trailer(avf); if (tee_slave->bsfs) { - for (i = 0; i < avf->nb_streams; ++i) { - AVBitStreamFilterContext *bsf_next, *bsf = tee_slave->bsfs[i]; - while (bsf) { - bsf_next = bsf->next; - av_bitstream_filter_close(bsf); - bsf = bsf_next; - } - } + for (i = 0; i < avf->nb_streams; ++i) + av_bsf_free(&tee_slave->bsfs[i]); } av_freep(&tee_slave->stream_map); av_freep(&tee_slave->bsfs); @@ -312,7 +306,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) "output '%s', filters will be ignored\n", i, filename); continue; } - ret = parse_bsfs(avf, entry->value, &tee_slave->bsfs[i]); + ret = av_bsf_list_parse_str(entry->value, &tee_slave->bsfs[i]); if (ret < 0) { av_log(avf, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s' associated to " @@ -325,6 +319,31 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) av_dict_set(&options, entry->key, NULL, 0); } + for (i = 0; i < avf2->nb_streams; i++){ + if (!tee_slave->bsfs[i]) { + /* Add pass-through bitstream filter */ + ret = av_bsf_get_null_filter(&tee_slave->bsfs[i]); + if (ret < 0) { + av_log(avf, AV_LOG_ERROR, + "Failed to create pass-through bitstream filter: %s\n", + av_err2str(ret)); + goto end; + } + } + + tee_slave->bsfs[i]->time_base_in = avf2->streams[i]->time_base; + ret = avcodec_parameters_copy(tee_slave->bsfs[i]->par_in, + avf2->streams[i]->codecpar); + + ret = av_bsf_init(tee_slave->bsfs[i]); + if (ret < 0) { + av_log(avf, AV_LOG_ERROR, + "Failed to initialize bitstream filter(s): %s\n", + av_err2str(ret)); + goto end; + } + } + if (options) { entry = NULL; while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX))) @@ -349,20 +368,16 @@ static void log_slave(TeeSlave *slave, void *log_ctx, int log_level) slave->avf->filename, slave->avf->oformat->name); for (i = 0; i < slave->avf->nb_streams; i++) { AVStream *st = slave->avf->streams[i]; - AVBitStreamFilterContext *bsf = slave->bsfs[i]; + AVBSFContext *bsf = slave->bsfs[i]; + const char * bsf_name; av_log(log_ctx, log_level, " stream:%d codec:%s type:%s", i, avcodec_get_name(st->codecpar->codec_id), av_get_media_type_string(st->codecpar->codec_type)); - if (bsf) { - av_log(log_ctx, log_level, " bsfs:"); - while (bsf) { - av_log(log_ctx, log_level, "%s%s", - bsf->filter->name, bsf->next ? "," : ""); - bsf = bsf->next; - } - } - av_log(log_ctx, log_level, "\n"); + + bsf_name = bsf->filter->priv_class ? + bsf->filter->priv_class->item_name(bsf) : bsf->filter->name; + av_log(log_ctx, log_level, " bsfs: %s\n", bsf_name); } } @@ -506,13 +521,32 @@ static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt) av_packet_rescale_ts(&pkt2, tb, tb2); pkt2.stream_index = s2; - if ((ret = av_apply_bitstream_filters(avf2->streams[s2]->codec, &pkt2, - tee->slaves[i].bsfs[s2])) < 0 || - (ret = av_interleaved_write_frame(avf2, &pkt2)) < 0) { + ret = av_bsf_send_packet(tee->slaves[i].bsfs[s2], &pkt2); + if (ret < 0) { + av_log(avf, AV_LOG_ERROR, "Error while sending packet to bitstream filter: %s\n", + av_err2str(ret)); ret = tee_process_slave_failure(avf, i, ret); if (!ret_all && ret < 0) ret_all = ret; } + + do { + ret = av_bsf_receive_packet(tee->slaves[i].bsfs[s2], &pkt2); + if (ret < 0) + break; + + av_packet_rescale_ts(&pkt2, tb, tb2); + ret = av_interleaved_write_frame(avf2, &pkt2); + } while (!ret); + + if (ret == AVERROR(EAGAIN)) { + ret = 0; + } else if (ret < 0) { + ret = tee_process_slave_failure(avf, i, ret); + if (!ret_all && ret < 0) + ret_all = ret; + } + } return ret_all; }