diff options
author | Aaron Boxer <boxerab@gmail.com> | 2016-06-21 12:41:46 -0400 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-06-24 11:23:31 +0300 |
commit | e7e6a3579d7ec3b61c80040c679c48c216fb7065 (patch) | |
tree | ec228601c62ac75235d708b6f627d8f22630614d /gst/videoparsers | |
parent | 539c032345e3f063b5c166262aa7f7346a0d1e2f (diff) | |
download | gstreamer-plugins-bad-e7e6a3579d7ec3b61c80040c679c48c216fb7065.tar.gz |
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
Diffstat (limited to 'gst/videoparsers')
-rw-r--r-- | gst/videoparsers/Makefile.am | 1 | ||||
-rw-r--r-- | gst/videoparsers/gstjpeg2000parse.c | 147 | ||||
-rw-r--r-- | gst/videoparsers/gstjpeg2000parse.h | 6 | ||||
-rw-r--r-- | gst/videoparsers/gstjpeg2000sampling.h | 86 |
4 files changed, 69 insertions, 171 deletions
diff --git a/gst/videoparsers/Makefile.am b/gst/videoparsers/Makefile.am index 588c78137..f81cc0ee3 100644 --- a/gst/videoparsers/Makefile.am +++ b/gst/videoparsers/Makefile.am @@ -31,7 +31,6 @@ noinst_HEADERS = gsth263parse.h h263parse.h \ gsth264parse.h gstmpegvideoparse.h \ gstmpeg4videoparse.h \ gstjpeg2000parse.h \ - gstjpeg2000sampling.h \ gstpngparse.h \ gstvc1parse.h \ gsth265parse.h diff --git a/gst/videoparsers/gstjpeg2000parse.c b/gst/videoparsers/gstjpeg2000parse.c index 003874797..1aa6e6d0f 100644 --- a/gst/videoparsers/gstjpeg2000parse.c +++ b/gst/videoparsers/gstjpeg2000parse.c @@ -26,44 +26,19 @@ #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 -gst_jpeg2000_parse_get_subsampling (const gchar * sampling, guint8 * dx, +gst_jpeg2000_parse_get_subsampling (GstJPEG2000Sampling sampling, guint8 * dx, guint8 * dy) { *dx = 1; *dy = 1; - if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR422)) { + if (sampling == GST_JPEG2000_SAMPLING_YBR422) { *dx = 2; - } else if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR420)) { + } else if (sampling == GST_JPEG2000_SAMPLING_YBR420) { *dx = 2; *dy = 2; - } else if (!g_strcmp0 (sampling, GST_RTP_J2K_YBR410)) { + } else if (sampling == GST_JPEG2000_SAMPLING_YBR410) { *dx = 4; *dy = 2; } @@ -88,26 +63,25 @@ static GstStaticPadTemplate srctemplate = GST_PAD_ALWAYS, GST_STATIC_CAPS ("image/x-jpc," " width = (int)[1, MAX], height = (int)[1, MAX]," - GST_RTP_J2K_SAMPLING_LIST "," - "colorspace = (string) { sRGB, sYUV, GRAY }, " + GST_JPEG2000_SAMPLING_LIST "," + GST_JPEG2000_COLORSPACE_LIST "," " parsed = (boolean) true;" "image/x-j2c," " width = (int)[1, MAX], height = (int)[1, MAX]," - GST_RTP_J2K_SAMPLING_LIST "," - "colorspace = (string) { sRGB, sYUV, GRAY }, " - " parsed = (boolean) true") + GST_JPEG2000_SAMPLING_LIST "," + GST_JPEG2000_COLORSPACE_LIST "," " parsed = (boolean) true") ); static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("image/x-jpc," - GST_RTP_J2K_SAMPLING_LIST ";" + GST_JPEG2000_SAMPLING_LIST ";" "image/x-jpc, " - "colorspace = (string) { sRGB, sYUV, GRAY };" + GST_JPEG2000_COLORSPACE_LIST ";" "image/x-j2c," - GST_RTP_J2K_SAMPLING_LIST ";" - "image/x-j2c, " "colorspace = (string) { sRGB, sYUV, GRAY }") + GST_JPEG2000_SAMPLING_LIST ";" + "image/x-j2c, " GST_JPEG2000_COLORSPACE_LIST) ); #define parent_class gst_jpeg2000_parse_parent_class @@ -155,8 +129,8 @@ gst_jpeg2000_parse_start (GstBaseParse * parse) jpeg2000parse->width = 0; jpeg2000parse->height = 0; - jpeg2000parse->sampling = NULL; - jpeg2000parse->colorspace = NULL; + jpeg2000parse->sampling = GST_JPEG2000_SAMPLING_NONE; + jpeg2000parse->colorspace = GST_JPEG2000_COLORSPACE_NONE; jpeg2000parse->codec_format = GST_JPEG2000_PARSE_NO_CODEC; return TRUE; } @@ -212,16 +186,16 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse, guint eoc_offset = 0; GstCaps *current_caps = NULL; GstStructure *current_caps_struct = NULL; - const gchar *colorspace = NULL; + GstJPEG2000Colorspace colorspace = GST_JPEG2000_COLORSPACE_NONE; guint x0, y0, x1, y1; guint width = 0, height = 0; guint8 dx[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS]; guint8 dy[GST_JPEG2000_PARSE_MAX_SUPPORTED_COMPONENTS]; guint16 numcomps; guint16 compno; - const char *parsed_sampling = NULL; - const char *sink_sampling = NULL; - const char *source_sampling = NULL; + GstJPEG2000Sampling parsed_sampling = GST_JPEG2000_SAMPLING_NONE; + GstJPEG2000Sampling sink_sampling = GST_JPEG2000_SAMPLING_NONE; + GstJPEG2000Sampling source_sampling = GST_JPEG2000_SAMPLING_NONE; guint magic_offset = 0; guint j2c_box_id_offset = 0; 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; } - colorspace = gst_structure_get_string (current_caps_struct, "colorspace"); - sink_sampling = gst_structure_get_string (current_caps_struct, "sampling"); + colorspace = + 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) { @@ -396,30 +374,32 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse, "Chroma channel sub-sampling factors are not equal"); } for (compno = 0; compno < numcomps; ++compno) { - if (colorspace && g_strcmp0 (colorspace, "sYUV") && (dx[compno] > 1 - || dy[compno] > 1)) { + if (colorspace != GST_JPEG2000_COLORSPACE_NONE + && (colorspace != GST_JPEG2000_COLORSPACE_YUV) + && (dx[compno] > 1 || dy[compno] > 1)) { GST_WARNING_OBJECT (jpeg2000parse, "Sub-sampled RGB or monochrome color spaces"); } - if (sink_sampling) { + if (sink_sampling != GST_JPEG2000_SAMPLING_NONE) { guint8 dx_caps, dy_caps; gst_jpeg2000_parse_get_subsampling (sink_sampling, &dx_caps, &dy_caps); 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, "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]); /* try to guess correct color space */ - if (gst_jpeg2000_parse_is_mono (sink_sampling)) - inferred_colorspace = "GRAY"; - else if (gst_jpeg2000_parse_is_rgb (sink_sampling)) - inferred_colorspace = "sRGB"; - else if (gst_jpeg2000_parse_is_yuv (sink_sampling)) - inferred_colorspace = "sYUV"; + if (gst_jpeg2000_sampling_is_mono (sink_sampling)) + inferred_colorspace = GST_JPEG2000_COLORSPACE_GRAY; + else if (gst_jpeg2000_sampling_is_rgb (sink_sampling)) + inferred_colorspace = GST_JPEG2000_COLORSPACE_RGB; + else if (gst_jpeg2000_sampling_is_yuv (sink_sampling)) + inferred_colorspace = GST_JPEG2000_COLORSPACE_YUV; else if (colorspace) inferred_colorspace = colorspace; - if (inferred_colorspace) { - sink_sampling = NULL; + if (inferred_colorspace != GST_JPEG2000_COLORSPACE_NONE) { + sink_sampling = GST_JPEG2000_SAMPLING_NONE; colorspace = inferred_colorspace; break; } 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) { - if (!g_strcmp0 (colorspace, "sYUV")) { + if (colorspace != GST_JPEG2000_COLORSPACE_NONE) { + if (colorspace == GST_JPEG2000_COLORSPACE_YUV) { if (numcomps == 4) { guint i; - parsed_sampling = GST_RTP_J2K_YBRA; + parsed_sampling = GST_JPEG2000_SAMPLING_YBRA4444_EXT; for (i = 0; i < 4; ++i) { if (dx[i] > 1 || dy[i] > 1) { GST_WARNING_OBJECT (jpeg2000parse, "Sub-sampled YUVA images"); @@ -448,41 +428,45 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse, } else if (numcomps == 3) { /* use sub-sampling from U chroma channel */ 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) { - parsed_sampling = GST_RTP_J2K_YBR420; + parsed_sampling = GST_JPEG2000_SAMPLING_YBR420; } 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) { - parsed_sampling = GST_RTP_J2K_YBR422; + parsed_sampling = GST_JPEG2000_SAMPLING_YBR422; } else { GST_WARNING_OBJECT (jpeg2000parse, "Unsupported sub-sampling factors %d,%d", dx[1], dy[1]); /* best effort */ - parsed_sampling = GST_RTP_J2K_YBR444; + parsed_sampling = GST_JPEG2000_SAMPLING_YBR444; } } - } else if (!g_strcmp0 (colorspace, "GRAY")) { - parsed_sampling = GST_RTP_J2K_GRAYSCALE; + } else if (colorspace == GST_JPEG2000_COLORSPACE_GRAY) { + parsed_sampling = GST_JPEG2000_SAMPLING_GRAYSCALE; } 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 { - if (gst_jpeg2000_parse_is_mono (sink_sampling)) { - colorspace = "GRAY"; - } else if (gst_jpeg2000_parse_is_rgb (sink_sampling)) { - colorspace = "sRGB"; + if (gst_jpeg2000_sampling_is_mono (sink_sampling)) { + colorspace = GST_JPEG2000_COLORSPACE_GRAY; + } else if (gst_jpeg2000_sampling_is_rgb (sink_sampling)) { + colorspace = GST_JPEG2000_COLORSPACE_RGB; } else { /* best effort */ - colorspace = "sYUV"; + colorspace = GST_JPEG2000_COLORSPACE_YUV; } } + /* now we can set the source caps, if something has changed */ - source_sampling = sink_sampling ? sink_sampling : parsed_sampling; - if (width != jpeg2000parse->width || - height != jpeg2000parse->height || - g_strcmp0 (jpeg2000parse->sampling, source_sampling) || - g_strcmp0 (jpeg2000parse->colorspace, colorspace)) { + source_sampling = + sink_sampling != + GST_JPEG2000_SAMPLING_NONE ? sink_sampling : parsed_sampling; + if (width != jpeg2000parse->width || height != jpeg2000parse->height + || jpeg2000parse->sampling != source_sampling + || jpeg2000parse->colorspace != colorspace) { gint fr_num = 0, fr_denom = 0; jpeg2000parse->width = width; @@ -493,8 +477,9 @@ gst_jpeg2000_parse_handle_frame (GstBaseParse * parse, src_caps = gst_caps_new_simple (gst_structure_get_name (current_caps_struct), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, - "colorspace", G_TYPE_STRING, colorspace, - "sampling", G_TYPE_STRING, source_sampling, NULL); + "colorspace", G_TYPE_STRING, + 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, &fr_denom)) { diff --git a/gst/videoparsers/gstjpeg2000parse.h b/gst/videoparsers/gstjpeg2000parse.h index fdcf4349a..e1230668e 100644 --- a/gst/videoparsers/gstjpeg2000parse.h +++ b/gst/videoparsers/gstjpeg2000parse.h @@ -24,7 +24,7 @@ #include <gst/gst.h> #include <gst/base/gstadapter.h> #include <gst/base/gstbaseparse.h> -#include "gstjpeg2000sampling.h" +#include <gst-libs/gst/codecparsers/gstjpeg2000sampling.h> G_BEGIN_DECLS #define GST_TYPE_JPEG2000_PARSE \ @@ -62,8 +62,8 @@ struct _GstJPEG2000Parse guint width; guint height; - const gchar *sampling; - const gchar *colorspace; + GstJPEG2000Sampling sampling; + GstJPEG2000Colorspace colorspace; GstJPEG2000ParseFormats codec_format; }; diff --git a/gst/videoparsers/gstjpeg2000sampling.h b/gst/videoparsers/gstjpeg2000sampling.h deleted file mode 100644 index e6334f275..000000000 --- a/gst/videoparsers/gstjpeg2000sampling.h +++ /dev/null @@ -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 |