*
* Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <vlc_plugin.h>
#include <vlc_demux.h>
#include <vlc_image.h>
+#include "mxpeg_helper.h"
/*****************************************************************************
* Module descriptor
"If non empty and image-decode is true, the image will be " \
"converted to the specified chroma.")
-#define DURATION_TEXT N_("Duration in second")
+#define DURATION_TEXT N_("Duration in seconds")
#define DURATION_LONGTEXT N_( \
- "Duration in second before simulating an end of file. " \
+ "Duration in seconds before simulating an end of file. " \
"A negative value means an unlimited play time.")
#define FPS_TEXT N_("Frame rate")
vlc_module_begin()
set_description(N_("Image demuxer"))
+ set_shortname(N_("Image"))
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_DEMUX)
add_integer("image-id", -1, ID_TEXT, ID_LONGTEXT, true)
change_safe()
add_string("image-chroma", "", CHROMA_TEXT, CHROMA_LONGTEXT, true)
change_safe()
- add_float("image-duration", 10, DURATION_TEXT, DURATION_LONGTEXT, true)
+ add_float("image-duration", 10, DURATION_TEXT, DURATION_LONGTEXT, false)
change_safe()
add_string("image-fps", "10/1", FPS_TEXT, FPS_LONGTEXT, true)
change_safe()
bool is_realtime;
mtime_t pts_origin;
mtime_t pts_next;
- date_t pts;
+ date_t pts;
};
static block_t *Load(demux_t *demux)
size += image->p[i].i_visible_pitch *
image->p[i].i_visible_lines;
- data = block_New(demux, size);
+ data = block_Alloc(size);
if (!data) {
picture_Release(image);
return NULL;
{
demux_sys_t *sys = demux->p_sys;
- switch (query) {
+ switch (query) {
case DEMUX_GET_POSITION: {
double *position = va_arg(args, double *);
if (sys->duration > 0)
if (sys->duration < 0 || sys->is_realtime)
return VLC_EGENERIC;
int64_t time = va_arg(args, int64_t);
- date_Set(&sys->pts, __MIN(__MAX(time - sys->pts_origin, 0),
- sys->duration));
+ date_Set(&sys->pts, VLC_CLIP(time - sys->pts_origin, 0, sys->duration));
return VLC_SUCCESS;
}
case DEMUX_SET_NEXT_DEMUX_TIME: {
case DEMUX_GET_META:
case DEMUX_HAS_UNSUPPORTED_META:
case DEMUX_GET_ATTACHMENTS:
- default:
- return VLC_EGENERIC;
- }
+ default:
+ return VLC_EGENERIC;
+ }
}
static bool IsBmp(stream_t *s)
return true;
}
+static bool IsExif(stream_t *s)
+{
+ const uint8_t *header;
+ int size = stream_Peek(s, &header, 256);
+ int position = 0;
+
+ if (FindJpegMarker(&position, header, size) != 0xd8)
+ return false;
+ if (FindJpegMarker(&position, header, size) != 0xe1)
+ return false;
+ position += 2; /* Skip size */
+ if (position + 5 > size)
+ return false;
+ if (memcmp(&header[position], "Exif\0", 5))
+ return false;
+ return true;
+}
+
+static bool FindSVGmarker(int *position, const uint8_t *data, const int size, const char *marker)
+{
+ for( int i = *position; i < size; i++)
+ {
+ if (memcmp(&data[i], marker, strlen(marker)) == 0)
+ {
+ *position = i;
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool IsSVG(stream_t *s)
+{
+ char *ext = strstr(s->psz_path, ".svg");
+ if (!ext) return false;
+
+ const uint8_t *header;
+ int size = stream_Peek(s, &header, 4096);
+ int position = 0;
+
+ const char xml[] = "<?xml version=\"";
+ if (!FindSVGmarker(&position, header, size, xml))
+ return false;
+ if (position != 0)
+ return false;
+
+ const char endxml[] = ">\0";
+ if (!FindSVGmarker(&position, header, size, endxml))
+ return false;
+ if (position <= 15)
+ return false;
+
+ const char svg[] = "<svg";
+ if (!FindSVGmarker(&position, header, size, svg))
+ return false;
+ if (position < 19)
+ return false;
+
+ /* SVG Scalable Vector Graphics image */
+
+ /* NOTE: some SVG images have the mimetype set in a meta data section
+ * and some do not */
+ return true;
+}
+
+static bool IsTarga(stream_t *s)
+{
+ /* The header is not enough to ensure proper detection, we need
+ * to have a look at the footer. But doing so can be slow. So
+ * try to avoid it when possible */
+ const uint8_t *header;
+ if (stream_Peek(s, &header, 18) < 18) /* Targa fixed header */
+ return false;
+ if (header[1] > 1) /* Color Map Type */
+ return false;
+ if ((header[1] != 0 || header[3 + 4] != 0) &&
+ header[3 + 4] != 8 &&
+ header[3 + 4] != 15 && header[3 + 4] != 16 &&
+ header[3 + 4] != 24 && header[3 + 4] != 32)
+ return false;
+ if ((header[2] > 3 && header[2] < 9) || header[2] > 11) /* Image Type */
+ return false;
+ if (GetWLE(&header[8 + 4]) <= 0 || /* Width */
+ GetWLE(&header[8 + 6]) <= 0) /* Height */
+ return false;
+ if (header[8 + 8] != 8 &&
+ header[8 + 8] != 15 && header[8 + 8] != 16 &&
+ header[8 + 8] != 24 && header[8 + 8] != 32)
+ return false;
+ if (header[8 + 9] & 0xc0) /* Reserved bits */
+ return false;
+
+ const int64_t size = stream_Size(s);
+ if (size <= 18 + 26)
+ return false;
+ bool can_seek;
+ if (stream_Control(s, STREAM_CAN_SEEK, &can_seek) || !can_seek)
+ return false;
+
+ const int64_t position = stream_Tell(s);
+ if (stream_Seek(s, size - 26))
+ return false;
+
+ const uint8_t *footer;
+ bool is_targa = stream_Peek(s, &footer, 26) >= 26 &&
+ !memcmp(&footer[8], "TRUEVISION-XFILE.\x00", 18);
+ stream_Seek(s, position);
+ return is_targa;
+}
+
typedef struct {
vlc_fourcc_t codec;
int marker_size;
{ .codec = VLC_CODEC_PNM,
.detect = IsPnm,
},
+ { .codec = VLC_CODEC_MXPEG,
+ .detect = IsMxpeg,
+ },
{ .codec = VLC_CODEC_JPEG,
.detect = IsJfif,
},
{ .codec = VLC_CODEC_JPEG,
.detect = IsSpiff,
},
+ { .codec = VLC_CODEC_JPEG,
+ .detect = IsExif,
+ },
+ { .codec = VLC_CODEC_SVG,
+ .detect = IsSVG,
+ },
+ { .codec = VLC_CODEC_TARGA,
+ .detect = IsTarga,
+ },
{ .codec = 0 }
};
msg_Dbg(demux, "Detected image: %s",
vlc_fourcc_GetDescription(VIDEO_ES, img->codec));
+ if( img->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);