From 57e20dd6b6ee47576e83a26c6215d99211421003 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sat, 2 Mar 2024 19:29:27 +0100 Subject: [PATCH] avformat/avio: Avoid function pointer casts It is undefined behaviour to use a different type for a call than the actual type of the function. Signed-off-by: Andreas Rheinhardt --- libavformat/avio.c | 5 ++--- libavformat/librtmp.c | 6 ++++-- libavformat/mmsh.c | 3 ++- libavformat/rtmpproto.c | 6 ++++-- libavformat/url.h | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libavformat/avio.c b/libavformat/avio.c index 794ebd4bd8..1622a03d7f 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -450,9 +450,8 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) (*s)->max_packet_size = max_packet_size; (*s)->min_packet_size = h->min_packet_size; if(h->prot) { - (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause; - (*s)->read_seek = - (int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek; + (*s)->read_pause = h->prot->url_read_pause; + (*s)->read_seek = h->prot->url_read_seek; if (h->prot->url_read_seek) (*s)->seekable |= AVIO_SEEKABLE_TIME; diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c index 5fa788fac8..bdd82ce15f 100644 --- a/libavformat/librtmp.c +++ b/libavformat/librtmp.c @@ -220,8 +220,9 @@ static int rtmp_read(URLContext *s, uint8_t *buf, int size) return ret; } -static int rtmp_read_pause(URLContext *s, int pause) +static int rtmp_read_pause(void *opaque, int pause) { + URLContext *s = opaque; LibRTMPContext *ctx = s->priv_data; RTMP *r = &ctx->rtmp; @@ -230,9 +231,10 @@ static int rtmp_read_pause(URLContext *s, int pause) return 0; } -static int64_t rtmp_read_seek(URLContext *s, int stream_index, +static int64_t rtmp_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags) { + URLContext *s = opaque; LibRTMPContext *ctx = s->priv_data; RTMP *r = &ctx->rtmp; diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c index 672f4b3788..60113d61d2 100644 --- a/libavformat/mmsh.c +++ b/libavformat/mmsh.c @@ -371,9 +371,10 @@ static int mmsh_read(URLContext *h, uint8_t *buf, int size) return res; } -static int64_t mmsh_read_seek(URLContext *h, int stream_index, +static int64_t mmsh_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags) { + URLContext *h = opaque; MMSHContext *mmsh_old = h->priv_data; MMSHContext *mmsh = av_mallocz(sizeof(*mmsh)); int ret; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 817c27b7ef..4b01b67d28 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -2952,9 +2952,10 @@ static int rtmp_read(URLContext *s, uint8_t *buf, int size) return orig_size; } -static int64_t rtmp_seek(URLContext *s, int stream_index, int64_t timestamp, +static int64_t rtmp_seek(void *opaque, int stream_index, int64_t timestamp, int flags) { + URLContext *s = opaque; RTMPContext *rt = s->priv_data; int ret; av_log(s, AV_LOG_DEBUG, @@ -2972,8 +2973,9 @@ static int64_t rtmp_seek(URLContext *s, int stream_index, int64_t timestamp, return timestamp; } -static int rtmp_pause(URLContext *s, int pause) +static int rtmp_pause(void *opaque, int pause) { + URLContext *s = opaque; RTMPContext *rt = s->priv_data; int ret; av_log(s, AV_LOG_DEBUG, "Pause at timestamp %d\n", diff --git a/libavformat/url.h b/libavformat/url.h index 4f3bfb6d57..f62afedb78 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -76,8 +76,8 @@ typedef struct URLProtocol { int (*url_write)(URLContext *h, const unsigned char *buf, int size); int64_t (*url_seek)( URLContext *h, int64_t pos, int whence); int (*url_close)(URLContext *h); - int (*url_read_pause)(URLContext *h, int pause); - int64_t (*url_read_seek)(URLContext *h, int stream_index, + int (*url_read_pause)(void *urlcontext, int pause); + int64_t (*url_read_seek)(void *urlcontext, int stream_index, int64_t timestamp, int flags); int (*url_get_file_handle)(URLContext *h); int (*url_get_multi_file_handle)(URLContext *h, int **handles,