summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Boxer <boxerab@gmail.com>2016-06-01 19:01:44 -0400
committerSebastian Dröge <sebastian@centricular.com>2016-06-07 15:24:32 +0300
commiteebb65e934eda77c9b73b1b47e113117b6157689 (patch)
tree2a1c0d92491c902baed51fbb9704073b4e1f01d2
parent851c89ded9c417c462868d287fdf3aefb128f8ac (diff)
downloadgstreamer-plugins-bad-eebb65e934eda77c9b73b1b47e113117b6157689.tar.gz
openjpeg: set sampling in the caps
https://bugzilla.gnome.org/show_bug.cgi?id=766236
-rw-r--r--ext/openjpeg/gstopenjpegenc.c78
-rw-r--r--gst/videoparsers/Makefile.am1
-rw-r--r--gst/videoparsers/gstjpeg2000sampling.h86
3 files changed, 153 insertions, 12 deletions
diff --git a/ext/openjpeg/gstopenjpegenc.c b/ext/openjpeg/gstopenjpegenc.c
index 7a6e93711..66023a858 100644
--- a/ext/openjpeg/gstopenjpegenc.c
+++ b/ext/openjpeg/gstopenjpegenc.c
@@ -25,6 +25,7 @@
#endif
#include "gstopenjpegenc.h"
+#include "gst/videoparsers/gstjpeg2000sampling.h"
#include <string.h>
@@ -115,11 +116,13 @@ static GstStaticPadTemplate gst_openjpeg_enc_src_template =
"width = (int) [1, MAX], "
"height = (int) [1, MAX], "
"num-components = (int) [1, 4], "
+ GST_RTP_J2K_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }; "
"image/x-jpc, "
"width = (int) [1, MAX], "
"height = (int) [1, MAX], "
"num-components = (int) [1, 4], "
+ GST_RTP_J2K_SAMPLING_LIST ","
"colorspace = (string) { sRGB, sYUV, GRAY }; "
"image/jp2, " "width = (int) [1, MAX], " "height = (int) [1, MAX]")
);
@@ -557,7 +560,8 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (encoder);
GstCaps *allowed_caps, *caps;
GstStructure *s;
- const gchar *colorspace;
+ const gchar *colorspace = NULL;
+ const gchar *sampling = NULL;
gint ncomps;
GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
@@ -588,6 +592,7 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
ncomps = 4;
break;
case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_AYUV:
self->fill_image = fill_image_packed8_4;
ncomps = 4;
break;
@@ -608,10 +613,6 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
self->fill_image = fill_image_planar16_3;
ncomps = 3;
break;
- case GST_VIDEO_FORMAT_AYUV:
- self->fill_image = fill_image_packed8_3;
- ncomps = 3;
- break;
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y42B:
case GST_VIDEO_FORMAT_I420:
@@ -633,18 +634,71 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
g_assert_not_reached ();
}
- if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_YUV))
+
+ /* sampling */
+ /* note: encoder re-orders channels so that alpha channel is encoded as the last channel */
+ switch (state->info.finfo->format) {
+ case GST_VIDEO_FORMAT_ARGB64:
+ case GST_VIDEO_FORMAT_ARGB:
+ sampling = GST_RTP_J2K_RGBA;
+ break;
+ case GST_VIDEO_FORMAT_AYUV64:
+ case GST_VIDEO_FORMAT_AYUV:
+ sampling = GST_RTP_J2K_YBRA;
+ break;
+ case GST_VIDEO_FORMAT_xRGB:
+ sampling = GST_RTP_J2K_RGB;
+ break;
+ case GST_VIDEO_FORMAT_Y444_10LE:
+ case GST_VIDEO_FORMAT_Y444_10BE:
+ case GST_VIDEO_FORMAT_Y444:
+ sampling = GST_RTP_J2K_YBR444;
+ break;
+
+ case GST_VIDEO_FORMAT_I422_10LE:
+ case GST_VIDEO_FORMAT_I422_10BE:
+ case GST_VIDEO_FORMAT_Y42B:
+ sampling = GST_RTP_J2K_YBR422;
+ break;
+ case GST_VIDEO_FORMAT_YUV9:
+ sampling = GST_RTP_J2K_YBR410;
+ break;
+ case GST_VIDEO_FORMAT_I420_10LE:
+ case GST_VIDEO_FORMAT_I420_10BE:
+ case GST_VIDEO_FORMAT_I420:
+ sampling = GST_RTP_J2K_YBR420;
+ break;
+ case GST_VIDEO_FORMAT_GRAY8:
+ case GST_VIDEO_FORMAT_GRAY16_LE:
+ case GST_VIDEO_FORMAT_GRAY16_BE:
+ sampling = GST_RTP_J2K_GRAYSCALE;
+ break;
+ default:
+ break;
+ }
+
+
+
+ if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_YUV)) {
colorspace = "sYUV";
- else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_RGB))
+ } else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_RGB)) {
colorspace = "sRGB";
- else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_GRAY))
+ } else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_GRAY)) {
colorspace = "GRAY";
- else
+ } else
g_return_val_if_reached (FALSE);
- caps = gst_caps_new_simple (gst_structure_get_name (s),
- "colorspace", G_TYPE_STRING, colorspace,
- "num-components", G_TYPE_INT, ncomps, NULL);
+ if (sampling) {
+ caps = gst_caps_new_simple (gst_structure_get_name (s),
+ "colorspace", G_TYPE_STRING, colorspace,
+ "sampling", G_TYPE_STRING, sampling,
+ "num-components", G_TYPE_INT, ncomps, NULL);
+ } else {
+ caps = gst_caps_new_simple (gst_structure_get_name (s),
+ "colorspace", G_TYPE_STRING, colorspace,
+ "num-components", G_TYPE_INT, ncomps, NULL);
+
+ }
gst_caps_unref (allowed_caps);
if (self->output_state)
diff --git a/gst/videoparsers/Makefile.am b/gst/videoparsers/Makefile.am
index f1b0a119a..03d72040d 100644
--- a/gst/videoparsers/Makefile.am
+++ b/gst/videoparsers/Makefile.am
@@ -29,6 +29,7 @@ noinst_HEADERS = gsth263parse.h h263parse.h \
gstdiracparse.h dirac_parse.h \
gsth264parse.h gstmpegvideoparse.h \
gstmpeg4videoparse.h \
+ gstjpeg2000sampling.h \
gstpngparse.h \
gstvc1parse.h \
gsth265parse.h
diff --git a/gst/videoparsers/gstjpeg2000sampling.h b/gst/videoparsers/gstjpeg2000sampling.h
new file mode 100644
index 000000000..e6334f275
--- /dev/null
+++ b/gst/videoparsers/gstjpeg2000sampling.h
@@ -0,0 +1,86 @@
+/* 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