[vlc-commits] demux/image: revector, use ARRAY_SIZE()
Rémi Denis-Courmont
git at videolan.org
Sun Mar 3 10:25:09 CET 2019
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 3 10:34:22 2019 +0200| [db8827e5a75a7deea637ca3c3105e2fb0cb105e4] | committer: Rémi Denis-Courmont
demux/image: revector, use ARRAY_SIZE()
Move format detection to a separate function to ease writing the loop.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=db8827e5a75a7deea637ca3c3105e2fb0cb105e4
---
modules/demux/image.c | 63 +++++++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 29 deletions(-)
diff --git a/modules/demux/image.c b/modules/demux/image.c
index 049fb399c7..c1e99e11b5 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -645,51 +645,56 @@ static const image_format_t formats[] = {
{ .codec = VLC_CODEC_TARGA,
.detect = IsTarga,
},
- { .codec = 0 }
};
-static int Open(vlc_object_t *object)
+static vlc_fourcc_t Detect(stream_t *s)
{
- demux_t *demux = (demux_t*)object;
+ const uint8_t *peek;
+ size_t peek_size = 0;
- /* Detect the image type */
- const image_format_t *img;
+ for (size_t i = 0; i < ARRAY_SIZE(formats); i++) {
+ const image_format_t *img = &formats[i];
- const uint8_t *peek;
- ssize_t peek_size = 0;
- for (int i = 0; ; i++) {
- img = &formats[i];
- if (!img->codec)
- return VLC_EGENERIC;
+ if (img->detect != NULL) {
+ if (img->detect(s))
+ return img->codec;
- if (img->detect) {
- if (img->detect(demux->s))
- break;
/* detect callbacks can invalidate the current peek buffer */
peek_size = 0;
- } else {
- if ((size_t) peek_size < img->marker_size)
- {
- peek_size = vlc_stream_Peek(demux->s, &peek, img->marker_size);
- if (peek_size == -1)
- return VLC_ENOMEM;
- }
- if ((size_t) peek_size >= img->marker_size &&
- !memcmp(peek, img->marker, img->marker_size))
- break;
+ continue;
+ }
+
+ if (peek_size < img->marker_size) {
+ ssize_t val = vlc_stream_Peek(s, &peek, img->marker_size);
+ if (val < 0)
+ continue;
}
+
+ if (peek_size >= img->marker_size
+ && memcmp(peek, img->marker, img->marker_size) == 0)
+ return img->codec;
}
+ return 0;
+}
+
+static int Open(vlc_object_t *object)
+{
+ demux_t *demux = (demux_t*)object;
+
+ /* Detect the image type */
+ vlc_fourcc_t codec = Detect(demux->s);
+ if (codec == 0)
+ return VLC_EGENERIC;
+
msg_Dbg(demux, "Detected image: %s",
- vlc_fourcc_GetDescription(VIDEO_ES, img->codec));
+ vlc_fourcc_GetDescription(VIDEO_ES, codec));
- if( img->codec == VLC_CODEC_MXPEG )
- {
+ if (codec == VLC_CODEC_MXPEG)
return VLC_EGENERIC; //let avformat demux this file
- }
/* Load and if selected decode */
es_format_t fmt;
- es_format_Init(&fmt, VIDEO_ES, img->codec);
+ es_format_Init(&fmt, VIDEO_ES, codec);
fmt.video.i_chroma = fmt.i_codec;
block_t *data = Load(demux);
More information about the vlc-commits
mailing list