[gst-cvs] gst-plugins-bad: basevideodecoder: add capture pattern handling
David Schleef
ds at kemper.freedesktop.org
Sat Sep 18 19:27:24 PDT 2010
Module: gst-plugins-bad
Branch: master
Commit: 62a93835278d5b4167b54133207276d896462e4a
URL: http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=62a93835278d5b4167b54133207276d896462e4a
Author: David Schleef <ds at schleef.org>
Date: Sat Sep 18 19:21:47 2010 -0700
basevideodecoder: add capture pattern handling
Move typical scan_for_sync() usage into base class, which just
calls gst_adapter_masked_scan_uint32().
---
ext/schroedinger/gstschrodec.c | 36 ++-------------------
gst-libs/gst/video/gstbasevideodecoder.c | 52 +++++++++++++++++++-----------
gst-libs/gst/video/gstbasevideodecoder.h | 5 +++
3 files changed, 41 insertions(+), 52 deletions(-)
diff --git a/ext/schroedinger/gstschrodec.c b/ext/schroedinger/gstschrodec.c
index b5b768f..cfde8cd 100644
--- a/ext/schroedinger/gstschrodec.c
+++ b/ext/schroedinger/gstschrodec.c
@@ -90,8 +90,6 @@ static gboolean gst_schro_dec_stop (GstBaseVideoDecoder * dec);
static gboolean gst_schro_dec_reset (GstBaseVideoDecoder * dec);
static GstFlowReturn gst_schro_dec_parse_data (GstBaseVideoDecoder *
base_video_decoder, gboolean at_eos);
-static int gst_schro_dec_scan_for_sync (GstBaseVideoDecoder *
- base_video_decoder, gboolean at_eos, int offset, int n);
static GstFlowReturn gst_schro_dec_handle_frame (GstBaseVideoDecoder * decoder,
GstVideoFrame * frame);
static gboolean gst_schro_dec_finish (GstBaseVideoDecoder * base_video_decoder);
@@ -150,11 +148,12 @@ gst_schro_dec_class_init (GstSchroDecClass * klass)
base_video_decoder_class->reset = GST_DEBUG_FUNCPTR (gst_schro_dec_reset);
base_video_decoder_class->parse_data =
GST_DEBUG_FUNCPTR (gst_schro_dec_parse_data);
- base_video_decoder_class->scan_for_sync =
- GST_DEBUG_FUNCPTR (gst_schro_dec_scan_for_sync);
base_video_decoder_class->handle_frame =
GST_DEBUG_FUNCPTR (gst_schro_dec_handle_frame);
base_video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_schro_dec_finish);
+
+ gst_base_video_decoder_class_set_capture_pattern (base_video_decoder_class,
+ 0xffffffff, 0x42424344);
}
static void
@@ -536,35 +535,6 @@ gst_schro_dec_parse_data (GstBaseVideoDecoder * base_video_decoder,
return GST_FLOW_OK;
}
-static int
-gst_schro_dec_scan_for_sync (GstBaseVideoDecoder * base_video_decoder,
- gboolean at_eos, int offset, int n)
-{
- GstAdapter *adapter = base_video_decoder->input_adapter;
- int n_available;
- int ret;
-
- n_available = gst_adapter_available (adapter) - offset;
-
- if (n_available < 4) {
- if (at_eos) {
- return n_available;
- } else {
- return 0;
- }
- }
-
- n = MIN (n, n_available - 3);
-
- ret = gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x42424344,
- offset, n);
- if (ret == -1) {
- return n;
- }
- return ret;
-}
-
-
static void
gst_schrodec_send_tags (GstSchroDec * schro_dec)
{
diff --git a/gst-libs/gst/video/gstbasevideodecoder.c b/gst-libs/gst/video/gstbasevideodecoder.c
index 198b3a8..42e7b11 100644
--- a/gst-libs/gst/video/gstbasevideodecoder.c
+++ b/gst-libs/gst/video/gstbasevideodecoder.c
@@ -862,32 +862,36 @@ gst_base_video_decoder_chain (GstPad * pad, GstBuffer * buf)
GST_DEBUG ("no sync, scanning");
n = gst_adapter_available (base_video_decoder->input_adapter);
- m = klass->scan_for_sync (base_video_decoder, FALSE, 0, n);
+ if (klass->capture_mask != 0) {
+ m = gst_adapter_masked_scan_uint32 (base_video_decoder->input_adapter,
+ klass->capture_mask, klass->capture_pattern, 0, n - 3);
+ } else if (klass->scan_for_sync) {
+ m = klass->scan_for_sync (base_video_decoder, FALSE, 0, n);
+ } else {
+ m = 0;
+ }
if (m == -1) {
+ GST_ERROR ("scan returned no sync");
+ gst_adapter_flush (base_video_decoder->input_adapter, n - 3);
+
gst_object_unref (base_video_decoder);
return GST_FLOW_OK;
- }
-
- if (m < 0) {
- g_warning ("subclass returned negative scan %d", m);
- }
-
- if (m >= n) {
- GST_ERROR ("subclass scanned past end %d >= %d", m, n);
- }
+ } else {
+ if (m > 0) {
+ if (m >= n) {
+ GST_ERROR ("subclass scanned past end %d >= %d", m, n);
+ }
- gst_adapter_flush (base_video_decoder->input_adapter, m);
+ gst_adapter_flush (base_video_decoder->input_adapter, m);
- if (m < n) {
- GST_DEBUG ("found possible sync after %d bytes (of %d)", m, n);
+ if (m < n) {
+ GST_DEBUG ("found possible sync after %d bytes (of %d)", m, n);
- /* this is only "maybe" sync */
- base_video_decoder->have_sync = TRUE;
- }
+ /* this is only "maybe" sync */
+ base_video_decoder->have_sync = TRUE;
+ }
+ }
- if (!base_video_decoder->have_sync) {
- gst_object_unref (base_video_decoder);
- return GST_FLOW_OK;
}
}
@@ -1496,3 +1500,13 @@ gst_base_video_decoder_get_max_decode_time (GstBaseVideoDecoder *
return deadline;
}
+
+void
+gst_base_video_decoder_class_set_capture_pattern (GstBaseVideoDecoderClass *
+ base_video_decoder_class, guint32 mask, guint32 pattern)
+{
+ g_return_if_fail (((~mask) & pattern) == 0);
+
+ base_video_decoder_class->capture_mask = mask;
+ base_video_decoder_class->capture_pattern = pattern;
+}
diff --git a/gst-libs/gst/video/gstbasevideodecoder.h b/gst-libs/gst/video/gstbasevideodecoder.h
index 6bc606d..f996a58 100644
--- a/gst-libs/gst/video/gstbasevideodecoder.h
+++ b/gst-libs/gst/video/gstbasevideodecoder.h
@@ -137,10 +137,15 @@ struct _GstBaseVideoDecoderClass
GstFlowReturn (*shape_output) (GstBaseVideoDecoder *coder, GstVideoFrame *frame);
GstCaps *(*get_caps) (GstBaseVideoDecoder *coder);
+ guint32 capture_mask;
+ guint32 capture_pattern;
};
GType gst_base_video_decoder_get_type (void);
+void gst_base_video_decoder_class_set_capture_pattern (GstBaseVideoDecoderClass *klass,
+ guint32 mask, guint32 pattern);
+
int gst_base_video_decoder_get_width (GstBaseVideoDecoder *coder);
int gst_base_video_decoder_get_height (GstBaseVideoDecoder *coder);
More information about the Gstreamer-commits
mailing list