diff mbox series

[FFmpeg-devel,3/17] avformat/avformat: Allow const AVOutputFormat where possible

Message ID 20200302043520.14165-3-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/17] avformat: Use correct error in case muxer is not found
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 2, 2020, 4:35 a.m. UTC
9461e4bc made preparations to constify the various AVOutputFormat
pointers because the underlying AVOutputFormats should not be changed.
To do this, a preprocessor directive (ff_const59) is used that will add
const to certain AVOutputFormat * after the next major version bump.

This approach has the drawback that it does not allow users to write
future-proof code now (if one needs to use av_guess_format(), e.g.
because of the mime_type parameter). Yet this is possible: Currently both
avformat_alloc_output_context2() and av_guess_codec() have a pointer
to AVOutputFormat as function parameter. They can also accept a pointer
to const AVOutputFormat without imparing ABI/API compability. Users can
then already write future-proof code now by using const.

This also makes it possible to already use const now in certain parts of
our own code.

For the time being, avformat_alloc_output_context2() will have to cast
the const away internally until the next major version bump.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 doc/APIchanges           | 4 ++++
 libavformat/avformat.h   | 4 ++--
 libavformat/fifo.c       | 4 ++--
 libavformat/format.c     | 4 ++--
 libavformat/hlsenc.c     | 4 ++--
 libavformat/mux.c        | 4 ++--
 libavformat/segment.c    | 2 +-
 libavformat/version.h    | 4 ++--
 libavformat/webm_chunk.c | 2 +-
 9 files changed, 18 insertions(+), 14 deletions(-)

Comments

Carl Eugen Hoyos March 2, 2020, 9:01 a.m. UTC | #1
Am Mo., 2. März 2020 um 05:36 Uhr schrieb Andreas Rheinhardt
<andreas.rheinhardt@gmail.com>:

> -int avformat_alloc_output_context2(AVFormatContext **ctx, ff_const59 AVOutputFormat *oformat,
> +int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat,
>                                     const char *format_name, const char *filename);

I believe this breaks C++ code using libavformat.

Carl Eugen
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 5bfb0a654e..a2d428e4ef 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@  libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-03-01 - xxxxxxxxxx - lavf 58.40.100 - avformat.h
+  avformat_alloc_output_context2() and av_guess_codec() now accept
+  pointer to const AVOutputFormat.
+
 2020-02-21 - xxxxxxxxxx - lavc 58.73.101 - avcodec.h
   Add AV_CODEC_EXPORT_DATA_PRFT.
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 9b9b634ec3..a260c02072 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2224,7 +2224,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, ff_const59 AVOutputFormat *oformat,
+int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat,
                                    const char *format_name, const char *filename);
 
 /**
@@ -2707,7 +2707,7 @@  ff_const59 AVOutputFormat *av_guess_format(const char *short_name,
 /**
  * Guess the codec ID based upon muxer and filename.
  */
-enum AVCodecID av_guess_codec(ff_const59 AVOutputFormat *fmt, const char *short_name,
+enum AVCodecID av_guess_codec(const 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 7b37fff6da..3989ca4119 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -441,7 +441,7 @@  static void *fifo_consumer_thread(void *data)
     return NULL;
 }
 
-static int fifo_mux_init(AVFormatContext *avf, ff_const59 AVOutputFormat *oformat,
+static int fifo_mux_init(AVFormatContext *avf, const AVOutputFormat *oformat,
                          const char *filename)
 {
     FifoContext *fifo = avf->priv_data;
@@ -480,7 +480,7 @@  static int fifo_mux_init(AVFormatContext *avf, ff_const59 AVOutputFormat *oforma
 static int fifo_init(AVFormatContext *avf)
 {
     FifoContext *fifo = avf->priv_data;
-    ff_const59 AVOutputFormat *oformat;
+    const 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 c47490c8eb..a926d5be0c 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -84,12 +84,12 @@  ff_const59 AVOutputFormat *av_guess_format(const char *short_name, const char *f
     return fmt_found;
 }
 
-enum AVCodecID av_guess_codec(ff_const59 AVOutputFormat *fmt, const char *short_name,
+enum AVCodecID av_guess_codec(const 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)) {
-        ff_const59 AVOutputFormat *fmt2 = av_guess_format(NULL, filename, NULL);
+        const AVOutputFormat *fmt2 = av_guess_format(NULL, filename, NULL);
         if (fmt2)
             fmt = fmt2;
     }
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e58da7328f..d685ec0179 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -113,8 +113,8 @@  typedef struct VariantStream {
     unsigned var_stream_idx;
     unsigned number;
     int64_t sequence;
-    ff_const59 AVOutputFormat *oformat;
-    ff_const59 AVOutputFormat *vtt_oformat;
+    const AVOutputFormat *oformat;
+    const AVOutputFormat *vtt_oformat;
     AVIOContext *out;
     int packets_written;
     int init_range_length;
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 565a7d7c18..6a973186ff 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, ff_const59 AVOutputFormat *oformat,
+int avformat_alloc_output_context2(AVFormatContext **avctx, const AVOutputFormat *oformat,
                                    const char *format, const char *filename)
 {
     AVFormatContext *s = avformat_alloc_context();
@@ -174,7 +174,7 @@  int avformat_alloc_output_context2(AVFormatContext **avctx, ff_const59 AVOutputF
         }
     }
 
-    s->oformat = oformat;
+    s->oformat = (ff_const59 AVOutputFormat *)oformat;
     if (s->oformat->priv_data_size > 0) {
         s->priv_data = av_mallocz(s->oformat->priv_data_size);
         if (!s->priv_data)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index bf9e706c1c..5f7fe76600 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
-    ff_const59 AVOutputFormat *oformat;
+    const AVOutputFormat *oformat;
     AVFormatContext *avf;
     char *format;              ///< format to use for output segment files
     AVDictionary *format_options;
diff --git a/libavformat/version.h b/libavformat/version.h
index 4724269b3c..a233b67351 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,8 +32,8 @@ 
 // 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  39
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR  40
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c
index 4e2ce21a79..bc3d346a00 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;
     int64_t prev_pts;
-    ff_const59 AVOutputFormat *oformat;
+    const AVOutputFormat *oformat;
     AVFormatContext *avf;
 } WebMChunkContext;