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
2 2
3API changes, most recent first:3API changes, most recent first:
4 4
52023-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
52023-09-07 - xxxxxxxxxx - lavc 60.26.100 - defs.h92023-09-07 - xxxxxxxxxx - lavc 60.26.100 - defs.h
6 Add AV_PROFILE_* and AV_LEVEL_* replacements in defs.h for the10 Add AV_PROFILE_* and AV_LEVEL_* replacements in defs.h for the
7 defines from avcodec.h. The latter are deprecated.11 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
408 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);408 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
409}409}
410 410
411#if FF_API_AVIO_WRITE_NONCONST
411int ffurl_write2(void *urlcontext, uint8_t *buf, int size)412int ffurl_write2(void *urlcontext, uint8_t *buf, int size)
413#else
414int ffurl_write2(void *urlcontext, const uint8_t *buf, int size)
415#endif
412{416{
413 URLContext *h = urlcontext;417 URLContext *h = urlcontext;
414 418
libavformat/avio.h+13−0
@@ -238,7 +238,11 @@ typedef struct AVIOContext { · 237 unmodified lines
238 void *opaque; /**< A private pointer, passed to the read/write/seek/...238 void *opaque; /**< A private pointer, passed to the read/write/seek/...
239 functions. */239 functions. */
240 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);240 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
241#if FF_API_AVIO_WRITE_NONCONST
241 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);242 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
242 int64_t (*seek)(void *opaque, int64_t offset, int whence);246 int64_t (*seek)(void *opaque, int64_t offset, int whence);
243 int64_t pos; /**< position in the file of the current buffer */247 int64_t pos; /**< position in the file of the current buffer */
244 int eof_reached; /**< true if was unable to read due to error or eof */248 int eof_reached; /**< true if was unable to read due to error or eof */
@@ -286,8 +290,13 @@ typedef struct AVIOContext { · 41 unmodified lines
286 /**290 /**
287 * A callback that is used instead of write_packet.291 * A callback that is used instead of write_packet.
288 */292 */
293#if FF_API_AVIO_WRITE_NONCONST
289 int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,294 int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
290 enum AVIODataMarkerType type, int64_t time);295 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
291 /**300 /**
292 * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,301 * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,
293 * but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly302 * 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
407 int write_flag,416 int write_flag,
408 void *opaque,417 void *opaque,
409 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),418 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
419#if FF_API_AVIO_WRITE_NONCONST
410 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),420 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
411 int64_t (*seek)(void *opaque, int64_t offset, int whence));424 int64_t (*seek)(void *opaque, int64_t offset, int whence));
412 425
413/**426/**
libavformat/avio_internal.h+4−0
@@ -89,7 +89,11 @@ void ffio_init_context(FFIOContext *s, · 88 unmodified lines
89 int write_flag,89 int write_flag,
90 void *opaque,90 void *opaque,
91 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),91 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
92#if FF_API_AVIO_WRITE_NONCONST
92 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),93 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
93 int64_t (*seek)(void *opaque, int64_t offset, int whence));97 int64_t (*seek)(void *opaque, int64_t offset, int whence));
94 98
95/**99/**
libavformat/aviobuf.c+28−0
@@ -84,7 +84,11 @@ void ffio_init_context(FFIOContext *ctx, · 83 unmodified lines
84 int write_flag,84 int write_flag,
85 void *opaque,85 void *opaque,
86 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),86 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
87#if FF_API_AVIO_WRITE_NONCONST
87 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),88 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
88 int64_t (*seek)(void *opaque, int64_t offset, int whence))92 int64_t (*seek)(void *opaque, int64_t offset, int whence))
89{93{
90 AVIOContext *const s = &ctx->pub;94 AVIOContext *const s = &ctx->pub;
@@ -143,7 +147,11 @@ AVIOContext *avio_alloc_context( · 52 unmodified lines
143 int write_flag,147 int write_flag,
144 void *opaque,148 void *opaque,
145 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),149 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
150#if FF_API_AVIO_WRITE_NONCONST
146 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),151 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
147 int64_t (*seek)(void *opaque, int64_t offset, int whence))155 int64_t (*seek)(void *opaque, int64_t offset, int whence))
148{156{
149 FFIOContext *s = av_malloc(sizeof(*s));157 FFIOContext *s = av_malloc(sizeof(*s));
@@ -165,12 +173,20 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len) · 15 unmodified lines
165 if (!s->error) {173 if (!s->error) {
166 int ret = 0;174 int ret = 0;
167 if (s->write_data_type)175 if (s->write_data_type)
176#if FF_API_AVIO_WRITE_NONCONST
168 ret = s->write_data_type(s->opaque, (uint8_t *)data,177 ret = s->write_data_type(s->opaque, (uint8_t *)data,
178#else
179 ret = s->write_data_type(s->opaque, data,
180#endif
169 len,181 len,
170 ctx->current_type,182 ctx->current_type,
171 ctx->last_time);183 ctx->last_time);
172 else if (s->write_packet)184 else if (s->write_packet)
185#if FF_API_AVIO_WRITE_NONCONST
173 ret = s->write_packet(s->opaque, (uint8_t *)data, len);186 ret = s->write_packet(s->opaque, (uint8_t *)data, len);
187#else
188 ret = s->write_packet(s->opaque, data, len);
189#endif
174 if (ret < 0) {190 if (ret < 0) {
175 s->error = ret;191 s->error = ret;
176 } else {192 } else {
@@ -1396,7 +1412,11 @@ typedef struct DynBuffer { · 1219 unmodified lines
1396 uint8_t io_buffer[1];1412 uint8_t io_buffer[1];
1397} DynBuffer;1413} DynBuffer;
1398 1414
1415#if FF_API_AVIO_WRITE_NONCONST
1399static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)1416static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1417#else
1418static int dyn_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1419#endif
1400{1420{
1401 DynBuffer *d = opaque;1421 DynBuffer *d = opaque;
1402 unsigned new_size;1422 unsigned new_size;
@@ -1428,7 +1448,11 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) · 25 unmodified lines
1428 return buf_size;1448 return buf_size;
1429}1449}
1430 1450
1451#if FF_API_AVIO_WRITE_NONCONST
1431static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)1452static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1453#else
1454static int dyn_packet_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1455#endif
1432{1456{
1433 unsigned char buf1[4];1457 unsigned char buf1[4];
1434 int ret;1458 int ret;
@@ -1565,7 +1589,11 @@ void ffio_free_dyn_buf(AVIOContext **s) · 130 unmodified lines
1565 avio_context_free(s);1589 avio_context_free(s);
1566}1590}
1567 1591
1592#if FF_API_AVIO_WRITE_NONCONST
1568static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)1593static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1594#else
1595static int null_buf_write(void *opaque, const uint8_t *buf, int buf_size)
1596#endif
1569{1597{
1570 DynBuffer *d = opaque;1598 DynBuffer *d = opaque;
1571 1599
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
112 return 0;112 return 0;
113}113}
114 114
115#if FF_API_AVIO_WRITE_NONCONST
115static int hds_write(void *opaque, uint8_t *buf, int buf_size)116static int hds_write(void *opaque, uint8_t *buf, int buf_size)
117#else
118static int hds_write(void *opaque, const uint8_t *buf, int buf_size)
119#endif
116{120{
117 OutputStream *os = opaque;121 OutputStream *os = opaque;
118 if (os->out) {122 if (os->out) {
libavformat/smoothstreamingenc.c+4−0
@@ -75,7 +75,11 @@ typedef struct SmoothStreamingContext { · 74 unmodified lines
75 int nb_fragments;75 int nb_fragments;
76} SmoothStreamingContext;76} SmoothStreamingContext;
77 77
78#if FF_API_AVIO_WRITE_NONCONST
78static int ism_write(void *opaque, uint8_t *buf, int buf_size)79static int ism_write(void *opaque, uint8_t *buf, int buf_size)
80#else
81static int ism_write(void *opaque, const uint8_t *buf, int buf_size)
82#endif
79{83{
80 OutputStream *os = opaque;84 OutputStream *os = opaque;
81 if (os->out)85 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
194 */194 */
195int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);195int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
196 196
197#if FF_API_AVIO_WRITE_NONCONST
197int ffurl_write2(void *urlcontext, uint8_t *buf, int size);198int ffurl_write2(void *urlcontext, uint8_t *buf, int size);
199#else
200int ffurl_write2(void *urlcontext, const uint8_t *buf, int size);
201#endif
198/**202/**
199 * Write size bytes from buf to the resource accessed by h.203 * Write size bytes from buf to the resource accessed by h.
200 *204 *
@@ -203,7 +207,11 @@ int ffurl_write2(void *urlcontext, uint8_t *buf, int size); · 2 unmodified lines
203 */207 */
204static inline int ffurl_write(URLContext *h, const uint8_t *buf, int size)208static inline int ffurl_write(URLContext *h, const uint8_t *buf, int size)
205{209{
210#if FF_API_AVIO_WRITE_NONCONST
206 return ffurl_write2(h, (uint8_t*)buf, size);211 return ffurl_write2(h, (uint8_t*)buf, size);
212#else
213 return ffurl_write2(h, buf, size);
214#endif
207}215}
208 216
209int64_t ffurl_seek2(void *urlcontext, int64_t pos, int whence);217int64_t ffurl_seek2(void *urlcontext, int64_t pos, int whence);
libavformat/version.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
31 31
32#include "version_major.h"32#include "version_major.h"
33 33
34#define LIBAVFORMAT_VERSION_MINOR 1134#define LIBAVFORMAT_VERSION_MINOR 12
35#define LIBAVFORMAT_VERSION_MICRO 10035#define LIBAVFORMAT_VERSION_MICRO 100
36 36
37#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \37#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
libavformat/version_major.h+1−0
@@ -45,6 +45,7 @@ · 44 unmodified lines
45#define FF_API_GET_END_PTS (LIBAVFORMAT_VERSION_MAJOR < 61)45#define FF_API_GET_END_PTS (LIBAVFORMAT_VERSION_MAJOR < 61)
46#define FF_API_AVIODIRCONTEXT (LIBAVFORMAT_VERSION_MAJOR < 61)46#define FF_API_AVIODIRCONTEXT (LIBAVFORMAT_VERSION_MAJOR < 61)
47#define FF_API_AVFORMAT_IO_CLOSE (LIBAVFORMAT_VERSION_MAJOR < 61)47#define FF_API_AVFORMAT_IO_CLOSE (LIBAVFORMAT_VERSION_MAJOR < 61)
48#define FF_API_AVIO_WRITE_NONCONST (LIBAVFORMAT_VERSION_MAJOR < 61)
48 49
49 50
50#define FF_API_R_FRAME_RATE 151#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