From patchwork Sun Jan 21 18:24:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 7382 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.156.27 with SMTP id q27csp2063802jak; Sun, 21 Jan 2018 10:25:37 -0800 (PST) X-Google-Smtp-Source: AH8x224/GnRqoexRpjXJJfLgvX1gEOkI+LGZkrq4eGtWGJF/VJBSpb07q2pkdubrLM4a/BWAzyhn X-Received: by 10.223.139.218 with SMTP id w26mr4042420wra.67.1516559137092; Sun, 21 Jan 2018 10:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516559137; cv=none; d=google.com; s=arc-20160816; b=bQ7ScaAU1N6wSl0hTm0OL2fEusMdbN/43ccEftloOzwGjZ9kxLDz4cB69fptqw3i1+ DeSJ1JC5ccYNUmCwSO7+TUv45JZ/9RBBXEAXYdiU6AeoGUYJEHpvk3g5hDwZ2UkJiGYG qRV2uwn3tH/piYP7Q9dJAJ02i1IHXaS5wlYYgqFeVwqgk08XU1V8j0EdwtBf9GuIsVLc IfLFtgBm+uTiqOK+WJZKJA9R/wy8CeISUKUsTsuUn0h/0XG5Quo0HpBAtcjyuSlaHe+D /xzfZBsxhbwY2XLTRbzZDBLLJN2m6W2X5nTCq4tuVIXBD5vW5xM9HSBtF03rvepj8MuM W51A== 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:cc: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:delivered-to:arc-authentication-results; bh=u8YaGWJwdTARWICdnTicwcNcErVNkXHN+LEY3fGr+F0=; b=s2fBwaW66NHSgeuocEum/bLKhqjNAim8f0nLUsqIdEaJdXCMC4ObW0+JYRVu227O7c ZKuzu2j+kzivN4HDQQ8ZHptfbgIcEFk6UnqnntwNM9inrIG8Aft/v1/LP2QWLv4D8f4x I2oq7qXkZnIW5ZXU9ylvXlhijpeBCFCzN4DhWFMMQacoyfR7njq4T6R3VmLnzQLSz3HZ tWAct3wlLoa4K6gf3pQ9sEKklQFs7QYo1MGrZmRi0UJZiz3T9RLziUUgmTWFDo9+pm1J wrzIFkKyKHwqdDaSt1mmBWva6vz3CVmS7eq4N7uEtZD9N+LtJMcW0mspChm7swUztNte GLQA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y8si10670804wrh.446.2018.01.21.10.25.36; Sun, 21 Jan 2018 10:25:37 -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; 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 EEB9668A263; Sun, 21 Jan 2018 20:25:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E2B868A1F8 for ; Sun, 21 Jan 2018 20:25:15 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DBFE5E1420; Sun, 21 Jan 2018 19:25:16 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nvg2XNErdr4M; Sun, 21 Jan 2018 19:25:16 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 00934E164C; Sun, 21 Jan 2018 19:25:15 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Jan 2018 19:24:06 +0100 Message-Id: <20180121182411.22224-3-cus@passwd.hu> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180121182411.22224-1-cus@passwd.hu> References: <20180121182411.22224-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/7] avformat: add url field to AVFormatContext 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This will replace the 1024 character limited filename field. Compatiblity for output contexts are provided by copying filename field to URL if URL is unset and by providing an internal function for muxers to set both url and filename at once. Signed-off-by: Marton Balint --- doc/APIchanges | 3 +++ libavformat/avformat.h | 15 +++++++++++++++ libavformat/internal.h | 7 +++++++ libavformat/mux.c | 11 ++++++++++- libavformat/utils.c | 14 ++++++++++++++ libavformat/version.h | 2 +- 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 7699365879..490f57bb2f 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2018-xx-xx - xxxxxxx - lavf 58.6.100 - avformat.h + Add url field to AVFormatContext and add ff_format_set_url helper function. + 2018-01-xx - xxxxxxx - lavf 58.5.100 - avformat.h Explicitly make avformat_network_init() and avformat_network_deinit() optional. If these are not called, network initialization and deinitialization is diff --git a/libavformat/avformat.h b/libavformat/avformat.h index e5740be2b4..81ac7e58e8 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1398,6 +1398,21 @@ typedef struct AVFormatContext { char filename[1024]; /** + * input or output URL. Unlike the old filename field, this field has no + * length restriction. + * + * - demuxing: set by avformat_open_input(), initialized to an empty + * string if url parameter was NULL in avformat_open_input(). + * - muxing: may be set by the caller before calling avformat_write_header() + * (or avformat_init_output() if that is called first) to a string + * which is freeable by av_free(). Set to an empty string if it + * was NULL in avformat_init_output(). + * + * Freed by libavformat in avformat_free_context(). + */ + char *url; + + /** * Position of the first frame of the component, in * AV_TIME_BASE fractional seconds. NEVER set this value directly: * It is deduced from the AVStream values. diff --git a/libavformat/internal.h b/libavformat/internal.h index 0cd0556dc7..1e2a3e05a1 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -696,4 +696,11 @@ int ff_interleaved_peek(AVFormatContext *s, int stream, int ff_lock_avformat(void); int ff_unlock_avformat(void); +/** + * Set AVFormatContext url field to the provided pointer. The pointer must + * point to a valid string. The existing url field is freed if necessary. Also + * set the legacy filename field to the same string which was provided in url. + */ +void ff_format_set_url(AVFormatContext *s, char *url); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/mux.c b/libavformat/mux.c index ea9f13fdf5..de63f2ca25 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -186,8 +186,12 @@ int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *ofor } else s->priv_data = NULL; - if (filename) + if (filename) { av_strlcpy(s->filename, filename, sizeof(s->filename)); + if (!(s->url = av_strdup(filename))) + goto nomem; + + } *avctx = s; return 0; nomem: @@ -251,6 +255,11 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) (ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0) goto fail; + if (!s->url && !(s->url = av_strdup(s->filename))) { + ret = AVERROR(ENOMEM); + goto fail; + } + #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT) { diff --git a/libavformat/utils.c b/libavformat/utils.c index 3d733417e1..8bf27c3b35 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -555,6 +555,11 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, if ((ret = av_opt_set_dict(s, &tmp)) < 0) goto fail; + if (!(s->url = av_strdup(filename ? filename : ""))) { + ret = AVERROR(ENOMEM); + goto fail; + } + av_strlcpy(s->filename, filename ? filename : "", sizeof(s->filename)); if ((ret = init_input(s, filename, &tmp)) < 0) goto fail; @@ -4369,6 +4374,7 @@ void avformat_free_context(AVFormatContext *s) av_freep(&s->streams); flush_packet_queue(s); av_freep(&s->internal); + av_freep(&s->url); av_free(s); } @@ -5634,3 +5640,11 @@ FF_ENABLE_DEPRECATION_WARNINGS return st->internal->avctx->time_base; #endif } + +void ff_format_set_url(AVFormatContext *s, char *url) +{ + av_assert0(url); + av_freep(&s->url); + s->url = url; + av_strlcpy(s->filename, url, sizeof(s->filename)); +} diff --git a/libavformat/version.h b/libavformat/version.h index 87758b027c..5ff8a89ae0 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 5 +#define LIBAVFORMAT_VERSION_MINOR 6 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \