2009-08-19 10:22:30 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* jpegparse: a parser for JPEG streams
|
|
|
|
*
|
|
|
|
* Copyright (C) <2009> Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
|
2021-12-22 18:23:37 +00:00
|
|
|
* <2022> Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
|
2009-08-19 10:22:30 +00:00
|
|
|
*
|
|
|
|
* This library 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 library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-08-19 10:22:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-jpegparse
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: jpegparse
|
2009-08-19 10:22:30 +00:00
|
|
|
* @short_description: JPEG parser
|
|
|
|
*
|
|
|
|
* Parses a JPEG stream into JPEG images. It looks for EOI boundaries to
|
|
|
|
* split a continuous stream into single-frame buffers. Also reads the
|
|
|
|
* image header searching for image properties such as width and height
|
2010-05-07 19:53:17 +00:00
|
|
|
* among others. Jpegparse can also extract metadata (e.g. xmp).
|
2010-03-24 14:05:20 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Example launch line
|
2009-08-19 10:22:30 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v souphttpsrc location=... ! jpegparse ! matroskamux ! filesink location=...
|
2009-08-19 10:22:30 +00:00
|
|
|
* ]|
|
|
|
|
* The above pipeline fetches a motion JPEG stream from an IP camera over
|
|
|
|
* HTTP and stores it in a matroska file.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2009-08-19 10:22:30 +00:00
|
|
|
*/
|
2010-05-07 19:53:17 +00:00
|
|
|
/* FIXME: output plain JFIF APP marker only. This provides best code reuse.
|
|
|
|
* JPEG decoders would not need to handle this part anymore. Also when remuxing
|
|
|
|
* (... ! jpegparse ! ... ! jifmux ! ...) metadata consolidation would be
|
|
|
|
* easier.
|
|
|
|
*/
|
2021-12-22 18:23:37 +00:00
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* + APP2 -- ICC color profile
|
|
|
|
* + APP3 -- meta (same as exif)
|
|
|
|
* + APP12 -- Photoshop Save for Web: Ducky / Picture info
|
|
|
|
* + APP13 -- Adobe IRB
|
2023-02-15 18:02:35 +00:00
|
|
|
* + check for interlaced mjpeg
|
2021-12-22 18:23:37 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-19 10:22:30 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-02 09:22:06 +00:00
|
|
|
#include <string.h>
|
2009-08-19 10:22:30 +00:00
|
|
|
#include <gst/base/gstbytereader.h>
|
2021-12-22 17:13:17 +00:00
|
|
|
#include <gst/codecparsers/gstjpegparser.h>
|
2010-03-11 19:32:28 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2009-08-19 10:22:30 +00:00
|
|
|
|
|
|
|
#include "gstjpegparse.h"
|
2021-12-22 17:13:17 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
enum ParserState
|
|
|
|
{
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_SOI = 1 << 0,
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_SOF = 1 << 1,
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_SOS = 1 << 2,
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_JFIF = 1 << 3,
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_ADOBE = 1 << 4,
|
|
|
|
|
|
|
|
GST_JPEG_PARSER_STATE_VALID_PICTURE = (GST_JPEG_PARSER_STATE_GOT_SOI |
|
|
|
|
GST_JPEG_PARSER_STATE_GOT_SOF | GST_JPEG_PARSER_STATE_GOT_SOS),
|
|
|
|
};
|
2009-08-19 10:22:30 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_jpeg_parse_src_pad_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("image/jpeg, "
|
|
|
|
"framerate = (fraction) [ 0/1, MAX ], " "parsed = (boolean) true")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_jpeg_parse_sink_pad_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-04-12 15:01:38 +00:00
|
|
|
GST_STATIC_CAPS ("image/jpeg")
|
2009-08-19 10:22:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (jpeg_parse_debug);
|
|
|
|
#define GST_CAT_DEFAULT jpeg_parse_debug
|
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_jpeg_parse_handle_frame (GstBaseParse * bparse, GstBaseParseFrame * frame,
|
|
|
|
gint * skipsize);
|
|
|
|
static gboolean gst_jpeg_parse_set_sink_caps (GstBaseParse * parse,
|
2012-09-11 23:36:24 +00:00
|
|
|
GstCaps * caps);
|
2014-04-22 02:05:48 +00:00
|
|
|
static gboolean gst_jpeg_parse_sink_event (GstBaseParse * parse,
|
2012-09-11 23:36:24 +00:00
|
|
|
GstEvent * event);
|
2014-04-22 02:05:48 +00:00
|
|
|
static gboolean gst_jpeg_parse_start (GstBaseParse * parse);
|
|
|
|
static gboolean gst_jpeg_parse_stop (GstBaseParse * parse);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2011-10-05 18:06:20 +00:00
|
|
|
#define gst_jpeg_parse_parent_class parent_class
|
2014-04-22 02:05:48 +00:00
|
|
|
G_DEFINE_TYPE (GstJpegParse, gst_jpeg_parse, GST_TYPE_BASE_PARSE);
|
2023-02-16 14:48:32 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (jpegparse, "jpegparse", GST_RANK_PRIMARY,
|
2021-02-25 14:22:15 +00:00
|
|
|
GST_TYPE_JPEG_PARSE);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2022-06-16 15:02:43 +00:00
|
|
|
enum GstJPEGColorspace
|
2021-12-22 18:23:37 +00:00
|
|
|
{
|
2022-06-16 15:02:43 +00:00
|
|
|
GST_JPEG_COLORSPACE_NONE,
|
|
|
|
GST_JPEG_COLORSPACE_RGB,
|
|
|
|
GST_JPEG_COLORSPACE_YUV,
|
|
|
|
GST_JPEG_COLORSPACE_GRAY,
|
|
|
|
GST_JPEG_COLORSPACE_CMYK,
|
|
|
|
GST_JPEG_COLORSPACE_YCCK,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *gst_jpeg_colorspace_strings[] = {
|
|
|
|
[GST_JPEG_COLORSPACE_NONE] = NULL,
|
|
|
|
[GST_JPEG_COLORSPACE_RGB] = "sRGB",
|
|
|
|
[GST_JPEG_COLORSPACE_YUV] = "sYUV",
|
|
|
|
[GST_JPEG_COLORSPACE_GRAY] = "GRAY",
|
|
|
|
[GST_JPEG_COLORSPACE_CMYK] = "CMYK",
|
|
|
|
[GST_JPEG_COLORSPACE_YCCK] = "YCCK",
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GstJPEGSampling
|
|
|
|
{
|
|
|
|
GST_JPEG_SAMPLING_NONE,
|
|
|
|
GST_JPEG_SAMPLING_RGB,
|
|
|
|
GST_JPEG_SAMPLING_BGR,
|
|
|
|
GST_JPEG_SAMPLING_YBR444,
|
|
|
|
GST_JPEG_SAMPLING_YBR422,
|
|
|
|
GST_JPEG_SAMPLING_YBR420,
|
|
|
|
GST_JPEG_SAMPLING_YBR440,
|
|
|
|
GST_JPEG_SAMPLING_YBR410,
|
|
|
|
GST_JPEG_SAMPLING_YBR411,
|
|
|
|
GST_JPEG_SAMPLING_GRAYSCALE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *gst_jpeg_sampling_strings[] = {
|
|
|
|
[GST_JPEG_SAMPLING_NONE] = NULL,
|
|
|
|
[GST_JPEG_SAMPLING_RGB] = "RGB",
|
|
|
|
[GST_JPEG_SAMPLING_BGR] = "BGR",
|
|
|
|
[GST_JPEG_SAMPLING_YBR444] = "YCbCr-4:4:4",
|
|
|
|
[GST_JPEG_SAMPLING_YBR422] = "YCbCr-4:2:2",
|
|
|
|
[GST_JPEG_SAMPLING_YBR420] = "YCbCr-4:2:0",
|
|
|
|
[GST_JPEG_SAMPLING_YBR440] = "YCbCr-4:4:0",
|
|
|
|
[GST_JPEG_SAMPLING_YBR410] = "YCbCr-4:1:0",
|
|
|
|
[GST_JPEG_SAMPLING_YBR411] = "YCbCr-4:1:1",
|
|
|
|
[GST_JPEG_SAMPLING_GRAYSCALE] = "GRAYSCALE",
|
2021-12-22 18:23:37 +00:00
|
|
|
};
|
|
|
|
|
2009-08-19 10:22:30 +00:00
|
|
|
static void
|
|
|
|
gst_jpeg_parse_class_init (GstJpegParseClass * klass)
|
|
|
|
{
|
2014-04-22 02:05:48 +00:00
|
|
|
GstBaseParseClass *gstbaseparse_class;
|
2009-08-19 10:22:30 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
gstbaseparse_class = (GstBaseParseClass *) klass;
|
2009-08-19 10:22:30 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
gstbaseparse_class->start = gst_jpeg_parse_start;
|
|
|
|
gstbaseparse_class->stop = gst_jpeg_parse_stop;
|
|
|
|
gstbaseparse_class->set_sink_caps = gst_jpeg_parse_set_sink_caps;
|
|
|
|
gstbaseparse_class->sink_event = gst_jpeg_parse_sink_event;
|
|
|
|
gstbaseparse_class->handle_frame = gst_jpeg_parse_handle_frame;
|
2011-10-05 18:06:20 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_jpeg_parse_src_pad_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_jpeg_parse_sink_pad_template);
|
2011-10-05 18:06:20 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-10-05 18:06:20 +00:00
|
|
|
"JPEG stream parser",
|
2021-12-22 18:23:37 +00:00
|
|
|
"Codec/Parser/Image",
|
2011-10-05 18:06:20 +00:00
|
|
|
"Parse JPEG images into single-frame buffers",
|
2021-12-22 18:23:37 +00:00
|
|
|
"Víctor Jáquez <vjaquez@igalia.com>");
|
2011-10-05 18:06:20 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (jpeg_parse_debug, "jpegparse", 0, "JPEG parser");
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-05 18:06:20 +00:00
|
|
|
gst_jpeg_parse_init (GstJpegParse * parse)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
parse->sof = -1;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
static void
|
|
|
|
parse_avid (GstJpegParse * parse, const guint8 * data, guint16 len)
|
|
|
|
{
|
|
|
|
parse->avid = 1;
|
|
|
|
if (len > 14 && data[12] == 1) /* 1 - NTSC */
|
|
|
|
parse->field_order = GST_VIDEO_FIELD_ORDER_BOTTOM_FIELD_FIRST;
|
|
|
|
if (len > 14 && data[12] == 2) /* 2 - PAL */
|
|
|
|
parse->field_order = GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST;
|
|
|
|
GST_INFO_OBJECT (parse, "AVID: %s",
|
|
|
|
gst_video_field_order_to_string (parse->field_order));
|
|
|
|
}
|
|
|
|
|
2009-08-19 10:22:30 +00:00
|
|
|
static gboolean
|
2014-04-22 02:05:48 +00:00
|
|
|
gst_jpeg_parse_set_sink_caps (GstBaseParse * bparse, GstCaps * caps)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2014-04-22 02:05:48 +00:00
|
|
|
GstJpegParse *parse = GST_JPEG_PARSE_CAST (bparse);
|
2009-08-19 10:22:30 +00:00
|
|
|
GstStructure *s = gst_caps_get_structure (caps, 0);
|
2023-12-19 09:39:31 +00:00
|
|
|
const GValue *codec_data;
|
|
|
|
const char *interlace_mode, *field_order;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "get sink caps %" GST_PTR_FORMAT, caps);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_structure_get_fraction (s, "framerate",
|
|
|
|
&parse->framerate_numerator, &parse->framerate_denominator);
|
2010-02-01 15:46:29 +00:00
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
gst_structure_get_int (s, "height", &parse->orig_height);
|
|
|
|
gst_structure_get_int (s, "width", &parse->orig_width);
|
|
|
|
|
2023-12-20 20:41:00 +00:00
|
|
|
gst_structure_get_fraction (s, "pixel-aspect-ration", &parse->par_num,
|
|
|
|
&parse->par_den);
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
codec_data = gst_structure_get_value (s, "codec_data");
|
|
|
|
if (codec_data && G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
gst_clear_buffer (&parse->codec_data);
|
|
|
|
|
|
|
|
parse->codec_data = GST_BUFFER (g_value_dup_boxed (codec_data));
|
|
|
|
if (gst_buffer_map (parse->codec_data, &map, GST_MAP_READ)) {
|
|
|
|
if (map.size > 8 && map.data[0] == 0x2c && map.data[4] == 0x18)
|
|
|
|
parse_avid (parse, map.data, map.size);
|
|
|
|
gst_buffer_unmap (parse->codec_data, &map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interlace_mode = gst_structure_get_string (s, "interlace-mode");
|
|
|
|
if (interlace_mode) {
|
|
|
|
parse->interlace_mode =
|
|
|
|
gst_video_interlace_mode_from_string (interlace_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parse->interlace_mode != GST_VIDEO_INTERLACE_MODE_PROGRESSIVE) {
|
|
|
|
field_order = gst_structure_get_string (s, "field-order");
|
|
|
|
if (field_order)
|
|
|
|
parse->field_order = gst_video_field_order_from_string (field_order);
|
|
|
|
}
|
|
|
|
|
2023-12-19 12:13:48 +00:00
|
|
|
g_clear_pointer (&parse->colorimetry, g_free);
|
|
|
|
parse->colorimetry = g_strdup (gst_structure_get_string (s, "colorimetry"));
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return TRUE;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
2021-12-22 18:23:37 +00:00
|
|
|
valid_state (guint state, guint ref_state)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
return (state & ref_state) == ref_state;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* https://zpl.fi/chroma-subsampling-and-jpeg-sampling-factors/ */
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const struct
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
gint h[3];
|
|
|
|
gint v[3];
|
2022-06-16 15:02:43 +00:00
|
|
|
enum GstJPEGSampling sampling;
|
2021-12-22 18:23:37 +00:00
|
|
|
} subsampling_map[] = {
|
2022-06-16 15:02:43 +00:00
|
|
|
{{1, 1, 1}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR444},
|
|
|
|
{{2, 2, 2}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR444},
|
|
|
|
{{3, 3, 3}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR444},
|
|
|
|
{{1, 1, 1}, {2, 2, 2}, GST_JPEG_SAMPLING_YBR444},
|
|
|
|
{{1, 1, 1}, {3, 3, 3}, GST_JPEG_SAMPLING_YBR444},
|
|
|
|
{{1, 1, 1}, {2, 1, 1}, GST_JPEG_SAMPLING_YBR440},
|
|
|
|
{{2, 2, 2}, {2, 1, 1}, GST_JPEG_SAMPLING_YBR440},
|
|
|
|
{{1, 1, 1}, {4, 2, 2}, GST_JPEG_SAMPLING_YBR440},
|
|
|
|
{{2, 1, 1}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR422},
|
|
|
|
{{2, 1, 1}, {2, 2, 2}, GST_JPEG_SAMPLING_YBR422},
|
|
|
|
{{4, 2, 2}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR422},
|
|
|
|
{{2, 1, 1}, {2, 1, 1}, GST_JPEG_SAMPLING_YBR420},
|
|
|
|
{{4, 1, 1}, {1, 1, 1}, GST_JPEG_SAMPLING_YBR411},
|
|
|
|
{{4, 1, 1}, {2, 1, 1}, GST_JPEG_SAMPLING_YBR410},
|
2021-12-22 18:23:37 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
static guint16
|
|
|
|
yuv_sampling (GstJpegFrameHdr * frame_hdr)
|
|
|
|
{
|
|
|
|
int i, h0, h1, h2, v0, v1, v2;
|
|
|
|
|
2022-06-16 15:02:43 +00:00
|
|
|
g_return_val_if_fail (frame_hdr->num_components == 3, GST_JPEG_SAMPLING_NONE);
|
2021-12-22 18:23:37 +00:00
|
|
|
|
|
|
|
h0 = frame_hdr->components[0].horizontal_factor;
|
|
|
|
h1 = frame_hdr->components[1].horizontal_factor;
|
|
|
|
h2 = frame_hdr->components[2].horizontal_factor;
|
|
|
|
v0 = frame_hdr->components[0].vertical_factor;
|
|
|
|
v1 = frame_hdr->components[1].vertical_factor;
|
|
|
|
v2 = frame_hdr->components[2].vertical_factor;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (subsampling_map); i++) {
|
|
|
|
if (subsampling_map[i].h[0] == h0
|
|
|
|
&& subsampling_map[i].h[1] == h1 && subsampling_map[i].h[2] == h2
|
|
|
|
&& subsampling_map[i].v[0] == v0
|
|
|
|
&& subsampling_map[i].v[1] == v1 && subsampling_map[i].v[2] == v2)
|
|
|
|
return subsampling_map[i].sampling;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2022-06-16 15:02:43 +00:00
|
|
|
return GST_JPEG_SAMPLING_NONE;
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
static const gchar *
|
2022-06-16 15:02:43 +00:00
|
|
|
colorspace_to_string (enum GstJPEGColorspace colorspace)
|
2021-12-22 18:23:37 +00:00
|
|
|
{
|
2022-06-16 15:02:43 +00:00
|
|
|
return gst_jpeg_colorspace_strings[colorspace];
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* https://entropymine.wordpress.com/2018/10/22/how-is-a-jpeg-images-color-type-determined/ */
|
|
|
|
/* T-REC-T.872-201206 6.1 Colour encodings and associated values to define white and black */
|
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_sof (GstJpegParse * parse, GstJpegSegment * seg)
|
|
|
|
{
|
|
|
|
GstJpegFrameHdr hdr = { 0, };
|
2023-12-19 12:16:02 +00:00
|
|
|
guint colorspace;
|
|
|
|
guint sampling;
|
2010-05-31 16:30:19 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_jpeg_segment_parse_frame_header (seg, &hdr)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_NONE;
|
|
|
|
sampling = GST_JPEG_SAMPLING_NONE;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
switch (hdr.num_components) {
|
|
|
|
case 1:
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_GRAY;
|
|
|
|
sampling = GST_JPEG_SAMPLING_GRAYSCALE;
|
2021-12-22 18:23:37 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_JFIF)) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YUV;
|
|
|
|
sampling = yuv_sampling (&hdr);
|
2021-12-22 18:23:37 +00:00
|
|
|
} else {
|
|
|
|
if (valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_ADOBE)) {
|
|
|
|
if (parse->adobe_transform == 0) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_RGB;
|
|
|
|
sampling = GST_JPEG_SAMPLING_RGB;
|
2021-12-22 18:23:37 +00:00
|
|
|
} else if (parse->adobe_transform == 1) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YUV;;
|
|
|
|
sampling = yuv_sampling (&hdr);
|
2021-12-22 18:23:37 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Unknown Adobe color transform code");
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YUV;;
|
|
|
|
sampling = yuv_sampling (&hdr);
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int cid0, cid1, cid2;
|
|
|
|
|
|
|
|
cid0 = hdr.components[0].identifier;
|
|
|
|
cid1 = hdr.components[1].identifier;
|
|
|
|
cid2 = hdr.components[2].identifier;
|
|
|
|
|
|
|
|
if (cid0 == 1 && cid1 == 2 && cid2 == 3) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YUV;
|
|
|
|
sampling = yuv_sampling (&hdr);
|
2021-12-22 18:23:37 +00:00
|
|
|
} else if (cid0 == 'R' && cid1 == 'G' && cid2 == 'B') {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_RGB;
|
|
|
|
sampling = GST_JPEG_SAMPLING_RGB;
|
2021-12-22 18:23:37 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Unrecognized component IDs");
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YUV;
|
|
|
|
sampling = yuv_sampling (&hdr);
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
2010-05-31 16:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-22 18:23:37 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_ADOBE)) {
|
|
|
|
if (parse->adobe_transform == 0) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_CMYK;
|
2021-12-22 18:23:37 +00:00
|
|
|
} else if (parse->adobe_transform == 2) {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YCCK;
|
2021-12-22 18:23:37 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Unknown Adobe color transform code");
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_YCCK;
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-12-19 12:16:02 +00:00
|
|
|
colorspace = GST_JPEG_COLORSPACE_CMYK;
|
2010-05-31 16:30:19 +00:00
|
|
|
}
|
2021-12-22 18:23:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (parse, "Unknown color space");
|
|
|
|
break;
|
2010-05-31 16:30:19 +00:00
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-19 12:16:02 +00:00
|
|
|
if (hdr.width != parse->width || hdr.height != parse->height
|
|
|
|
|| colorspace != parse->colorspace || sampling != parse->sampling) {
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->width = hdr.width;
|
|
|
|
parse->height = hdr.height;
|
2023-12-19 12:16:02 +00:00
|
|
|
parse->colorspace = colorspace;
|
|
|
|
parse->sampling = sampling;
|
2023-12-19 09:39:31 +00:00
|
|
|
|
|
|
|
if (parse->first_picture && !parse->multiscope) {
|
|
|
|
if (parse->orig_height > 0
|
|
|
|
&& parse->height < ((parse->orig_height * 3) / 4)) {
|
|
|
|
parse->interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
|
|
|
} else if (parse->avid) {
|
|
|
|
if (parse->orig_height == 0)
|
|
|
|
parse->orig_height = 2 * hdr.height;
|
|
|
|
parse->interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parse->first_picture = FALSE;
|
2023-12-19 12:16:02 +00:00
|
|
|
parse->renegotiate = TRUE;
|
2023-12-19 09:39:31 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
GST_INFO_OBJECT (parse, "SOF [%dx%d] %d comp - %s", parse->width,
|
|
|
|
parse->height, hdr.num_components,
|
|
|
|
GST_STR_NULL (colorspace_to_string (parse->colorspace)));
|
|
|
|
return TRUE;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
static inline GstTagList *
|
|
|
|
get_tag_list (GstJpegParse * parse)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!parse->tags)
|
|
|
|
parse->tags = gst_tag_list_new_empty ();
|
|
|
|
return parse->tags;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_app0 (GstJpegParse * parse, GstJpegSegment * seg)
|
|
|
|
{
|
|
|
|
GstByteReader reader;
|
|
|
|
guint16 xd, yd;
|
|
|
|
guint8 unit, xt, yt;
|
2023-12-20 19:58:04 +00:00
|
|
|
guint32 id;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-02-19 09:41:51 +00:00
|
|
|
if (seg->size < 6) /* less than 6 means no id string */
|
2009-08-19 10:22:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size);
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 2);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-20 19:58:04 +00:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
if (!gst_byte_reader_get_uint32_le (&reader, &id))
|
2009-08-19 10:22:30 +00:00
|
|
|
return FALSE;
|
2023-12-20 19:58:04 +00:00
|
|
|
#else
|
|
|
|
if (!gst_byte_reader_get_uint32_be (&reader, &id))
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_JFIF)
|
2023-12-20 19:58:04 +00:00
|
|
|
&& GST_MAKE_FOURCC ('J', 'F', 'I', 'F') == id) {
|
2021-12-22 18:23:37 +00:00
|
|
|
|
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_JFIF;
|
|
|
|
|
2023-12-20 19:58:04 +00:00
|
|
|
/* trailing zero-byte */
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 1);
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* version */
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 2);
|
|
|
|
|
|
|
|
/* units */
|
|
|
|
if (!gst_byte_reader_get_uint8 (&reader, &unit))
|
2009-08-19 10:22:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* x density */
|
2023-12-20 20:34:29 +00:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
if (!gst_byte_reader_get_uint16_le (&reader, &xd))
|
|
|
|
return FALSE;
|
|
|
|
/* y density */
|
|
|
|
if (!gst_byte_reader_get_uint16_le (&reader, &yd))
|
|
|
|
return FALSE;
|
|
|
|
#else
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_byte_reader_get_uint16_be (&reader, &xd))
|
|
|
|
return FALSE;
|
|
|
|
/* y density */
|
|
|
|
if (!gst_byte_reader_get_uint16_be (&reader, &yd))
|
2009-08-19 10:22:30 +00:00
|
|
|
return FALSE;
|
2023-12-20 20:34:29 +00:00
|
|
|
#endif
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* x thumbnail */
|
|
|
|
if (!gst_byte_reader_get_uint8 (&reader, &xt))
|
|
|
|
return FALSE;
|
|
|
|
/* y thumbnail */
|
|
|
|
if (!gst_byte_reader_get_uint8 (&reader, &yt))
|
2009-08-19 10:22:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (unit == 0) {
|
|
|
|
/* no units, X and Y specify the pixel aspect ratio */
|
2023-12-20 20:41:00 +00:00
|
|
|
if (parse->par_num != xd || parse->par_den != yd) {
|
2023-12-19 12:16:02 +00:00
|
|
|
parse->renegotiate = TRUE;
|
2023-12-20 20:41:00 +00:00
|
|
|
parse->par_num = xd;
|
|
|
|
parse->par_den = yd;
|
2023-12-19 12:16:02 +00:00
|
|
|
}
|
2021-12-22 18:23:37 +00:00
|
|
|
} else if (unit == 1 || unit == 2) {
|
|
|
|
/* tag pixel per inches */
|
|
|
|
double hppi = xd, vppi = yd;
|
|
|
|
|
|
|
|
/* cm to in */
|
|
|
|
if (unit == 2) {
|
|
|
|
hppi *= 2.54;
|
|
|
|
vppi *= 2.54;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_tag_register_musicbrainz_tags ();
|
|
|
|
gst_tag_list_add (get_tag_list (parse), GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_IMAGE_HORIZONTAL_PPI, hppi, GST_TAG_IMAGE_VERTICAL_PPI, vppi,
|
|
|
|
NULL);
|
|
|
|
}
|
2010-02-01 13:04:28 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (xt > 0 && yt > 0)
|
|
|
|
GST_FIXME_OBJECT (parse, "embedded thumbnail ignored");
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-11-16 16:35:36 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* JFIF Extension */
|
2023-12-20 19:58:04 +00:00
|
|
|
if (GST_MAKE_FOURCC ('J', 'F', 'X', 'X') == id) {
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_JFIF))
|
|
|
|
return FALSE;
|
2010-11-16 16:35:36 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return TRUE;
|
2010-11-21 14:05:43 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 18:02:35 +00:00
|
|
|
/* https://exiftool.org/TagNames/JPEG.html#AVI1 */
|
2023-12-20 19:58:04 +00:00
|
|
|
if (GST_MAKE_FOURCC ('A', 'V', 'I', '1') == id) {
|
2023-02-15 18:02:35 +00:00
|
|
|
/* polarity */
|
|
|
|
if (!gst_byte_reader_get_uint8 (&reader, &unit))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->avid = TRUE;
|
|
|
|
parse->field = unit == 1 ? 0 : 1;
|
|
|
|
|
2023-02-15 18:02:35 +00:00
|
|
|
/* TODO: update caps for interlaced MJPEG */
|
|
|
|
GST_DEBUG_OBJECT (parse, "MJPEG interleaved field: %d", unit);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-12-20 19:35:32 +00:00
|
|
|
GST_MEMDUMP_OBJECT (parse, "Unhandled app0", seg->data + seg->offset,
|
|
|
|
seg->size);
|
2023-02-19 09:41:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2010-11-16 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const struct
|
2010-11-21 14:09:17 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
const gchar *suffix;
|
|
|
|
GstTagList *(*tag_func) (GstBuffer * buff);
|
|
|
|
} TagMap[] = {
|
|
|
|
{"Exif", gst_tag_list_from_exif_buffer_with_tiff_header},
|
|
|
|
{"http://ns.adobe.com/xap/1.0/", gst_tag_list_from_xmp_buffer},
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2010-11-21 14:09:17 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_app1 (GstJpegParse * parse, GstJpegSegment * seg)
|
2010-11-16 17:22:07 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
GstByteReader reader;
|
2010-11-16 17:22:07 +00:00
|
|
|
GstBuffer *buf;
|
2021-12-22 18:23:37 +00:00
|
|
|
guint16 size = 0;
|
|
|
|
const gchar *id_str;
|
|
|
|
const guint8 *data;
|
|
|
|
gint i;
|
|
|
|
|
2023-02-19 09:41:51 +00:00
|
|
|
if (seg->size < 6) /* less than 6 means no id string */
|
|
|
|
return FALSE;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size);
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 2);
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_byte_reader_get_string_utf8 (&reader, &id_str))
|
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (TagMap); i++) {
|
|
|
|
if (!g_str_has_suffix (id_str, TagMap[i].suffix))
|
|
|
|
continue;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* skip NUL only for Exif */
|
|
|
|
if (i == 0) {
|
|
|
|
if (!gst_byte_reader_skip (&reader, 1))
|
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
size = gst_byte_reader_get_remaining (&reader);
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_byte_reader_get_data (&reader, size, &data))
|
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
buf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
|
|
|
|
(gpointer) data, size, 0, size, NULL, NULL);
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (buf) {
|
|
|
|
GstTagList *tags;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
tags = TagMap[i].tag_func (buf);
|
|
|
|
gst_buffer_unref (buf);
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (tags) {
|
|
|
|
GST_LOG_OBJECT (parse, "parsed marker %x: '%s' %" GST_PTR_FORMAT,
|
|
|
|
GST_JPEG_MARKER_APP1, id_str, tags);
|
|
|
|
gst_tag_list_insert (get_tag_list (parse), tags, GST_TAG_MERGE_REPLACE);
|
|
|
|
gst_tag_list_unref (tags);
|
|
|
|
} else {
|
|
|
|
GST_INFO_OBJECT (parse, "failed to parse %s: %s", id_str, data);
|
2023-02-19 09:41:51 +00:00
|
|
|
return FALSE;
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2023-12-20 19:35:32 +00:00
|
|
|
GST_MEMDUMP_OBJECT (parse, "Unhandled app1", seg->data + seg->offset,
|
|
|
|
seg->size);
|
2023-02-19 09:41:51 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_app14 (GstJpegParse * parse, GstJpegSegment * seg)
|
|
|
|
{
|
|
|
|
GstByteReader reader;
|
|
|
|
const gchar *id_str;
|
|
|
|
guint8 transform;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2023-02-19 09:41:51 +00:00
|
|
|
if (seg->size < 6) /* less than 6 means no id string */
|
2021-12-22 18:23:37 +00:00
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size);
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 2);
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_byte_reader_get_string_utf8 (&reader, &id_str))
|
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2023-02-19 09:41:51 +00:00
|
|
|
if (!g_str_has_prefix (id_str, "Adobe")) {
|
|
|
|
GST_DEBUG_OBJECT (parse, "Unhandled app14: %s", id_str);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* skip version and flags */
|
|
|
|
if (!gst_byte_reader_skip (&reader, 6))
|
|
|
|
return FALSE;
|
2010-11-16 17:22:07 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_ADOBE;
|
|
|
|
|
|
|
|
/* transform bit might not exist */
|
|
|
|
if (!gst_byte_reader_get_uint8 (&reader, &transform))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
parse->adobe_transform = transform;
|
2010-11-16 17:22:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-13 10:38:02 +00:00
|
|
|
static inline gchar *
|
|
|
|
get_utf8_from_data (const guint8 * data, guint16 size)
|
|
|
|
{
|
|
|
|
const gchar *env_vars[] = { "GST_JPEG_TAG_ENCODING",
|
|
|
|
"GST_TAG_ENCODING", NULL
|
|
|
|
};
|
|
|
|
const char *str = (gchar *) data;
|
2023-12-19 12:16:34 +00:00
|
|
|
char *ret;
|
2010-08-13 10:38:02 +00:00
|
|
|
|
2023-12-19 12:16:34 +00:00
|
|
|
ret = gst_tag_freeform_string_to_utf8 (str, size, env_vars);
|
|
|
|
if (!ret)
|
|
|
|
GST_MEMDUMP ("non-parsed marker data", data, size);
|
|
|
|
|
|
|
|
return ret;
|
2010-08-13 10:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read comment and post as tag */
|
|
|
|
static inline gboolean
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_jpeg_parse_com (GstJpegParse * parse, GstJpegSegment * seg)
|
2010-08-13 10:38:02 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
GstByteReader reader;
|
2010-08-13 10:38:02 +00:00
|
|
|
const guint8 *data = NULL;
|
2021-12-22 18:23:37 +00:00
|
|
|
guint16 size;
|
2023-12-19 09:39:31 +00:00
|
|
|
const gchar *buf;
|
2010-08-13 10:38:02 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_byte_reader_init (&reader, seg->data + seg->offset, seg->size);
|
|
|
|
gst_byte_reader_skip_unchecked (&reader, 2);
|
2010-08-13 10:38:02 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
size = gst_byte_reader_get_remaining (&reader);
|
|
|
|
if (!gst_byte_reader_get_data (&reader, size, &data))
|
2010-08-13 10:38:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
buf = (const gchar *) data;
|
|
|
|
/* buggy avid, it puts EOI only at every 10th frame */
|
|
|
|
if (g_str_has_prefix (buf, "AVID")) {
|
|
|
|
parse_avid (parse, data, size);
|
|
|
|
} else if (g_str_has_prefix (buf, "MULTISCOPE II")) {
|
2023-12-20 20:41:00 +00:00
|
|
|
parse->par_num = 1;
|
|
|
|
parse->par_den = 2;
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->multiscope = TRUE;
|
|
|
|
} else {
|
|
|
|
gchar *comment;
|
|
|
|
|
|
|
|
comment = get_utf8_from_data (data, size);
|
|
|
|
if (!comment)
|
|
|
|
return FALSE;
|
2010-08-13 10:38:02 +00:00
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
GST_INFO_OBJECT (parse, "comment found: %s", comment);
|
|
|
|
gst_tag_list_add (get_tag_list (parse), GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_COMMENT, comment, NULL);
|
|
|
|
g_free (comment);
|
|
|
|
}
|
2010-08-13 10:38:02 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
/* reset per image */
|
2021-12-22 18:23:37 +00:00
|
|
|
static void
|
|
|
|
gst_jpeg_parse_reset (GstJpegParse * parse)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
parse->last_offset = 0;
|
|
|
|
parse->state = 0;
|
|
|
|
parse->adobe_transform = 0;
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->field = 0;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (parse->tags) {
|
|
|
|
gst_tag_list_unref (parse->tags);
|
|
|
|
parse->tags = NULL;
|
2011-10-05 18:06:20 +00:00
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 15:02:43 +00:00
|
|
|
static const gchar *
|
|
|
|
sampling_to_string (enum GstJPEGSampling sampling)
|
|
|
|
{
|
|
|
|
return gst_jpeg_sampling_strings[sampling];
|
|
|
|
}
|
|
|
|
|
2009-08-19 10:22:30 +00:00
|
|
|
static gboolean
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_jpeg_parse_set_new_caps (GstJpegParse * parse)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2023-12-19 12:16:02 +00:00
|
|
|
GstEvent *event;
|
2009-08-19 10:22:30 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2023-12-19 12:16:02 +00:00
|
|
|
if (!parse->renegotiate)
|
|
|
|
return TRUE;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
caps = gst_caps_new_simple ("image/jpeg", "parsed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (parse->width > 0)
|
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, parse->width, NULL);
|
2023-12-19 09:39:31 +00:00
|
|
|
if (parse->orig_height > 0 && parse->orig_height > parse->height)
|
|
|
|
gst_caps_set_simple (caps, "height", G_TYPE_INT, parse->orig_height, NULL);
|
|
|
|
else if (parse->height > 0)
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_caps_set_simple (caps, "height", G_TYPE_INT, parse->height, NULL);
|
|
|
|
if (parse->sof >= 0)
|
|
|
|
gst_caps_set_simple (caps, "sof-marker", G_TYPE_INT, parse->sof, NULL);
|
2022-06-16 15:02:43 +00:00
|
|
|
if (parse->colorspace != GST_JPEG_COLORSPACE_NONE) {
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_caps_set_simple (caps, "colorspace", G_TYPE_STRING,
|
|
|
|
colorspace_to_string (parse->colorspace), NULL);
|
|
|
|
}
|
2022-06-16 15:02:43 +00:00
|
|
|
if (parse->sampling != GST_JPEG_SAMPLING_NONE) {
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_caps_set_simple (caps, "sampling", G_TYPE_STRING,
|
2022-06-16 15:02:43 +00:00
|
|
|
sampling_to_string (parse->sampling), NULL);
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
2010-02-01 13:04:28 +00:00
|
|
|
|
2023-12-19 12:13:48 +00:00
|
|
|
if (parse->colorimetry) {
|
|
|
|
gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, parse->colorimetry,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING,
|
|
|
|
gst_video_interlace_mode_to_string (parse->interlace_mode), NULL);
|
|
|
|
|
|
|
|
if (parse->interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) {
|
|
|
|
gst_caps_set_simple (caps, "field-order", G_TYPE_STRING,
|
|
|
|
gst_video_field_order_to_string (parse->field_order), NULL);
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION,
|
|
|
|
parse->framerate_numerator, parse->framerate_denominator, NULL);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-20 20:41:00 +00:00
|
|
|
if (parse->par_num > 0 && parse->par_den > 0) {
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
2023-12-20 20:41:00 +00:00
|
|
|
parse->par_num, parse->par_den, NULL);
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
if (parse->codec_data) {
|
|
|
|
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, parse->codec_data,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2023-12-19 12:16:02 +00:00
|
|
|
parse->renegotiate = FALSE;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2010-02-01 13:04:28 +00:00
|
|
|
GST_DEBUG_OBJECT (parse,
|
|
|
|
"setting downstream caps on %s:%s to %" GST_PTR_FORMAT,
|
2014-04-22 02:05:48 +00:00
|
|
|
GST_DEBUG_PAD_NAME (GST_BASE_PARSE_SRC_PAD (parse)), caps);
|
2021-12-22 18:23:37 +00:00
|
|
|
|
2023-12-19 12:16:02 +00:00
|
|
|
event = gst_event_new_caps (caps);
|
|
|
|
res = gst_pad_push_event (GST_BASE_PARSE_SRC_PAD (parse), event);
|
2009-08-19 10:22:30 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2023-02-12 14:37:01 +00:00
|
|
|
gst_jpeg_parse_finish_frame (GstJpegParse * parse, GstBaseParseFrame * frame,
|
2021-12-22 18:23:37 +00:00
|
|
|
gint size)
|
2014-04-22 02:05:48 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
GstBaseParse *bparse = GST_BASE_PARSE (parse);
|
2023-02-12 14:37:01 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
if (parse->tags)
|
|
|
|
gst_base_parse_merge_tags (bparse, parse->tags, GST_TAG_MERGE_REPLACE);
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_jpeg_parse_set_new_caps (parse))
|
|
|
|
return GST_FLOW_ERROR;
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_VALID_PICTURE)) {
|
|
|
|
/* this validation breaks unit tests */
|
|
|
|
/* frame->flags |= GST_BASE_PARSE_FRAME_FLAG_DROP; */
|
|
|
|
GST_WARNING_OBJECT (parse, "Potentially invalid picture");
|
2014-04-22 02:05:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-12 14:37:01 +00:00
|
|
|
ret = gst_base_parse_finish_frame (bparse, frame, size);
|
|
|
|
|
|
|
|
gst_jpeg_parse_reset (parse);
|
|
|
|
|
|
|
|
return ret;
|
2014-04-22 02:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_jpeg_parse_handle_frame (GstBaseParse * bparse, GstBaseParseFrame * frame,
|
|
|
|
gint * skipsize)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2014-04-22 02:05:48 +00:00
|
|
|
GstJpegParse *parse = GST_JPEG_PARSE_CAST (bparse);
|
|
|
|
GstMapInfo mapinfo;
|
2021-12-22 18:23:37 +00:00
|
|
|
GstJpegMarker marker;
|
|
|
|
GstJpegSegment seg;
|
|
|
|
guint offset;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
GST_TRACE_OBJECT (parse, "frame %" GST_PTR_FORMAT, frame->buffer);
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!gst_buffer_map (frame->buffer, &mapinfo, GST_MAP_READ))
|
2014-04-22 02:05:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
offset = parse->last_offset;
|
|
|
|
if (offset > 0)
|
|
|
|
offset -= 1; /* it migth be in the middle marker */
|
|
|
|
|
|
|
|
while (offset < mapinfo.size) {
|
|
|
|
if (!gst_jpeg_parse (&seg, mapinfo.data, mapinfo.size, offset)) {
|
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_SOI)) {
|
|
|
|
/* Skip any garbage until SOI */
|
|
|
|
*skipsize = mapinfo.size;
|
|
|
|
GST_INFO_OBJECT (parse, "skipping %d bytes", *skipsize);
|
|
|
|
} else {
|
|
|
|
/* Accept anything after SOI */
|
|
|
|
parse->last_offset = mapinfo.size;
|
|
|
|
}
|
|
|
|
goto beach;
|
|
|
|
}
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
offset = seg.offset;
|
|
|
|
marker = seg.marker;
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_SOI)
|
|
|
|
&& marker != GST_JPEG_MARKER_SOI)
|
|
|
|
continue;
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
/* check if the whole segment is available */
|
|
|
|
if (offset + seg.size > mapinfo.size) {
|
2023-02-28 17:48:24 +00:00
|
|
|
GST_DEBUG_OBJECT (parse, "incomplete segment: %x [offset %d]", marker,
|
2021-12-22 18:23:37 +00:00
|
|
|
offset);
|
|
|
|
parse->last_offset = offset - 2;
|
|
|
|
goto beach;
|
|
|
|
}
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
offset += seg.size;
|
2014-04-22 02:05:48 +00:00
|
|
|
|
2023-02-28 17:48:24 +00:00
|
|
|
GST_LOG_OBJECT (parse, "marker found: %x [offset %d / size %"
|
2021-12-22 18:23:37 +00:00
|
|
|
G_GSSIZE_FORMAT "]", marker, seg.offset, seg.size);
|
2010-02-02 09:22:06 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
switch (marker) {
|
|
|
|
case GST_JPEG_MARKER_SOI:
|
2023-02-12 14:37:01 +00:00
|
|
|
/* This means that new SOI comes without an previous EOI. */
|
2023-12-19 09:39:31 +00:00
|
|
|
if (offset > 2
|
|
|
|
&& (parse->interlace_mode == GST_VIDEO_INTERLACE_MODE_PROGRESSIVE
|
|
|
|
|| parse->field == 0)) {
|
2023-02-12 14:37:01 +00:00
|
|
|
/* If already some data segment parsed, push it as a frame. */
|
|
|
|
if (valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_SOS)) {
|
|
|
|
gst_buffer_unmap (frame->buffer, &mapinfo);
|
|
|
|
|
|
|
|
frame->out_buffer = gst_buffer_copy_region (frame->buffer,
|
|
|
|
GST_BUFFER_COPY_ALL, 0, seg.offset - 2);
|
|
|
|
GST_MINI_OBJECT_FLAGS (frame->out_buffer) |=
|
|
|
|
GST_BUFFER_FLAG_CORRUPTED;
|
|
|
|
|
2023-02-28 17:48:24 +00:00
|
|
|
GST_WARNING_OBJECT (parse, "Push a frame without EOI, size %d",
|
2023-02-12 14:37:01 +00:00
|
|
|
seg.offset - 2);
|
|
|
|
return gst_jpeg_parse_finish_frame (parse, frame, seg.offset - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_jpeg_parse_reset (parse);
|
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_SOI;
|
|
|
|
/* unset tags */
|
|
|
|
gst_base_parse_merge_tags (bparse, NULL, GST_TAG_MERGE_UNDEFINED);
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
*skipsize = offset - 2;
|
|
|
|
GST_DEBUG_OBJECT (parse, "skipping %d bytes before SOI", *skipsize);
|
|
|
|
parse->last_offset = 2;
|
|
|
|
goto beach;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-02-12 14:37:01 +00:00
|
|
|
/* unset tags */
|
|
|
|
gst_base_parse_merge_tags (bparse, NULL, GST_TAG_MERGE_UNDEFINED);
|
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_SOI;
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_EOI:
|
2023-12-19 09:39:31 +00:00
|
|
|
if (parse->interlace_mode == GST_VIDEO_INTERLACE_MODE_PROGRESSIVE
|
|
|
|
|| parse->field == 1) {
|
|
|
|
gst_buffer_unmap (frame->buffer, &mapinfo);
|
|
|
|
return gst_jpeg_parse_finish_frame (parse, frame, seg.offset);
|
|
|
|
} else if (parse->interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED
|
|
|
|
&& parse->field == 0) {
|
|
|
|
parse->field = 1;
|
|
|
|
parse->state = 0;
|
|
|
|
}
|
2023-02-12 14:37:01 +00:00
|
|
|
break;
|
2021-12-22 18:23:37 +00:00
|
|
|
case GST_JPEG_MARKER_SOS:
|
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_SOF))
|
|
|
|
GST_WARNING_OBJECT (parse, "SOS marker without SOF one");
|
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_SOS;
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_COM:
|
2023-12-19 12:16:34 +00:00
|
|
|
if (!gst_jpeg_parse_com (parse, &seg))
|
|
|
|
GST_WARNING_OBJECT (parse, "Failed to parse com segment");
|
2021-12-22 18:23:37 +00:00
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_APP0:
|
|
|
|
if (!gst_jpeg_parse_app0 (parse, &seg)) {
|
|
|
|
GST_ELEMENT_WARNING (parse, STREAM, FORMAT,
|
2023-05-15 15:31:58 +00:00
|
|
|
("Invalid data"), ("Failed to parse app0 segment"));
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_APP1:
|
|
|
|
if (!gst_jpeg_parse_app1 (parse, &seg)) {
|
|
|
|
GST_ELEMENT_WARNING (parse, STREAM, FORMAT,
|
2023-05-15 15:31:58 +00:00
|
|
|
("Invalid data"), ("Failed to parse app1 segment"));
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_APP14:
|
|
|
|
if (!gst_jpeg_parse_app14 (parse, &seg)) {
|
|
|
|
GST_ELEMENT_WARNING (parse, STREAM, FORMAT,
|
2023-05-15 15:31:58 +00:00
|
|
|
("Invalid data"), ("Failed to parse app14 segment"));
|
2021-12-22 18:23:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_JPEG_MARKER_DHT:
|
|
|
|
case GST_JPEG_MARKER_DAC:
|
|
|
|
/* to avoid break the below SOF interval */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* SOFn segments */
|
|
|
|
if (marker >= GST_JPEG_MARKER_SOF_MIN &&
|
|
|
|
marker <= GST_JPEG_MARKER_SOF_MAX) {
|
|
|
|
if (!valid_state (parse->state, GST_JPEG_PARSER_STATE_GOT_SOF)
|
|
|
|
&& gst_jpeg_parse_sof (parse, &seg)) {
|
2023-12-19 12:16:02 +00:00
|
|
|
gint8 sof;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
parse->state |= GST_JPEG_PARSER_STATE_GOT_SOF;
|
2023-12-19 12:16:02 +00:00
|
|
|
sof = marker - 0xc0;
|
|
|
|
if (parse->sof != sof) {
|
|
|
|
parse->sof = sof;
|
|
|
|
parse->renegotiate = TRUE;
|
|
|
|
}
|
2021-12-22 18:23:37 +00:00
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (parse, STREAM, FORMAT,
|
2023-05-15 15:31:58 +00:00
|
|
|
("Invalid data"), ("Duplicated or bad SOF marker"));
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_buffer_unmap (frame->buffer, &mapinfo);
|
|
|
|
gst_jpeg_parse_reset (parse);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
parse->last_offset = offset;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
beach:
|
|
|
|
gst_buffer_unmap (frame->buffer, &mapinfo);
|
|
|
|
return GST_FLOW_OK;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-04-22 02:05:48 +00:00
|
|
|
gst_jpeg_parse_sink_event (GstBaseParse * bparse, GstEvent * event)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2014-04-22 02:05:48 +00:00
|
|
|
GstJpegParse *parse = GST_JPEG_PARSE_CAST (bparse);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (parse, "event : %s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2010-05-31 16:30:36 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_jpeg_parse_reset (parse);
|
2010-08-17 20:30:10 +00:00
|
|
|
break;
|
2009-08-19 10:22:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
return GST_BASE_PARSE_CLASS (parent_class)->sink_event (bparse, event);
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_start (GstBaseParse * bparse)
|
2009-08-19 10:22:30 +00:00
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
GstJpegParse *parse = GST_JPEG_PARSE_CAST (bparse);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2018-06-23 21:51:37 +00:00
|
|
|
parse->framerate_numerator = 0;
|
|
|
|
parse->framerate_denominator = 1;
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->first_picture = TRUE;
|
2023-12-19 12:16:02 +00:00
|
|
|
parse->renegotiate = TRUE;
|
2023-12-19 09:39:31 +00:00
|
|
|
|
2023-12-20 20:41:00 +00:00
|
|
|
parse->par_num = parse->par_den = 1;
|
|
|
|
|
2023-12-19 09:39:31 +00:00
|
|
|
parse->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
|
|
|
parse->field_order = GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST;
|
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_jpeg_parse_reset (parse);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_base_parse_set_min_frame_size (bparse, 2);
|
2010-08-17 20:30:10 +00:00
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_jpeg_parse_stop (GstBaseParse * bparse)
|
|
|
|
{
|
2021-12-22 18:23:37 +00:00
|
|
|
GstJpegParse *parse = GST_JPEG_PARSE_CAST (bparse);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2018-06-23 21:51:37 +00:00
|
|
|
if (parse->tags) {
|
|
|
|
gst_tag_list_unref (parse->tags);
|
|
|
|
parse->tags = NULL;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|
2023-12-19 09:39:31 +00:00
|
|
|
gst_clear_buffer (&parse->codec_data);
|
2021-12-22 18:23:37 +00:00
|
|
|
gst_clear_caps (&parse->prev_caps);
|
2023-12-19 12:13:48 +00:00
|
|
|
g_clear_pointer (&parse->colorimetry, g_free);
|
2009-08-19 10:22:30 +00:00
|
|
|
|
2014-04-22 02:05:48 +00:00
|
|
|
return TRUE;
|
2009-08-19 10:22:30 +00:00
|
|
|
}
|