jpeg2000parse: use enums for colorspace and sampling, rather than strings

Also, move gstjpeg2000sampling to codecparsers project

https://bugzilla.gnome.org/show_bug.cgi?id=767908
This commit is contained in:
Aaron Boxer 2016-06-21 12:41:46 -04:00 committed by Sebastian Dröge
parent 539c032345
commit e7e6a3579d
11 changed files with 323 additions and 240 deletions

View file

@ -4,6 +4,7 @@ libgstopenjpeg_la_SOURCES = gstopenjpegdec.c gstopenjpegenc.c gstopenjpeg.c
libgstopenjpeg_la_CFLAGS = \ libgstopenjpeg_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(OPENJPEG_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(OPENJPEG_CFLAGS)
libgstopenjpeg_la_LIBADD = \ libgstopenjpeg_la_LIBADD = \
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_API_VERSION).la \
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_API_VERSION) \ $(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_API_VERSION) \
$(GST_LIBS) $(OPENJPEG_LIBS) $(GST_LIBS) $(OPENJPEG_LIBS)
libgstopenjpeg_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstopenjpeg_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)

View file

@ -25,7 +25,7 @@
#endif #endif
#include "gstopenjpegdec.h" #include "gstopenjpegdec.h"
#include "../../gst/videoparsers/gstjpeg2000sampling.h"
#include <string.h> #include <string.h>
@ -49,41 +49,13 @@ static gboolean gst_openjpeg_dec_decide_allocation (GstVideoDecoder * decoder,
#define YUV10 "Y444_10BE, I422_10BE, I420_10BE" #define YUV10 "Y444_10BE, I422_10BE, I420_10BE"
#endif #endif
/* convenience methods */
static gboolean
gst_openjpeg_dec_is_rgb (const gchar * sampling)
{
return (!g_strcmp0 (sampling, GST_RTP_J2K_RGB) ||
!g_strcmp0 (sampling, GST_RTP_J2K_RGBA) ||
!g_strcmp0 (sampling, GST_RTP_J2K_BGR) ||
!g_strcmp0 (sampling, GST_RTP_J2K_BGRA));
}
static gboolean
gst_openjpeg_dec_is_yuv (const gchar * sampling)
{
return (!g_strcmp0 (sampling, GST_RTP_J2K_YBRA) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR444) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR422) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR420) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR410));
}
static gboolean
gst_openjpeg_dec_is_mono (const gchar * sampling)
{
return !g_strcmp0 (sampling, GST_RTP_J2K_GRAYSCALE);
}
static GstStaticPadTemplate gst_openjpeg_dec_sink_template = static GstStaticPadTemplate gst_openjpeg_dec_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-j2c, " GST_STATIC_CAPS ("image/x-j2c, "
GST_RTP_J2K_SAMPLING_LIST "; " GST_JPEG2000_SAMPLING_LIST "; "
"image/x-jpc, " GST_RTP_J2K_SAMPLING_LIST "; " "image/jp2") "image/x-jpc, " GST_JPEG2000_SAMPLING_LIST "; " "image/jp2")
); );
static GstStaticPadTemplate gst_openjpeg_dec_src_template = static GstStaticPadTemplate gst_openjpeg_dec_src_template =
@ -144,7 +116,7 @@ gst_openjpeg_dec_init (GstOpenJPEGDec * self)
#ifdef HAVE_OPENJPEG_1 #ifdef HAVE_OPENJPEG_1
self->params.cp_limit_decoding = NO_LIMITATION; self->params.cp_limit_decoding = NO_LIMITATION;
#endif #endif
self->sampling = NULL; self->sampling = GST_JPEG2000_SAMPLING_NONE;
} }
static gboolean static gboolean
@ -174,11 +146,6 @@ gst_openjpeg_dec_stop (GstVideoDecoder * video_decoder)
self->input_state = NULL; self->input_state = NULL;
} }
if (self->sampling) {
g_free (self->sampling);
self->sampling = NULL;
}
GST_DEBUG_OBJECT (self, "Stopped"); GST_DEBUG_OBJECT (self, "Stopped");
return TRUE; return TRUE;
@ -210,18 +177,17 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
} }
if (self->sampling)
g_free (self->sampling); self->sampling =
self->sampling = g_strdup (gst_structure_get_string (s, "sampling")); gst_jpeg2000_sampling_from_string (gst_structure_get_string (s,
/* note: self->sampling may be NULL, for case of JP2 */ "sampling"));
if (self->sampling) { if (gst_jpeg2000_sampling_is_rgb (self->sampling))
if (gst_openjpeg_dec_is_rgb (self->sampling)) self->color_space = OPJ_CLRSPC_SRGB;
self->color_space = OPJ_CLRSPC_SRGB; else if (gst_jpeg2000_sampling_is_mono (self->sampling))
else if (gst_openjpeg_dec_is_mono (self->sampling)) self->color_space = OPJ_CLRSPC_GRAY;
self->color_space = OPJ_CLRSPC_GRAY; else if (gst_jpeg2000_sampling_is_yuv (self->sampling))
else if (gst_openjpeg_dec_is_yuv (self->sampling)) self->color_space = OPJ_CLRSPC_SYCC;
self->color_space = OPJ_CLRSPC_SYCC;
}
self->ncomps = 0; self->ncomps = 0;
gst_structure_get_int (s, "num-components", &self->ncomps); gst_structure_get_int (s, "num-components", &self->ncomps);
@ -233,10 +199,10 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
} }
static gboolean static gboolean
reverse_rgb_channels (const gchar * sampling) reverse_rgb_channels (GstJPEG2000Sampling sampling)
{ {
return (!g_strcmp0 (sampling, GST_RTP_J2K_BGR) return sampling == GST_JPEG2000_SAMPLING_BGR
|| !g_strcmp0 (sampling, GST_RTP_J2K_BGRA)); || sampling == GST_JPEG2000_SAMPLING_BGRA;
} }
static void static void

View file

@ -24,6 +24,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst-libs/gst/codecparsers/gstjpeg2000sampling.h>
#include "gstopenjpeg.h" #include "gstopenjpeg.h"
@ -54,7 +55,7 @@ struct _GstOpenJPEGDec
OPJ_CODEC_FORMAT codec_format; OPJ_CODEC_FORMAT codec_format;
gboolean is_jp2c; gboolean is_jp2c;
OPJ_COLOR_SPACE color_space; OPJ_COLOR_SPACE color_space;
gchar *sampling; GstJPEG2000Sampling sampling;
gint ncomps; gint ncomps;
void (*fill_frame) (GstVideoFrame *frame, opj_image_t * image); void (*fill_frame) (GstVideoFrame *frame, opj_image_t * image);

View file

@ -25,7 +25,7 @@
#endif #endif
#include "gstopenjpegenc.h" #include "gstopenjpegenc.h"
#include "../../gst/videoparsers/gstjpeg2000sampling.h" #include <gst-libs/gst/codecparsers/gstjpeg2000sampling.h>
#include <string.h> #include <string.h>
@ -116,14 +116,14 @@ static GstStaticPadTemplate gst_openjpeg_enc_src_template =
"width = (int) [1, MAX], " "width = (int) [1, MAX], "
"height = (int) [1, MAX], " "height = (int) [1, MAX], "
"num-components = (int) [1, 4], " "num-components = (int) [1, 4], "
GST_RTP_J2K_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }; " GST_JPEG2000_COLORSPACE_LIST "; "
"image/x-jpc, " "image/x-jpc, "
"width = (int) [1, MAX], " "width = (int) [1, MAX], "
"height = (int) [1, MAX], " "height = (int) [1, MAX], "
"num-components = (int) [1, 4], " "num-components = (int) [1, 4], "
GST_RTP_J2K_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }; " GST_JPEG2000_COLORSPACE_LIST "; "
"image/jp2, " "width = (int) [1, MAX], " "height = (int) [1, MAX]") "image/jp2, " "width = (int) [1, MAX], " "height = (int) [1, MAX]")
); );
@ -561,7 +561,7 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
GstCaps *allowed_caps, *caps; GstCaps *allowed_caps, *caps;
GstStructure *s; GstStructure *s;
const gchar *colorspace = NULL; const gchar *colorspace = NULL;
const gchar *sampling = NULL; GstJPEG2000Sampling sampling = GST_JPEG2000_SAMPLING_NONE;
gint ncomps; gint ncomps;
GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps); GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
@ -640,38 +640,38 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
switch (state->info.finfo->format) { switch (state->info.finfo->format) {
case GST_VIDEO_FORMAT_ARGB64: case GST_VIDEO_FORMAT_ARGB64:
case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ARGB:
sampling = GST_RTP_J2K_RGBA; sampling = GST_JPEG2000_SAMPLING_RGBA;
break; break;
case GST_VIDEO_FORMAT_AYUV64: case GST_VIDEO_FORMAT_AYUV64:
case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV:
sampling = GST_RTP_J2K_YBRA; sampling = GST_JPEG2000_SAMPLING_YBRA4444_EXT;
break; break;
case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_xRGB:
sampling = GST_RTP_J2K_RGB; sampling = GST_JPEG2000_COLORSPACE_RGB;
break; break;
case GST_VIDEO_FORMAT_Y444_10LE: case GST_VIDEO_FORMAT_Y444_10LE:
case GST_VIDEO_FORMAT_Y444_10BE: case GST_VIDEO_FORMAT_Y444_10BE:
case GST_VIDEO_FORMAT_Y444: case GST_VIDEO_FORMAT_Y444:
sampling = GST_RTP_J2K_YBR444; sampling = GST_JPEG2000_SAMPLING_YBR444;
break; break;
case GST_VIDEO_FORMAT_I422_10LE: case GST_VIDEO_FORMAT_I422_10LE:
case GST_VIDEO_FORMAT_I422_10BE: case GST_VIDEO_FORMAT_I422_10BE:
case GST_VIDEO_FORMAT_Y42B: case GST_VIDEO_FORMAT_Y42B:
sampling = GST_RTP_J2K_YBR422; sampling = GST_JPEG2000_SAMPLING_YBR422;
break; break;
case GST_VIDEO_FORMAT_YUV9: case GST_VIDEO_FORMAT_YUV9:
sampling = GST_RTP_J2K_YBR410; sampling = GST_JPEG2000_SAMPLING_YBR410;
break; break;
case GST_VIDEO_FORMAT_I420_10LE: case GST_VIDEO_FORMAT_I420_10LE:
case GST_VIDEO_FORMAT_I420_10BE: case GST_VIDEO_FORMAT_I420_10BE:
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
sampling = GST_RTP_J2K_YBR420; sampling = GST_JPEG2000_SAMPLING_YBR420;
break; break;
case GST_VIDEO_FORMAT_GRAY8: case GST_VIDEO_FORMAT_GRAY8:
case GST_VIDEO_FORMAT_GRAY16_LE: case GST_VIDEO_FORMAT_GRAY16_LE:
case GST_VIDEO_FORMAT_GRAY16_BE: case GST_VIDEO_FORMAT_GRAY16_BE:
sampling = GST_RTP_J2K_GRAYSCALE; sampling = GST_JPEG2000_SAMPLING_GRAYSCALE;
break; break;
default: default:
break; break;
@ -688,10 +688,10 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
} else } else
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
if (sampling) { if (sampling != GST_JPEG2000_SAMPLING_NONE) {
caps = gst_caps_new_simple (gst_structure_get_name (s), caps = gst_caps_new_simple (gst_structure_get_name (s),
"colorspace", G_TYPE_STRING, colorspace, "colorspace", G_TYPE_STRING, colorspace,
"sampling", G_TYPE_STRING, sampling, "sampling", G_TYPE_STRING, gst_jpeg2000_sampling_to_string (sampling),
"num-components", G_TYPE_INT, ncomps, NULL); "num-components", G_TYPE_INT, ncomps, NULL);
} else { } else {
caps = gst_caps_new_simple (gst_structure_get_name (s), caps = gst_caps_new_simple (gst_structure_get_name (s),

View file

@ -6,6 +6,7 @@ libgstcodecparsers_@GST_API_VERSION@_la_SOURCES = \
parserutils.c nalutils.c dboolhuff.c vp8utils.c \ parserutils.c nalutils.c dboolhuff.c vp8utils.c \
gstjpegparser.c \ gstjpegparser.c \
gstmpegvideometa.c \ gstmpegvideometa.c \
gstjpeg2000sampling.c \
gstvp9parser.c vp9utils.c gstvp9parser.c vp9utils.c
libgstcodecparsers_@GST_API_VERSION@includedir = \ libgstcodecparsers_@GST_API_VERSION@includedir = \
@ -18,6 +19,7 @@ libgstcodecparsers_@GST_API_VERSION@include_HEADERS = \
gsth265parser.h gstvp8parser.h gstvp8rangedecoder.h \ gsth265parser.h gstvp8parser.h gstvp8rangedecoder.h \
gstjpegparser.h \ gstjpegparser.h \
gstmpegvideometa.h \ gstmpegvideometa.h \
gstjpeg2000sampling.h \
gstvp9parser.h gstvp9parser.h
libgstcodecparsers_@GST_API_VERSION@_la_CFLAGS = \ libgstcodecparsers_@GST_API_VERSION@_la_CFLAGS = \

View file

@ -0,0 +1,123 @@
/* GStreamer JPEG 2000 Sampling
* Copyright (C) <2016> Grok Image Compression Inc.
* @author Aaron Boxer <boxerab@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*/
/**
* SECTION:gstjpeg2000sampling
* @short_description: Manage JPEG 2000 sampling and colorspace fields
*
*/
#include "gstjpeg2000sampling.h"
/* string values corresponding to GstJPEG2000Sampling enums */
static const gchar *gst_jpeg2000_sampling_strings[] = {
"RGB",
"BGR",
"RGBA",
"BGRA",
"YCbCr-4:4:4",
"YCbCr-4:2:2",
"YCbCr-4:2:0",
"YCbCr-4:1:0",
"GRAYSCALE",
"YCbCrA-4:4:4:4",
};
/* convert string to GstJPEG2000Sampling enum */
GstJPEG2000Sampling
gst_jpeg2000_sampling_from_string (const gchar * sampling_string)
{
GstJPEG2000Sampling i;
g_return_val_if_fail (sampling_string != NULL, GST_JPEG2000_SAMPLING_NONE);
for (i = 0; i < sizeof (gst_jpeg2000_sampling_strings); ++i) {
if (!g_strcmp0 (sampling_string, gst_jpeg2000_sampling_strings[i]))
return (i + 1);
}
return GST_JPEG2000_SAMPLING_NONE;
}
/* convert GstJPEG2000Sampling enum to string */
const gchar *
gst_jpeg2000_sampling_to_string (GstJPEG2000Sampling sampling)
{
g_return_val_if_fail (sampling > 0
&& sampling <= sizeof (gst_jpeg2000_sampling_strings), NULL);
return gst_jpeg2000_sampling_strings[sampling - 1];
}
/* check if @sampling is in RGB color space */
gboolean
gst_jpeg2000_sampling_is_rgb (GstJPEG2000Sampling sampling)
{
return sampling == GST_JPEG2000_SAMPLING_RGB ||
sampling == GST_JPEG2000_SAMPLING_RGBA ||
sampling == GST_JPEG2000_SAMPLING_BGR
|| sampling == GST_JPEG2000_SAMPLING_BGRA;
}
/* check if @sampling is in YUV color space */
gboolean
gst_jpeg2000_sampling_is_yuv (GstJPEG2000Sampling sampling)
{
return sampling = GST_JPEG2000_SAMPLING_YBRA4444_EXT ||
sampling == GST_JPEG2000_SAMPLING_YBR444 ||
sampling == GST_JPEG2000_SAMPLING_YBR422 ||
sampling == GST_JPEG2000_SAMPLING_YBR420
|| sampling == GST_JPEG2000_SAMPLING_YBR410;
}
/* check if @sampling is in GRAYSCALE color space */
gboolean
gst_jpeg2000_sampling_is_mono (GstJPEG2000Sampling sampling)
{
return sampling == GST_JPEG2000_SAMPLING_GRAYSCALE;
}
/* string values corresponding to GstJPEG2000Colorspace enums */
static const gchar *gst_jpeg2000_colorspace_strings[] = {
"sRGB",
"sYUV",
"GRAY",
};
/* convert GstJPEG2000Colorspace enum to string */
GstJPEG2000Colorspace
gst_jpeg2000_colorspace_from_string (const gchar * colorspace_string)
{
GstJPEG2000Colorspace i;
g_return_val_if_fail (colorspace_string != NULL,
GST_JPEG2000_COLORSPACE_NONE);
for (i = 0; i < sizeof (gst_jpeg2000_colorspace_strings); ++i) {
if (!g_strcmp0 (colorspace_string, gst_jpeg2000_colorspace_strings[i]))
return (i + 1);
}
return GST_JPEG2000_COLORSPACE_NONE;
}
/* convert string to GstJPEG2000Colorspace enum */
const gchar *
gst_jpeg2000_colorspace_to_string (GstJPEG2000Colorspace colorspace)
{
g_return_val_if_fail (colorspace >= 0
&& colorspace <= sizeof (gst_jpeg2000_colorspace_strings), NULL);
return gst_jpeg2000_colorspace_strings[colorspace - 1];
}

View file

@ -0,0 +1,92 @@
/* GStreamer JPEG 2000 Sampling
* Copyright (C) <2016> Grok Image Compression Inc.
* @author Aaron Boxer <boxerab@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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_JPEG2000_SAMPLING_H__
#define __GST_JPEG2000_SAMPLING_H__
#include <gst/gst.h>
/**
* GstJPEG2000Sampling:
* Sampling values from RF 5371 for JPEG 2000 over RTP : https://datatracker.ietf.org/doc/rfc5371/C
* Note: sampling extensions that are not listed in the RFC are signified by an _EXT at the end of the enum
*
* @GST_JPEG2000_SAMPLING_NONE: no sampling
* @GST_JPEG2000_SAMPLING_RGB: standard Red, Green, Blue color space.
* @GST_JPEG2000_SAMPLING_BGR: standard Blue, Green, Red color space.
* @GST_JPEG2000_SAMPLING_RGBA: standard Red, Green, Blue, Alpha color space.
* @GST_JPEG2000_SAMPLING_BGRA: standard Blue, Green, Red, Alpha color space.
* @GST_JPEG2000_SAMPLING_YCbCr-4:4:4: standard YCbCr color space; no subsampling.
* @GST_JPEG2000_SAMPLING_YCbCr-4:2:2: standard YCbCr color space; Cb and Cr are subsampled horizontally by 1/2.
* @GST_JPEG2000_SAMPLING_YCbCr-4:2:0: standard YCbCr color space; Cb and Cr are subsampled horizontally and vertically by 1/2.
* @GST_JPEG2000_SAMPLING_YCbCr-4:1:1: standard YCbCr color space; Cb and Cr are subsampled vertically by 1/4.
* @GST_JPEG2000_SAMPLING_GRAYSCALE: basically, a single component image of just multilevels of grey.
* @GST_JPEG2000_SAMPLING_YBRA4444_EXT: standard YCbCr color space, alpha channel, no subsampling,
*/
typedef enum
{
GST_JPEG2000_SAMPLING_NONE,
GST_JPEG2000_SAMPLING_RGB,
GST_JPEG2000_SAMPLING_BGR,
GST_JPEG2000_SAMPLING_RGBA,
GST_JPEG2000_SAMPLING_BGRA,
GST_JPEG2000_SAMPLING_YBR444,
GST_JPEG2000_SAMPLING_YBR422,
GST_JPEG2000_SAMPLING_YBR420,
GST_JPEG2000_SAMPLING_YBR410,
GST_JPEG2000_SAMPLING_GRAYSCALE,
GST_JPEG2000_SAMPLING_YBRA4444_EXT
} GstJPEG2000Sampling;
/* GST_JPEG2000_SAMPLING_LIST: sampling strings in list form, for use in caps */
#define GST_JPEG2000_SAMPLING_LIST "sampling = (string) {\"RGB\", \"BGR\", \"RGBA\", \"BGRA\", \"YCbCr-4:4:4\", \"YCbCr-4:2:2\", \"YCbCr-4:2:0\", \"YCbCr-4:1:1\", \"GRAYSCALE\" , \"YCbCrA-4:4:4:4\"}"
const gchar *gst_jpeg2000_sampling_to_string (GstJPEG2000Sampling sampling);
GstJPEG2000Sampling gst_jpeg2000_sampling_from_string (const gchar *
sampling_string);
gboolean gst_jpeg2000_sampling_is_rgb (GstJPEG2000Sampling sampling);
gboolean gst_jpeg2000_sampling_is_yuv (GstJPEG2000Sampling sampling);
gboolean gst_jpeg2000_sampling_is_mono (GstJPEG2000Sampling sampling);
/**
* GstJPEG2000Colorspace:
* @GST_JPEG2000_COLORSPACE_NONE: no color space
* @GST_JPEG2000_COLORSPACE_RGB: standard RGB color space
* @GST_JPEG2000_COLORSPACE_YUV: standard YUV color space
* @GST_JPEG2000_COLORSPACE_GRAY: monochrome color space
*/
typedef enum
{
GST_JPEG2000_COLORSPACE_NONE,
GST_JPEG2000_COLORSPACE_RGB,
GST_JPEG2000_COLORSPACE_YUV,
GST_JPEG2000_COLORSPACE_GRAY
} GstJPEG2000Colorspace;
const gchar *gst_jpeg2000_colorspace_to_string (GstJPEG2000Colorspace
colorspace);
GstJPEG2000Colorspace gst_jpeg2000_colorspace_from_string (const gchar *
colorspace_string);
/* GST_JPEG2000_COLORSPACE_LIST: color space strings in list form, for use in caps */
#define GST_JPEG2000_COLORSPACE_LIST "colorspace = (string) { \"sRGB\", \"sYUV\", \"GRAY\" }"
#endif

View file

@ -31,7 +31,6 @@ noinst_HEADERS = gsth263parse.h h263parse.h \
gsth264parse.h gstmpegvideoparse.h \ gsth264parse.h gstmpegvideoparse.h \
gstmpeg4videoparse.h \ gstmpeg4videoparse.h \
gstjpeg2000parse.h \ gstjpeg2000parse.h \
gstjpeg2000sampling.h \
gstpngparse.h \ gstpngparse.h \
gstvc1parse.h \ gstvc1parse.h \
gsth265parse.h gsth265parse.h

View file

@ -26,44 +26,19 @@
#include <gst/base/base.h> #include <gst/base/base.h>
/* convenience methods */
static gboolean
gst_jpeg2000_parse_is_rgb (const gchar * sampling)
{
return (!g_strcmp0 (sampling, GST_RTP_J2K_RGB) ||
!g_strcmp0 (sampling, GST_RTP_J2K_RGBA) ||
!g_strcmp0 (sampling, GST_RTP_J2K_BGR) ||
!g_strcmp0 (sampling, GST_RTP_J2K_BGRA));
}
static gboolean
gst_jpeg2000_parse_is_yuv (const gchar * sampling)
{
return (!g_strcmp0 (sampling, GST_RTP_J2K_YBRA) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR444) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR422) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR420) ||
!g_strcmp0 (sampling, GST_RTP_J2K_YBR410));
}
static gboolean
gst_jpeg2000_parse_is_mono (const gchar * sampling)
{
return !g_strcmp0 (sampling, GST_RTP_J2K_GRAYSCALE);
}
static void static void
gst_jpeg2000_parse_get_subsampling (const gchar * sampling, guint8 * dx, gst_jpeg2000_parse_get_subsampling (GstJPEG2000Sampling sampling, guint8 * dx,
guint8 * dy) guint8 * dy)
{ {
*dx = 1; *dx = 1;
*dy = 1; *dy = 1;
if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR422)) { if (sampling == GST_JPEG2000_SAMPLING_YBR422) {
*dx = 2; *dx = 2;
} else if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR420)) { } else if (sampling == GST_JPEG2000_SAMPLING_YBR420) {
*dx = 2; *dx = 2;
*dy = 2; *dy = 2;
} else if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR410)) { } else if (sampling == GST_JPEG2000_SAMPLING_YBR410) {
*dx = 4; *dx = 4;
*dy = 2; *dy = 2;
} }
@ -88,26 +63,25 @@ static GstStaticPadTemplate srctemplate =
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-jpc," GST_STATIC_CAPS ("image/x-jpc,"
" width = (int)[1, MAX], height = (int)[1, MAX]," " width = (int)[1, MAX], height = (int)[1, MAX],"
GST_RTP_J2K_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }, " GST_JPEG2000_COLORSPACE_LIST ","
" parsed = (boolean) true;" " parsed = (boolean) true;"
"image/x-j2c," "image/x-j2c,"
" width = (int)[1, MAX], height = (int)[1, MAX]," " width = (int)[1, MAX], height = (int)[1, MAX],"
GST_RTP_J2K_SAMPLING_LIST "," GST_JPEG2000_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }, " GST_JPEG2000_COLORSPACE_LIST "," " parsed = (boolean) true")
" parsed = (boolean) true")
); );
static GstStaticPadTemplate sinktemplate = static GstStaticPadTemplate sinktemplate =
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-jpc," GST_STATIC_CAPS ("image/x-jpc,"
GST_RTP_J2K_SAMPLING_LIST ";" GST_JPEG2000_SAMPLING_LIST ";"
"image/x-jpc, " "image/x-jpc, "
"colorspace = (string) { sRGB, sYUV, GRAY };" GST_JPEG2000_COLORSPACE_LIST ";"
"image/x-j2c," "image/x-j2c,"
GST_RTP_J2K_SAMPLING_LIST ";" GST_JPEG2000_SAMPLING_LIST ";"
"image/x-j2c, " "colorspace = (string) { sRGB, sYUV, GRAY }") "image/x-j2c, " GST_JPEG2000_COLORSPACE_LIST)
); );
#define parent_class gst_jpeg2000_parse_parent_class #define parent_class gst_jpeg2000_parse_parent_class
@ -155,8 +129,8 @@ gst_jpeg2000_parse_start (GstBaseParse * parse)
jpeg2000parse->width = 0; jpeg2000parse->width = 0;
jpeg2000parse->height = 0; jpeg2000parse->height = 0;
jpeg2000parse->sampling = NULL; jpeg2000parse->sampling = GST_JPEG2000_SAMPLING_NONE;
jpeg2000parse->colorspace = NULL; jpeg2000parse->colorspace = GST_JPEG2000_COLORSPACE_NONE;
jpeg2000parse->codec_format = GST_JPEG2000_PARSE_NO_CODEC; jpeg2000parse->codec_format = GST_JPEG2000_PARSE_NO_CODEC;
return TRUE; return TRUE;
} }
@ -212,16 +186,16 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
guint eoc_offset = 0; guint eoc_offset = 0;
GstCaps *current_caps = NULL; GstCaps *current_caps = NULL;
GstStructure *current_caps_struct = NULL; GstStructure *current_caps_struct = NULL;
const gchar *colorspace = NULL; GstJPEG2000Colorspace colorspace = GST_JPEG2000_COLORSPACE_NONE;
guint x0, y0, x1, y1; guint x0, y0, x1, y1;
guint width = 0, height = 0; guint width = 0, height = 0;
guint8 dx[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS]; guint8 dx[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS];
guint8 dy[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS]; guint8 dy[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS];
guint16 numcomps; guint16 numcomps;
guint16 compno; guint16 compno;
const char *parsed_sampling = NULL; GstJPEG2000Sampling parsed_sampling = GST_JPEG2000_SAMPLING_NONE;
const char *sink_sampling = NULL; GstJPEG2000Sampling sink_sampling = GST_JPEG2000_SAMPLING_NONE;
const char *source_sampling = NULL; GstJPEG2000Sampling source_sampling = GST_JPEG2000_SAMPLING_NONE;
guint magic_offset = 0; guint magic_offset = 0;
guint j2c_box_id_offset = 0; guint j2c_box_id_offset = 0;
guint num_prefix_bytes = 0; /* number of bytes to skip before actual code stream */ guint num_prefix_bytes = 0; /* number of bytes to skip before actual code stream */
@ -367,8 +341,12 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
goto beach; goto beach;
} }
colorspace = gst_structure_get_string (current_caps_struct, "colorspace"); colorspace =
sink_sampling = gst_structure_get_string (current_caps_struct, "sampling"); gst_jpeg2000_colorspace_from_string (gst_structure_get_string
(current_caps_struct, "colorspace"));
sink_sampling =
gst_jpeg2000_sampling_from_string (gst_structure_get_string
(current_caps_struct, "sampling"));
for (compno = 0; compno < numcomps; ++compno) { for (compno = 0; compno < numcomps; ++compno) {
@ -396,30 +374,32 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
"Chroma channel sub-sampling factors are not equal"); "Chroma channel sub-sampling factors are not equal");
} }
for (compno = 0; compno < numcomps; ++compno) { for (compno = 0; compno < numcomps; ++compno) {
if (colorspace && g_strcmp0 (colorspace, "sYUV") && (dx[compno] > 1 if (colorspace != GST_JPEG2000_COLORSPACE_NONE
|| dy[compno] > 1)) { && (colorspace != GST_JPEG2000_COLORSPACE_YUV)
&& (dx[compno] > 1 || dy[compno] > 1)) {
GST_WARNING_OBJECT (jpeg2000parse, GST_WARNING_OBJECT (jpeg2000parse,
"Sub-sampled RGB or monochrome color spaces"); "Sub-sampled RGB or monochrome color spaces");
} }
if (sink_sampling) { if (sink_sampling != GST_JPEG2000_SAMPLING_NONE) {
guint8 dx_caps, dy_caps; guint8 dx_caps, dy_caps;
gst_jpeg2000_parse_get_subsampling (sink_sampling, &dx_caps, &dy_caps); gst_jpeg2000_parse_get_subsampling (sink_sampling, &dx_caps, &dy_caps);
if (dx_caps != dx[compno] || dy_caps != dy[compno]) { if (dx_caps != dx[compno] || dy_caps != dy[compno]) {
const gchar *inferred_colorspace = NULL; GstJPEG2000Colorspace inferred_colorspace =
GST_JPEG2000_COLORSPACE_NONE;
GST_WARNING_OBJECT (jpeg2000parse, GST_WARNING_OBJECT (jpeg2000parse,
"Sink caps sub-sampling %d,%d for channel %d does not match stream sub-sampling %d,%d", "Sink caps sub-sampling %d,%d for channel %d does not match stream sub-sampling %d,%d",
dx_caps, dy_caps, compno, dx[compno], dy[compno]); dx_caps, dy_caps, compno, dx[compno], dy[compno]);
/* try to guess correct color space */ /* try to guess correct color space */
if (gst_jpeg2000_parse_is_mono (sink_sampling)) if (gst_jpeg2000_sampling_is_mono (sink_sampling))
inferred_colorspace = "GRAY"; inferred_colorspace = GST_JPEG2000_COLORSPACE_GRAY;
else if (gst_jpeg2000_parse_is_rgb (sink_sampling)) else if (gst_jpeg2000_sampling_is_rgb (sink_sampling))
inferred_colorspace = "sRGB"; inferred_colorspace = GST_JPEG2000_COLORSPACE_RGB;
else if (gst_jpeg2000_parse_is_yuv (sink_sampling)) else if (gst_jpeg2000_sampling_is_yuv (sink_sampling))
inferred_colorspace = "sYUV"; inferred_colorspace = GST_JPEG2000_COLORSPACE_YUV;
else if (colorspace) else if (colorspace)
inferred_colorspace = colorspace; inferred_colorspace = colorspace;
if (inferred_colorspace) { if (inferred_colorspace != GST_JPEG2000_COLORSPACE_NONE) {
sink_sampling = NULL; sink_sampling = GST_JPEG2000_SAMPLING_NONE;
colorspace = inferred_colorspace; colorspace = inferred_colorspace;
break; break;
} else { } else {
@ -435,11 +415,11 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
/*************************************/ /*************************************/
/* if colorspace is present, we can work out the parsed_sampling field */ /* if colorspace is present, we can work out the parsed_sampling field */
if (colorspace) { if (colorspace != GST_JPEG2000_COLORSPACE_NONE) {
if (!g_strcmp0 (colorspace, "sYUV")) { if (colorspace == GST_JPEG2000_COLORSPACE_YUV) {
if (numcomps == 4) { if (numcomps == 4) {
guint i; guint i;
parsed_sampling = GST_RTP_J2K_YBRA; parsed_sampling = GST_JPEG2000_SAMPLING_YBRA4444_EXT;
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
if (dx[i] > 1 || dy[i] > 1) { if (dx[i] > 1 || dy[i] > 1) {
GST_WARNING_OBJECT (jpeg2000parse, "Sub-sampled YUVA images"); GST_WARNING_OBJECT (jpeg2000parse, "Sub-sampled YUVA images");
@ -448,41 +428,45 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
} else if (numcomps == 3) { } else if (numcomps == 3) {
/* use sub-sampling from U chroma channel */ /* use sub-sampling from U chroma channel */
if (dx[1] == 1 && dy[1] == 1) { if (dx[1] == 1 && dy[1] == 1) {
parsed_sampling = GST_RTP_J2K_YBR444; parsed_sampling = GST_JPEG2000_SAMPLING_YBR444;
} else if (dx[1] == 2 && dy[1] == 2) { } else if (dx[1] == 2 && dy[1] == 2) {
parsed_sampling = GST_RTP_J2K_YBR420; parsed_sampling = GST_JPEG2000_SAMPLING_YBR420;
} else if (dx[1] == 4 && dy[1] == 2) { } else if (dx[1] == 4 && dy[1] == 2) {
parsed_sampling = GST_RTP_J2K_YBR410; parsed_sampling = GST_JPEG2000_SAMPLING_YBR410;
} else if (dx[1] == 2 && dy[1] == 1) { } else if (dx[1] == 2 && dy[1] == 1) {
parsed_sampling = GST_RTP_J2K_YBR422; parsed_sampling = GST_JPEG2000_SAMPLING_YBR422;
} else { } else {
GST_WARNING_OBJECT (jpeg2000parse, GST_WARNING_OBJECT (jpeg2000parse,
"Unsupported sub-sampling factors %d,%d", dx[1], dy[1]); "Unsupported sub-sampling factors %d,%d", dx[1], dy[1]);
/* best effort */ /* best effort */
parsed_sampling = GST_RTP_J2K_YBR444; parsed_sampling = GST_JPEG2000_SAMPLING_YBR444;
} }
} }
} else if (!g_strcmp0 (colorspace, "GRAY")) { } else if (colorspace == GST_JPEG2000_COLORSPACE_GRAY) {
parsed_sampling = GST_RTP_J2K_GRAYSCALE; parsed_sampling = GST_JPEG2000_SAMPLING_GRAYSCALE;
} else { } else {
parsed_sampling = (numcomps == 4) ? GST_RTP_J2K_RGBA : GST_RTP_J2K_RGB; parsed_sampling =
(numcomps ==
4) ? GST_JPEG2000_SAMPLING_RGBA : GST_JPEG2000_COLORSPACE_RGB;
} }
} else { } else {
if (gst_jpeg2000_parse_is_mono (sink_sampling)) { if (gst_jpeg2000_sampling_is_mono (sink_sampling)) {
colorspace = "GRAY"; colorspace = GST_JPEG2000_COLORSPACE_GRAY;
} else if (gst_jpeg2000_parse_is_rgb (sink_sampling)) { } else if (gst_jpeg2000_sampling_is_rgb (sink_sampling)) {
colorspace = "sRGB"; colorspace = GST_JPEG2000_COLORSPACE_RGB;
} else { } else {
/* best effort */ /* best effort */
colorspace = "sYUV"; colorspace = GST_JPEG2000_COLORSPACE_YUV;
} }
} }
/* now we can set the source caps, if something has changed */ /* now we can set the source caps, if something has changed */
source_sampling = sink_sampling ? sink_sampling : parsed_sampling; source_sampling =
if (width != jpeg2000parse->width || sink_sampling !=
height != jpeg2000parse->height || GST_JPEG2000_SAMPLING_NONE ? sink_sampling : parsed_sampling;
g_strcmp0 (jpeg2000parse->sampling, source_sampling) || if (width != jpeg2000parse->width || height != jpeg2000parse->height
g_strcmp0 (jpeg2000parse->colorspace, colorspace)) { || jpeg2000parse->sampling != source_sampling
|| jpeg2000parse->colorspace != colorspace) {
gint fr_num = 0, fr_denom = 0; gint fr_num = 0, fr_denom = 0;
jpeg2000parse->width = width; jpeg2000parse->width = width;
@ -493,8 +477,9 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse,
src_caps = src_caps =
gst_caps_new_simple (gst_structure_get_name (current_caps_struct), gst_caps_new_simple (gst_structure_get_name (current_caps_struct),
"width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height,
"colorspace", G_TYPE_STRING, colorspace, "colorspace", G_TYPE_STRING,
"sampling", G_TYPE_STRING, source_sampling, NULL); gst_jpeg2000_colorspace_to_string (colorspace), "sampling",
G_TYPE_STRING, gst_jpeg2000_sampling_to_string (source_sampling), NULL);
if (gst_structure_get_fraction (current_caps_struct, "framerate", &fr_num, if (gst_structure_get_fraction (current_caps_struct, "framerate", &fr_num,
&fr_denom)) { &fr_denom)) {

View file

@ -24,7 +24,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstadapter.h> #include <gst/base/gstadapter.h>
#include <gst/base/gstbaseparse.h> #include <gst/base/gstbaseparse.h>
#include "gstjpeg2000sampling.h" #include <gst-libs/gst/codecparsers/gstjpeg2000sampling.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_JPEG2000_PARSE \ #define GST_TYPE_JPEG2000_PARSE \
@ -62,8 +62,8 @@ struct _GstJPEG2000Parse
guint width; guint width;
guint height; guint height;
const gchar *sampling; GstJPEG2000Sampling sampling;
const gchar *colorspace; GstJPEG2000Colorspace colorspace;
GstJPEG2000ParseFormats codec_format; GstJPEG2000ParseFormats codec_format;
}; };

View file

@ -1,86 +0,0 @@
/* GStreamer JPEG 2000 Sampling
* Copyright (C) <2016> Grok Image Compression Inc.
* @author Aaron Boxer <boxerab@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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_JPEG2000_SAMPLING_H__
#define __GST_JPEG2000_SAMPLING_H__
/* Sampling values from RF 5371 for JPEG 2000 over RTP : https://datatracker.ietf.org/doc/rfc5371/C
RGB: standard Red, Green, Blue color space.
BGR: standard Blue, Green, Red color space.
RGBA: standard Red, Green, Blue, Alpha color space.
BGRA: standard Blue, Green, Red, Alpha color space.
YCbCr-4:4:4: standard YCbCr color space; no subsampling.
YCbCr-4:2:2: standard YCbCr color space; Cb and Cr are subsampled horizontally by 1/2.
YCbCr-4:2:0: standard YCbCr color space; Cb and Cr are subsampled horizontally and vertically by 1/2.
YCbCr-4:1:1: standard YCbCr color space; Cb and Cr are subsampled vertically by 1/4.
GRAYSCALE: basically, a single component image of just multilevels of grey.
*/
#define GST_RTP_J2K_RGB "RGB"
#define GST_RTP_J2K_BGR "BGR"
#define GST_RTP_J2K_RGBA "RGBA"
#define GST_RTP_J2K_BGRA "BGRA"
#define GST_RTP_J2K_YBRA "YCbCrA"
#define GST_RTP_J2K_YBR444 "YCbCr-4:4:4"
#define GST_RTP_J2K_YBR422 "YCbCr-4:2:2"
#define GST_RTP_J2K_YBR420 "YCbCr-4:2:0"
#define GST_RTP_J2K_YBR410 "YCbCr-4:1:0"
#define GST_RTP_J2K_GRAYSCALE "GRAYSCALE"
#define GST_RTP_J2K_SAMPLING_LIST "sampling = (string) {\"RGB\", \"BGR\", \"RGBA\", \"BGRA\", \"YCbCrA\", \"YCbCr-4:4:4\", \"YCbCr-4:2:2\", \"YCbCr-4:2:0\", \"YCbCr-4:1:1\", \"GRAYSCALE\"}"
/*
* GstJ2KMarker:
* @GST_J2K_MARKER: Prefix for JPEG 2000 marker
* @GST_J2K_MARKER_SOC: Start of code stream
* @GST_J2K_MARKER_SOT: Start of tile
* @GST_J2K_MARKER_EOC: End of code stream
*
* Identifiers for markers in JPEG 2000 code streams
*/
typedef enum
{
GST_J2K_MARKER = 0xFF,
GST_J2K_MARKER_SOC = 0x4F,
GST_J2K_MARKER_SIZ = 0x51,
GST_J2K_MARKER_COD = 0x52,
GST_J2K_MARKER_SOT = 0x90,
GST_J2K_MARKER_SOP = 0x91,
GST_J2K_MARKER_EPH = 0x92,
GST_J2K_MARKER_SOD = 0x93,
GST_J2K_MARKER_EOC = 0xD9
} GstJ2KMarker;
#endif