From patchwork Thu Aug 25 22:53:07 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: 296 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp42372vsd; Thu, 25 Aug 2016 15:54:02 -0700 (PDT) X-Received: by 10.28.16.3 with SMTP id 3mr32668941wmq.58.1472165642557; Thu, 25 Aug 2016 15:54:02 -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 h130si33915659wme.36.2016.08.25.15.53.41; Thu, 25 Aug 2016 15:54:02 -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 36E9F689941; Fri, 26 Aug 2016 01:53:26 +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 1138C689941 for ; Fri, 26 Aug 2016 01:53:11 +0300 (EEST) Received: by mail-wm0-f67.google.com with SMTP id o80so9208804wme.0 for ; Thu, 25 Aug 2016 15:53:14 -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:in-reply-to:references; bh=koYBZvpAyH6IJmOcEnybfawZg2kx2GSHmTqEaBNK1KI=; b=rRSvQYHVWwTwx0KzQfVOjy7TzbH5mDGGQQvARiJQSrkVfEVGoBWiZB3Mgv0bitcw9p R4U0APjj9Y9v5vbT4STU3TTGnyajOptXT9WFjFTEXJowoPzV3T3ZFcG+icOAkEi4HMHd 90lHKXRk0JufYypiFaTRNMGSzi20r38oqBn21B1h28JOUgA5YoXq73dQ4Zwe9VNaaPKr YLCHB2hkqwwJ5G4uYL3SYxk9Iz4+VGqDu8zXWBPng8310OnDbbYY8Bv1Pw7UmXyTOjz6 GXnsnuOg/bLmg0jlc4lsxZmvsuH7SH3SVVZTr+xv1NqbTrIKRol22IIiwHaAbpf61ikj hCXg== 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:in-reply-to :references; bh=koYBZvpAyH6IJmOcEnybfawZg2kx2GSHmTqEaBNK1KI=; b=WghGaE2TVhLTVs7MANqCLP7guGevwzofIDuVm6if2RM8+5lcU7wHbaVuWTWVMmzIUn tx/rB9jhMUBw17ods3QT+8CToxKkscj4L6F2Ujf9kVf7EgSf8Fmo1FUJMuCr7U9y6bBv y50CNXPvPBAmudTNVuMhZwZgNlygtceb/AhlayVBRTHzN6w7gCN5qsvvNOZkpKtSCEtH FtJ36WjJ+KLc9xAix28N6oqYFV8ZYACYA7LhmWPk72yNYuNrZr9pO/vyU8BEAXxUofmo v00T6c7lGiYeP6IeqYZtCM8+usf8HKyO0BvioGdUHhJLjXk0QNtJ7qhb2+dU9AhXOE2h wUKg== X-Gm-Message-State: AE9vXwMwrCUlDjDzq4NVUllgkpv2PbHf1vVrhrNtO7g4+nUa8vnsRSSzUqt399gMAdaZsw== X-Received: by 10.28.72.139 with SMTP id v133mr42110wma.32.1472165593360; Thu, 25 Aug 2016 15:53:13 -0700 (PDT) Received: from localhost.localdomain (adsl-dyn-46.95-102-121.t-com.sk. [95.102.121.46]) by smtp.gmail.com with ESMTPSA id d80sm40956567wmd.14.2016.08.25.15.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 15:53:12 -0700 (PDT) From: sebechlebskyjan@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Aug 2016 00:53:07 +0200 Message-Id: <1472165587-15462-1-git-send-email-sebechlebskyjan@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20160821125702.GG5460@nb4> References: <20160821125702.GG5460@nb4> Subject: [FFmpeg-devel] [PATCH v4 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 --- I believe I have fixed handling input / output timebase and input parameters to bitstream filters list. libavformat/tee.c | 131 ++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 67 deletions(-) diff --git a/libavformat/tee.c b/libavformat/tee.c index 5689ca3..ba852c3 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; @@ -64,46 +64,6 @@ static const AVClass tee_muxer_class = { .version = LIBAVUTIL_VERSION_INT, }; -/** - * Parse list of bitstream filters and add them to the list of filters - * pointed to by bsfs. - * - * The list must be specified in the form: - * BSFS ::= BSF[,BSFS] - */ -static int parse_bsfs(void *log_ctx, const char *bsfs_spec, - AVBitStreamFilterContext **bsfs) -{ - char *bsf_name, *buf, *dup, *saveptr; - int ret = 0; - - if (!(dup = buf = av_strdup(bsfs_spec))) - return AVERROR(ENOMEM); - - while (bsf_name = av_strtok(buf, ",", &saveptr)) { - AVBitStreamFilterContext *bsf = av_bitstream_filter_init(bsf_name); - - if (!bsf) { - av_log(log_ctx, AV_LOG_ERROR, - "Cannot initialize bitstream filter with name '%s', " - "unknown filter or internal error happened\n", - bsf_name); - ret = AVERROR_UNKNOWN; - goto end; - } - - /* append bsf context to the list of bsf contexts */ - *bsfs = bsf; - bsfs = &bsf->next; - - buf = NULL; - } - -end: - av_free(dup); - return ret; -} - static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave) { if (!opt) { @@ -135,14 +95,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 +266,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 +279,35 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) av_dict_set(&options, entry->key, NULL, 0); } + for (i = 0; i < avf->nb_streams; i++){ + int target_stream = tee_slave->stream_map[i]; + if (target_stream < 0) + continue; + + if (!tee_slave->bsfs[target_stream]) { + /* Add pass-through bitstream filter */ + ret = av_bsf_get_null_filter(&tee_slave->bsfs[target_stream]); + 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[target_stream]->time_base_in = avf->streams[i]->time_base; + ret = avcodec_parameters_copy(tee_slave->bsfs[target_stream]->par_in, + avf->streams[i]->codecpar); + + ret = av_bsf_init(tee_slave->bsfs[target_stream]); + 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 +332,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); } } @@ -469,11 +448,11 @@ static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt) { TeeContext *tee = avf->priv_data; AVFormatContext *avf2; + AVBSFContext *bsfs; AVPacket pkt2; int ret_all = 0, ret; unsigned i, s; int s2; - AVRational tb, tb2; for (i = 0; i < tee->nb_slaves; i++) { if (!(avf2 = tee->slaves[i].avf)) @@ -501,18 +480,36 @@ static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt) ret_all = ret; continue; } - tb = avf ->streams[s ]->time_base; - tb2 = avf2->streams[s2]->time_base; - av_packet_rescale_ts(&pkt2, tb, tb2); + bsfs = tee->slaves[i].bsfs[s2]; 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(bsfs, &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(bsfs, &pkt2); + if (ret < 0) + break; + + av_packet_rescale_ts(&pkt2, bsfs->time_base_out, + avf2->streams[s2]->time_base); + 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; }