From patchwork Sat Feb 9 14:44:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 12009 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EAC0E445BED for ; Sat, 9 Feb 2019 16:45:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BBC9868A6B5; Sat, 9 Feb 2019 16:45:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f194.google.com (mail-it1-f194.google.com [209.85.166.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1BA3568A6B5 for ; Sat, 9 Feb 2019 16:45:02 +0200 (EET) Received: by mail-it1-f194.google.com with SMTP id x124so11440773itd.1 for ; Sat, 09 Feb 2019 06:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=5kwUtwJQGWw4+BcDqNo7Y3GVCnxUY6pRRtTS0SDARps=; b=Xm5cXoldRDo4Bp8Bd6TvZaTgGZdLTDyvK7b7bs3gsGcpE2MZEBnLKHIfH0Hd6y5Gxn g34VuzYdXfgYbE9DdajDjmIKHIOlYEZrlQ48G3vcew4Hr4tjqmiuvW3+WmBjRWXPjwB0 2Ss0AeyjMVYN4hbSEkpVAopBXWPm8rgKoBji7J+pFtDDtAytne2cyLdm+zJZ6l2bfi7J LwZNIazSeoSgSRXtnYjIBabUbN1oxGhs8wZK/LuOMPHdu+Ujxh6vZyRFBEz7wAbWuRxh v04lQ3+65VOFC8EWaWJJMbFg6O9u5i6iK+Lmbyn+lrELNEYfq0KPSZFzmzocpifqww/T Z6BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=5kwUtwJQGWw4+BcDqNo7Y3GVCnxUY6pRRtTS0SDARps=; b=PAHCMvNz76uaWFqJvDQl7Tqzh1gN3n/HsKt7G8S2Pmjz7urDogu1f40aJUDGaYdX+R etUxr25UmmPH7WETH4OiQU3cIKwAZ7UPTe7n5G8PoBLpTCuOgDE5ANVAyAqrOTUPGIZ5 lpKnEJzgP9PhXDygoT1TFLBEBtHWpDkGND/BQarsOcwMM5EYpXw/rlYo12st5rvKghb4 TSofJNK7P0+nQQ11WwPmUk98yFZnJ7+20hg9opzMcgAGE9sQ5N5Si57ooH6aYF7ciLQ9 JPsekXghkQg+w51WAP4xsr17ZjZnaetDKFGvV/9GZTGDIY7NTnyY74zxo8AYQ4Ax+uzT wdLQ== X-Gm-Message-State: AHQUAuYCzYXWbsQKSgFWZ5uMlot59y2vqE14xz9y4wP98HqtHiBXrjrm r2IRYycEBQCJOG1+JWY90OSuQaX2dW1D749WwHApBg== X-Google-Smtp-Source: AHgI3IY722XyxO+o1wr4HbO4TUc6MpYzZmE5GDlObhhDZdLvgPfk1LcqHP8IW1h6XImyc262kkTW+vh7d8ij2cf7FqQ= X-Received: by 2002:a5d:9685:: with SMTP id m5mr7540616ion.55.1549723500541; Sat, 09 Feb 2019 06:45:00 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:c890:0:0:0:0:0 with HTTP; Sat, 9 Feb 2019 06:44:59 -0800 (PST) In-Reply-To: <432361f9-b365-e617-52b0-67a1b8748be0@gmail.com> References: <432361f9-b365-e617-52b0-67a1b8748be0@gmail.com> From: Carl Eugen Hoyos Date: Sat, 9 Feb 2019 15:44:59 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavf:Constify AVOutputFormat pointer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2019-02-09 15:42 GMT+01:00, James Almer : > On 2/9/2019 11:23 AM, Carl Eugen Hoyos wrote: >> Hi! >> >> Attached patch is supposed to constify all occurrences of >> AVOutputFormat in libavformat. >> >> Please comment, Carl Eugen >> >> >> 0001-lavf-Constify-AVOutputFormat-pointer.patch >> >> From ba32f41824df07b7a6cb45964ef912c5fc05b276 Mon Sep 17 00:00:00 2001 >> From: Carl Eugen Hoyos >> Date: Sat, 9 Feb 2019 15:21:17 +0100 >> Subject: [PATCH] lavf: Constify AVOutputFormat pointer. >> >> --- >> libavformat/allformats.c | 4 ++++ >> libavformat/avformat.h | 15 ++++++++++----- >> libavformat/fifo.c | 4 ++-- >> libavformat/format.c | 6 +++--- >> libavformat/hdsenc.c | 2 +- >> libavformat/hlsenc.c | 4 ++-- >> libavformat/mux.c | 4 ++-- >> libavformat/rtp.c | 2 +- >> libavformat/rtpenc_chain.c | 2 +- >> libavformat/rtpenc_mpegts.c | 4 ++-- >> libavformat/segment.c | 2 +- >> libavformat/smoothstreamingenc.c | 2 +- >> libavformat/version.h | 3 +++ >> libavformat/webm_chunk.c | 2 +- >> 14 files changed, 34 insertions(+), 22 deletions(-) >> >> diff --git a/libavformat/allformats.c b/libavformat/allformats.c >> index 0684498..64d0f02 100644 >> --- a/libavformat/allformats.c >> +++ b/libavformat/allformats.c >> @@ -595,7 +595,11 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat >> *f) >> ff_thread_once(&av_format_next_init, av_format_init_next); >> >> if (f) >> +#if FF_API_AVIOFORMAT >> + return (AVOutputFormat *) f->next; >> +#else >> return f->next; >> +#endif >> else { >> void *opaque = NULL; >> return (AVOutputFormat *)av_muxer_iterate(&opaque); >> diff --git a/libavformat/avformat.h b/libavformat/avformat.h >> index fdaffa5..52922c0 100644 >> --- a/libavformat/avformat.h >> +++ b/libavformat/avformat.h >> @@ -532,7 +532,12 @@ typedef struct AVOutputFormat { >> * New public fields should be added right above. >> ***************************************************************** >> */ >> - struct AVOutputFormat *next; >> +#if FF_API_AVIOFORMAT >> +#define av_const59 const >> +#else >> +#define av_const59 >> +#endif > > Shouldn't it be the other way around? FF_API_AVIOFORMAT > evaluates to 1 when major is < 59. Yes, I had realized this in the meantime, new patch attached. Please comment, Carl Eugen From 12857febacc9786c591d6d4c464bba1e4f4d7548 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sat, 9 Feb 2019 15:43:42 +0100 Subject: [PATCH] lavf: Constify AVOutputFormat pointer. --- libavformat/allformats.c | 4 ++++ libavformat/avformat.h | 15 ++++++++++----- libavformat/fifo.c | 4 ++-- libavformat/format.c | 6 +++--- libavformat/hdsenc.c | 2 +- libavformat/hlsenc.c | 4 ++-- libavformat/mux.c | 4 ++-- libavformat/rtp.c | 2 +- libavformat/rtpenc_chain.c | 2 +- libavformat/rtpenc_mpegts.c | 4 ++-- libavformat/segment.c | 2 +- libavformat/smoothstreamingenc.c | 2 +- libavformat/version.h | 3 +++ libavformat/webm_chunk.c | 2 +- 14 files changed, 34 insertions(+), 22 deletions(-) diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 0684498..411cfe7 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -595,7 +595,11 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f) ff_thread_once(&av_format_next_init, av_format_init_next); if (f) +#if FF_API_AVIOFORMAT return f->next; +#else + return (AVOutputFormat *) f->next; +#endif else { void *opaque = NULL; return (AVOutputFormat *)av_muxer_iterate(&opaque); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index fdaffa5..c8dfe88 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -532,7 +532,12 @@ typedef struct AVOutputFormat { * New public fields should be added right above. ***************************************************************** */ - struct AVOutputFormat *next; +#if FF_API_AVIOFORMAT +#define av_const59 +#else +#define av_const59 const +#endif + av_const59 struct AVOutputFormat *next; /** * size of private data so that it can be allocated in the wrapper */ @@ -1353,7 +1358,7 @@ typedef struct AVFormatContext { * * Muxing only, must be set by the caller before avformat_write_header(). */ - struct AVOutputFormat *oformat; + av_const59 struct AVOutputFormat *oformat; /** * Format private data. This is an AVOptions-enabled struct @@ -2211,7 +2216,7 @@ AVProgram *av_new_program(AVFormatContext *s, int id); * @return >= 0 in case of success, a negative AVERROR code in case of * failure */ -int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, +int avformat_alloc_output_context2(AVFormatContext **ctx, av_const59 AVOutputFormat *oformat, const char *format_name, const char *filename); /** @@ -2687,14 +2692,14 @@ int av_write_trailer(AVFormatContext *s); * @param mime_type if non-NULL checks if mime_type matches with the * MIME type of the registered formats */ -AVOutputFormat *av_guess_format(const char *short_name, +av_const59 AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type); /** * Guess the codec ID based upon muxer and filename. */ -enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, +enum AVCodecID av_guess_codec(av_const59 AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type); diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 145e2e2..2bc63fa 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -442,7 +442,7 @@ static void *fifo_consumer_thread(void *data) return NULL; } -static int fifo_mux_init(AVFormatContext *avf, AVOutputFormat *oformat, +static int fifo_mux_init(AVFormatContext *avf, av_const59 AVOutputFormat *oformat, const char *filename) { FifoContext *fifo = avf->priv_data; @@ -481,7 +481,7 @@ static int fifo_mux_init(AVFormatContext *avf, AVOutputFormat *oformat, static int fifo_init(AVFormatContext *avf) { FifoContext *fifo = avf->priv_data; - AVOutputFormat *oformat; + av_const59 AVOutputFormat *oformat; int ret = 0; if (fifo->recovery_wait_streamtime && !fifo->drop_pkts_on_overflow) { diff --git a/libavformat/format.c b/libavformat/format.c index 2c4c895..4b89a1a 100644 --- a/libavformat/format.c +++ b/libavformat/format.c @@ -48,7 +48,7 @@ int av_match_ext(const char *filename, const char *extensions) return 0; } -AVOutputFormat *av_guess_format(const char *short_name, const char *filename, +av_const59 AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type) { const AVOutputFormat *fmt = NULL; @@ -84,12 +84,12 @@ AVOutputFormat *av_guess_format(const char *short_name, const char *filename, return fmt_found; } -enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, +enum AVCodecID av_guess_codec(av_const59 AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type) { if (av_match_name("segment", fmt->name) || av_match_name("ssegment", fmt->name)) { - AVOutputFormat *fmt2 = av_guess_format(NULL, filename, NULL); + av_const59 AVOutputFormat *fmt2 = av_guess_format(NULL, filename, NULL); if (fmt2) fmt = fmt2; } diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index d82aee1..2c5f1da 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -315,7 +315,7 @@ static int hds_write_header(AVFormatContext *s) { HDSContext *c = s->priv_data; int ret = 0, i; - AVOutputFormat *oformat; + av_const59 AVOutputFormat *oformat; if (mkdir(s->url, 0777) == -1 && errno != EEXIST) { ret = AVERROR(errno); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index d91960d..24a991b 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -110,8 +110,8 @@ typedef struct VariantStream { unsigned var_stream_idx; unsigned number; int64_t sequence; - AVOutputFormat *oformat; - AVOutputFormat *vtt_oformat; + av_const59 AVOutputFormat *oformat; + av_const59 AVOutputFormat *vtt_oformat; AVIOContext *out; int packets_written; int init_range_length; diff --git a/libavformat/mux.c b/libavformat/mux.c index 2847a02..d1546d1 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -145,7 +145,7 @@ enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st } -int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, +int avformat_alloc_output_context2(AVFormatContext **avctx, av_const59 AVOutputFormat *oformat, const char *format, const char *filename) { AVFormatContext *s = avformat_alloc_context(); @@ -246,7 +246,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) AVStream *st; AVDictionary *tmp = NULL; AVCodecParameters *par = NULL; - AVOutputFormat *of = s->oformat; + const AVOutputFormat *of = s->oformat; const AVCodecDescriptor *desc; AVDictionaryEntry *e; diff --git a/libavformat/rtp.c b/libavformat/rtp.c index 4745e54..38e2343 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -91,7 +91,7 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, int idx) { int i; - AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL; + const AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL; /* Was the payload type already specified for the RTP muxer? */ if (ofmt && ofmt->priv_class && fmt->priv_data) { diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index d3c1bc9..14b0a94 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -31,7 +31,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, { AVFormatContext *rtpctx = NULL; int ret; - AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); + av_const59 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); uint8_t *rtpflags; AVDictionary *opts = NULL; diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c index 5f81e1a..fa7d018 100644 --- a/libavformat/rtpenc_mpegts.c +++ b/libavformat/rtpenc_mpegts.c @@ -48,8 +48,8 @@ static int rtp_mpegts_write_header(AVFormatContext *s) { struct MuxChain *chain = s->priv_data; AVFormatContext *mpegts_ctx = NULL, *rtp_ctx = NULL; - AVOutputFormat *mpegts_format = av_guess_format("mpegts", NULL, NULL); - AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); + av_const59 AVOutputFormat *mpegts_format = av_guess_format("mpegts", NULL, NULL); + av_const59 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); int i, ret = AVERROR(ENOMEM); AVStream *st; diff --git a/libavformat/segment.c b/libavformat/segment.c index e2ac2c3..605ea25 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -72,7 +72,7 @@ typedef struct SegmentContext { int segment_idx_wrap; ///< number after which the index wraps int segment_idx_wrap_nb; ///< number of time the index has wraped int segment_count; ///< number of segment files already written - AVOutputFormat *oformat; + av_const59 AVOutputFormat *oformat; AVFormatContext *avf; char *format; ///< format to use for output segment files char *format_options_str; ///< format options to use for output segment files diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 094712a..1ab5191 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -293,7 +293,7 @@ static int ism_write_header(AVFormatContext *s) { SmoothStreamingContext *c = s->priv_data; int ret = 0, i; - AVOutputFormat *oformat; + av_const59 AVOutputFormat *oformat; if (mkdir(s->url, 0777) == -1 && errno != EEXIST) { ret = AVERROR(errno); diff --git a/libavformat/version.h b/libavformat/version.h index 4408eca..3774903 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -103,6 +103,9 @@ #ifndef FF_API_LAVF_MP4A_LATM #define FF_API_LAVF_MP4A_LATM (LIBAVFORMAT_VERSION_MAJOR < 59) #endif +#ifndef FF_API_AVIOFORMAT +#define FF_API_AVIOFORMAT (LIBAVFORMAT_VERSION_MAJOR < 58) +#endif #ifndef FF_API_R_FRAME_RATE diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 7ceb276..4af7fda 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -53,7 +53,7 @@ typedef struct WebMChunkContext { char *http_method; uint64_t duration_written; int prev_pts; - AVOutputFormat *oformat; + av_const59 AVOutputFormat *oformat; AVFormatContext *avf; } WebMChunkContext; -- 1.7.10.4