History

avformat/avio: Constify data pointees of write callbacks

They are currently non-const for reasons unknown, although avio_write() accepts a const buffer.

Andreas Rheinhardt committed 3 years ago

Commit 2a68d941 parent e8704a810 files · +71 −1Browse files

Unified · Split

10 files
  1. doc/APIchanges +4 −0
  2. libavformat/avio.c +4 −0
  3. libavformat/avio.h +13 −0
  4. libavformat/avio_internal.h +4 −0
  5. libavformat/aviobuf.c +28 −0
  6. libavformat/hdsenc.c +4 −0
  7. libavformat/smoothstreamingenc.c +4 −0
  8. libavformat/url.h +8 −0
  9. libavformat/version.h +1 −1
  10. libavformat/version_major.h +1 −0
doc/APIchanges+4−0
@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2023-02-09 · 1 unmodified line
22
33 API changes, most recent first:
44
5+2023-09-07 - xxxxxxxxxx - lavf 60.12.100 - avio.h
6+ Constify the buffer pointees in the write_packet and write_data_type
7+ callbacks of AVIOContext on the next major bump.
8+
59 2023-09-07 - xxxxxxxxxx - lavc 60.26.100 - defs.h
610 Add AV_PROFILE_* and AV_LEVEL_* replacements in defs.h for the
711 defines from avcodec.h. The latter are deprecated.
libavformat/avio.c+4−0
@@ -408,7 +408,11 @@ int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) · 407 unmodified lines
408408 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
409409 }
410410
411+#if FF_API_AVIO_WRITE_NONCONST
411412 int ffurl_write2(void *urlcontext, uint8_t *buf, int size)
413+#else
414+int ffurl_write2(void *urlcontext, const uint8_t *buf, int size)
415+#endif
412416 {
413417 URLContext *h = urlcontext;
414418
libavformat/avio.h+13−0
@@ -238,7 +238,11 @@ typedef struct AVIOContext { · 237 unmodified lines
238238 void *opaque; /**< A private pointer, passed to the read/write/seek/...
239239 functions. */
240240 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
241+#if FF_API_AVIO_WRITE_NONCONST
241242 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
243+#else
244+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size);
245+#endif
242246 int64_t (*seek)(void *opaque, int64_t offset, int whence);
243247 int64_t pos; /**< position in the file of the current buffer */
244248 int eof_reached; /**< true if was unable to read due to error or eof */
@@ -286,8 +290,13 @@ typedef struct AVIOContext { · 41 unmodified lines
286290 /**
287291 * A callback that is used instead of write_packet.
288292 */
293+#if FF_API_AVIO_WRITE_NONCONST
289294 int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
290295 enum AVIODataMarkerType type, int64_t time);
296+#else
297+ int (*write_data_type)(void *opaque, const uint8_t *buf, int buf_size,
298+ enum AVIODataMarkerType type, int64_t time);
299+#endif
291300 /**
292301 * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,
293302 * but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly
@@ -407,7 +416,11 @@ AVIOContext *avio_alloc_context( · 113 unmodified lines
407416 int write_flag,
408417 void *opaque,
409418 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
419+#if FF_API_AVIO_WRITE_NONCONST
410420 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
421+#else
422+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size),
423+#endif
411424 int64_t (*seek)(void *opaque, int64_t offset, int whence));
412425
413426 /**
libavformat/avio_internal.h+4−0
@@ -89,7 +89,11 @@ void ffio_init_context(FFIOContext *s, · 88 unmodified lines
8989 int write_flag,
9090 void *opaque,
9191 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
92+#if FF_API_AVIO_WRITE_NONCONST
9293 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
94+#else
95+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size),
96+#endif
9397 int64_t (*seek)(void *opaque, int64_t offset, int whence));
9498
9599 /**
libavformat/aviobuf.c+28−0
@@ -84,7 +84,11 @@ void ffio_init_context(FFIOContext *ctx, · 83 unmodified lines
8484 int write_flag,
8585 void *opaque,
8686 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
87+#if FF_API_AVIO_WRITE_NONCONST
8788 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
89+#else
90+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size),
91+#endif
8892 int64_t (*seek)(void *opaque, int64_t offset, int whence))
8993 {
9094 AVIOContext *const s = &ctx->pub;
@@ -143,7 +147,11 @@ AVIOContext *avio_alloc_context( · 52 unmodified lines
143147 int write_flag,
144148 void *opaque,
145149 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
150+#if FF_API_AVIO_WRITE_NONCONST
146151 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
152+#else
153+ int (*write_packet)(void *opaque, const uint8_t *buf, int buf_size),
154+#endif
147155 int64_t (*seek)(void *opaque, int64_t offset, int whence))
148156 {
149157 FFIOContext *s = av_malloc(sizeof(*s));
@@ -165,12 +173,20 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len) · 15 unmodified lines
165173 if (!s->error) {
166174 int ret = 0;
167175 if (s->write_data_type)
176+#if FF_API_AVIO_WRITE_NONCONST
168177 ret = s->write_data_type(s->opaque, (uint8_t *)data,
178+#else
179+ ret = s->write_data_type(s->opaque, data,
180+#endif
169181 len,
170182 ctx->current_type,
171183 ctx->last_time);
172184 else if (s->write_packet)
185+#if FF_API_AVIO_WRITE_NONCONST
173186 ret = s->write_packet(s->opaque, (uint8_t *)data, len);
187+#else
188+ ret = s->write_packet(s->opaque, data, len);
189+#endif
174190 if (ret < 0) {
175191 s->error = ret;
176192 } else {
@@ -1396,7 +1412,11 @@ typedef struct DynBuffer { · 1219 unmodified lines
13961412 uint8_t io_buffer[1];
13971413 } DynBuffer;
13981414
1415+#if FF_API_AVIO_WRITE_NONCONST
13991416 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1417+#else
1418+static int dyn_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1419+#endif
14001420 {
14011421 DynBuffer *d = opaque;
14021422 unsigned new_size;
@@ -1428,7 +1448,11 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) · 25 unmodified lines
14281448 return buf_size;
14291449 }
14301450
1451+#if FF_API_AVIO_WRITE_NONCONST
14311452 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1453+#else
1454+static int dyn_packet_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1455+#endif
14321456 {
14331457 unsigned char buf1[4];
14341458 int ret;
@@ -1565,7 +1589,11 @@ void ffio_free_dyn_buf(AVIOContext **s) · 130 unmodified lines
15651589 avio_context_free(s);
15661590 }
15671591
1592+#if FF_API_AVIO_WRITE_NONCONST
15681593 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1594+#else
1595+static int null_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1596+#endif
15691597 {
15701598 DynBuffer *d = opaque;
15711599
libavformat/hdsenc.c+4−0
@@ -112,7 +112,11 @@ static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size) · 111 unmodified lines
112112 return 0;
113113 }
114114
115+#if FF_API_AVIO_WRITE_NONCONST
115116 static int hds_write(void *opaque, uint8_t *buf, int buf_size)
117+#else
118+static int hds_write(void *opaque, const uint8_t *buf, int buf_size)
119+#endif
116120 {
117121 OutputStream *os = opaque;
118122 if (os->out) {
libavformat/smoothstreamingenc.c+4−0
@@ -75,7 +75,11 @@ typedef struct SmoothStreamingContext { · 74 unmodified lines
7575 int nb_fragments;
7676 } SmoothStreamingContext;
7777
78+#if FF_API_AVIO_WRITE_NONCONST
7879 static int ism_write(void *opaque, uint8_t *buf, int buf_size)
80+#else
81+static int ism_write(void *opaque, const uint8_t *buf, int buf_size)
82+#endif
7983 {
8084 OutputStream *os = opaque;
8185 if (os->out)
libavformat/url.h+8−0
@@ -194,7 +194,11 @@ static inline int ffurl_read(URLContext *h, uint8_t *buf, int size) · 193 unmodified lines
194194 */
195195 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
196196
197+#if FF_API_AVIO_WRITE_NONCONST
197198 int ffurl_write2(void *urlcontext, uint8_t *buf, int size);
199+#else
200+int ffurl_write2(void *urlcontext, const uint8_t *buf, int size);
201+#endif
198202 /**
199203 * Write size bytes from buf to the resource accessed by h.
200204 *
@@ -203,7 +207,11 @@ int ffurl_write2(void *urlcontext, uint8_t *buf, int size); · 2 unmodified lines
203207 */
204208 static inline int ffurl_write(URLContext *h, const uint8_t *buf, int size)
205209 {
210+#if FF_API_AVIO_WRITE_NONCONST
206211 return ffurl_write2(h, (uint8_t*)buf, size);
212+#else
213+ return ffurl_write2(h, buf, size);
214+#endif
207215 }
208216
209217 int64_t ffurl_seek2(void *urlcontext, int64_t pos, int whence);
libavformat/version.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
3131
3232 #include "version_major.h"
3333
34−#define LIBAVFORMAT_VERSION_MINOR 11
34+#define LIBAVFORMAT_VERSION_MINOR 12
3535 #define LIBAVFORMAT_VERSION_MICRO 100
3636
3737 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
libavformat/version_major.h+1−0
@@ -45,6 +45,7 @@ · 44 unmodified lines
4545 #define FF_API_GET_END_PTS (LIBAVFORMAT_VERSION_MAJOR < 61)
4646 #define FF_API_AVIODIRCONTEXT (LIBAVFORMAT_VERSION_MAJOR < 61)
4747 #define FF_API_AVFORMAT_IO_CLOSE (LIBAVFORMAT_VERSION_MAJOR < 61)
48+#define FF_API_AVIO_WRITE_NONCONST (LIBAVFORMAT_VERSION_MAJOR < 61)
4849
4950
5051 #define FF_API_R_FRAME_RATE 1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t