mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
jpegformat: Use codecparsers' for JPEG markers.
Instead of repeating JPEG markers definition, this patch uses those defined in gstcodecparsers library. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1473>
This commit is contained in:
parent
547d324325
commit
17046fc1ad
5 changed files with 79 additions and 158 deletions
|
@ -57,6 +57,7 @@ gst-launch-1.0 videotestsrc num-buffers=1 ! jpegenc ! taginject tags="comment=te
|
|||
#include <string.h>
|
||||
#include <gst/base/gstbytereader.h>
|
||||
#include <gst/base/gstbytewriter.h>
|
||||
#include <gst/codecparsers/gstjpegparser.h>
|
||||
#include <gst/tag/tag.h>
|
||||
#include <gst/tag/xmpwriter.h>
|
||||
|
||||
|
@ -281,20 +282,20 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
|
|||
goto error;
|
||||
|
||||
switch (marker) {
|
||||
case RST0:
|
||||
case RST1:
|
||||
case RST2:
|
||||
case RST3:
|
||||
case RST4:
|
||||
case RST5:
|
||||
case RST6:
|
||||
case RST7:
|
||||
case SOI:
|
||||
case GST_JPEG_MARKER_RST0:
|
||||
case GST_JPEG_MARKER_RST1:
|
||||
case GST_JPEG_MARKER_RST2:
|
||||
case GST_JPEG_MARKER_RST3:
|
||||
case GST_JPEG_MARKER_RST4:
|
||||
case GST_JPEG_MARKER_RST5:
|
||||
case GST_JPEG_MARKER_RST6:
|
||||
case GST_JPEG_MARKER_RST7:
|
||||
case GST_JPEG_MARKER_SOI:
|
||||
GST_DEBUG_OBJECT (self, "marker = %x", marker);
|
||||
m = gst_jif_mux_new_marker (marker, 0, NULL, FALSE);
|
||||
self->markers = g_list_prepend (self->markers, m);
|
||||
break;
|
||||
case EOI:
|
||||
case GST_JPEG_MARKER_EOI:
|
||||
GST_DEBUG_OBJECT (self, "marker = %x", marker);
|
||||
m = gst_jif_mux_new_marker (marker, 0, NULL, FALSE);
|
||||
self->markers = g_list_prepend (self->markers, m);
|
||||
|
@ -312,14 +313,15 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
|
|||
break;
|
||||
}
|
||||
|
||||
if (marker == SOS) {
|
||||
if (marker == GST_JPEG_MARKER_SOS) {
|
||||
gint eoi_pos = -1;
|
||||
gint i;
|
||||
|
||||
/* search the last 5 bytes for the EOI marker */
|
||||
g_assert (map.size >= 5);
|
||||
for (i = 5; i >= 2; i--) {
|
||||
if (map.data[map.size - i] == 0xFF && map.data[map.size - i + 1] == EOI) {
|
||||
if (map.data[map.size - i] == 0xFF
|
||||
&& map.data[map.size - i + 1] == GST_JPEG_MARKER_EOI) {
|
||||
eoi_pos = map.size - i;
|
||||
break;
|
||||
}
|
||||
|
@ -388,7 +390,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
m = (GstJifMuxMarker *) node->data;
|
||||
|
||||
switch (m->marker) {
|
||||
case APP0:
|
||||
case GST_JPEG_MARKER_APP0:
|
||||
if (m->size > 5 && !memcmp (m->data, "JFIF\0", 5)) {
|
||||
GST_DEBUG_OBJECT (self, "found APP0 JFIF");
|
||||
colorspace |= COLORSPACE_GRAYSCALE | COLORSPACE_YUV;
|
||||
|
@ -396,7 +398,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
app0_jfif = node;
|
||||
}
|
||||
break;
|
||||
case APP1:
|
||||
case GST_JPEG_MARKER_APP1:
|
||||
if (m->size > 6 && (!memcmp (m->data, "EXIF\0\0", 6) ||
|
||||
!memcmp (m->data, "Exif\0\0", 6))) {
|
||||
GST_DEBUG_OBJECT (self, "found APP1 EXIF");
|
||||
|
@ -409,7 +411,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
app1_xmp = node;
|
||||
}
|
||||
break;
|
||||
case APP14:
|
||||
case GST_JPEG_MARKER_APP14:
|
||||
/* check if this contains RGB */
|
||||
/*
|
||||
* This marker should have:
|
||||
|
@ -441,32 +443,32 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
}
|
||||
|
||||
break;
|
||||
case COM:
|
||||
case GST_JPEG_MARKER_COM:
|
||||
GST_INFO_OBJECT (self, "found COM, will be replaced");
|
||||
if (!com)
|
||||
com = node;
|
||||
break;
|
||||
case DQT:
|
||||
case SOF0:
|
||||
case SOF1:
|
||||
case SOF2:
|
||||
case SOF3:
|
||||
case SOF5:
|
||||
case SOF6:
|
||||
case SOF7:
|
||||
case SOF9:
|
||||
case SOF10:
|
||||
case SOF11:
|
||||
case SOF13:
|
||||
case SOF14:
|
||||
case SOF15:
|
||||
case GST_JPEG_MARKER_DQT:
|
||||
case GST_JPEG_MARKER_SOF0:
|
||||
case GST_JPEG_MARKER_SOF1:
|
||||
case GST_JPEG_MARKER_SOF2:
|
||||
case GST_JPEG_MARKER_SOF3:
|
||||
case GST_JPEG_MARKER_SOF5:
|
||||
case GST_JPEG_MARKER_SOF6:
|
||||
case GST_JPEG_MARKER_SOF7:
|
||||
case GST_JPEG_MARKER_SOF9:
|
||||
case GST_JPEG_MARKER_SOF10:
|
||||
case GST_JPEG_MARKER_SOF11:
|
||||
case GST_JPEG_MARKER_SOF13:
|
||||
case GST_JPEG_MARKER_SOF14:
|
||||
case GST_JPEG_MARKER_SOF15:
|
||||
if (!frame_hdr)
|
||||
frame_hdr = node;
|
||||
break;
|
||||
case DAC:
|
||||
case DHT:
|
||||
case DRI:
|
||||
case SOS:
|
||||
case GST_JPEG_MARKER_DAC:
|
||||
case GST_JPEG_MARKER_DHT:
|
||||
case GST_JPEG_MARKER_DRI:
|
||||
case GST_JPEG_MARKER_SOS:
|
||||
if (!scan_hdr)
|
||||
scan_hdr = node;
|
||||
break;
|
||||
|
@ -477,6 +479,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
/* check if we don't have JFIF APP0 */
|
||||
if (!app0_jfif && (colorspace & (COLORSPACE_GRAYSCALE | COLORSPACE_YUV))) {
|
||||
/* build jfif header */
|
||||
/* *INDENT-OFF* */
|
||||
static const struct
|
||||
{
|
||||
gchar id[5];
|
||||
|
@ -484,13 +487,16 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
guint8 du;
|
||||
guint8 xd[2], yd[2];
|
||||
guint8 tw, th;
|
||||
} jfif_data = {
|
||||
"JFIF", {
|
||||
1, 2}, 0, {
|
||||
0, 1}, /* FIXME: check pixel-aspect from caps */
|
||||
{
|
||||
0, 1}, 0, 0};
|
||||
m = gst_jif_mux_new_marker (APP0, sizeof (jfif_data),
|
||||
} jfif_data = { "JFIF",
|
||||
{ 1, 2 },
|
||||
0,
|
||||
{ 0, 1 }, /* FIXME: check pixel-aspect from caps */
|
||||
{ 0, 1 },
|
||||
0, 0
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
m = gst_jif_mux_new_marker (GST_JPEG_MARKER_APP0, sizeof (jfif_data),
|
||||
(const guint8 *) &jfif_data, FALSE);
|
||||
/* insert into self->markers list */
|
||||
self->markers = g_list_insert (self->markers, m, 1);
|
||||
|
@ -538,7 +544,8 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
data = g_malloc0 (exif_size + 6);
|
||||
memcpy (data, "Exif", 4);
|
||||
gst_buffer_extract (exif_data, 0, data + 6, exif_size);
|
||||
m = gst_jif_mux_new_marker (APP1, exif_size + 6, data, TRUE);
|
||||
m = gst_jif_mux_new_marker (GST_JPEG_MARKER_APP1, exif_size + 6, data,
|
||||
TRUE);
|
||||
gst_buffer_unref (exif_data);
|
||||
|
||||
if (app1_exif) {
|
||||
|
@ -574,7 +581,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
data = g_malloc (size + 29);
|
||||
memcpy (data, "http://ns.adobe.com/xap/1.0/\0", 29);
|
||||
gst_buffer_extract (xmp_data, 0, &data[29], size);
|
||||
m = gst_jif_mux_new_marker (APP1, size + 29, data, TRUE);
|
||||
m = gst_jif_mux_new_marker (GST_JPEG_MARKER_APP1, size + 29, data, TRUE);
|
||||
|
||||
/*
|
||||
* Replace the old xmp marker and not add a new one.
|
||||
|
@ -608,8 +615,8 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
if (str) {
|
||||
GST_DEBUG_OBJECT (self, "set COM marker to '%s'", str);
|
||||
/* insert new marker into self->markers list */
|
||||
m = gst_jif_mux_new_marker (COM, strlen (str) + 1, (const guint8 *) str,
|
||||
TRUE);
|
||||
m = gst_jif_mux_new_marker (GST_JPEG_MARKER_COM, strlen (str) + 1,
|
||||
(const guint8 *) str, TRUE);
|
||||
/* FIXME: if we have one already, replace */
|
||||
/* this should go before SOS, maybe at the end of file-header */
|
||||
self->markers = g_list_insert_before (self->markers, frame_hdr, m);
|
||||
|
@ -672,7 +679,7 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
|
|||
writer_status &= gst_byte_writer_put_data (writer, m->data, m->size);
|
||||
}
|
||||
|
||||
if (m->marker == SOS) {
|
||||
if (m->marker == GST_JPEG_MARKER_SOS) {
|
||||
GST_DEBUG_OBJECT (self, "scan data, size = %u", self->scan_size);
|
||||
writer_status &=
|
||||
gst_byte_writer_put_data (writer, self->scan_data, self->scan_size);
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "gstjpegformat.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_JIF_MUX \
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* jpegformat: a plugin for JPEG Interchange Format
|
||||
*
|
||||
* Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_JPEG_FORMAT_H__
|
||||
#define __GST_JPEG_FORMAT_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* JPEG Markers
|
||||
*/
|
||||
|
||||
/* Start Of Frame markers, non-differential, Huffman coding */
|
||||
#define SOF0 0xc0 /* Baseline DCT */
|
||||
#define SOF1 0xc1 /* Extended sequential DCT */
|
||||
#define SOF2 0xc2 /* Progressive DCT */
|
||||
#define SOF3 0xc3 /* Lossless */
|
||||
|
||||
/* Start Of Frame markers, differential, Huffman coding */
|
||||
#define SOF5 0xc5
|
||||
#define SOF6 0xc6
|
||||
#define SOF7 0xc7
|
||||
|
||||
/* Start Of Frame markers, non-differential, arithmetic coding */
|
||||
#define JPG 0xc8 /* Reserved */
|
||||
#define SOF9 0xc9
|
||||
#define SOF10 0xca
|
||||
#define SOF11 0xcb
|
||||
|
||||
/* Start Of Frame markers, differential, arithmetic coding */
|
||||
#define SOF13 0xcd
|
||||
#define SOF14 0xce
|
||||
#define SOF15 0xcf
|
||||
|
||||
/* Restart interval termination */
|
||||
#define RST0 0xd0 /* Restart ... */
|
||||
#define RST1 0xd1
|
||||
#define RST2 0xd2
|
||||
#define RST3 0xd3
|
||||
#define RST4 0xd4
|
||||
#define RST5 0xd5
|
||||
#define RST6 0xd6
|
||||
#define RST7 0xd7
|
||||
|
||||
#define SOI 0xd8 /* Start of image */
|
||||
#define EOI 0xd9 /* End Of Image */
|
||||
#define SOS 0xda /* Start Of Scan */
|
||||
|
||||
#define DHT 0xc4 /* Huffman Table(s) */
|
||||
#define DAC 0xcc /* Algorithmic Coding Table */
|
||||
#define DQT 0xdb /* Quantisation Table(s) */
|
||||
#define DNL 0xdc /* Number of lines */
|
||||
#define DRI 0xdd /* Restart Interval */
|
||||
#define DHP 0xde /* Hierarchical progression */
|
||||
#define EXP 0xdf
|
||||
|
||||
#define APP0 0xe0 /* Application marker */
|
||||
#define APP1 0xe1
|
||||
#define APP2 0xe2
|
||||
#define APP13 0xed
|
||||
#define APP14 0xee
|
||||
#define APP15 0xef
|
||||
|
||||
#define JPG0 0xf0 /* Reserved ... */
|
||||
#define JPG13 0xfd
|
||||
#define COM 0xfe /* Comment */
|
||||
|
||||
#define TEM 0x01
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_JPEG_FORMAT_H__ */
|
|
@ -50,10 +50,14 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <gst/base/gstbytereader.h>
|
||||
#include <gst/codecparsers/gstjpegparser.h>
|
||||
#include <gst/tag/tag.h>
|
||||
|
||||
#include "gstjpegparse.h"
|
||||
#include "gstjpegformat.h"
|
||||
|
||||
#define GST_JPEG_MARKER_JPG 0xC8
|
||||
#define GST_JPEG_MARKER_JPG0 0xF0
|
||||
#define GST_JPEG_MARKER_JPG13 0xFD
|
||||
|
||||
static GstStaticPadTemplate gst_jpeg_parse_src_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
|
@ -185,7 +189,8 @@ gst_jpeg_parse_skip_to_jpeg_header (GstJpegParse * parse, GstMapInfo * mapinfo,
|
|||
static inline gboolean
|
||||
gst_jpeg_parse_parse_tag_has_entropy_segment (guint8 tag)
|
||||
{
|
||||
if (tag == SOS || (tag >= RST0 && tag <= RST7))
|
||||
if (tag == GST_JPEG_MARKER_SOS
|
||||
|| (tag >= GST_JPEG_MARKER_RST0 && tag <= GST_JPEG_MARKER_RST7))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -427,7 +432,7 @@ gst_jpeg_parse_skip_marker (GstJpegParse * parse,
|
|||
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
/* We'd pry the id of the skipped application segment */
|
||||
if (marker >= APP0 && marker <= APP15) {
|
||||
if (marker >= GST_JPEG_MARKER_APP0 && marker <= GST_JPEG_MARKER_APP15) {
|
||||
const gchar *id_str = NULL;
|
||||
|
||||
if (gst_byte_reader_peek_string_utf8 (reader, &id_str)) {
|
||||
|
@ -511,7 +516,7 @@ gst_jpeg_parse_app1 (GstJpegParse * parse, GstByteReader * reader)
|
|||
gst_tag_list_from_exif_buffer_with_tiff_header);
|
||||
|
||||
GST_LOG_OBJECT (parse, "parsed marker %x: '%s' %u bytes",
|
||||
APP1, id_str, size);
|
||||
GST_JPEG_MARKER_APP1, id_str, size);
|
||||
|
||||
} else if (!strncmp (id_str, "http://ns.adobe.com/xap/1.0/", 28)) {
|
||||
|
||||
|
@ -528,13 +533,13 @@ gst_jpeg_parse_app1 (GstJpegParse * parse, GstByteReader * reader)
|
|||
gst_tag_list_from_xmp_buffer);
|
||||
|
||||
GST_LOG_OBJECT (parse, "parsed marker %x: '%s' %u bytes",
|
||||
APP1, id_str, size);
|
||||
GST_JPEG_MARKER_APP1, id_str, size);
|
||||
|
||||
} else {
|
||||
/* restore the byte position and size */
|
||||
reader->size += 2;
|
||||
reader->byte -= 2;
|
||||
if (!gst_jpeg_parse_skip_marker (parse, reader, APP1))
|
||||
if (!gst_jpeg_parse_skip_marker (parse, reader, GST_JPEG_MARKER_APP1))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -602,35 +607,35 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstMapInfo * map, gint len)
|
|||
GST_DEBUG_OBJECT (parse, "marker = %x", marker);
|
||||
|
||||
switch (marker) {
|
||||
case SOS: /* start of scan (begins compressed data) */
|
||||
case GST_JPEG_MARKER_SOS: /* start of scan (begins compressed data) */
|
||||
goto done;
|
||||
|
||||
case SOI:
|
||||
case GST_JPEG_MARKER_SOI:
|
||||
break;
|
||||
|
||||
case DRI:
|
||||
case GST_JPEG_MARKER_DRI:
|
||||
if (!gst_byte_reader_skip (&reader, 4)) /* fixed size */
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case COM:
|
||||
case GST_JPEG_MARKER_COM:
|
||||
if (!gst_jpeg_parse_com (parse, &reader))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case APP1:
|
||||
case GST_JPEG_MARKER_APP1:
|
||||
if (!gst_jpeg_parse_app1 (parse, &reader))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case DHT:
|
||||
case DQT:
|
||||
case GST_JPEG_MARKER_DHT:
|
||||
case GST_JPEG_MARKER_DQT:
|
||||
/* Ignore these codes */
|
||||
if (!gst_jpeg_parse_skip_marker (parse, &reader, marker))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case SOF0:
|
||||
case GST_JPEG_MARKER_SOF0:
|
||||
/* parse Start Of Frame */
|
||||
if (!gst_jpeg_parse_sof (parse, &reader))
|
||||
goto error;
|
||||
|
@ -639,8 +644,11 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstMapInfo * map, gint len)
|
|||
goto done;
|
||||
|
||||
default:
|
||||
if (marker == JPG || (marker >= JPG0 && marker <= JPG13) ||
|
||||
(marker >= APP0 && marker <= APP15)) {
|
||||
if (marker == GST_JPEG_MARKER_JPG
|
||||
|| (marker >= GST_JPEG_MARKER_JPG0
|
||||
&& marker <= GST_JPEG_MARKER_JPG13)
|
||||
|| (marker >= GST_JPEG_MARKER_APP0
|
||||
&& marker <= GST_JPEG_MARKER_APP15)) {
|
||||
if (!gst_jpeg_parse_skip_marker (parse, &reader, marker))
|
||||
goto error;
|
||||
} else
|
||||
|
|
|
@ -6,9 +6,9 @@ jpegf_sources = [
|
|||
|
||||
gstjpegformat = library('gstjpegformat',
|
||||
jpegf_sources,
|
||||
c_args : gst_plugins_bad_args,
|
||||
c_args : gst_plugins_bad_args + [ '-DGST_USE_UNSTABLE_API' ],
|
||||
include_directories : [configinc],
|
||||
dependencies : [gstbase_dep, gsttag_dep],
|
||||
dependencies : [gstbase_dep, gstcodecparsers_dep, gsttag_dep],
|
||||
install : true,
|
||||
install_dir : plugins_install_dir,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue