diff mbox series

[FFmpeg-devel] avformat: do not use AVIO_FLAG_* with avio_alloc_context

Message ID 20211121232516.82986-1-epirat07@gmail.com
State Accepted
Commit c6f4e10111debf5b547a399661a5fe997d761033
Headers show
Series [FFmpeg-devel] avformat: do not use AVIO_FLAG_* with avio_alloc_context | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Marvin Scholz Nov. 21, 2021, 11:25 p.m. UTC
The documentation states that here 0 should be used for read-only and
1 for a writable buffer. AVIO_FLAG_WRITE however is 2, while it works
due to the way the flag is handled internally, it is still wrong
according to the documentation.

Additionally it makes it seem as if the AVIO_FLAG_* values could be used
here, which is actually not true, as when AVIO_FLAG_READ would be used
here it would create a writable buffer as AVIO_FLAG_READ is defined as 1.
---
 libavformat/hdsenc.c             | 2 +-
 libavformat/segment.c            | 2 +-
 libavformat/smoothstreamingenc.c | 2 +-
 libavformat/tests/movenc.c       | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

Comments

Anton Khirnov Nov. 29, 2021, 9:21 a.m. UTC | #1
Quoting Marvin Scholz (2021-11-22 00:25:16)
> The documentation states that here 0 should be used for read-only and
> 1 for a writable buffer. AVIO_FLAG_WRITE however is 2, while it works
> due to the way the flag is handled internally, it is still wrong
> according to the documentation.
> 
> Additionally it makes it seem as if the AVIO_FLAG_* values could be used
> here, which is actually not true, as when AVIO_FLAG_READ would be used
> here it would create a writable buffer as AVIO_FLAG_READ is defined as 1.
> ---
>  libavformat/hdsenc.c             | 2 +-
>  libavformat/segment.c            | 2 +-
>  libavformat/smoothstreamingenc.c | 2 +-
>  libavformat/tests/movenc.c       | 2 +-
>  4 files changed, 4 insertions(+), 4 deletions(-)

Looks good, will push.
diff mbox series

Patch

diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index e5353bac65..d8ec6a0b8e 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -370,7 +370,7 @@  static int hds_write_header(AVFormatContext *s)
             ctx->flags = s->flags;
 
             ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf),
-                                         AVIO_FLAG_WRITE, os,
+                                         1, os,
                                          NULL, hds_write, NULL);
             if (!ctx->pb) {
                 return AVERROR(ENOMEM);
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 2b024fd373..5482aa1868 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -569,7 +569,7 @@  static int open_null_ctx(AVIOContext **ctx)
     uint8_t *buf = av_malloc(buf_size);
     if (!buf)
         return AVERROR(ENOMEM);
-    *ctx = avio_alloc_context(buf, buf_size, AVIO_FLAG_WRITE, NULL, NULL, NULL, NULL);
+    *ctx = avio_alloc_context(buf, buf_size, 1, NULL, NULL, NULL, NULL);
     if (!*ctx) {
         av_free(buf);
         return AVERROR(ENOMEM);
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 27b59c299c..6bede7c254 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -335,7 +335,7 @@  static int ism_write_header(AVFormatContext *s)
         st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
         st->time_base = s->streams[i]->time_base;
 
-        ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek);
+        ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), 1, os, NULL, ism_write, ism_seek);
         if (!ctx->pb) {
             return AVERROR(ENOMEM);
         }
diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c
index 04155dde76..2af72f11c7 100644
--- a/libavformat/tests/movenc.c
+++ b/libavformat/tests/movenc.c
@@ -186,7 +186,7 @@  static void init_fps(int bf, int audio_preroll, int fps)
     ctx->oformat = av_guess_format(format, NULL, NULL);
     if (!ctx->oformat)
         exit(1);
-    ctx->pb = avio_alloc_context(iobuf, iobuf_size, AVIO_FLAG_WRITE, NULL, NULL, io_write, NULL);
+    ctx->pb = avio_alloc_context(iobuf, iobuf_size, 1, NULL, NULL, io_write, NULL);
     if (!ctx->pb)
         exit(1);
     ctx->pb->write_data_type = io_write_data_type;