diff options
Diffstat (limited to 'sys')
69 files changed, 1506 insertions, 1407 deletions
diff --git a/sys/Makefile.am b/sys/Makefile.am index 879f5f00c..b0ddf9e06 100644 --- a/sys/Makefile.am +++ b/sys/Makefile.am @@ -112,11 +112,11 @@ else VCD_DIR= endif -if USE_VDPAU -VDPAU_DIR=vdpau -else -VDPAU_DIR= -endif +#if USE_VDPAU +#VDPAU_DIR=vdpau +#else +#VDPAU_DIR= +#endif if USE_DIRECT3D9 WINSCREENCAP_DIR=winscreencap diff --git a/sys/acmenc/acmenc.c b/sys/acmenc/acmenc.c index 2b637a54c..b2db28eba 100644 --- a/sys/acmenc/acmenc.c +++ b/sys/acmenc/acmenc.c @@ -470,10 +470,10 @@ acmenc_base_init (ACMEncClass * klass) gchar *shortname, *longname, *detail, *description; MMRESULT res; - gst_element_class_add_static_pad_template (element_class, - &acmenc_sink_template); - gst_element_class_add_static_pad_template (element_class, - &acmenc_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&acmenc_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&acmenc_src_template)); params = (ACMEncParams *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass), ACMENC_PARAMS_QDATA); diff --git a/sys/acmmp3dec/acmmp3dec.c b/sys/acmmp3dec/acmmp3dec.c index 870a9bff3..2f2799270 100644 --- a/sys/acmmp3dec/acmmp3dec.c +++ b/sys/acmmp3dec/acmmp3dec.c @@ -405,10 +405,10 @@ acmmp3dec_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, - &acmmp3dec_sink_template); - gst_element_class_add_static_pad_template (element_class, - &acmmp3dec_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&acmmp3dec_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&acmmp3dec_src_template)); gst_element_class_set_details_simple (element_class, "ACM MP3 decoder", "Codec/Decoder/Audio", "Decode MP3 using ACM decoder", diff --git a/sys/applemedia/Makefile.am b/sys/applemedia/Makefile.am index 844cd72b6..f7b853dfe 100644 --- a/sys/applemedia/Makefile.am +++ b/sys/applemedia/Makefile.am @@ -2,10 +2,6 @@ plugin_LTLIBRARIES = libgstapplemedia.la libgstapplemedia_la_SOURCES = \ plugin.m \ - vth264decbin.c \ - vth264encbin.c \ - vtenc.c \ - vtdec.c \ vtutil.c \ bufferfactory.m \ corevideobuffer.c \ @@ -82,8 +78,7 @@ else libgstapplemedia_la_SOURCES += \ qtkitvideosrc.m \ - miovideosrc.c \ - miovideodevice.c \ + vtdec.c \ mioapi.c libgstapplemedia_la_LDFLAGS += \ diff --git a/sys/applemedia/avfvideosrc.m b/sys/applemedia/avfvideosrc.m index d20f94207..e6fb49613 100644 --- a/sys/applemedia/avfvideosrc.m +++ b/sys/applemedia/avfvideosrc.m @@ -421,7 +421,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer [bufQueueLock lockWhenCondition:HAS_BUFFER_OR_STOP_REQUEST]; if (stopRequest) { [bufQueueLock unlock]; - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } sbuf = (CMSampleBufferRef) [bufQueue lastObject]; @@ -567,7 +567,8 @@ gst_avf_video_src_base_init (gpointer gclass) "Reads frames from an iOS AVFoundation device", "Ole André Vadla Ravnås <oravnas@cisco.com>"); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); } static void diff --git a/sys/applemedia/bufferfactory.m b/sys/applemedia/bufferfactory.m index 27fce4de9..744f0c33a 100644 --- a/sys/applemedia/bufferfactory.m +++ b/sys/applemedia/bufferfactory.m @@ -50,7 +50,7 @@ - (GstBuffer *)createGstBufferForCoreVideoBuffer:(CFTypeRef)cvbuf { - return gst_core_video_buffer_new (coreMediaCtx, (CVBufferRef) cvbuf); + return gst_core_video_buffer_new (coreMediaCtx, (CVBufferRef) cvbuf, NULL); } - (GstBuffer *)createGstBufferForSampleBuffer:(CFTypeRef)sbuf diff --git a/sys/applemedia/celvideosrc.c b/sys/applemedia/celvideosrc.c index 2ef107631..60f9c1974 100644 --- a/sys/applemedia/celvideosrc.c +++ b/sys/applemedia/celvideosrc.c @@ -470,7 +470,7 @@ gst_cel_video_src_create (GstPushSrc * pushsrc, GstBuffer ** buf) shutting_down: { cm->FigSampleBufferRelease (sbuf); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } } @@ -833,7 +833,8 @@ gst_cel_video_src_base_init (gpointer gclass) "Reads frames from an iOS Celestial device", "Ole André Vadla Ravnås <oravnas@cisco.com>"); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); } static void diff --git a/sys/applemedia/cmapi.h b/sys/applemedia/cmapi.h index a75352a07..28500f1e0 100644 --- a/sys/applemedia/cmapi.h +++ b/sys/applemedia/cmapi.h @@ -134,7 +134,7 @@ struct _GstCMApi CFDictionaryRef extensions, CMFormatDescriptionRef * desc); OSStatus (* FigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom) (CFAllocatorRef allocator, UInt32 formatId, UInt32 width, UInt32 height, - UInt32 atomId, const UInt8 * data, CFIndex len, + UInt32 atomId, const UInt8 * data, CFIndex len, void *unk1, CMFormatDescriptionRef * formatDesc); CMVideoDimensions (* CMVideoFormatDescriptionGetDimensions) ( const CMFormatDescriptionRef desc); @@ -142,9 +142,13 @@ struct _GstCMApi CMTime (* CMTimeMake) (int64_t value, int32_t timescale); OSStatus (* CMSampleBufferCreate) (CFAllocatorRef allocator, - CMBlockBufferRef blockBuf, Boolean unkBool, UInt32 unkDW1, UInt32 unkDW2, - CMFormatDescriptionRef fmtDesc, UInt32 unkCountA, UInt32 unkCountB, - const void * unkTimeData, UInt32 unkCountC, const void * unkDWordData, + CMBlockBufferRef blockBuf, Boolean dataReady, + void *makeDataReadyCallback, + void *makeDataReadyRefcon, + CMFormatDescriptionRef fmtDesc, size_t numSamples, + size_t numSampleTimingEntries, + const void *sampleTimingArray, + size_t numSampleSizeEntries, const size_t *sampleSizeArray, CMSampleBufferRef * sampleBuffer); Boolean (* CMSampleBufferDataIsReady) ( const CMSampleBufferRef buf); @@ -164,9 +168,10 @@ struct _GstCMApi CMSampleBufferRef (* FigSampleBufferRetain) (CMSampleBufferRef buf); OSStatus (* CMBlockBufferCreateWithMemoryBlock) - (CFAllocatorRef allocator, Byte * data, UInt32 size, - CFAllocatorRef dataAllocator, void *unk1, UInt32 sizeA, UInt32 sizeB, - Boolean unkBool, CMBlockBufferRef * blockBuffer); + (CFAllocatorRef allocator, void * memoryBlock, size_t blockLength, + CFAllocatorRef dataAllocator, void *customBlockSource, + size_t offsetToData, size_t dataLength, + int flags, CMBlockBufferRef * blockBuffer); SInt32 (* CMBlockBufferGetDataLength) (const CMBlockBufferRef buf); OSStatus (* CMBlockBufferGetDataPointer) ( const CMBlockBufferRef buf, UInt32 unk1, UInt32 unk2, UInt32 unk3, diff --git a/sys/applemedia/coremediabuffer.c b/sys/applemedia/coremediabuffer.c index 216f79e91..14ff9cd9a 100644 --- a/sys/applemedia/coremediabuffer.c +++ b/sys/applemedia/coremediabuffer.c @@ -19,29 +19,31 @@ #include "coremediabuffer.h" -G_DEFINE_TYPE (GstCoreMediaBuffer, gst_core_media_buffer, GST_TYPE_BUFFER); - static void -gst_core_media_buffer_init (GstCoreMediaBuffer * self) +gst_core_media_meta_free (GstCoreMediaMeta * meta, GstBuffer * buf) { - GST_BUFFER_FLAG_SET (self, GST_BUFFER_FLAG_READONLY); + if (meta->image_buf != NULL) { + GstCVApi *cv = meta->ctx->cv; + cv->CVPixelBufferUnlockBaseAddress (meta->image_buf, + kCVPixelBufferLock_ReadOnly); + } + meta->ctx->cm->FigSampleBufferRelease (meta->sample_buf); + g_object_unref (meta->ctx); } -static void -gst_core_media_buffer_finalize (GstMiniObject * mini_object) +static const GstMetaInfo * +gst_core_media_meta_get_info (void) { - GstCoreMediaBuffer *self = GST_CORE_MEDIA_BUFFER_CAST (mini_object); - - if (self->image_buf != NULL) { - GstCVApi *cv = self->ctx->cv; - cv->CVPixelBufferUnlockBaseAddress (self->image_buf, - kCVPixelBufferLock_ReadOnly); + static const GstMetaInfo *core_media_meta_info = NULL; + + if (core_media_meta_info == NULL) { + core_media_meta_info = gst_meta_register ("GstCoreMediaeMeta", + "GstCoreMediaMeta", sizeof (GstCoreMediaMeta), + (GstMetaInitFunction) NULL, + (GstMetaFreeFunction) gst_core_media_meta_free, + (GstMetaTransformFunction) NULL); } - self->ctx->cm->FigSampleBufferRelease (self->sample_buf); - g_object_unref (self->ctx); - - GST_MINI_OBJECT_CLASS (gst_core_media_buffer_parent_class)->finalize - (mini_object); + return core_media_meta_info; } GstBuffer * @@ -55,7 +57,8 @@ gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf) Byte *data = NULL; UInt32 size; OSStatus status; - GstCoreMediaBuffer *buf; + GstBuffer *buf; + GstCoreMediaMeta *meta; image_buf = cm->CMSampleBufferGetImageBuffer (sample_buf); pixel_buf = NULL; @@ -95,33 +98,32 @@ gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf) goto error; } - buf = - GST_CORE_MEDIA_BUFFER (gst_mini_object_new (GST_TYPE_CORE_MEDIA_BUFFER)); - buf->ctx = g_object_ref (ctx); - buf->sample_buf = cm->FigSampleBufferRetain (sample_buf); - buf->image_buf = image_buf; - buf->pixel_buf = pixel_buf; - buf->block_buf = block_buf; + buf = gst_buffer_new (); + + meta = (GstCoreMediaMeta *) gst_buffer_add_meta (buf, + gst_core_media_meta_get_info (), NULL); + meta->ctx = g_object_ref (ctx); + meta->sample_buf = cm->FigSampleBufferRetain (sample_buf); + meta->image_buf = image_buf; + meta->pixel_buf = pixel_buf; + meta->block_buf = block_buf; - GST_BUFFER_DATA (buf) = data; - GST_BUFFER_SIZE (buf) = size; + gst_buffer_take_memory (buf, -1, + gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, + size, 0, size, NULL, NULL)); - return GST_BUFFER_CAST (buf); + return buf; error: return NULL; } CVPixelBufferRef -gst_core_media_buffer_get_pixel_buffer (GstCoreMediaBuffer * buf) -{ - return buf->ctx->cv->CVPixelBufferRetain (buf->pixel_buf); -} - -static void -gst_core_media_buffer_class_init (GstCoreMediaBufferClass * klass) +gst_core_media_buffer_get_pixel_buffer (GstBuffer * buf) { - GstMiniObjectClass *miniobject_class = GST_MINI_OBJECT_CLASS (klass); + GstCoreMediaMeta *meta = (GstCoreMediaMeta *) gst_buffer_get_meta (buf, + gst_core_media_meta_get_info ()); + g_return_val_if_fail (meta != NULL, NULL); - miniobject_class->finalize = gst_core_media_buffer_finalize; + return meta->ctx->cv->CVPixelBufferRetain (meta->pixel_buf); } diff --git a/sys/applemedia/coremediabuffer.h b/sys/applemedia/coremediabuffer.h index a22fd2860..1b7b8dd00 100644 --- a/sys/applemedia/coremediabuffer.h +++ b/sys/applemedia/coremediabuffer.h @@ -26,38 +26,22 @@ G_BEGIN_DECLS -#define GST_TYPE_CORE_MEDIA_BUFFER (gst_core_media_buffer_get_type ()) - -#define GST_IS_CORE_MEDIA_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - GST_TYPE_CORE_MEDIA_BUFFER)) -#define GST_CORE_MEDIA_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - GST_TYPE_CORE_MEDIA_BUFFER, GstCoreMediaBuffer)) -#define GST_CORE_MEDIA_BUFFER_CAST(obj) ((GstCoreMediaBuffer *) (obj)) - -typedef struct _GstCoreMediaBuffer GstCoreMediaBuffer; -typedef struct _GstCoreMediaBufferClass GstCoreMediaBufferClass; - -struct _GstCoreMediaBuffer +typedef struct _GstCoreMediaMeta { - GstBuffer buffer; + GstMeta meta; GstCoreMediaCtx * ctx; CMSampleBufferRef sample_buf; CVImageBufferRef image_buf; CVPixelBufferRef pixel_buf; CMBlockBufferRef block_buf; -}; +} GstCoreMediaMeta; -struct _GstCoreMediaBufferClass -{ - GstBufferClass parent_class; -}; -GType gst_core_media_buffer_get_type (void) G_GNUC_CONST; GstBuffer * gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf); CVPixelBufferRef gst_core_media_buffer_get_pixel_buffer - (GstCoreMediaBuffer * buf); + (GstBuffer * buf); G_END_DECLS diff --git a/sys/applemedia/corevideobuffer.c b/sys/applemedia/corevideobuffer.c index b605e1ddc..eee0a8fc0 100644 --- a/sys/applemedia/corevideobuffer.c +++ b/sys/applemedia/corevideobuffer.c @@ -19,76 +19,106 @@ #include "corevideobuffer.h" -G_DEFINE_TYPE (GstCoreVideoBuffer, gst_core_video_buffer, GST_TYPE_BUFFER); - -static void -gst_core_video_buffer_init (GstCoreVideoBuffer * self) -{ - GST_BUFFER_FLAG_SET (self, GST_BUFFER_FLAG_READONLY); -} - static void -gst_core_video_buffer_finalize (GstMiniObject * mini_object) +gst_core_video_meta_free (GstCoreVideoMeta * meta, GstBuffer * buf) { - GstCoreVideoBuffer *self = GST_CORE_VIDEO_BUFFER_CAST (mini_object); - GstCVApi *cv = self->ctx->cv; + GstCVApi *cv = meta->ctx->cv; - if (self->pixbuf != NULL) { - cv->CVPixelBufferUnlockBaseAddress (self->pixbuf, + if (meta->pixbuf != NULL) { + cv->CVPixelBufferUnlockBaseAddress (meta->pixbuf, kCVPixelBufferLock_ReadOnly); } - cv->CVBufferRelease (self->cvbuf); - - g_object_unref (self->ctx); + cv->CVBufferRelease (meta->cvbuf); + g_object_unref (meta->ctx); +} - GST_MINI_OBJECT_CLASS (gst_core_video_buffer_parent_class)->finalize - (mini_object); +static const GstMetaInfo * +gst_core_video_meta_get_info (void) +{ + static const GstMetaInfo *core_video_meta_info = NULL; + + if (core_video_meta_info == NULL) { + core_video_meta_info = gst_meta_register ("GstCoreVideoeMeta", + "GstCoreVideoMeta", sizeof (GstCoreVideoMeta), + (GstMetaInitFunction) NULL, + (GstMetaFreeFunction) gst_core_video_meta_free, + (GstMetaTransformFunction) NULL); + } + return core_video_meta_info; } GstBuffer * -gst_core_video_buffer_new (GstCoreMediaCtx * ctx, CVBufferRef cvbuf) +gst_core_video_buffer_new (GstCoreMediaCtx * ctx, CVBufferRef cvbuf, + GstVideoInfo * vinfo) { GstCVApi *cv = ctx->cv; void *data; size_t size; CVPixelBufferRef pixbuf = NULL; - GstCoreVideoBuffer *buf; - - if (CFGetTypeID (cvbuf) == cv->CVPixelBufferGetTypeID ()) { - pixbuf = (CVPixelBufferRef) cvbuf; - - if (cv->CVPixelBufferLockBaseAddress (pixbuf, - kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { - goto error; - } - data = cv->CVPixelBufferGetBaseAddress (pixbuf); - size = cv->CVPixelBufferGetBytesPerRow (pixbuf) * - cv->CVPixelBufferGetHeight (pixbuf); - } else { + GstBuffer *buf; + GstCoreVideoMeta *meta; + guint width, height, n_planes, i; + gsize offset[GST_VIDEO_MAX_PLANES]; + gint stride[GST_VIDEO_MAX_PLANES]; + + if (CFGetTypeID (cvbuf) != cv->CVPixelBufferGetTypeID ()) /* TODO: Do we need to handle other buffer types? */ goto error; + + pixbuf = (CVPixelBufferRef) cvbuf; + + if (cv->CVPixelBufferLockBaseAddress (pixbuf, + kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { + goto error; } - buf = GST_CORE_VIDEO_BUFFER_CAST (gst_mini_object_new - (GST_TYPE_CORE_VIDEO_BUFFER)); - buf->ctx = g_object_ref (ctx); - buf->cvbuf = cv->CVBufferRetain (cvbuf); - buf->pixbuf = pixbuf; + buf = gst_buffer_new (); + + /* add the corevideo meta to free the underlying corevideo buffer */ + meta = (GstCoreVideoMeta *) gst_buffer_add_meta (buf, + gst_core_video_meta_get_info (), NULL); + meta->ctx = g_object_ref (ctx); + meta->cvbuf = cv->CVBufferRetain (cvbuf); + meta->pixbuf = pixbuf; + + /* set stride, offset and size */ + memset (&offset, 0, sizeof (offset)); + memset (&stride, 0, sizeof (stride)); + + data = cv->CVPixelBufferGetBaseAddress (pixbuf); + height = cv->CVPixelBufferGetHeight (pixbuf); + if (cv->CVPixelBufferIsPlanar (pixbuf)) { + GstVideoInfo tmp_vinfo; + + n_planes = cv->CVPixelBufferGetPlaneCount (pixbuf); + for (i = 0; i < n_planes; ++i) + stride[i] = cv->CVPixelBufferGetBytesPerRowOfPlane (pixbuf, i); + + /* FIXME: don't hardcode NV12 */ + gst_video_info_set_format (&tmp_vinfo, + GST_VIDEO_FORMAT_NV12, stride[0], height); + offset[1] = tmp_vinfo.offset[1]; + size = tmp_vinfo.size; + } else { + n_planes = 1; + size = cv->CVPixelBufferGetBytesPerRow (pixbuf) * height; + } - GST_BUFFER_DATA (buf) = data; - GST_BUFFER_SIZE (buf) = size; + gst_buffer_take_memory (buf, -1, + gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, + size, 0, size, NULL, NULL)); - return GST_BUFFER_CAST (buf); + if (vinfo) { + GstVideoMeta *video_meta; -error: - return NULL; -} + width = vinfo->width; + video_meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FLAG_NONE, + GST_VIDEO_FORMAT_NV12, width, height, n_planes, offset, stride); + } -static void -gst_core_video_buffer_class_init (GstCoreVideoBufferClass * klass) -{ - GstMiniObjectClass *miniobject_class = GST_MINI_OBJECT_CLASS (klass); + return buf; - miniobject_class->finalize = gst_core_video_buffer_finalize; +error: + return NULL; } diff --git a/sys/applemedia/corevideobuffer.h b/sys/applemedia/corevideobuffer.h index fe12b013c..09040d28c 100644 --- a/sys/applemedia/corevideobuffer.h +++ b/sys/applemedia/corevideobuffer.h @@ -21,39 +21,25 @@ #define __GST_CORE_VIDEO_BUFFER_H__ #include <gst/gst.h> +#include <gst/video/video.h> +#include <gst/video/gstvideometa.h> #include "coremediactx.h" G_BEGIN_DECLS -#define GST_TYPE_CORE_VIDEO_BUFFER (gst_core_video_buffer_get_type ()) - -#define GST_IS_CORE_VIDEO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - GST_TYPE_CORE_VIDEO_BUFFER)) -#define GST_CORE_VIDEO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - GST_TYPE_CORE_VIDEO_BUFFER, GstCoreVideoBuffer)) -#define GST_CORE_VIDEO_BUFFER_CAST(obj) ((GstCoreVideoBuffer *) (obj)) - -typedef struct _GstCoreVideoBuffer GstCoreVideoBuffer; -typedef struct _GstCoreVideoBufferClass GstCoreVideoBufferClass; - -struct _GstCoreVideoBuffer +typedef struct _GstCoreVideoMeta { - GstBuffer buffer; + GstMeta meta; GstCoreMediaCtx *ctx; CVBufferRef cvbuf; CVPixelBufferRef pixbuf; -}; - -struct _GstCoreVideoBufferClass -{ - GstBufferClass parent_class; -}; +} GstCoreVideoMeta; -GType gst_core_video_buffer_get_type (void) G_GNUC_CONST; GstBuffer * gst_core_video_buffer_new (GstCoreMediaCtx * ctx, - CVBufferRef cvbuf); + CVBufferRef cvbuf, + GstVideoInfo *info); G_END_DECLS diff --git a/sys/applemedia/miovideosrc.c b/sys/applemedia/miovideosrc.c index aec4a56a7..f505b2c80 100644 --- a/sys/applemedia/miovideosrc.c +++ b/sys/applemedia/miovideosrc.c @@ -441,7 +441,7 @@ shutting_down: *buf = NULL; } - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } unexpected_format: { @@ -1129,7 +1129,8 @@ gst_mio_video_src_base_init (gpointer gclass) "Reads frames from a Mac OS X MIO device", "Ole André Vadla Ravnås <oravnas@cisco.com>"); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); } static void diff --git a/sys/applemedia/plugin.m b/sys/applemedia/plugin.m index 02f7ca0cb..3d211aa74 100644 --- a/sys/applemedia/plugin.m +++ b/sys/applemedia/plugin.m @@ -60,16 +60,20 @@ plugin_init (GstPlugin * plugin) res = gst_element_register (plugin, "qtkitvideosrc", GST_RANK_PRIMARY, GST_TYPE_QTKIT_VIDEO_SRC); +#if 0 res &= gst_element_register (plugin, "miovideosrc", GST_RANK_NONE, GST_TYPE_MIO_VIDEO_SRC); #endif +#endif +#if 0 res &= gst_element_register (plugin, "vth264decbin", GST_RANK_NONE, GST_TYPE_VT_H264_DEC_BIN); res &= gst_element_register (plugin, "vth264encbin", GST_RANK_NONE, GST_TYPE_VT_H264_ENC_BIN); gst_vtenc_register_elements (plugin); +#endif gst_vtdec_register_elements (plugin); return res; diff --git a/sys/applemedia/qtkitvideosrc.m b/sys/applemedia/qtkitvideosrc.m index 8553bd13b..e0506e57f 100644 --- a/sys/applemedia/qtkitvideosrc.m +++ b/sys/applemedia/qtkitvideosrc.m @@ -38,36 +38,36 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ( - "video/x-raw-yuv, " - "format = (fourcc) " DEVICE_YUV_FOURCC ", " + "video/x-raw, " + "format =" DEVICE_YUV_FOURCC ", " "width = (int) 640, " "height = (int) 480, " "framerate = [0/1, 100/1], " "pixel-aspect-ratio = (fraction) 1/1" "; " - "video/x-raw-yuv, " - "format = (fourcc) " DEVICE_YUV_FOURCC ", " + "video/x-raw, " + "format =" DEVICE_YUV_FOURCC ", " "width = (int) 160, " "height = (int) 120, " "framerate = [0/1, 100/1], " "pixel-aspect-ratio = (fraction) 1/1" "; " - "video/x-raw-yuv, " - "format = (fourcc) " DEVICE_YUV_FOURCC ", " + "video/x-raw, " + "format =" DEVICE_YUV_FOURCC ", " "width = (int) 176, " "height = (int) 144, " "framerate = [0/1, 100/1], " "pixel-aspect-ratio = (fraction) 12/11" "; " - "video/x-raw-yuv, " - "format = (fourcc) " DEVICE_YUV_FOURCC ", " + "video/x-raw, " + "format =" DEVICE_YUV_FOURCC ", " "width = (int) 320, " "height = (int) 240, " "framerate = [0/1, 100/1], " "pixel-aspect-ratio = (fraction) 1/1" "; " - "video/x-raw-yuv, " - "format = (fourcc) " DEVICE_YUV_FOURCC ", " + "video/x-raw, " + "format =" DEVICE_YUV_FOURCC ", " "width = (int) 352, " "height = (int) 288, " "framerate = [0/1, 100/1], " @@ -81,8 +81,7 @@ typedef enum _QueueState { HAS_FRAME_OR_STOP_REQUEST, } QueueState; -GST_BOILERPLATE (GstQTKitVideoSrc, gst_qtkit_video_src, GstPushSrc, - GST_TYPE_PUSH_SRC); +G_DEFINE_TYPE (GstQTKitVideoSrc, gst_qtkit_video_src, GST_TYPE_PUSH_SRC); @interface GstQTKitVideoSrcImpl : NSObject { GstElement *element; @@ -239,7 +238,6 @@ openFailed: GstStructure *s; NSDictionary *outputAttrs; BOOL success; - NSRunLoop *mainRunLoop; NSTimeInterval interval; g_assert (device != nil); @@ -293,21 +291,13 @@ openFailed: [output setDelegate:self]; [session startRunning]; - mainRunLoop = [NSRunLoop mainRunLoop]; - if ([mainRunLoop currentMode] == nil) { - /* QTCaptureSession::addInput and QTCaptureSession::addOutput call - * NSObject::performSelectorOnMainThread internally. If the mainRunLoop is - * not running we need to run it for a while for those methods to complete - */ - GST_INFO ("mainRunLoop not running"); - [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; - } - return YES; } - (BOOL)start { + NSRunLoop *mainRunLoop; + queueLock = [[NSConditionLock alloc] initWithCondition:NO_FRAMES]; queue = [[NSMutableArray alloc] initWithCapacity:FRAME_QUEUE_SIZE]; stopRequest = NO; @@ -318,6 +308,21 @@ openFailed: fps_d = 1; duration = GST_CLOCK_TIME_NONE; + /* this will trigger negotiation and open the device in setCaps */ + gst_base_src_start_complete (baseSrc, GST_FLOW_OK); + + mainRunLoop = [NSRunLoop mainRunLoop]; + if ([mainRunLoop currentMode] == nil) { + /* QTCaptureSession::addInput and QTCaptureSession::addOutput, called from + * setCaps, call NSObject::performSelectorOnMainThread internally. If the + * mainRunLoop is not running we need to run it for a while for those + * methods to complete. + */ + GST_INFO ("mainRunLoop not running"); + [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + } + + return YES; } @@ -351,7 +356,7 @@ openFailed: gst_query_set_latency (query, TRUE, min_latency, max_latency); } } else { - result = GST_BASE_SRC_CLASS (parent_class)->query (baseSrc, query); + result = GST_BASE_SRC_CLASS (gst_qtkit_video_src_parent_class)->query (baseSrc, query); } return result; @@ -396,7 +401,7 @@ openFailed: return GST_STATE_CHANGE_FAILURE; } - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + ret = GST_ELEMENT_CLASS (gst_qtkit_video_src_parent_class)->change_state (element, transition); if (transition == GST_STATE_CHANGE_READY_TO_NULL) [self closeDevice]; @@ -434,7 +439,7 @@ openFailed: [queueLock lockWhenCondition:HAS_FRAME_OR_STOP_REQUEST]; if (stopRequest) { [queueLock unlock]; - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } frame = (CVPixelBufferRef) [queue lastObject]; @@ -515,19 +520,6 @@ static GstFlowReturn gst_qtkit_video_src_create (GstPushSrc * pushsrc, static void gst_qtkit_video_src_fixate (GstBaseSrc * basesrc, GstCaps * caps); static void -gst_qtkit_video_src_base_init (gpointer gclass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - - gst_element_class_set_details_simple (element_class, - "Video Source (QTKit)", "Source/Video", - "Reads frames from a Mac OS X QTKit device", - "Ole André Vadla Ravnås <oravnas@cisco.com>"); - - gst_element_class_add_static_pad_template (element_class, &src_template); -} - -static void gst_qtkit_video_src_class_init (GstQTKitVideoSrcClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); @@ -535,6 +527,14 @@ gst_qtkit_video_src_class_init (GstQTKitVideoSrcClass * klass) GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); + gst_element_class_set_details_simple (gstelement_class, + "Video Source (QTKit)", "Source/Video", + "Reads frames from a Mac OS X QTKit device", + "Ole André Vadla Ravnås <oravnas@cisco.com>"); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&src_template)); + gobject_class->finalize = gst_qtkit_video_src_finalize; gobject_class->get_property = gst_qtkit_video_src_get_property; gobject_class->set_property = gst_qtkit_video_src_set_property; @@ -569,11 +569,15 @@ gst_qtkit_video_src_class_init (GstQTKitVideoSrcClass * klass) [pool release] static void -gst_qtkit_video_src_init (GstQTKitVideoSrc * src, GstQTKitVideoSrcClass * gclass) +gst_qtkit_video_src_init (GstQTKitVideoSrc * src) { OBJC_CALLOUT_BEGIN (); src->impl = [[GstQTKitVideoSrcImpl alloc] initWithSrc:GST_PUSH_SRC (src)]; OBJC_CALLOUT_END (); + + /* pretend to be async so we can spin the mainRunLoop from the main thread if + * needed (see ::start) */ + gst_base_src_set_async (GST_BASE_SRC (src), TRUE); } static void @@ -583,7 +587,7 @@ gst_qtkit_video_src_finalize (GObject * obj) [GST_QTKIT_VIDEO_SRC_IMPL (obj) release]; OBJC_CALLOUT_END (); - G_OBJECT_CLASS (parent_class)->finalize (obj); + G_OBJECT_CLASS (gst_qtkit_video_src_parent_class)->finalize (obj); } static void diff --git a/sys/applemedia/vtdec.c b/sys/applemedia/vtdec.c index 982f73c6f..6ddf7fbb3 100644 --- a/sys/applemedia/vtdec.c +++ b/sys/applemedia/vtdec.c @@ -32,8 +32,9 @@ static GstElementClass *parent_class = NULL; static GstStateChangeReturn gst_vtdec_change_state (GstElement * element, GstStateChange transition); -static gboolean gst_vtdec_sink_setcaps (GstPad * pad, GstCaps * caps); -static GstFlowReturn gst_vtdec_chain (GstPad * pad, GstBuffer * buf); +static gboolean gst_vtdec_sink_setcaps (GstVTDec * dec, GstCaps * caps); +static GstFlowReturn gst_vtdec_chain (GstPad * pad, GstObject * parent, + GstBuffer * buf); static CMFormatDescriptionRef gst_vtdec_create_format_description (GstVTDec * self); @@ -47,6 +48,8 @@ static void gst_vtdec_destroy_session (GstVTDec * self, static GstFlowReturn gst_vtdec_decode_buffer (GstVTDec * self, GstBuffer * buf); static void gst_vtdec_enqueue_frame (void *data, gsize unk1, VTStatus result, gsize unk2, CVBufferRef cvbuf); +static gboolean gst_vtdec_sink_event (GstPad * pad, GstObject * parent, + GstEvent * event); static CMSampleBufferRef gst_vtdec_sample_buffer_from (GstVTDec * self, GstBuffer * buf); @@ -63,19 +66,17 @@ gst_vtdec_base_init (GstVTDecClass * klass) const int min_fps_d = 1, max_fps_d = 1; GstPadTemplate *sink_template, *src_template; GstCaps *sink_caps; - GstElementDetails details; + gchar *longname, *description; - details.longname = g_strdup_printf ("%s decoder", codec_details->name); - details.klass = g_strdup_printf ("Codec/Decoder/Video"); - details.description = g_strdup_printf ("%s decoder", codec_details->name); + longname = g_strdup_printf ("%s decoder", codec_details->name); + description = g_strdup_printf ("%s decoder", codec_details->name); - gst_element_class_set_details_simple (element_class, - details.longname, details.klass, details.description, + gst_element_class_set_metadata (element_class, longname, + "Codec/Decoder/Video", description, "Ole André Vadla Ravnås <oravnas@cisco.com>"); - g_free (details.longname); - g_free (details.klass); - g_free (details.description); + g_free (longname); + g_free (description); sink_caps = gst_caps_new_simple (codec_details->mimetype, "width", GST_TYPE_INT_RANGE, min_width, max_width, @@ -89,19 +90,17 @@ gst_vtdec_base_init (GstVTDecClass * klass) sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps); gst_element_class_add_pad_template (element_class, sink_template); - gst_object_unref (sink_template); src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - gst_caps_new_simple ("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('N', 'V', '1', '2'), + gst_caps_new_simple ("video/x-raw", + "format", G_TYPE_STRING, "NV12", "width", GST_TYPE_INT_RANGE, min_width, max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height, "framerate", GST_TYPE_FRACTION_RANGE, min_fps_n, min_fps_d, max_fps_n, max_fps_d, NULL)); gst_element_class_add_pad_template (element_class, src_template); - gst_object_unref (src_template); } static void @@ -128,7 +127,7 @@ gst_vtdec_init (GstVTDec * self) self->sinkpad = gst_pad_new_from_template (gst_element_class_get_pad_template (element_klass, "sink"), "sink"); gst_element_add_pad (element, self->sinkpad); - gst_pad_set_setcaps_function (self->sinkpad, gst_vtdec_sink_setcaps); + gst_pad_set_event_function (self->sinkpad, gst_vtdec_sink_event); gst_pad_set_chain_function (self->sinkpad, gst_vtdec_chain); self->srcpad = gst_pad_new_from_template @@ -160,10 +159,7 @@ gst_vtdec_change_state (GstElement * element, GstStateChange transition) self->ctx->cm->FigFormatDescriptionRelease (self->fmt_desc); self->fmt_desc = NULL; - self->negotiated_width = self->negotiated_height = 0; - self->negotiated_fps_n = self->negotiated_fps_d = 0; - self->caps_width = self->caps_height = 0; - self->caps_fps_n = self->caps_fps_d = 0; + gst_video_info_init (&self->vinfo); g_ptr_array_free (self->cur_outbufs, TRUE); self->cur_outbufs = NULL; @@ -184,25 +180,69 @@ api_error: } static gboolean -gst_vtdec_sink_setcaps (GstPad * pad, GstCaps * caps) +gst_vtdec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) +{ + GstVTDec *self = GST_VTDEC_CAST (parent); + gboolean forward = TRUE; + gboolean res = TRUE; + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + res = gst_vtdec_sink_setcaps (self, caps); + } + default: + break; + } + + if (forward) + res = gst_pad_event_default (pad, parent, event); + return res; +} + +static gboolean +gst_vtdec_sink_setcaps (GstVTDec * self, GstCaps * caps) { - GstVTDec *self = GST_VTDEC_CAST (GST_PAD_PARENT (pad)); GstStructure *structure; CMFormatDescriptionRef fmt_desc = NULL; + GstVideoFormat format = GST_VIDEO_FORMAT_NV12; + gint width, height; + gint fps_n, fps_d; + gint par_n, par_d; structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "width", &self->negotiated_width)) + if (!gst_structure_get_int (structure, "width", &width)) goto incomplete_caps; - if (!gst_structure_get_int (structure, "height", &self->negotiated_height)) + if (!gst_structure_get_int (structure, "height", &height)) goto incomplete_caps; - gst_structure_get_fraction (structure, "framerate", - &self->negotiated_fps_n, &self->negotiated_fps_d); - /* FIXME */ - if (self->negotiated_fps_n == 0) - self->negotiated_fps_n = 30; - if (self->negotiated_fps_d == 0) - self->negotiated_fps_d = 1; + gst_video_info_set_format (&self->vinfo, format, width, height); + + if (gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d)) { + if (fps_n == 0) { + /* variable framerate */ + self->vinfo.flags |= GST_VIDEO_FLAG_VARIABLE_FPS; + /* see if we have a max-framerate */ + gst_structure_get_fraction (structure, "max-framerate", &fps_n, &fps_d); + } + self->vinfo.fps_n = fps_n; + self->vinfo.fps_d = fps_d; + } else { + /* unspecified is variable framerate */ + self->vinfo.fps_n = 0; + self->vinfo.fps_d = 1; + } + if (gst_structure_get_fraction (structure, "pixel-aspect-ratio", + &par_n, &par_d)) { + self->vinfo.par_n = par_n; + self->vinfo.par_d = par_d; + } else { + self->vinfo.par_n = 1; + self->vinfo.par_d = 1; + } if (self->details->format_id == kVTFormatH264) { const GValue *codec_data_value; @@ -228,12 +268,14 @@ gst_vtdec_sink_setcaps (GstPad * pad, GstCaps * caps) goto session_create_error; } + /* renegotiate when upstream caps change */ + gst_pad_mark_reconfigure (self->srcpad); + return TRUE; /* ERRORS */ incomplete_caps: { - self->negotiated_width = self->negotiated_height = -1; return TRUE; } session_create_error: @@ -247,7 +289,7 @@ session_create_error: static gboolean gst_vtdec_is_negotiated (GstVTDec * self) { - return self->negotiated_width != 0; + return self->vinfo.width != 0; } static gboolean @@ -255,42 +297,26 @@ gst_vtdec_negotiate_downstream (GstVTDec * self) { gboolean result; GstCaps *caps; - GstStructure *s; - if (self->caps_width == self->negotiated_width && - self->caps_height == self->negotiated_height && - self->caps_fps_n == self->negotiated_fps_n && - self->caps_fps_d == self->negotiated_fps_d) { + if (!gst_pad_check_reconfigure (self->srcpad)) return TRUE; - } - caps = gst_caps_copy (gst_pad_get_pad_template_caps (self->srcpad)); - s = gst_caps_get_structure (caps, 0); - gst_structure_set (s, - "width", G_TYPE_INT, self->negotiated_width, - "height", G_TYPE_INT, self->negotiated_height, - "framerate", GST_TYPE_FRACTION, - self->negotiated_fps_n, self->negotiated_fps_d, NULL); + caps = gst_video_info_to_caps (&self->vinfo); result = gst_pad_set_caps (self->srcpad, caps); gst_caps_unref (caps); - self->caps_width = self->negotiated_width; - self->caps_height = self->negotiated_height; - self->caps_fps_n = self->negotiated_fps_n; - self->caps_fps_d = self->negotiated_fps_d; - return result; } static GstFlowReturn -gst_vtdec_chain (GstPad * pad, GstBuffer * buf) +gst_vtdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) { - GstVTDec *self = GST_VTDEC_CAST (GST_PAD_PARENT (pad)); + GstVTDec *self = GST_VTDEC_CAST (parent); if (!gst_vtdec_is_negotiated (self)) goto not_negotiated; - if (self->session == NULL || self->negotiated_width < 0) + if (self->session == NULL) goto pending_caps; return gst_vtdec_decode_buffer (self, buf); @@ -313,7 +339,7 @@ gst_vtdec_create_format_description (GstVTDec * self) OSStatus status; status = self->ctx->cm->CMVideoFormatDescriptionCreate (NULL, - self->details->format_id, self->negotiated_width, self->negotiated_height, + self->details->format_id, self->vinfo.width, self->vinfo.height, NULL, &fmt_desc); if (status == noErr) return fmt_desc; @@ -327,13 +353,18 @@ gst_vtdec_create_format_description_from_codec_data (GstVTDec * self, { CMFormatDescriptionRef fmt_desc; OSStatus status; + GstMapInfo map; + + gst_buffer_map (codec_data, &map, GST_MAP_READ); status = self->ctx->cm-> FigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom (NULL, - self->details->format_id, self->negotiated_width, self->negotiated_height, - 'avcC', GST_BUFFER_DATA (codec_data), GST_BUFFER_SIZE (codec_data), - &fmt_desc); + self->details->format_id, self->vinfo.width, self->vinfo.height, + 'avcC', map.data, map.size, NULL, &fmt_desc); + + gst_buffer_unmap (codec_data, &map); + if (status == noErr) return fmt_desc; else @@ -354,11 +385,11 @@ gst_vtdec_create_session (GstVTDec * self, CMFormatDescriptionRef fmt_desc) gst_vtutil_dict_set_i32 (pb_attrs, *(cv->kCVPixelBufferPixelFormatTypeKey), kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange); gst_vtutil_dict_set_i32 (pb_attrs, *(cv->kCVPixelBufferWidthKey), - self->negotiated_width); + self->vinfo.width); gst_vtutil_dict_set_i32 (pb_attrs, *(cv->kCVPixelBufferHeightKey), - self->negotiated_height); + self->vinfo.height); gst_vtutil_dict_set_i32 (pb_attrs, - *(cv->kCVPixelBufferBytesPerRowAlignmentKey), 2 * self->negotiated_width); + *(cv->kCVPixelBufferBytesPerRowAlignmentKey), 2 * self->vinfo.width); callback.func = gst_vtdec_enqueue_frame; callback.data = self; @@ -366,7 +397,7 @@ gst_vtdec_create_session (GstVTDec * self, CMFormatDescriptionRef fmt_desc) status = self->ctx->vt->VTDecompressionSessionCreate (NULL, fmt_desc, NULL, pb_attrs, &callback, &session); GST_INFO_OBJECT (self, "VTDecompressionSessionCreate for %d x %d => %d", - self->negotiated_width, self->negotiated_height, status); + self->vinfo.width, self->vinfo.height, status); CFRelease (pb_attrs); @@ -418,7 +449,6 @@ gst_vtdec_decode_buffer (GstVTDec * self, GstBuffer * buf) GstBuffer *buf = g_ptr_array_index (self->cur_outbufs, i); if (ret == GST_FLOW_OK) { - gst_buffer_set_caps (buf, GST_PAD_CAPS (self->srcpad)); ret = gst_pad_push (self->srcpad, buf); } else { gst_buffer_unref (buf); @@ -439,9 +469,8 @@ gst_vtdec_enqueue_frame (void *data, gsize unk1, VTStatus result, gsize unk2, if (result != kVTSuccess) goto beach; - buf = gst_core_video_buffer_new (self->ctx, cvbuf); - gst_buffer_copy_metadata (buf, self->cur_inbuf, - GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); + buf = gst_core_video_buffer_new (self->ctx, cvbuf, &self->vinfo); + gst_buffer_copy_into (buf, self->cur_inbuf, GST_BUFFER_COPY_METADATA, 0, -1); g_ptr_array_add (self->cur_outbufs, buf); @@ -456,23 +485,33 @@ gst_vtdec_sample_buffer_from (GstVTDec * self, GstBuffer * buf) OSStatus status; CMBlockBufferRef bbuf = NULL; CMSampleBufferRef sbuf = NULL; + GstMapInfo map; g_assert (self->fmt_desc != NULL); + gst_buffer_map (buf, &map, GST_MAP_READ); + status = cm->CMBlockBufferCreateWithMemoryBlock (NULL, - GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf), kCFAllocatorNull, NULL, - 0, GST_BUFFER_SIZE (buf), FALSE, &bbuf); + map.data, (gint64) map.size, kCFAllocatorNull, NULL, 0, (gint64) map.size, + FALSE, &bbuf); + + gst_buffer_unmap (buf, &map); + if (status != noErr) - goto beach; + goto error; status = cm->CMSampleBufferCreate (NULL, bbuf, TRUE, 0, 0, self->fmt_desc, 1, 0, NULL, 0, NULL, &sbuf); if (status != noErr) - goto beach; + goto error; beach: cm->FigBlockBufferRelease (bbuf); return sbuf; + +error: + GST_ERROR_OBJECT (self, "err %d", status); + goto beach; } static void diff --git a/sys/applemedia/vtdec.h b/sys/applemedia/vtdec.h index 3ebb26f9a..e1f3bbe21 100644 --- a/sys/applemedia/vtdec.h +++ b/sys/applemedia/vtdec.h @@ -21,6 +21,7 @@ #define __GST_VTDEC_H__ #include <gst/gst.h> +#include <gst/video/video.h> #include "coremediactx.h" @@ -62,10 +63,7 @@ struct _GstVTDec GstCoreMediaCtx * ctx; - gint negotiated_width, negotiated_height; - gint negotiated_fps_n, negotiated_fps_d; - gint caps_width, caps_height; - gint caps_fps_n, caps_fps_d; + GstVideoInfo vinfo; CMFormatDescriptionRef fmt_desc; VTDecompressionSessionRef session; diff --git a/sys/applemedia/vtenc.c b/sys/applemedia/vtenc.c index aa0bcdda6..c7878482c 100644 --- a/sys/applemedia/vtenc.c +++ b/sys/applemedia/vtenc.c @@ -118,7 +118,6 @@ gst_vtenc_base_init (GstVTEncClass * klass) "framerate", GST_TYPE_FRACTION_RANGE, min_fps_n, min_fps_d, max_fps_n, max_fps_d, NULL)); gst_element_class_add_pad_template (element_class, sink_template); - gst_object_unref (sink_template); src_caps = gst_caps_new_simple (codec_details->mimetype, "width", GST_TYPE_INT_RANGE, min_width, max_width, @@ -132,7 +131,6 @@ gst_vtenc_base_init (GstVTEncClass * klass) src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps); gst_element_class_add_pad_template (element_class, src_template); - gst_object_unref (src_template); } static void diff --git a/sys/applemedia/vth264decbin.c b/sys/applemedia/vth264decbin.c index 816e15ec5..fbc718b3a 100644 --- a/sys/applemedia/vth264decbin.c +++ b/sys/applemedia/vth264decbin.c @@ -218,10 +218,10 @@ gst_vt_h264_dec_bin_base_init (gpointer gclass) "VideoToolbox H.264 decoder bin", "Ole André Vadla Ravnås <oravnas@cisco.com>"); - gst_element_class_add_static_pad_template (element_class, - &vth264decbin_sink_template); - gst_element_class_add_static_pad_template (element_class, - &vth264decbin_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vth264decbin_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vth264decbin_src_template)); } static void diff --git a/sys/applemedia/vth264encbin.c b/sys/applemedia/vth264encbin.c index 222a73142..e97ef29d5 100644 --- a/sys/applemedia/vth264encbin.c +++ b/sys/applemedia/vth264encbin.c @@ -80,10 +80,10 @@ gst_vt_h264_enc_bin_base_init (gpointer gclass) "VideoToolbox H.264 encoder bin", "Ole André Vadla Ravnås <oravnas@cisco.com>"); - gst_element_class_add_static_pad_template (element_class, - &vth264encbin_sink_template); - gst_element_class_add_static_pad_template (element_class, - &vth264encbin_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vth264encbin_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vth264encbin_src_template)); } static void diff --git a/sys/avc/gstavcsrc.cpp b/sys/avc/gstavcsrc.cpp index 405355282..d9c07bdd5 100644 --- a/sys/avc/gstavcsrc.cpp +++ b/sys/avc/gstavcsrc.cpp @@ -99,8 +99,8 @@ gst_avc_src_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_static_pad_template (element_class, - &gst_avc_src_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_avc_src_src_template)); gst_element_class_set_details_simple (element_class, "AVC Video Services Source", "Video/Source", @@ -391,7 +391,7 @@ gst_avc_src_create (GstBaseSrc * src, guint64 offset, guint size, if (avcsrc->unlock) { if (buffer) gst_buffer_unref (buffer); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } gst_buffer_set_caps (buffer, GST_PAD_CAPS (avcsrc->srcpad)); diff --git a/sys/d3dvideosink/d3dvideosink.c b/sys/d3dvideosink/d3dvideosink.c index eef480a1a..bbcf3ad32 100644 --- a/sys/d3dvideosink/d3dvideosink.c +++ b/sys/d3dvideosink/d3dvideosink.c @@ -268,7 +268,8 @@ gst_d3dvideosink_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); gst_element_class_set_details_simple (element_class, "Direct3D video sink", "Sink/Video", @@ -444,7 +445,7 @@ static GstCaps * gst_d3dvideosink_get_caps (GstBaseSink * basesink) { GstD3DVideoSink *sink = GST_D3DVIDEOSINK (basesink); - GstCaps *caps = gst_caps_new_empty (); + GstCaps *caps; const GstCaps *tempCaps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink)); @@ -454,11 +455,13 @@ gst_d3dvideosink_get_caps (GstBaseSink * basesink) if (FAILED (IDirect3D9_GetAdapterDisplayMode (shared.d3d, D3DADAPTER_DEFAULT, &d3ddm))) { GST_WARNING ("Unable to request adapter display mode"); - gst_caps_unref (caps); - caps = gst_caps_copy (tempCaps); + caps = tempCaps; } else { gint i; - GstCaps *c = gst_caps_normalize (tempCaps); + GstCaps *c; + + caps = gst_caps_new_empty (); + c = gst_caps_normalize (tempCaps); for (i = 0; i < gst_caps_get_size (c); i++) { D3DFORMAT d3dfourcc = 0; @@ -488,8 +491,7 @@ gst_d3dvideosink_get_caps (GstBaseSink * basesink) gst_caps_unref (c); } } else { - gst_caps_unref (caps); - caps = gst_caps_copy (tempCaps); + caps = tempCaps; } return caps; } @@ -1751,7 +1753,7 @@ success: #if 0 wrong_state: GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; /*unexpected:*/ /* GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK(sink); */ /* */ diff --git a/sys/decklink/gstdecklinksink.cpp b/sys/decklink/gstdecklinksink.cpp index bbf08a73f..6a105d46d 100644 --- a/sys/decklink/gstdecklinksink.cpp +++ b/sys/decklink/gstdecklinksink.cpp @@ -183,8 +183,8 @@ gst_decklink_sink_base_init (gpointer g_class) gst_decklink_mode_get_template_caps ()); gst_element_class_add_pad_template (element_class, pad_template); gst_object_unref (pad_template); - gst_element_class_add_static_pad_template (element_class, - &gst_decklink_sink_audiosink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_decklink_sink_audiosink_template)); gst_element_class_set_details_simple (element_class, "Decklink Sink", "Video/Sink", "Decklink Sink", "David Schleef <ds@entropywave.com>"); @@ -577,7 +577,7 @@ static gboolean gst_decklink_sink_set_clock (GstElement * element, GstClock * clock) { - return TRUE; + return GST_ELEMENT_CLASS (parent_class)->set_clock (element, clock); } static GstIndex * @@ -785,7 +785,7 @@ gst_decklink_sink_videosink_chain (GstPad * pad, GstBuffer * buffer) ret = GST_FLOW_OK; } else { - ret = GST_FLOW_WRONG_STATE; + ret = GST_FLOW_FLUSHING; } frame->Release (); @@ -1003,7 +1003,7 @@ gst_decklink_sink_audiosink_chain (GstPad * pad, GstBuffer * buffer) // concatenate both buffers g_mutex_lock (decklinksink->audio_mutex); decklinksink->audio_buffer = - gst_buffer_join (decklinksink->audio_buffer, buffer); + gst_buffer_append (decklinksink->audio_buffer, buffer); g_mutex_unlock (decklinksink->audio_mutex); // GST_DEBUG("Audio Buffer Size: %d", GST_BUFFER_SIZE (decklinksink->audio_buffer)); diff --git a/sys/decklink/gstdecklinksrc.cpp b/sys/decklink/gstdecklinksrc.cpp index 710802304..d1a776dce 100644 --- a/sys/decklink/gstdecklinksrc.cpp +++ b/sys/decklink/gstdecklinksrc.cpp @@ -176,15 +176,12 @@ static void gst_decklink_src_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - GstPadTemplate *pad_template; - gst_element_class_add_static_pad_template (element_class, - &gst_decklink_src_audio_src_template); - pad_template = + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_decklink_src_audio_src_template)); + gst_element_class_add_pad_template (element_class, gst_pad_template_new ("videosrc", GST_PAD_SRC, GST_PAD_ALWAYS, - gst_decklink_mode_get_template_caps ()); - gst_element_class_add_pad_template (element_class, pad_template); - gst_object_unref (pad_template); + gst_decklink_mode_get_template_caps ())); gst_element_class_set_details_simple (element_class, "Decklink source", "Source/Video", "DeckLink Source", "David Schleef <ds@entropywave.com>"); @@ -743,7 +740,7 @@ static gboolean gst_decklink_src_set_clock (GstElement * element, GstClock * clock) { - return TRUE; + return GST_ELEMENT_CLASS (parent_class)->set_clock (element, clock); } static GstIndex * diff --git a/sys/decklink/win/DeckLinkAPI_i.c b/sys/decklink/win/DeckLinkAPI_i.c index e9346db6a..ca14206ac 100644 --- a/sys/decklink/win/DeckLinkAPI_i.c +++ b/sys/decklink/win/DeckLinkAPI_i.c @@ -18,12 +18,13 @@ */ //@@MIDL_FILE_HEADING( ) -#pragma warning( disable: 4049 ) /* more than 64k source lines */ +#pragma warning( disable: 4049 ) /* more than 64k source lines */ #ifdef __cplusplus -extern "C"{ -#endif +extern "C" +{ +#endif #include <rpc.h> @@ -42,218 +43,277 @@ extern "C"{ #define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) -#else // !_MIDL_USE_GUIDDEF_ +#else // !_MIDL_USE_GUIDDEF_ #ifndef __IID_DEFINED__ #define __IID_DEFINED__ -typedef struct _IID -{ + typedef struct _IID + { unsigned long x; unsigned short s1; unsigned short s2; - unsigned char c[8]; -} IID; + unsigned char c[8]; + } IID; -#endif // __IID_DEFINED__ +#endif // __IID_DEFINED__ #ifndef CLSID_DEFINED #define CLSID_DEFINED -typedef IID CLSID; -#endif // CLSID_DEFINED + typedef IID CLSID; +#endif // CLSID_DEFINED #define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} -#endif !_MIDL_USE_GUIDDEF_ +#endif /* !_MIDL_USE_GUIDDEF_ */ -MIDL_DEFINE_GUID(IID, LIBID_DeckLinkAPI,0xD864517A,0xEDD5,0x466D,0x86,0x7D,0xC8,0x19,0xF1,0xC0,0x52,0xBB); + MIDL_DEFINE_GUID (IID, LIBID_DeckLinkAPI, 0xD864517A, 0xEDD5, 0x466D, 0x86, + 0x7D, 0xC8, 0x19, 0xF1, 0xC0, 0x52, 0xBB); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoOutputCallback,0x20AA5225,0x1958,0x47CB,0x82,0x0B,0x80,0xA8,0xD5,0x21,0xA6,0xEE); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoOutputCallback, 0x20AA5225, 0x1958, + 0x47CB, 0x82, 0x0B, 0x80, 0xA8, 0xD5, 0x21, 0xA6, 0xEE); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInputCallback,0xDD04E5EC,0x7415,0x42AB,0xAE,0x4A,0xE8,0x0C,0x4D,0xFC,0x04,0x4A); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInputCallback, 0xDD04E5EC, 0x7415, + 0x42AB, 0xAE, 0x4A, 0xE8, 0x0C, 0x4D, 0xFC, 0x04, 0x4A); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkMemoryAllocator,0xB36EB6E7,0x9D29,0x4AA8,0x92,0xEF,0x84,0x3B,0x87,0xA2,0x89,0xE8); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkMemoryAllocator, 0xB36EB6E7, 0x9D29, + 0x4AA8, 0x92, 0xEF, 0x84, 0x3B, 0x87, 0xA2, 0x89, 0xE8); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkAudioOutputCallback,0x403C681B,0x7F46,0x4A12,0xB9,0x93,0x2B,0xB1,0x27,0x08,0x4E,0xE6); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkAudioOutputCallback, 0x403C681B, 0x7F46, + 0x4A12, 0xB9, 0x93, 0x2B, 0xB1, 0x27, 0x08, 0x4E, 0xE6); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkIterator,0x74E936FC,0xCC28,0x4A67,0x81,0xA0,0x1E,0x94,0xE5,0x2D,0x4E,0x69); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkIterator, 0x74E936FC, 0xCC28, 0x4A67, + 0x81, 0xA0, 0x1E, 0x94, 0xE5, 0x2D, 0x4E, 0x69); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkAPIInformation,0x7BEA3C68,0x730D,0x4322,0xAF,0x34,0x8A,0x71,0x52,0xB5,0x32,0xA4); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkAPIInformation, 0x7BEA3C68, 0x730D, + 0x4322, 0xAF, 0x34, 0x8A, 0x71, 0x52, 0xB5, 0x32, 0xA4); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayModeIterator,0x9C88499F,0xF601,0x4021,0xB8,0x0B,0x03,0x2E,0x4E,0xB4,0x1C,0x35); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayModeIterator, 0x9C88499F, 0xF601, + 0x4021, 0xB8, 0x0B, 0x03, 0x2E, 0x4E, 0xB4, 0x1C, 0x35); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayMode,0x3EB2C1AB,0x0A3D,0x4523,0xA3,0xAD,0xF4,0x0D,0x7F,0xB1,0x4E,0x78); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayMode, 0x3EB2C1AB, 0x0A3D, 0x4523, + 0xA3, 0xAD, 0xF4, 0x0D, 0x7F, 0xB1, 0x4E, 0x78); -MIDL_DEFINE_GUID(IID, IID_IDeckLink,0x62BFF75D,0x6569,0x4E55,0x8D,0x4D,0x66,0xAA,0x03,0x82,0x9A,0xBC); + MIDL_DEFINE_GUID (IID, IID_IDeckLink, 0x62BFF75D, 0x6569, 0x4E55, 0x8D, + 0x4D, 0x66, 0xAA, 0x03, 0x82, 0x9A, 0xBC); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkOutput,0xA3EF0963,0x0862,0x44ED,0x92,0xA9,0xEE,0x89,0xAB,0xF4,0x31,0xC7); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkOutput, 0xA3EF0963, 0x0862, 0x44ED, + 0x92, 0xA9, 0xEE, 0x89, 0xAB, 0xF4, 0x31, 0xC7); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInput,0x6D40EF78,0x28B9,0x4E21,0x99,0x0D,0x95,0xBB,0x77,0x50,0xA0,0x4F); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInput, 0x6D40EF78, 0x28B9, 0x4E21, 0x99, + 0x0D, 0x95, 0xBB, 0x77, 0x50, 0xA0, 0x4F); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkTimecode,0xBC6CFBD3,0x8317,0x4325,0xAC,0x1C,0x12,0x16,0x39,0x1E,0x93,0x40); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkTimecode, 0xBC6CFBD3, 0x8317, 0x4325, + 0xAC, 0x1C, 0x12, 0x16, 0x39, 0x1E, 0x93, 0x40); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoFrame,0x3F716FE0,0xF023,0x4111,0xBE,0x5D,0xEF,0x44,0x14,0xC0,0x5B,0x17); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoFrame, 0x3F716FE0, 0xF023, 0x4111, + 0xBE, 0x5D, 0xEF, 0x44, 0x14, 0xC0, 0x5B, 0x17); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkMutableVideoFrame,0x69E2639F,0x40DA,0x4E19,0xB6,0xF2,0x20,0xAC,0xE8,0x15,0xC3,0x90); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkMutableVideoFrame, 0x69E2639F, 0x40DA, + 0x4E19, 0xB6, 0xF2, 0x20, 0xAC, 0xE8, 0x15, 0xC3, 0x90); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoFrame3DExtensions,0xDA0F7E4A,0xEDC7,0x48A8,0x9C,0xDD,0x2D,0xB5,0x1C,0x72,0x9C,0xD7); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoFrame3DExtensions, 0xDA0F7E4A, + 0xEDC7, 0x48A8, 0x9C, 0xDD, 0x2D, 0xB5, 0x1C, 0x72, 0x9C, 0xD7); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoInputFrame,0x05CFE374,0x537C,0x4094,0x9A,0x57,0x68,0x05,0x25,0x11,0x8F,0x44); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoInputFrame, 0x05CFE374, 0x537C, + 0x4094, 0x9A, 0x57, 0x68, 0x05, 0x25, 0x11, 0x8F, 0x44); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoFrameAncillary,0x732E723C,0xD1A4,0x4E29,0x9E,0x8E,0x4A,0x88,0x79,0x7A,0x00,0x04); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoFrameAncillary, 0x732E723C, 0xD1A4, + 0x4E29, 0x9E, 0x8E, 0x4A, 0x88, 0x79, 0x7A, 0x00, 0x04); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkAudioInputPacket,0xE43D5870,0x2894,0x11DE,0x8C,0x30,0x08,0x00,0x20,0x0C,0x9A,0x66); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkAudioInputPacket, 0xE43D5870, 0x2894, + 0x11DE, 0x8C, 0x30, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkScreenPreviewCallback,0xB1D3F49A,0x85FE,0x4C5D,0x95,0xC8,0x0B,0x5D,0x5D,0xCC,0xD4,0x38); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkScreenPreviewCallback, 0xB1D3F49A, + 0x85FE, 0x4C5D, 0x95, 0xC8, 0x0B, 0x5D, 0x5D, 0xCC, 0xD4, 0x38); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkGLScreenPreviewHelper,0x504E2209,0xCAC7,0x4C1A,0x9F,0xB4,0xC5,0xBB,0x62,0x74,0xD2,0x2F); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkGLScreenPreviewHelper, 0x504E2209, + 0xCAC7, 0x4C1A, 0x9F, 0xB4, 0xC5, 0xBB, 0x62, 0x74, 0xD2, 0x2F); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkConfiguration,0xC679A35B,0x610C,0x4D09,0xB7,0x48,0x1D,0x04,0x78,0x10,0x0F,0xC0); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkConfiguration, 0xC679A35B, 0x610C, + 0x4D09, 0xB7, 0x48, 0x1D, 0x04, 0x78, 0x10, 0x0F, 0xC0); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkAttributes,0xABC11843,0xD966,0x44CB,0x96,0xE2,0xA1,0xCB,0x5D,0x31,0x35,0xC4); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkAttributes, 0xABC11843, 0xD966, 0x44CB, + 0x96, 0xE2, 0xA1, 0xCB, 0x5D, 0x31, 0x35, 0xC4); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkKeyer,0x89AFCAF5,0x65F8,0x421E,0x98,0xF7,0x96,0xFE,0x5F,0x5B,0xFB,0xA3); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkKeyer, 0x89AFCAF5, 0x65F8, 0x421E, 0x98, + 0xF7, 0x96, 0xFE, 0x5F, 0x5B, 0xFB, 0xA3); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoConversion,0x3BBCB8A2,0xDA2C,0x42D9,0xB5,0xD8,0x88,0x08,0x36,0x44,0xE9,0x9A); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoConversion, 0x3BBCB8A2, 0xDA2C, + 0x42D9, 0xB5, 0xD8, 0x88, 0x08, 0x36, 0x44, 0xE9, 0x9A); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDeckControlStatusCallback,0xE5F693C1,0x4283,0x4716,0xB1,0x8F,0xC1,0x43,0x15,0x21,0x95,0x5B); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDeckControlStatusCallback, 0xE5F693C1, + 0x4283, 0x4716, 0xB1, 0x8F, 0xC1, 0x43, 0x15, 0x21, 0x95, 0x5B); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDeckControl,0x522A9E39,0x0F3C,0x4742,0x94,0xEE,0xD8,0x0D,0xE3,0x35,0xDA,0x1D); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDeckControl, 0x522A9E39, 0x0F3C, 0x4742, + 0x94, 0xEE, 0xD8, 0x0D, 0xE3, 0x35, 0xDA, 0x1D); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkIterator,0xD9EDA3B3,0x2887,0x41FA,0xB7,0x24,0x01,0x7C,0xF1,0xEB,0x1D,0x37); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkIterator, 0xD9EDA3B3, 0x2887, + 0x41FA, 0xB7, 0x24, 0x01, 0x7C, 0xF1, 0xEB, 0x1D, 0x37); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkAPIInformation,0x263CA19F,0xED09,0x482E,0x9F,0x9D,0x84,0x00,0x57,0x83,0xA2,0x37); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkAPIInformation, 0x263CA19F, 0xED09, + 0x482E, 0x9F, 0x9D, 0x84, 0x00, 0x57, 0x83, 0xA2, 0x37); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkGLScreenPreviewHelper,0xF63E77C7,0xB655,0x4A4A,0x9A,0xD0,0x3C,0xA8,0x5D,0x39,0x43,0x43); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkGLScreenPreviewHelper, 0xF63E77C7, + 0xB655, 0x4A4A, 0x9A, 0xD0, 0x3C, 0xA8, 0x5D, 0x39, 0x43, 0x43); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkVideoConversion,0x7DBBBB11,0x5B7B,0x467D,0xAE,0xA4,0xCE,0xA4,0x68,0xFD,0x36,0x8C); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkVideoConversion, 0x7DBBBB11, 0x5B7B, + 0x467D, 0xAE, 0xA4, 0xCE, 0xA4, 0x68, 0xFD, 0x36, 0x8C); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDeckControl_v7_9,0xA4D81043,0x0619,0x42B7,0x8E,0xD6,0x60,0x2D,0x29,0x04,0x1D,0xF7); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDeckControl_v7_9, 0xA4D81043, 0x0619, + 0x42B7, 0x8E, 0xD6, 0x60, 0x2D, 0x29, 0x04, 0x1D, 0xF7); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayModeIterator_v7_6,0x455D741F,0x1779,0x4800,0x86,0xF5,0x0B,0x5D,0x13,0xD7,0x97,0x51); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayModeIterator_v7_6, 0x455D741F, + 0x1779, 0x4800, 0x86, 0xF5, 0x0B, 0x5D, 0x13, 0xD7, 0x97, 0x51); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayMode_v7_6,0x87451E84,0x2B7E,0x439E,0xA6,0x29,0x43,0x93,0xEA,0x4A,0x85,0x50); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayMode_v7_6, 0x87451E84, 0x2B7E, + 0x439E, 0xA6, 0x29, 0x43, 0x93, 0xEA, 0x4A, 0x85, 0x50); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkOutput_v7_6,0x29228142,0xEB8C,0x4141,0xA6,0x21,0xF7,0x40,0x26,0x45,0x09,0x55); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkOutput_v7_6, 0x29228142, 0xEB8C, 0x4141, + 0xA6, 0x21, 0xF7, 0x40, 0x26, 0x45, 0x09, 0x55); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInput_v7_6,0x300C135A,0x9F43,0x48E2,0x99,0x06,0x6D,0x79,0x11,0xD9,0x3C,0xF1); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInput_v7_6, 0x300C135A, 0x9F43, 0x48E2, + 0x99, 0x06, 0x6D, 0x79, 0x11, 0xD9, 0x3C, 0xF1); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkTimecode_v7_6,0xEFB9BCA6,0xA521,0x44F7,0xBD,0x69,0x23,0x32,0xF2,0x4D,0x9E,0xE6); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkTimecode_v7_6, 0xEFB9BCA6, 0xA521, + 0x44F7, 0xBD, 0x69, 0x23, 0x32, 0xF2, 0x4D, 0x9E, 0xE6); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoFrame_v7_6,0xA8D8238E,0x6B18,0x4196,0x99,0xE1,0x5A,0xF7,0x17,0xB8,0x3D,0x32); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoFrame_v7_6, 0xA8D8238E, 0x6B18, + 0x4196, 0x99, 0xE1, 0x5A, 0xF7, 0x17, 0xB8, 0x3D, 0x32); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkMutableVideoFrame_v7_6,0x46FCEE00,0xB4E6,0x43D0,0x91,0xC0,0x02,0x3A,0x7F,0xCE,0xB3,0x4F); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkMutableVideoFrame_v7_6, 0x46FCEE00, + 0xB4E6, 0x43D0, 0x91, 0xC0, 0x02, 0x3A, 0x7F, 0xCE, 0xB3, 0x4F); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoInputFrame_v7_6,0x9A74FA41,0xAE9F,0x47AC,0x8C,0xF4,0x01,0xF4,0x2D,0xD5,0x99,0x65); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoInputFrame_v7_6, 0x9A74FA41, + 0xAE9F, 0x47AC, 0x8C, 0xF4, 0x01, 0xF4, 0x2D, 0xD5, 0x99, 0x65); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkScreenPreviewCallback_v7_6,0x373F499D,0x4B4D,0x4518,0xAD,0x22,0x63,0x54,0xE5,0xA5,0x82,0x5E); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkScreenPreviewCallback_v7_6, 0x373F499D, + 0x4B4D, 0x4518, 0xAD, 0x22, 0x63, 0x54, 0xE5, 0xA5, 0x82, 0x5E); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkGLScreenPreviewHelper_v7_6,0xBA575CD9,0xA15E,0x497B,0xB2,0xC2,0xF9,0xAF,0xE7,0xBE,0x4E,0xBA); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkGLScreenPreviewHelper_v7_6, 0xBA575CD9, + 0xA15E, 0x497B, 0xB2, 0xC2, 0xF9, 0xAF, 0xE7, 0xBE, 0x4E, 0xBA); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoConversion_v7_6,0x3EB504C9,0xF97D,0x40FE,0xA1,0x58,0xD4,0x07,0xD4,0x8C,0xB5,0x3B); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoConversion_v7_6, 0x3EB504C9, + 0xF97D, 0x40FE, 0xA1, 0x58, 0xD4, 0x07, 0xD4, 0x8C, 0xB5, 0x3B); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkConfiguration_v7_6,0xB8EAD569,0xB764,0x47F0,0xA7,0x3F,0xAE,0x40,0xDF,0x6C,0xBF,0x10); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkConfiguration_v7_6, 0xB8EAD569, 0xB764, + 0x47F0, 0xA7, 0x3F, 0xAE, 0x40, 0xDF, 0x6C, 0xBF, 0x10); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoOutputCallback_v7_6,0xE763A626,0x4A3C,0x49D1,0xBF,0x13,0xE7,0xAD,0x36,0x92,0xAE,0x52); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoOutputCallback_v7_6, 0xE763A626, + 0x4A3C, 0x49D1, 0xBF, 0x13, 0xE7, 0xAD, 0x36, 0x92, 0xAE, 0x52); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInputCallback_v7_6,0x31D28EE7,0x88B6,0x4CB1,0x89,0x7A,0xCD,0xBF,0x79,0xA2,0x64,0x14); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInputCallback_v7_6, 0x31D28EE7, 0x88B6, + 0x4CB1, 0x89, 0x7A, 0xCD, 0xBF, 0x79, 0xA2, 0x64, 0x14); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkGLScreenPreviewHelper_v7_6,0xD398CEE7,0x4434,0x4CA3,0x9B,0xA6,0x5A,0xE3,0x45,0x56,0xB9,0x05); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkGLScreenPreviewHelper_v7_6, + 0xD398CEE7, 0x4434, 0x4CA3, 0x9B, 0xA6, 0x5A, 0xE3, 0x45, 0x56, 0xB9, + 0x05); -MIDL_DEFINE_GUID(CLSID, CLSID_CDeckLinkVideoConversion_v7_6,0xFFA84F77,0x73BE,0x4FB7,0xB0,0x3E,0xB5,0xE4,0x4B,0x9F,0x75,0x9B); + MIDL_DEFINE_GUID (CLSID, CLSID_CDeckLinkVideoConversion_v7_6, 0xFFA84F77, + 0x73BE, 0x4FB7, 0xB0, 0x3E, 0xB5, 0xE4, 0x4B, 0x9F, 0x75, 0x9B); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInputCallback_v7_3,0xFD6F311D,0x4D00,0x444B,0x9E,0xD4,0x1F,0x25,0xB5,0x73,0x0A,0xD0); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInputCallback_v7_3, 0xFD6F311D, 0x4D00, + 0x444B, 0x9E, 0xD4, 0x1F, 0x25, 0xB5, 0x73, 0x0A, 0xD0); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkOutput_v7_3,0x271C65E3,0xC323,0x4344,0xA3,0x0F,0xD9,0x08,0xBC,0xB2,0x0A,0xA3); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkOutput_v7_3, 0x271C65E3, 0xC323, 0x4344, + 0xA3, 0x0F, 0xD9, 0x08, 0xBC, 0xB2, 0x0A, 0xA3); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInput_v7_3,0x4973F012,0x9925,0x458C,0x87,0x1C,0x18,0x77,0x4C,0xDB,0xBE,0xCB); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInput_v7_3, 0x4973F012, 0x9925, 0x458C, + 0x87, 0x1C, 0x18, 0x77, 0x4C, 0xDB, 0xBE, 0xCB); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoInputFrame_v7_3,0xCF317790,0x2894,0x11DE,0x8C,0x30,0x08,0x00,0x20,0x0C,0x9A,0x66); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoInputFrame_v7_3, 0xCF317790, + 0x2894, 0x11DE, 0x8C, 0x30, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayModeIterator_v7_1,0xB28131B6,0x59AC,0x4857,0xB5,0xAC,0xCD,0x75,0xD5,0x88,0x3E,0x2F); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayModeIterator_v7_1, 0xB28131B6, + 0x59AC, 0x4857, 0xB5, 0xAC, 0xCD, 0x75, 0xD5, 0x88, 0x3E, 0x2F); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkDisplayMode_v7_1,0xAF0CD6D5,0x8376,0x435E,0x84,0x33,0x54,0xF9,0xDD,0x53,0x0A,0xC3); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkDisplayMode_v7_1, 0xAF0CD6D5, 0x8376, + 0x435E, 0x84, 0x33, 0x54, 0xF9, 0xDD, 0x53, 0x0A, 0xC3); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoFrame_v7_1,0x333F3A10,0x8C2D,0x43CF,0xB7,0x9D,0x46,0x56,0x0F,0xEE,0xA1,0xCE); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoFrame_v7_1, 0x333F3A10, 0x8C2D, + 0x43CF, 0xB7, 0x9D, 0x46, 0x56, 0x0F, 0xEE, 0xA1, 0xCE); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoInputFrame_v7_1,0xC8B41D95,0x8848,0x40EE,0x9B,0x37,0x6E,0x34,0x17,0xFB,0x11,0x4B); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoInputFrame_v7_1, 0xC8B41D95, + 0x8848, 0x40EE, 0x9B, 0x37, 0x6E, 0x34, 0x17, 0xFB, 0x11, 0x4B); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkAudioInputPacket_v7_1,0xC86DE4F6,0xA29F,0x42E3,0xAB,0x3A,0x13,0x63,0xE2,0x9F,0x07,0x88); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkAudioInputPacket_v7_1, 0xC86DE4F6, + 0xA29F, 0x42E3, 0xAB, 0x3A, 0x13, 0x63, 0xE2, 0x9F, 0x07, 0x88); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkVideoOutputCallback_v7_1,0xEBD01AFA,0xE4B0,0x49C6,0xA0,0x1D,0xED,0xB9,0xD1,0xB5,0x5F,0xD9); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkVideoOutputCallback_v7_1, 0xEBD01AFA, + 0xE4B0, 0x49C6, 0xA0, 0x1D, 0xED, 0xB9, 0xD1, 0xB5, 0x5F, 0xD9); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInputCallback_v7_1,0x7F94F328,0x5ED4,0x4E9F,0x97,0x29,0x76,0xA8,0x6B,0xDC,0x99,0xCC); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInputCallback_v7_1, 0x7F94F328, 0x5ED4, + 0x4E9F, 0x97, 0x29, 0x76, 0xA8, 0x6B, 0xDC, 0x99, 0xCC); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkOutput_v7_1,0xAE5B3E9B,0x4E1E,0x4535,0xB6,0xE8,0x48,0x0F,0xF5,0x2F,0x6C,0xE5); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkOutput_v7_1, 0xAE5B3E9B, 0x4E1E, 0x4535, + 0xB6, 0xE8, 0x48, 0x0F, 0xF5, 0x2F, 0x6C, 0xE5); -MIDL_DEFINE_GUID(IID, IID_IDeckLinkInput_v7_1,0x2B54EDEF,0x5B32,0x429F,0xBA,0x11,0xBB,0x99,0x05,0x96,0xEA,0xCD); + MIDL_DEFINE_GUID (IID, IID_IDeckLinkInput_v7_1, 0x2B54EDEF, 0x5B32, 0x429F, + 0xBA, 0x11, 0xBB, 0x99, 0x05, 0x96, 0xEA, 0xCD); #undef MIDL_DEFINE_GUID #ifdef __cplusplus } #endif - - - diff --git a/sys/directdraw/gstdirectdrawsink.c b/sys/directdraw/gstdirectdrawsink.c index 518ca7cf6..08bb9e0ac 100644 --- a/sys/directdraw/gstdirectdrawsink.c +++ b/sys/directdraw/gstdirectdrawsink.c @@ -386,8 +386,8 @@ gst_directdraw_sink_base_init (gpointer g_class) "Sink/Video", "Output to a video card via Direct Draw", "Sebastien Moutte <sebastien@moutte.net>"); - gst_element_class_add_static_pad_template (element_class, - &directdrawsink_sink_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&directdrawsink_sink_factory)); } static void diff --git a/sys/directsound/gstdirectsoundsrc.c b/sys/directsound/gstdirectsoundsrc.c index 7f0072d25..54282f664 100644 --- a/sys/directsound/gstdirectsoundsrc.c +++ b/sys/directsound/gstdirectsoundsrc.c @@ -156,8 +156,8 @@ gst_directsound_src_base_init (gpointer g_class) "Capture from a soundcard via DIRECTSOUND", "Joni Valtanen <joni.valtanen@movial.fi>"); - gst_element_class_add_static_pad_template (element_class, - &directsound_src_src_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&directsound_src_src_factory)); } diff --git a/sys/dshowdecwrapper/gstdshowaudiodec.cpp b/sys/dshowdecwrapper/gstdshowaudiodec.cpp index bd4bd6496..884b8050d 100644 --- a/sys/dshowdecwrapper/gstdshowaudiodec.cpp +++ b/sys/dshowdecwrapper/gstdshowaudiodec.cpp @@ -349,9 +349,6 @@ gst_dshowaudiodec_base_init (gpointer klass) /* register */ gst_element_class_add_pad_template (element_class, src); gst_element_class_add_pad_template (element_class, sink); - - gst_object_unref (src); - gst_object_unref (sink); } static void @@ -582,7 +579,7 @@ gst_dshowaudiodec_chain (GstPad * pad, GstBuffer * buffer) if (!adec->setup) { /* we are not set up */ GST_WARNING_OBJECT (adec, "Decoder not set up, failing"); - adec->last_ret = GST_FLOW_WRONG_STATE; + adec->last_ret = GST_FLOW_FLUSHING; goto beach; } diff --git a/sys/dshowdecwrapper/gstdshowvideodec.cpp b/sys/dshowdecwrapper/gstdshowvideodec.cpp index fdcfb28bb..370f5192b 100644 --- a/sys/dshowdecwrapper/gstdshowvideodec.cpp +++ b/sys/dshowdecwrapper/gstdshowvideodec.cpp @@ -401,9 +401,6 @@ gst_dshowvideodec_base_init (gpointer klass) gst_element_class_add_pad_template (element_class, src); gst_element_class_add_pad_template (element_class, sink); - - gst_object_unref (src); - gst_object_unref (sink); } static void @@ -856,7 +853,7 @@ gst_dshowvideodec_chain (GstPad * pad, GstBuffer * buffer) if (!vdec->setup) { /* we are not setup */ GST_WARNING_OBJECT (vdec, "Decoder not set up, failing"); - vdec->last_ret = GST_FLOW_WRONG_STATE; + vdec->last_ret = GST_FLOW_FLUSHING; goto beach; } diff --git a/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp b/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp index fcd9f2fc5..e7fbadaab 100644 --- a/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp +++ b/sys/dshowsrcwrapper/gstdshowaudiosrc.cpp @@ -118,7 +118,8 @@ gst_dshowaudiosrc_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "Directshow audio capture source", "Source/Audio", diff --git a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp index 3fa13df3b..35d01ba0f 100644 --- a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp +++ b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp @@ -126,7 +126,8 @@ gst_dshowvideosrc_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "DirectShow video capture source", "Source/Video", @@ -867,7 +868,7 @@ gst_dshowvideosrc_create (GstPushSrc * psrc, GstBuffer ** buf) gst_buffer_unref (*buf); *buf = NULL; } - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } GST_DEBUG ("dshowvideosrc_create => pts %" GST_TIME_FORMAT " duration %" diff --git a/sys/dshowvideosink/dshowvideosink.cpp b/sys/dshowvideosink/dshowvideosink.cpp index 5ac2a5f3b..b1af014fd 100644 --- a/sys/dshowvideosink/dshowvideosink.cpp +++ b/sys/dshowvideosink/dshowvideosink.cpp @@ -212,14 +212,13 @@ gst_dshowvideosink_init_interfaces (GType type) GST_DEBUG_CATEGORY_INIT (dshowvideosink_debug, "dshowvideosink", 0, \ "DirectShow video sink"); } - static void gst_dshowvideosink_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, - &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); gst_element_class_set_details_simple (element_class, "DirectShow video sink", "Sink/Video", "Display data using a DirectShow video renderer", @@ -1676,13 +1675,13 @@ gst_dshowvideosink_show_frame (GstVideoSink *vsink, GstBuffer *buffer) if (!sink->graph_running){ retst = gst_dshowvideosink_start_graph(sink); if (retst == GST_STATE_CHANGE_FAILURE) - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } ret = sink->fakesrc->GetOutputPin()->PushBuffer (buffer); if (!sink->graph_running){ retst = gst_dshowvideosink_pause_graph(sink); if (retst == GST_STATE_CHANGE_FAILURE) - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } GST_DSHOWVIDEOSINK_GRAPH_UNLOCK(sink); GST_DEBUG_OBJECT (sink, "Done pushing buffer through fakesrc->renderer: %s", gst_flow_get_name(ret)); diff --git a/sys/dvb/dvbbasebin.c b/sys/dvb/dvbbasebin.c index a90860a7f..c0b7dd78d 100644 --- a/sys/dvb/dvbbasebin.c +++ b/sys/dvb/dvbbasebin.c @@ -34,13 +34,13 @@ GST_DEBUG_CATEGORY_STATIC (dvb_base_bin_debug); #define GST_CAT_DEFAULT dvb_base_bin_debug static GstStaticPadTemplate src_template = -GST_STATIC_PAD_TEMPLATE ("src%d", GST_PAD_SRC, +GST_STATIC_PAD_TEMPLATE ("src_%u", GST_PAD_SRC, GST_PAD_REQUEST, GST_STATIC_CAPS ("video/mpegts, " "systemstream = (boolean) true ") ); static GstStaticPadTemplate program_template = -GST_STATIC_PAD_TEMPLATE ("program_%d", GST_PAD_SRC, +GST_STATIC_PAD_TEMPLATE ("program_%u", GST_PAD_SRC, GST_PAD_SOMETIMES, GST_STATIC_CAPS ("video/mpegts, " "systemstream = (boolean) true ") ); @@ -99,21 +99,21 @@ static void dvb_base_bin_get_property (GObject * object, guint prop_id, static void dvb_base_bin_dispose (GObject * object); static void dvb_base_bin_finalize (GObject * object); -static gboolean dvb_base_bin_ts_pad_probe_cb (GstPad * pad, - GstBuffer * buf, gpointer user_data); +static GstPadProbeReturn dvb_base_bin_ts_pad_probe_cb (GstPad * pad, + GstPadProbeInfo * info, gpointer user_data); static GstStateChangeReturn dvb_base_bin_change_state (GstElement * element, GstStateChange transition); static void dvb_base_bin_handle_message (GstBin * bin, GstMessage * message); static void dvb_base_bin_pat_info_cb (DvbBaseBin * dvbbasebin, - GstStructure * pat); + const GstStructure * pat); static void dvb_base_bin_pmt_info_cb (DvbBaseBin * dvbbasebin, - GstStructure * pmt); + const GstStructure * pmt); static void dvb_base_bin_pad_added_cb (GstElement * mpegtsparse, GstPad * pad, DvbBaseBin * dvbbasebin); static void dvb_base_bin_pad_removed_cb (GstElement * mpegtsparse, GstPad * pad, DvbBaseBin * dvbbasebin); static GstPad *dvb_base_bin_request_new_pad (GstElement * element, - GstPadTemplate * templ, const gchar * name); + GstPadTemplate * templ, const gchar * name, const GstCaps * caps); static void dvb_base_bin_release_pad (GstElement * element, GstPad * pad); static void dvb_base_bin_rebuild_filter (DvbBaseBin * dvbbasebin); @@ -122,18 +122,6 @@ static void dvb_base_bin_uri_handler_init (gpointer g_iface, static void dvb_base_bin_program_destroy (gpointer data); -static void -dvb_base_bin_setup_interfaces (GType type) -{ - static const GInterfaceInfo urihandler_info = { - dvb_base_bin_uri_handler_init, - NULL, - NULL, - }; - - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); -} - static DvbBaseBinStream * dvb_base_bin_add_stream (DvbBaseBin * dvbbasebin, guint16 pid) { @@ -187,26 +175,10 @@ dvb_base_bin_get_program (DvbBaseBin * dvbbasebin, gint program_number) static guint signals [LAST_SIGNAL] = { 0 }; */ -GST_BOILERPLATE_FULL (DvbBaseBin, dvb_base_bin, GstBin, GST_TYPE_BIN, - dvb_base_bin_setup_interfaces); - -static void -dvb_base_bin_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - element_class->request_new_pad = dvb_base_bin_request_new_pad; - element_class->release_pad = dvb_base_bin_release_pad; - - gst_element_class_add_static_pad_template (element_class, - &program_template); - gst_element_class_add_static_pad_template (element_class, &src_template); - - gst_element_class_set_details_simple (element_class, "DVB bin", - "Source/Bin/Video", - "Access descramble and split DVB streams", - "Alessandro Decina <alessandro@nnva.org>"); -} +#define dvb_base_bin_parent_class parent_class +G_DEFINE_TYPE_WITH_CODE (DvbBaseBin, dvb_base_bin, GST_TYPE_BIN, + G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, + dvb_base_bin_uri_handler_init)); static void dvb_base_bin_class_init (DvbBaseBinClass * klass) @@ -246,6 +218,18 @@ dvb_base_bin_class_init (DvbBaseBinClass * klass) element_class = GST_ELEMENT_CLASS (klass); element_class->change_state = dvb_base_bin_change_state; + element_class->request_new_pad = dvb_base_bin_request_new_pad; + element_class->release_pad = dvb_base_bin_release_pad; + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&program_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); + + gst_element_class_set_details_simple (element_class, "DVB bin", + "Source/Bin/Video", + "Access descramble and split DVB streams", + "Alessandro Decina <alessandro@nnva.org>"); gobject_class = G_OBJECT_CLASS (klass); gobject_class->set_property = dvb_base_bin_set_property; @@ -310,6 +294,7 @@ dvb_base_bin_class_init (DvbBaseBinClass * klass) g_param_spec_string ("program-numbers", "Program Numbers", "Colon separated list of programs", "", G_PARAM_READWRITE)); + } static void @@ -331,7 +316,7 @@ dvb_base_bin_reset (DvbBaseBin * dvbbasebin) static gint16 initial_pids[] = { 0, 1, 0x10, 0x11, 0x12, 0x14, -1 }; static void -dvb_base_bin_init (DvbBaseBin * dvbbasebin, DvbBaseBinClass * klass) +dvb_base_bin_init (DvbBaseBin * dvbbasebin) { DvbBaseBinStream *stream; int i; @@ -472,7 +457,7 @@ dvb_base_bin_get_property (GObject * object, guint prop_id, static GstPad * dvb_base_bin_request_new_pad (GstElement * element, - GstPadTemplate * templ, const gchar * name) + GstPadTemplate * templ, const gchar * name, const GstCaps * caps) { GstPad *pad; GstPad *ghost; @@ -542,8 +527,9 @@ dvb_base_bin_reset_pmtlist (DvbBaseBin * dvbbasebin) dvbbasebin->pmtlist_changed = FALSE; } -static gboolean -dvb_base_bin_ts_pad_probe_cb (GstPad * pad, GstBuffer * buf, gpointer user_data) +static GstPadProbeReturn +dvb_base_bin_ts_pad_probe_cb (GstPad * pad, GstPadProbeInfo * info, + gpointer user_data) { DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (user_data); @@ -560,7 +546,7 @@ dvb_base_bin_ts_pad_probe_cb (GstPad * pad, GstBuffer * buf, gpointer user_data) } } - return TRUE; + return GST_PAD_PROBE_OK; } static void @@ -577,9 +563,10 @@ dvb_base_bin_init_cam (DvbBaseBin * dvbbasebin) if (cam_device_open (dvbbasebin->hwcam, ca_file)) { /* HACK: poll the cam in a buffer probe */ dvbbasebin->ts_pad = - gst_element_get_request_pad (dvbbasebin->mpegtsparse, "src%d"); - gst_pad_add_buffer_probe (dvbbasebin->ts_pad, - G_CALLBACK (dvb_base_bin_ts_pad_probe_cb), dvbbasebin); + gst_element_get_request_pad (dvbbasebin->mpegtsparse, "src_%u"); + gst_pad_add_probe (dvbbasebin->ts_pad, + GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, dvb_base_bin_ts_pad_probe_cb, + dvbbasebin, NULL); } else { GST_ERROR_OBJECT (dvbbasebin, "could not open %s", ca_file); cam_device_free (dvbbasebin->hwcam); @@ -796,12 +783,13 @@ dvb_base_bin_handle_message (GstBin * bin, GstMessage * message) if (message->type == GST_MESSAGE_ELEMENT && GST_ELEMENT (message->src) == GST_ELEMENT (dvbbasebin->mpegtsparse)) { - const gchar *structure_name = gst_structure_get_name (message->structure); + const GstStructure *s = gst_message_get_structure (message); + const gchar *structure_name = gst_structure_get_name (s); if (strcmp (structure_name, "pat") == 0) - dvb_base_bin_pat_info_cb (dvbbasebin, message->structure); + dvb_base_bin_pat_info_cb (dvbbasebin, s); else if (strcmp (structure_name, "pmt") == 0) - dvb_base_bin_pmt_info_cb (dvbbasebin, message->structure); + dvb_base_bin_pmt_info_cb (dvbbasebin, s); /*else if (strcmp (structure_name, "nit") == 0) dvb_base_bin_nit_info_cb (dvbbasebin, message->structure); @@ -821,7 +809,8 @@ dvb_base_bin_handle_message (GstBin * bin, GstMessage * message) static void -dvb_base_bin_pat_info_cb (DvbBaseBin * dvbbasebin, GstStructure * pat_info) +dvb_base_bin_pat_info_cb (DvbBaseBin * dvbbasebin, + const GstStructure * pat_info) { DvbBaseBinProgram *program; DvbBaseBinStream *stream; @@ -869,7 +858,7 @@ dvb_base_bin_pat_info_cb (DvbBaseBin * dvbbasebin, GstStructure * pat_info) } static void -dvb_base_bin_pmt_info_cb (DvbBaseBin * dvbbasebin, GstStructure * pmt) +dvb_base_bin_pmt_info_cb (DvbBaseBin * dvbbasebin, const GstStructure * pmt) { DvbBaseBinProgram *program; guint program_number; @@ -964,50 +953,58 @@ dvb_base_bin_pad_removed_cb (GstElement * mpegtsparse, } static guint -dvb_base_bin_uri_get_type (void) +dvb_base_bin_uri_get_type (GType type) { return GST_URI_SRC; } -static gchar ** -dvb_base_bin_uri_get_protocols (void) +static const gchar *const * +dvb_base_bin_uri_get_protocols (GType type) { - static gchar *protocols[] = { (char *) "dvb", NULL }; + static const gchar *protocols[] = { "dvb", NULL }; return protocols; } -static const gchar * +static gchar * dvb_base_bin_uri_get_uri (GstURIHandler * handler) { - return "dvb://"; + return g_strdup ("dvb://"); } static gboolean -dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri) +dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri, + GError ** error) { - gboolean ret; - gchar *protocol; DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (handler); + gchar *location; - protocol = gst_uri_get_protocol (uri); + location = gst_uri_get_location (uri); - if (strcmp (protocol, "dvb") != 0) { - ret = FALSE; - } else { - gchar *location = gst_uri_get_location (uri); + if (location == NULL) + goto no_location; - if (location != NULL) { - ret = set_properties_for_channel (G_OBJECT (dvbbasebin), location); - g_free (location); - } else - ret = FALSE; - } + if (!set_properties_for_channel (G_OBJECT (dvbbasebin), location)) + goto set_properties_failed; - /* here is where we parse channels.conf */ - g_free (protocol); + /* FIXME: here is where we parse channels.conf */ - return ret; + g_free (location); + return TRUE; +/* ERRORS */ +no_location: + { + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "No details to DVB URI"); + return FALSE; + } +set_properties_failed: + { + g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI, + "Could not set properties from DVB URI"); + g_free (location); + return FALSE; + } } static void diff --git a/sys/dvb/gstdvbsrc.c b/sys/dvb/gstdvbsrc.c index 13f5726d8..c13f33639 100644 --- a/sys/dvb/gstdvbsrc.c +++ b/sys/dvb/gstdvbsrc.c @@ -306,24 +306,8 @@ static GstStaticPadTemplate ts_src_factory = GST_STATIC_PAD_TEMPLATE ("src", ****************************** */ -GST_BOILERPLATE (GstDvbSrc, gst_dvbsrc, GstPushSrc, GST_TYPE_PUSH_SRC); - -static void -gst_dvbsrc_base_init (gpointer gclass) -{ - GstDvbSrcClass *klass = (GstDvbSrcClass *) gclass; - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_static_pad_template (element_class, - &ts_src_factory); - - gst_element_class_set_details_simple (element_class, "DVB Source", - "Source/Video", - "Digital Video Broadcast Source", - "P2P-VCR, C-Lab, University of Paderborn," - "Zaheer Abbas Merali <zaheerabbas at merali dot org>"); -} - +#define gst_dvbsrc_parent_class parent_class +G_DEFINE_TYPE (GstDvbSrc, gst_dvbsrc, GST_TYPE_PUSH_SRC); /* initialize the plugin's class */ static void @@ -344,6 +328,16 @@ gst_dvbsrc_class_init (GstDvbSrcClass * klass) gobject_class->finalize = gst_dvbsrc_finalize; gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_dvbsrc_change_state); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&ts_src_factory)); + + gst_element_class_set_details_simple (gstelement_class, "DVB Source", + "Source/Video", + "Digital Video Broadcast Source", + "P2P-VCR, C-Lab, University of Paderborn," + "Zaheer Abbas Merali <zaheerabbas at merali dot org>"); + gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvbsrc_start); gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvbsrc_stop); gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_dvbsrc_unlock); @@ -460,7 +454,7 @@ gst_dvbsrc_class_init (GstDvbSrcClass * klass) * initialize structure */ static void -gst_dvbsrc_init (GstDvbSrc * object, GstDvbSrcClass * klass) +gst_dvbsrc_init (GstDvbSrc * object) { int i = 0; @@ -497,7 +491,7 @@ gst_dvbsrc_init (GstDvbSrc * object, GstDvbSrcClass * klass) object->inversion = DEFAULT_INVERSION; object->stats_interval = DEFAULT_STATS_REPORTING_INTERVAL; - object->tune_mutex = g_mutex_new (); + g_mutex_init (&object->tune_mutex); object->timeout = DEFAULT_TIMEOUT; } @@ -626,9 +620,9 @@ gst_dvbsrc_set_property (GObject * _object, guint prop_id, /* if we are in paused/playing state tune now, otherwise in ready to paused state change */ if (GST_STATE (object) > GST_STATE_READY) { - g_mutex_lock (object->tune_mutex); + g_mutex_lock (&object->tune_mutex); gst_dvbsrc_tune (object); - g_mutex_unlock (object->tune_mutex); + g_mutex_unlock (&object->tune_mutex); } break; } @@ -865,7 +859,7 @@ gst_dvbsrc_finalize (GObject * _object) object = GST_DVBSRC (_object); /* freeing the mutex segfaults somehow */ - g_mutex_free (object->tune_mutex); + g_mutex_clear (&object->tune_mutex); if (G_OBJECT_CLASS (parent_class)->finalize) G_OBJECT_CLASS (parent_class)->finalize (_object); @@ -910,12 +904,14 @@ gst_dvbsrc_read_device (GstDvbSrc * object, int size) gint ret_val = 0; GstBuffer *buf = gst_buffer_new_and_alloc (size); GstClockTime timeout = object->timeout * GST_USECOND; + GstMapInfo map; g_return_val_if_fail (GST_IS_BUFFER (buf), NULL); if (object->fd_dvr < 0) return NULL; + gst_buffer_map (buf, &map, GST_MAP_WRITE); while (count < size) { ret_val = gst_poll_wait (object->poll, timeout); GST_LOG_OBJECT (object, "select returned %d", ret_val); @@ -928,10 +924,9 @@ gst_dvbsrc_read_device (GstDvbSrc * object, int size) /* timeout, post element message */ gst_element_post_message (GST_ELEMENT_CAST (object), gst_message_new_element (GST_OBJECT (object), - gst_structure_empty_new ("dvb-read-failure"))); + gst_structure_new_empty ("dvb-read-failure"))); } else { - int nread = - read (object->fd_dvr, GST_BUFFER_DATA (buf) + count, size - count); + int nread = read (object->fd_dvr, map.data + count, size - count); if (G_UNLIKELY (nread < 0)) { GST_WARNING_OBJECT @@ -940,23 +935,26 @@ gst_dvbsrc_read_device (GstDvbSrc * object, int size) object->adapter_number, object->frontend_number, errno); gst_element_post_message (GST_ELEMENT_CAST (object), gst_message_new_element (GST_OBJECT (object), - gst_structure_empty_new ("dvb-read-failure"))); + gst_structure_new_empty ("dvb-read-failure"))); } else count = count + nread; } } + gst_buffer_unmap (buf, &map); + gst_buffer_resize (buf, 0, count); - GST_BUFFER_SIZE (buf) = count; return buf; stopped: GST_DEBUG_OBJECT (object, "stop called"); + gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); return NULL; select_error: GST_ELEMENT_ERROR (object, RESOURCE, READ, (NULL), ("select error %d: %s (%d)", ret_val, g_strerror (errno), errno)); + gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); return NULL; } @@ -975,7 +973,7 @@ gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf) buffer_size = DEFAULT_BUFFER_SIZE; /* device can not be tuned during read */ - g_mutex_lock (object->tune_mutex); + g_mutex_lock (&object->tune_mutex); if (object->fd_dvr > -1) { @@ -983,13 +981,7 @@ gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf) GST_DEBUG_OBJECT (object, "Reading from DVR device"); *buf = gst_dvbsrc_read_device (object, buffer_size); if (*buf != NULL) { - GstCaps *caps; - retval = GST_FLOW_OK; - - caps = gst_pad_get_caps (GST_BASE_SRC_PAD (object)); - gst_buffer_set_caps (*buf, caps); - gst_caps_unref (caps); } if (object->stats_interval != 0 && @@ -999,7 +991,7 @@ gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf) } } - g_mutex_unlock (object->tune_mutex); + g_mutex_unlock (&object->tune_mutex); return retval; } diff --git a/sys/dvb/gstdvbsrc.h b/sys/dvb/gstdvbsrc.h index 8feac593f..e290f4d6b 100644 --- a/sys/dvb/gstdvbsrc.h +++ b/sys/dvb/gstdvbsrc.h @@ -41,7 +41,7 @@ G_BEGIN_DECLS GstPushSrc element; GstPad *srcpad; - GMutex *tune_mutex; + GMutex tune_mutex; gboolean need_tune; int adapter_type; diff --git a/sys/dvb/parsechannels.c b/sys/dvb/parsechannels.c index 6de7b12a3..b2d3aef2c 100644 --- a/sys/dvb/parsechannels.c +++ b/sys/dvb/parsechannels.c @@ -156,8 +156,8 @@ set_properties_for_channel (GObject * dvbbasebin, const gchar * channel_name) guint major, minor, micro, nano; gst_version (&major, &minor, µ, &nano); - filename = g_strdup_printf ("%s/.gstreamer-%d.%d/dvb-channels.conf", - g_get_home_dir (), major, minor); + filename = g_strdup_printf ("%s/gstreamer-%d.%d/dvb-channels.conf", + g_get_user_config_dir (), major, minor); } channels = parse_channels_conf_from_file (filename); g_free (filename); diff --git a/sys/dxr3/dxr3audiosink.c b/sys/dxr3/dxr3audiosink.c index b72544b2b..53a69636a 100644 --- a/sys/dxr3/dxr3audiosink.c +++ b/sys/dxr3/dxr3audiosink.c @@ -93,7 +93,8 @@ static gboolean dxr3audiosink_open (Dxr3AudioSink * sink); static gboolean dxr3audiosink_set_mode_pcm (Dxr3AudioSink * sink); static gboolean dxr3audiosink_set_mode_ac3 (Dxr3AudioSink * sink); static void dxr3audiosink_close (Dxr3AudioSink * sink); -static void dxr3audiosink_set_clock (GstElement * element, GstClock * clock); +static gboolean dxr3audiosink_set_clock (GstElement * element, + GstClock * clock); static GstPadLinkReturn dxr3audiosink_pcm_sinklink (GstPad * pad, const GstCaps * caps); @@ -148,10 +149,10 @@ dxr3audiosink_base_init (Dxr3AudioSinkClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, - &dxr3audiosink_pcm_sink_factory); - gst_element_class_add_static_pad_template (element_class, - &dxr3audiosink_ac3_sink_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&dxr3audiosink_pcm_sink_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&dxr3audiosink_ac3_sink_factory)); gst_element_class_set_details_simple (element_class, "dxr3/Hollywood+ mpeg decoder board audio plugin", "Audio/Sink", "Feeds audio to Sigma Designs em8300 based boards", @@ -440,12 +441,14 @@ dxr3audiosink_close (Dxr3AudioSink * sink) } -static void +static gboolean dxr3audiosink_set_clock (GstElement * element, GstClock * clock) { Dxr3AudioSink *src = DXR3AUDIOSINK (element); src->clock = clock; + + return GST_ELEMENT_CLASS (parent_class)->set_clock (element, clock); } diff --git a/sys/dxr3/dxr3spusink.c b/sys/dxr3/dxr3spusink.c index 7e4d021ef..ec713fbb4 100644 --- a/sys/dxr3/dxr3spusink.c +++ b/sys/dxr3/dxr3spusink.c @@ -72,7 +72,7 @@ static void dxr3spusink_get_property (GObject * object, static gboolean dxr3spusink_open (Dxr3SpuSink * sink); static void dxr3spusink_close (Dxr3SpuSink * sink); -static void dxr3spusink_set_clock (GstElement * element, GstClock * clock); +static gboolean dxr3spusink_set_clock (GstElement * element, GstClock * clock); static gboolean dxr3spusink_handle_event (GstPad * pad, GstEvent * event); static void dxr3spusink_chain (GstPad * pad, GstData * _data); @@ -126,8 +126,8 @@ dxr3spusink_base_init (Dxr3SpuSinkClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, - &dxr3spusink_sink_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&dxr3spusink_sink_factory)); gst_element_class_set_details_simple (element_class, "dxr3/Hollywood+ mpeg decoder board subpicture element", "Sink/Video", "Feeds subpicture information to Sigma Designs em8300 based boards", @@ -305,12 +305,14 @@ dxr3spusink_close (Dxr3SpuSink * sink) } -static void +static gboolean dxr3spusink_set_clock (GstElement * element, GstClock * clock) { Dxr3SpuSink *src = DXR3SPUSINK (element); src->clock = clock; + + return GST_ELEMENT_CLASS (element)->set_clock (element, clock); } diff --git a/sys/dxr3/dxr3videosink.c b/sys/dxr3/dxr3videosink.c index 437789cab..9ee27b4e1 100644 --- a/sys/dxr3/dxr3videosink.c +++ b/sys/dxr3/dxr3videosink.c @@ -96,7 +96,8 @@ static void dxr3videosink_get_property (GObject * object, static gboolean dxr3videosink_open (Dxr3VideoSink * sink); static void dxr3videosink_close (Dxr3VideoSink * sink); -static void dxr3videosink_set_clock (GstElement * element, GstClock * clock); +static gboolean dxr3videosink_set_clock (GstElement * element, + GstClock * clock); static void dxr3videosink_reset_parser (Dxr3VideoSink * sink); static int dxr3videosink_next_start_code (Dxr3VideoSink * sink); @@ -151,8 +152,8 @@ dxr3videosink_base_init (Dxr3VideoSinkClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, - &dxr3videosink_sink_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&dxr3videosink_sink_factory)); gst_element_class_set_details_simple (element_class, "dxr3/Hollywood+ mpeg decoder board video element", "Sink/Video", "Feeds MPEG2 video to Sigma Designs em8300 based boards", @@ -308,12 +309,14 @@ dxr3videosink_close (Dxr3VideoSink * sink) } -static void +static gboolean dxr3videosink_set_clock (GstElement * element, GstClock * clock) { Dxr3VideoSink *src = DXR3VIDEOSINK (element); src->clock = clock; + + return GST_ELEMENT_CLASS (parent_class)->set_clock (element, clock); } @@ -596,7 +599,6 @@ dxr3videosink_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); Dxr3VideoSink *sink; - GstBuffer *merged; g_return_if_fail (pad != NULL); g_return_if_fail (GST_IS_PAD (pad)); @@ -614,10 +616,7 @@ dxr3videosink_chain (GstPad * pad, GstData * _data) if (sink->cur_buf == NULL) { sink->cur_buf = buf; } else { - merged = gst_buffer_merge (sink->cur_buf, buf); - gst_buffer_unref (sink->cur_buf); - gst_buffer_unref (buf); - sink->cur_buf = merged; + sink->cur_buf = gst_buffer_append (sink->cur_buf, buf); } sink->last_ts = GST_BUFFER_TIMESTAMP (buf); diff --git a/sys/fbdev/gstfbdevsink.c b/sys/fbdev/gstfbdevsink.c index 7878fbfbc..8925f3d30 100644 --- a/sys/fbdev/gstfbdevsink.c +++ b/sys/fbdev/gstfbdevsink.c @@ -93,8 +93,8 @@ gst_fbdevsink_base_init (gpointer g_class) gst_element_class_set_details_simple (element_class, "fbdev video sink", "Sink/Video", "A linux framebuffer videosink", "Sean D'Epagnier <sean@depagnier.com>"); - gst_element_class_add_static_pad_template (element_class, - &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } diff --git a/sys/linsys/gstlinsyssdisink.c b/sys/linsys/gstlinsyssdisink.c index 28b64b2f9..57813d39a 100644 --- a/sys/linsys/gstlinsyssdisink.c +++ b/sys/linsys/gstlinsyssdisink.c @@ -99,8 +99,8 @@ gst_linsys_sdi_sink_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_static_pad_template (element_class, - &gst_linsys_sdi_sink_sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_linsys_sdi_sink_sink_template)); gst_element_class_set_details_simple (element_class, "SDI video sink", "Sink/Video", "Writes video from SDI transmit device", diff --git a/sys/linsys/gstlinsyssdisrc.c b/sys/linsys/gstlinsyssdisrc.c index a9732f51e..11384c8b3 100644 --- a/sys/linsys/gstlinsyssdisrc.c +++ b/sys/linsys/gstlinsyssdisrc.c @@ -103,8 +103,8 @@ gst_linsys_sdi_src_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_static_pad_template (element_class, - &gst_linsys_sdi_src_src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_linsys_sdi_src_src_template)); gst_element_class_set_details_simple (element_class, "SDI video source", "Source/Video", "Reads video from SDI capture device", @@ -415,7 +415,7 @@ gst_linsys_sdi_src_create (GstBaseSrc * src, guint64 _offset, guint size, guint8 *data = linsyssdisrc->tmpdata; if (linsyssdisrc->fd < 0) - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; if (linsyssdisrc->is_625) { sdi_width = 864; diff --git a/sys/osxvideo/osxvideosrc.c b/sys/osxvideo/osxvideosrc.c index 864806dcc..ed84619d7 100644 --- a/sys/osxvideo/osxvideosrc.c +++ b/sys/osxvideo/osxvideosrc.c @@ -639,7 +639,8 @@ gst_osx_video_src_base_init (gpointer gclass) GST_DEBUG ("%s", G_STRFUNC); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "Video Source (OSX)", "Source/Video", diff --git a/sys/pvr2d/gstpvr.c b/sys/pvr2d/gstpvr.c index 0112d1ee7..123d15d81 100644 --- a/sys/pvr2d/gstpvr.c +++ b/sys/pvr2d/gstpvr.c @@ -69,6 +69,34 @@ gst_ducati_alloc_2d (gint width, gint height, guint * sz) return MemMgr_Alloc (block, 2); } +static struct +{ + PVR2DERROR code; + const gchar *errstring; +} pvr2derrorcodestring[] = { + { + PVR2D_OK, "OK (0)"}, { + PVR2DERROR_INVALID_PARAMETER, "Invalid Parameter (-1)"}, { + PVR2DERROR_DEVICE_UNAVAILABLE, "Device Unavailable (-2)"}, { + PVR2DERROR_INVALID_CONTEXT, "Invalid Context (-3)"}, { + PVR2DERROR_MEMORY_UNAVAILABLE, "Memory Unavailable (-4)"}, { + PVR2DERROR_DEVICE_NOT_PRESENT, "Device not present (-5)"}, { + PVR2DERROR_IOCTL_ERROR, "ioctl Error (-6)"}, { + PVR2DERROR_GENERIC_ERROR, "Generic Error (-7)"}, { + PVR2DERROR_BLT_NOTCOMPLETE, "blt not complete (-8)"}, { + PVR2DERROR_HW_FEATURE_NOT_SUPPORTED, "Hardware feature not supported (-9)"}, { + PVR2DERROR_NOT_YET_IMPLEMENTED, "Not yet implemented (-10)"}, { + PVR2DERROR_MAPPING_FAILED, "Mapping failed (-11)"} +}; + +const gchar * +gst_pvr2d_error_get_string (PVR2DERROR code) +{ + if (code <= PVR2D_OK && code >= PVR2DERROR_MAPPING_FAILED) + return pvr2derrorcodestring[PVR2D_OK - code].errstring; + return "Uknown Error"; +} + /* PACKAGE: this is usually set by autotools depending on some _INIT macro * in configure.ac and then written into and defined in config.h, but we can * just set it ourselves here in case someone doesn't use autotools to diff --git a/sys/pvr2d/gstpvr.h b/sys/pvr2d/gstpvr.h index d2c57af00..bbde497ae 100644 --- a/sys/pvr2d/gstpvr.h +++ b/sys/pvr2d/gstpvr.h @@ -26,6 +26,8 @@ #include <tiler.h> #include <tilermem.h> #include <memmgr.h> +#include "pvr2d.h" + #include <gst/gst.h> @@ -37,6 +39,8 @@ G_BEGIN_DECLS void * gst_ducati_alloc_1d (gint sz); void * gst_ducati_alloc_2d (gint width, gint height, guint * sz); +const gchar * gst_pvr2d_error_get_string (PVR2DERROR code); + G_END_DECLS #endif /* __GST_DUCATI_H__ */ diff --git a/sys/pvr2d/gstpvrbufferpool.c b/sys/pvr2d/gstpvrbufferpool.c index 03bcafb68..5b2d43ef4 100644 --- a/sys/pvr2d/gstpvrbufferpool.c +++ b/sys/pvr2d/gstpvrbufferpool.c @@ -1,6 +1,8 @@ /* * GStreamer * Copyright (c) 2010, Texas Instruments Incorporated + * Copyright (c) 2011, Collabora Ltd + * @author: Edward Hervey <edward@collabora.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,304 +19,352 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "gstpvrbufferpool.h" +/* Debugging category */ +#include <gst/gstinfo.h> + +/* Helper functions */ +#include <gst/video/video.h> +#include <gst/video/gstvideometa.h> +#include <gst/video/gstvideopool.h> + + GST_DEBUG_CATEGORY_EXTERN (gst_debug_pvrvideosink); #define GST_CAT_DEFAULT gst_debug_pvrvideosink -/* - * GstDucatiBuffer - */ +static void +gst_pvr_meta_free (GstPVRMeta * meta, GstBuffer * buffer) +{ + GstPVRVideoSink *pvrsink = (GstPVRVideoSink *) meta->sink; -static GstBufferClass *buffer_parent_class; + GST_LOG ("Releasing PVRMeta for buffer %p (src_mem:%p)", + buffer, meta->src_mem); -/* Get the original buffer, or whatever is the best output buffer. - * Consumes the input reference, produces the output reference - */ -GstBuffer * -gst_ducati_buffer_get (GstDucatiBuffer * self) -{ - if (self->orig) { - // TODO copy to orig buffer.. if needed. - gst_buffer_unref (self->orig); - self->orig = NULL; + if (meta->src_mem) { + PVR2DERROR pvr_error; + + GST_OBJECT_LOCK (pvrsink); + if (pvrsink->dcontext == NULL || pvrsink->dcontext->pvr_context == NULL) { + GST_OBJECT_UNLOCK (pvrsink); + goto done; + } + pvr_error = PVR2DMemFree (pvrsink->dcontext->pvr_context, meta->src_mem); + GST_OBJECT_UNLOCK (pvrsink); + + if (pvr_error != PVR2D_OK) + GST_ERROR ("Failed to unwrap PVR memory buffer. Error : %s", + gst_pvr2d_error_get_string (pvr_error)); } - return GST_BUFFER (self); + +done: + gst_pvrvideosink_untrack_buffer (pvrsink, buffer); + gst_object_unref (pvrsink); } -PVR2DMEMINFO * -gst_ducati_buffer_get_meminfo (GstDucatiBuffer * self) +const GstMetaInfo * +gst_pvr_meta_get_info (void) { - return self->src_mem; -} + static const GstMetaInfo *pvr_meta_info = NULL; + + if (pvr_meta_info == NULL) { + pvr_meta_info = gst_meta_register ("GstPVRMeta", "GstPVRMeta", + sizeof (GstPVRMeta), + (GstMetaInitFunction) NULL, + (GstMetaFreeFunction) gst_pvr_meta_free, + (GstMetaCopyFunction) NULL, (GstMetaTransformFunction) NULL); + } + return pvr_meta_info; +} -static GstDucatiBuffer * -gst_ducati_buffer_new (GstPvrBufferPool * pool) +/* Wrap existing buffers */ +GstPVRMeta * +gst_buffer_add_pvr_meta (GstBuffer * buffer, GstElement * sink) { + guint8 *data; + gsize size; + GstPVRMeta *meta; PVR2DERROR pvr_error; - GstDucatiBuffer *self = (GstDucatiBuffer *) - gst_mini_object_new (GST_TYPE_DUCATIBUFFER); + GstPVRVideoSink *pvrsink = (GstPVRVideoSink *) sink; - GST_LOG_OBJECT (pool->element, "creating buffer %p in pool %p", self, pool); + g_return_val_if_fail (gst_buffer_n_memory (buffer) > 0, NULL); + g_return_val_if_fail (pvrsink != NULL, NULL); - self->pool = (GstPvrBufferPool *) - gst_mini_object_ref (GST_MINI_OBJECT (pool)); + GST_LOG_OBJECT (pvrsink, "Adding PVRMeta to buffer %p", buffer); - GST_BUFFER_DATA (self) = gst_ducati_alloc_1d (pool->size); - GST_BUFFER_SIZE (self) = pool->size; - GST_LOG_OBJECT (pool->element, "width=%d, height=%d and size=%d", - pool->padded_width, pool->padded_height, pool->size); + /* Add the meta */ + meta = (GstPVRMeta *) gst_buffer_add_meta (buffer, GST_PVR_META_INFO, NULL); + meta->src_mem = NULL; + meta->sink = gst_object_ref (pvrsink); + gst_pvrvideosink_track_buffer (pvrsink, buffer); - pvr_error = - PVR2DMemWrap (pool->pvr_context, GST_BUFFER_DATA (self), 0, pool->size, - NULL, &(self->src_mem)); - if (pvr_error != PVR2D_OK) { - GST_LOG_OBJECT (pool->element, "Failed to Wrap buffer memory" - "returned %d", pvr_error); - } else { - self->wrapped = TRUE; - } + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); - gst_buffer_set_caps (GST_BUFFER (self), pool->caps); + GST_LOG_OBJECT (pvrsink, "data:%p, size:%" G_GSIZE_FORMAT, data, size); - return self; -} + GST_OBJECT_LOCK (pvrsink); + if (pvrsink->dcontext == NULL || pvrsink->dcontext->pvr_context == NULL) + goto no_pvr_context; + /* Map the memory and wrap it */ + pvr_error = + PVR2DMemWrap (pvrsink->dcontext->pvr_context, data, 0, size, NULL, + &(meta->src_mem)); + GST_OBJECT_UNLOCK (pvrsink); + gst_buffer_unmap (buffer, data, size); -static void -gst_ducati_buffer_finalize (GstDucatiBuffer * self) -{ - PVR2DERROR pvr_error; - GstPvrBufferPool *pool = self->pool; - gboolean resuscitated = FALSE; - - GST_LOG_OBJECT (pool->element, "finalizing buffer %p", self); + if (pvr_error != PVR2D_OK) + goto wrap_error; - GST_PVR_BUFFERPOOL_LOCK (pool); - g_queue_remove (pool->used_buffers, self); - if (pool->running) { - resuscitated = TRUE; + return meta; - GST_LOG_OBJECT (pool->element, "reviving buffer %p", self); +wrap_error: + { + GST_WARNING_OBJECT (pvrsink, "Failed to Wrap buffer memory. Error : %s", + gst_pvr2d_error_get_string (pvr_error)); + gst_buffer_remove_meta (buffer, (GstMeta *) meta); - g_queue_push_head (pool->free_buffers, self); - } else { - GST_LOG_OBJECT (pool->element, "the pool is shutting down"); + return NULL; } - GST_PVR_BUFFERPOOL_UNLOCK (pool); - if (resuscitated) { - GST_LOG_OBJECT (pool->element, "reviving buffer %p, %d", self, index); - gst_buffer_ref (GST_BUFFER (self)); - GST_BUFFER_SIZE (self) = 0; - } - - if (!resuscitated) { - GST_LOG_OBJECT (pool->element, - "buffer %p (data %p, len %u) not recovered, freeing", - self, GST_BUFFER_DATA (self), GST_BUFFER_SIZE (self)); - - if (self->wrapped) { - pvr_error = PVR2DMemFree (pool->pvr_context, self->src_mem); - if (pvr_error != PVR2D_OK) { - GST_ERROR_OBJECT (pool->element, "Failed to Unwrap buffer memory" - "returned %d", pvr_error); - } - self->wrapped = FALSE; - } - MemMgr_Free ((void *) GST_BUFFER_DATA (self)); - GST_BUFFER_DATA (self) = NULL; - gst_mini_object_unref (GST_MINI_OBJECT (pool)); - GST_MINI_OBJECT_CLASS (buffer_parent_class)->finalize (GST_MINI_OBJECT - (self)); +no_pvr_context: + { + GST_OBJECT_UNLOCK (pvrsink); + GST_WARNING_OBJECT (pvrsink, "No PVR2D context available"); + gst_buffer_remove_meta (buffer, (GstMeta *) meta); + return NULL; } } -static void -gst_ducati_buffer_class_init (gpointer g_class, gpointer class_data) -{ - GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class); +/* + * GstDucatiBufferPool + */ +static void gst_pvr_buffer_pool_finalize (GObject * object); - buffer_parent_class = g_type_class_peek_parent (g_class); +#define gst_pvr_buffer_pool_parent_class parent_class +G_DEFINE_TYPE (GstPVRBufferPool, gst_pvr_buffer_pool, GST_TYPE_BUFFER_POOL); +static const gchar ** +pvr_buffer_pool_get_options (GstBufferPool * pool) +{ + static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT, NULL + }; - mini_object_class->finalize = (GstMiniObjectFinalizeFunction) - GST_DEBUG_FUNCPTR (gst_ducati_buffer_finalize); + return options; } -GType -gst_ducati_buffer_get_type (void) +static gboolean +pvr_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) { - static GType type; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo info = { - .class_size = sizeof (GstBufferClass), - .class_init = gst_ducati_buffer_class_init, - .instance_size = sizeof (GstDucatiBuffer), - }; - type = g_type_register_static (GST_TYPE_BUFFER, - "GstDucatiBufferPvrsink", &info, 0); + GstPVRBufferPool *pvrpool = GST_PVR_BUFFER_POOL_CAST (pool); + GstVideoInfo info; + guint size, align; + gboolean ret; + const GstCaps *caps; + + if (!gst_buffer_pool_config_get (config, &caps, &size, NULL, NULL, NULL, + &align)) + goto wrong_config; + + if (caps == NULL) + goto no_caps; + + /* now parse the caps from the config */ + if (!gst_video_info_from_caps (&info, caps)) + goto wrong_caps; + + GST_LOG_OBJECT (pool, "%dx%d, size:%u, align:%u caps %" GST_PTR_FORMAT, + info.width, info.height, size, align, caps); + + if (pvrpool->caps) + gst_caps_unref (pvrpool->caps); + pvrpool->caps = gst_caps_copy (caps); + pvrpool->info = info; + pvrpool->size = size; + gst_allocation_params_init (&pvrpool->params); + pvrpool->params.align = align; + pvrpool->padded_width = GST_VIDEO_INFO_WIDTH (&info); + pvrpool->padded_height = GST_VIDEO_INFO_HEIGHT (&info); + + /* enable metadata based on config of the pool */ + pvrpool->add_metavideo = + gst_buffer_pool_config_has_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_META); + +#if 0 + /* parse extra alignment info */ + priv->need_alignment = gst_buffer_pool_config_has_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); + + if (priv->need_alignment) { + gst_buffer_pool_config_get_video_alignment (config, &priv->align); + + GST_LOG_OBJECT (pool, "padding %u-%ux%u-%u", priv->align.padding_top, + priv->align.padding_left, priv->align.padding_left, + priv->align.padding_bottom); + + /* we need the video metadata too now */ + priv->add_metavideo = TRUE; } - return type; -} -/* - * GstDucatiBufferPool - */ + /* add the padding */ + priv->padded_width = + GST_VIDEO_INFO_WIDTH (&info) + priv->align.padding_left + + priv->align.padding_right; + priv->padded_height = + GST_VIDEO_INFO_HEIGHT (&info) + priv->align.padding_top + + priv->align.padding_bottom; +#endif -static GstMiniObjectClass *bufferpool_parent_class = NULL; + GST_DEBUG_OBJECT (pool, "before calling parent class"); -/** create new bufferpool - * @element : the element that owns this pool - * @caps: the caps to set on the buffer - * @num_buffers: the requested number of buffers in the pool - */ -GstPvrBufferPool * -gst_pvr_bufferpool_new (GstElement * element, GstCaps * caps, gint num_buffers, - gint size, PVR2DCONTEXTHANDLE pvr_context) -{ - GstPvrBufferPool *self = (GstPvrBufferPool *) - gst_mini_object_new (GST_TYPE_PVRBUFFERPOOL); - GstStructure *s = gst_caps_get_structure (caps, 0); - - self->element = gst_object_ref (element); - gst_structure_get_int (s, "width", &self->padded_width); - gst_structure_get_int (s, "height", &self->padded_height); - self->caps = gst_caps_ref (caps); - self->size = size; - self->pvr_context = pvr_context; - - self->free_buffers = g_queue_new (); - self->used_buffers = g_queue_new (); - self->lock = g_mutex_new (); - self->running = TRUE; - - return self; + ret = GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config); + + GST_DEBUG_OBJECT (pool, "parent_class returned %d", ret); + + return ret; + + /* ERRORS */ +wrong_config: + { + GST_WARNING_OBJECT (pool, "invalid config"); + return FALSE; + } +no_caps: + { + GST_WARNING_OBJECT (pool, "no caps in config"); + return FALSE; + } +wrong_caps: + { + GST_WARNING_OBJECT (pool, + "failed getting geometry from caps %" GST_PTR_FORMAT, caps); + return FALSE; + } } -static void -unwrap_buffer (gpointer buffer, gpointer user_data) +/* This function handles GstXImageBuffer creation depending on XShm availability */ +static GstFlowReturn +pvr_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, + GstBufferPoolAcquireParams * params) { - PVR2DERROR pvr_error; - GstDucatiBuffer *buf = GST_DUCATIBUFFER (buffer); - GstPvrBufferPool *pool = (GstPvrBufferPool *) user_data; - - if (buf->wrapped) { - pvr_error = PVR2DMemFree (pool->pvr_context, buf->src_mem); - if (pvr_error != PVR2D_OK) { - GST_ERROR_OBJECT (pool->element, "Failed to Unwrap buffer memory" - "returned %d", pvr_error); + GstPVRBufferPool *pvrpool = GST_PVR_BUFFER_POOL_CAST (pool); + GstVideoInfo *info; + GstBuffer *pvr; + GstPVRMeta *meta; + + info = &pvrpool->info; + + pvr = gst_buffer_new_allocate (NULL, pvrpool->size, &pvrpool->params); + meta = gst_buffer_add_pvr_meta (pvr, pvrpool->pvrsink); + if (meta == NULL) { + gst_buffer_unref (pvr); + goto no_buffer; + } + + if (pvrpool->add_metavideo) { + GstVideoMeta *meta; + + GST_DEBUG_OBJECT (pool, "adding GstVideoMeta"); + /* these are just the defaults for now */ + meta = gst_buffer_add_video_meta (pvr, 0, GST_VIDEO_INFO_FORMAT (info), + pvrpool->padded_width, pvrpool->padded_height); + if (G_UNLIKELY (meta == NULL)) + GST_WARNING_OBJECT (pool, "Failed to add GstVideoMeta"); + +#if 0 + const GstVideoFormatInfo *vinfo = info->finfo; + gint i; + + if (pvrpool->need_alignment) { + meta->width = GST_VIDEO_INFO_WIDTH (&pvrpool->info); + meta->height = GST_VIDEO_INFO_HEIGHT (&pvrpool->info); + + /* FIXME, not quite correct, NV12 would apply the vedge twice on the second + * plane */ + for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++) { + gint vedge, hedge, plane; + + hedge = + GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (vinfo, i, + pvrpool->align.padding_left); + vedge = + GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo, i, + pvrpool->align.padding_top); + plane = GST_VIDEO_FORMAT_INFO_PLANE (vinfo, i); + + GST_LOG_OBJECT (pool, "comp %d, plane %d: hedge %d, vedge %d", i, + plane, hedge, vedge); + + meta->offset[plane] += (vedge * meta->stride[plane]) + hedge; + } } - buf->wrapped = FALSE; +#endif + } + + *buffer = pvr; + + return GST_FLOW_OK; + + /* ERROR */ +no_buffer: + { + GST_WARNING_OBJECT (pool, "can't create image"); + return GST_FLOW_ERROR; } } -void -gst_pvr_bufferpool_stop_running (GstPvrBufferPool * self, gboolean unwrap) +/** create new bufferpool + */ +GstBufferPool * +gst_pvr_buffer_pool_new (GstElement * pvrsink) { - gboolean empty = FALSE; - - g_return_if_fail (self); - - GST_PVR_BUFFERPOOL_LOCK (self); - self->running = FALSE; - GST_PVR_BUFFERPOOL_UNLOCK (self); - - GST_DEBUG_OBJECT (self->element, "free available buffers"); - - /* free all buffers on the freelist */ - while (!empty) { - GstDucatiBuffer *buf; - GST_PVR_BUFFERPOOL_LOCK (self); - buf = g_queue_pop_head (self->free_buffers); - GST_PVR_BUFFERPOOL_UNLOCK (self); - if (buf) - gst_buffer_unref (GST_BUFFER (buf)); - else - empty = TRUE; - } + GstPVRBufferPool *pool; + + g_return_val_if_fail (GST_IS_PVRVIDEOSINK (pvrsink), NULL); - if (unwrap) - g_queue_foreach (self->used_buffers, unwrap_buffer, self); + GST_DEBUG_OBJECT (pvrsink, "Creating new GstPVRBufferPool"); - gst_mini_object_unref (GST_MINI_OBJECT (self)); + pool = g_object_new (GST_TYPE_PVR_BUFFER_POOL, NULL); + pool->pvrsink = gst_object_ref (pvrsink); + + return GST_BUFFER_POOL_CAST (pool); } -/** get buffer from bufferpool, allocate new buffer if needed */ -GstDucatiBuffer * -gst_pvr_bufferpool_get (GstPvrBufferPool * self, GstBuffer * orig) +static void +gst_pvr_buffer_pool_class_init (GstPVRBufferPoolClass * klass) { - GstDucatiBuffer *buf = NULL; - - g_return_val_if_fail (self, NULL); - - GST_PVR_BUFFERPOOL_LOCK (self); - if (self->running) { - /* re-use a buffer off the freelist if any are available - */ - buf = g_queue_pop_head (self->free_buffers); - if (!buf) - buf = gst_ducati_buffer_new (self); - buf->orig = orig; - g_queue_push_head (self->used_buffers, buf); - } - GST_PVR_BUFFERPOOL_UNLOCK (self); + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass; - if (buf && orig) { - GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_TIMESTAMP (orig); - GST_BUFFER_DURATION (buf) = GST_BUFFER_DURATION (orig); - } - GST_BUFFER_SIZE (buf) = self->size; + gobject_class->finalize = gst_pvr_buffer_pool_finalize; - return buf; + gstbufferpool_class->get_options = pvr_buffer_pool_get_options; + gstbufferpool_class->set_config = pvr_buffer_pool_set_config; + gstbufferpool_class->alloc_buffer = pvr_buffer_pool_alloc; } static void -gst_pvr_bufferpool_finalize (GstPvrBufferPool * self) +gst_pvr_buffer_pool_init (GstPVRBufferPool * pool) { - GST_DEBUG_OBJECT (self->element, "destroy bufferpool"); - g_mutex_free (self->lock); - self->lock = NULL; - - g_queue_free (self->free_buffers); - self->free_buffers = NULL; - g_queue_free (self->used_buffers); - self->used_buffers = NULL; - - gst_caps_unref (self->caps); - self->caps = NULL; - gst_object_unref (self->element); - self->element = NULL; - - GST_MINI_OBJECT_CLASS (bufferpool_parent_class)->finalize (GST_MINI_OBJECT - (self)); + } static void -gst_pvr_bufferpool_class_init (gpointer g_class, gpointer class_data) +gst_pvr_buffer_pool_finalize (GObject * object) { - GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class); + GstPVRBufferPool *pool = GST_PVR_BUFFER_POOL_CAST (object); - bufferpool_parent_class = g_type_class_peek_parent (g_class); + GST_LOG_OBJECT (pool, "finalize PVR buffer pool %p", pool); - mini_object_class->finalize = (GstMiniObjectFinalizeFunction) - GST_DEBUG_FUNCPTR (gst_pvr_bufferpool_finalize); -} + if (pool->caps) + gst_caps_unref (pool->caps); + gst_object_unref (pool->pvrsink); -GType -gst_pvr_bufferpool_get_type (void) -{ - static GType type; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo info = { - .class_size = sizeof (GstMiniObjectClass), - .class_init = gst_pvr_bufferpool_class_init, - .instance_size = sizeof (GstPvrBufferPool), - }; - type = g_type_register_static (GST_TYPE_MINI_OBJECT, - "GstPvrBufferPool", &info, 0); - } - return type; + G_OBJECT_CLASS (gst_pvr_buffer_pool_parent_class)->finalize (object); } diff --git a/sys/pvr2d/gstpvrbufferpool.h b/sys/pvr2d/gstpvrbufferpool.h index 1d90472b6..b749b7cf8 100644 --- a/sys/pvr2d/gstpvrbufferpool.h +++ b/sys/pvr2d/gstpvrbufferpool.h @@ -26,63 +26,57 @@ G_BEGIN_DECLS -GType gst_ducati_buffer_get_type (void); -#define GST_TYPE_DUCATIBUFFER (gst_ducati_buffer_get_type()) -#define GST_IS_DUCATIBUFFER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DUCATIBUFFER)) -#define GST_DUCATIBUFFER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DUCATIBUFFER, GstDucatiBuffer)) - -GType gst_pvr_bufferpool_get_type (void); -#define GST_TYPE_PVRBUFFERPOOL (gst_pvr_bufferpool_get_type()) -#define GST_IS_PVRBUFFERPOOL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PVRBUFFERPOOL)) -#define GST_PVRBUFFERPOOL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PVRBUFFERPOOL, \ - GstPvrBufferPool)) - -typedef struct _GstPvrBufferPool GstPvrBufferPool; -typedef struct _GstDucatiBuffer GstDucatiBuffer; - -struct _GstPvrBufferPool +typedef struct _GstPVRMeta GstPVRMeta; + +typedef struct _GstPVRBufferPool GstPVRBufferPool; +typedef struct _GstPVRBufferPoolClass GstPVRBufferPoolClass; + +#include "gstpvrvideosink.h" + +const GstMetaInfo * gst_pvr_meta_get_info (void); +#define GST_PVR_META_INFO (gst_pvr_meta_get_info()) + +#define gst_buffer_get_pvr_meta(b) ((GstPVRMeta*)gst_buffer_get_meta((b),GST_PVR_META_INFO)) + +struct _GstPVRMeta +{ + GstMeta meta; + + PVR2DMEMINFO *src_mem; /* Memory wrapped by pvr */ + GstElement *sink; /* sink, holds a ref */ +}; + +GstPVRMeta * +gst_buffer_add_pvr_meta(GstBuffer *buffer, GstElement *pvrsink); + +#define GST_TYPE_PVR_BUFFER_POOL (gst_pvr_buffer_pool_get_type()) +#define GST_IS_PVR_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PVR_BUFFER_POOL)) +#define GST_PVR_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PVR_BUFFER_POOL, GstPVRBufferPool)) +#define GST_PVR_BUFFER_POOL_CAST(obj) ((GstPVRBufferPool*)(obj)) + +struct _GstPVRBufferPool { - GstMiniObject parent; + GstBufferPool parent; /* output (padded) size including any codec padding: */ gint padded_width, padded_height; - gint size; - PVR2DCONTEXTHANDLE pvr_context; + guint size; + GstAllocationParams params; + + GstElement *pvrsink; GstCaps *caps; - GMutex *lock; - gboolean running; /* with lock */ - GstElement *element; /* the element that owns us.. */ - GQueue *free_buffers; - GQueue *used_buffers; - guint buffer_count; + GstVideoInfo info; + gboolean add_metavideo; }; -GstPvrBufferPool * gst_pvr_bufferpool_new (GstElement * element, - GstCaps * caps, gint num_buffers, gint size, - PVR2DCONTEXTHANDLE pvr_context); -void gst_pvr_bufferpool_stop_running (GstPvrBufferPool * pool, gboolean unwrap); -GstDucatiBuffer * gst_pvr_bufferpool_get (GstPvrBufferPool * self, - GstBuffer * orig); - -#define GST_PVR_BUFFERPOOL_LOCK(self) g_mutex_lock ((self)->lock) -#define GST_PVR_BUFFERPOOL_UNLOCK(self) g_mutex_unlock ((self)->lock) - -struct _GstDucatiBuffer { - GstBuffer parent; - - GstPvrBufferPool *pool; /* buffer-pool that this buffer belongs to */ - GstBuffer *orig; /* original buffer, if we need to copy output */ - PVR2DMEMINFO *src_mem; /* Memory wrapped by pvr */ - gboolean wrapped; +struct _GstPVRBufferPoolClass +{ + GstBufferPoolClass parent_class; }; -GstBuffer * gst_ducati_buffer_get (GstDucatiBuffer * self); -PVR2DMEMINFO * gst_ducati_buffer_get_meminfo (GstDucatiBuffer * self); +GType gst_pvr_buffer_pool_get_type (void); +GstBufferPool *gst_pvr_buffer_pool_new (GstElement *pvrsink); G_END_DECLS diff --git a/sys/pvr2d/gstpvrvideosink.c b/sys/pvr2d/gstpvrvideosink.c index 3bfa3ad2d..19cbad657 100644 --- a/sys/pvr2d/gstpvrvideosink.c +++ b/sys/pvr2d/gstpvrvideosink.c @@ -3,6 +3,7 @@ * Copyright (C) 2011 Collabora Ltda * Copyright (C) 2011 Texas Instruments * @author: Luciana Fujii Pontello <luciana.fujii@collabora.co.uk> + * @author: Edward Hervey <edward@collabora.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,10 +23,12 @@ /* Object header */ #include "gstpvrvideosink.h" - #include "gstpvrbufferpool.h" + #include <gst/video/gstvideosink.h> -#include <gst/interfaces/xoverlay.h> +#include <gst/video/videooverlay.h> +/* Helper functions */ +#include <gst/video/gstvideometa.h> /* Debugging category */ #include <gst/gstinfo.h> @@ -37,7 +40,6 @@ #include <servicesext.h> #define DEFAULT_QUEUE_SIZE 12 -#define DEFAULT_MIN_QUEUED_BUFS 1 GST_DEBUG_CATEGORY_EXTERN (gst_debug_pvrvideosink); #define GST_CAT_DEFAULT gst_debug_pvrvideosink @@ -55,23 +57,27 @@ GST_DEBUG_CATEGORY_EXTERN (gst_debug_pvrvideosink); /* end of internal definitions */ static void gst_pvrvideosink_reset (GstPVRVideoSink * pvrvideosink); -static GstFlowReturn gst_pvrvideosink_buffer_alloc (GstBaseSink * bsink, - guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf); static void gst_pvrvideosink_xwindow_draw_borders (GstPVRVideoSink * pvrvideosink, GstXWindow * xwindow, GstVideoRectangle rect); -static void gst_pvrvideosink_expose (GstXOverlay * overlay); +static void gst_pvrvideosink_expose (GstVideoOverlay * overlay); static void gst_pvrvideosink_xwindow_destroy (GstPVRVideoSink * pvrvideosink, GstXWindow * xwindow); +static void gst_pvrvideosink_dcontext_free (GstDrawContext * dcontext); + +static void gst_pvrvideosink_videooverlay_init (GstVideoOverlayInterface * + iface); + +#define gst_pvrvideosink_parent_class parent_class +G_DEFINE_TYPE_WITH_CODE (GstPVRVideoSink, gst_pvrvideosink, GST_TYPE_VIDEO_SINK, + G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY, + gst_pvrvideosink_videooverlay_init)); + static GstStaticPadTemplate gst_pvrvideosink_sink_template_factory = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw-yuv, " - "format = (fourcc) NV12, " - "width = " GST_VIDEO_SIZE_RANGE ", " - "height = " GST_VIDEO_SIZE_RANGE ", " - "framerate = " GST_VIDEO_FPS_RANGE)); + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("NV12"))); enum { @@ -81,8 +87,6 @@ enum PROP_WINDOW_HEIGHT }; -static GstVideoSinkClass *parent_class = NULL; - /* ============================================================= */ /* */ /* Private Methods */ @@ -91,12 +95,6 @@ static GstVideoSinkClass *parent_class = NULL; /* pvrvideo buffers */ -#define GST_TYPE_PVRVIDEO_BUFFER (gst_pvrvideo_buffer_get_type()) - -#define GST_IS_PVRVIDEO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PVRVIDEO_BUFFER)) -#define GST_PVRVIDEO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PVRVIDEO_BUFFER, GstPVRVideoBuffer)) -#define GST_PVRVIDEO_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PVRVIDEO_BUFFER, GstPVRVideoBufferClass)) - static void gst_pvrvideosink_xwindow_update_geometry (GstPVRVideoSink * pvrvideosink) { @@ -126,17 +124,16 @@ gst_pvrvideosink_xwindow_update_geometry (GstPVRVideoSink * pvrvideosink) } if (pvrvideosink->dcontext != NULL) { glerror = - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_DeleteDrawable (pvrvideosink->dcontext-> - drawable_handle); + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_DeleteDrawable (pvrvideosink->dcontext->drawable_handle); if (glerror != WSEGL_SUCCESS) { GST_ERROR_OBJECT (pvrvideosink, "Error destroying drawable"); return; } glerror = - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_CreateWindowDrawable (pvrvideosink->dcontext-> - display_handle, pvrvideosink->dcontext->glconfig, + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_CreateWindowDrawable (pvrvideosink->dcontext->display_handle, + pvrvideosink->dcontext->glconfig, &pvrvideosink->dcontext->drawable_handle, (NativeWindowType) pvrvideosink->xwindow->window, &pvrvideosink->dcontext->rotation); @@ -145,9 +142,9 @@ gst_pvrvideosink_xwindow_update_geometry (GstPVRVideoSink * pvrvideosink) return; } glerror = - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_GetDrawableParameters (pvrvideosink->dcontext-> - drawable_handle, &source_params, &pvrvideosink->render_params); + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_GetDrawableParameters (pvrvideosink->dcontext->drawable_handle, + &source_params, &pvrvideosink->render_params); if (glerror != WSEGL_SUCCESS) { GST_ERROR_OBJECT (pvrvideosink, "Error getting Drawable params"); return; @@ -198,7 +195,7 @@ gst_pvrvideosink_handle_xevents (GstPVRVideoSink * pvrvideosink) g_mutex_unlock (pvrvideosink->dcontext->x_lock); g_mutex_unlock (pvrvideosink->flow_lock); - gst_pvrvideosink_expose (GST_X_OVERLAY (pvrvideosink)); + gst_pvrvideosink_expose (GST_VIDEO_OVERLAY (pvrvideosink)); g_mutex_lock (pvrvideosink->flow_lock); g_mutex_lock (pvrvideosink->dcontext->x_lock); @@ -284,58 +281,108 @@ gst_pvrvideosink_manage_event_thread (GstPVRVideoSink * pvrvideosink) static GstDrawContext * gst_pvrvideosink_get_dcontext (GstPVRVideoSink * pvrvideosink) { - GstDrawContext *dcontext; + GstDrawContext *dcontext = NULL; PVR2DERROR pvr_error; gint refresh_rate; DRI2WSDisplay *displayImpl; WSEGLError glerror; const WSEGLCaps *glcaps; + GST_DEBUG_OBJECT (pvrvideosink, "Getting draw context"); + dcontext = g_new0 (GstDrawContext, 1); - dcontext->p_blt_info = 0; dcontext->x_lock = g_mutex_new (); dcontext->p_blt_info = g_new0 (PVR2D_3DBLT_EXT, 1); - if (!dcontext->p_blt_info) { - GST_ERROR_OBJECT (pvrvideosink, "Alloc of bltinfo failed"); - return NULL; - } + if (!dcontext->p_blt_info) + goto p_blt_info_alloc_failed; + dcontext->p_blt2d_info = g_new0 (PVR2DBLTINFO, 1); + GST_LOG_OBJECT (pvrvideosink, "Opening X Display"); dcontext->x_display = XOpenDisplay (NULL); + if (dcontext->x_display == NULL) + goto fail_open_display; + + GST_LOG_OBJECT (pvrvideosink, "WSEGL_GetFunctionTablePointer()"); dcontext->wsegl_table = WSEGL_GetFunctionTablePointer (); + + GST_LOG_OBJECT (pvrvideosink, "pfnWSEGL_IsDisplayValid()"); glerror = dcontext->wsegl_table->pfnWSEGL_IsDisplayValid ( (NativeDisplayType) dcontext->x_display); - if (glerror != WSEGL_SUCCESS) { - GST_ERROR_OBJECT (pvrvideosink, "Display is not valid"); - return NULL; - } + if (glerror != WSEGL_SUCCESS) + goto display_invalid; + + GST_LOG_OBJECT (pvrvideosink, "pfnWSEGL_InitialiseDisplay()"); glerror = dcontext->wsegl_table->pfnWSEGL_InitialiseDisplay ( (NativeDisplayType) dcontext->x_display, &dcontext->display_handle, &glcaps, &dcontext->glconfig); - if (glerror != WSEGL_SUCCESS) { - GST_ERROR_OBJECT (pvrvideosink, "Error initializing display"); - return NULL; - } + if (glerror != WSEGL_SUCCESS) + goto display_init_failed; displayImpl = (DRI2WSDisplay *) dcontext->display_handle; dcontext->pvr_context = displayImpl->hContext; + GST_LOG_OBJECT (pvrvideosink, "PVR2DGetScreenMode()"); + pvr_error = PVR2DGetScreenMode (dcontext->pvr_context, &dcontext->display_format, &dcontext->display_width, &dcontext->display_height, &dcontext->stride, &refresh_rate); - if (pvr_error != PVR2D_OK) { - GST_ERROR_OBJECT (pvrvideosink, "Failed) to get screen mode" - "returned %d", pvr_error); - return NULL; - } + if (pvr_error != PVR2D_OK) + goto screen_mode_failed; + + GST_DEBUG_OBJECT (pvrvideosink, + "Got format:%d, width:%d, height:%d, stride:%d, refresh_rate:%d", + dcontext->display_format, dcontext->display_width, + dcontext->display_height, dcontext->stride, refresh_rate); + dcontext->screen_num = DefaultScreen (dcontext->x_display); dcontext->black = XBlackPixel (dcontext->x_display, dcontext->screen_num); + GST_DEBUG_OBJECT (pvrvideosink, "Returning dcontext %p", dcontext); + return dcontext; + +p_blt_info_alloc_failed: + { + GST_ERROR_OBJECT (pvrvideosink, "Alloc of bltinfo failed"); + gst_pvrvideosink_dcontext_free (dcontext); + return NULL; + } + +fail_open_display: + { + GST_ERROR_OBJECT (pvrvideosink, "Failed to open X Display"); + gst_pvrvideosink_dcontext_free (dcontext); + return NULL; + } + +display_invalid: + { + GST_ERROR_OBJECT (pvrvideosink, "Display is not valid (glerror:%d)", + glerror); + gst_pvrvideosink_dcontext_free (dcontext); + return NULL; + } + +display_init_failed: + { + GST_ERROR_OBJECT (pvrvideosink, "Error initializing display (glerror:%d)", + glerror); + gst_pvrvideosink_dcontext_free (dcontext); + return NULL; + } + +screen_mode_failed: + { + GST_ERROR_OBJECT (pvrvideosink, "Failed to get screen mode. error : %s", + gst_pvr2d_error_get_string (pvr_error)); + gst_pvrvideosink_dcontext_free (dcontext); + return NULL; + } } static void @@ -438,8 +485,9 @@ gst_pvrvideosink_create_window (GstPVRVideoSink * pvrvideosink, gint width, g_mutex_unlock (pvrvideosink->dcontext->x_lock); glerror = - dcontext->wsegl_table->pfnWSEGL_CreateWindowDrawable (dcontext-> - display_handle, dcontext->glconfig, &(dcontext->drawable_handle), + dcontext->wsegl_table-> + pfnWSEGL_CreateWindowDrawable (dcontext->display_handle, + dcontext->glconfig, &(dcontext->drawable_handle), (NativeWindowType) xwindow->window, &(dcontext->rotation)); if (glerror != WSEGL_SUCCESS) { @@ -447,8 +495,9 @@ gst_pvrvideosink_create_window (GstPVRVideoSink * pvrvideosink, gint width, return NULL; } glerror = - dcontext->wsegl_table->pfnWSEGL_GetDrawableParameters (dcontext-> - drawable_handle, &source_params, &pvrvideosink->render_params); + dcontext->wsegl_table-> + pfnWSEGL_GetDrawableParameters (dcontext->drawable_handle, &source_params, + &pvrvideosink->render_params); client_mem_info = (PVRSRV_CLIENT_MEM_INFO *) pvrvideosink->render_params.hPrivateData; PVR2DMEMINFO_INITIALISE (&dcontext->dst_mem, client_mem_info); @@ -462,39 +511,38 @@ gst_pvrvideosink_blit (GstPVRVideoSink * pvrvideosink, GstBuffer * buffer) { PVR2DERROR pvr_error; GstDrawContext *dcontext = pvrvideosink->dcontext; - GstCaps *caps; - GstStructure *structure; gint video_width; gint video_height; - gboolean ret; gboolean draw_border = FALSE; PPVR2D_3DBLT_EXT p_blt_3d; PVR2DMEMINFO *src_mem; - PVR2DFORMAT pvr_format = pvrvideosink->format == GST_VIDEO_FORMAT_NV12 ? - PVR2D_YUV420_2PLANE : PVR2D_ARGB8888; + PVR2DFORMAT pvr_format; GstVideoRectangle result; + GstPVRMeta *meta; + GstVideoCropMeta *cropmeta; + + GST_DEBUG_OBJECT (pvrvideosink, "buffer %p", buffer); + + pvr_format = + GST_VIDEO_INFO_FORMAT (&pvrvideosink->info) == + GST_VIDEO_FORMAT_NV12 ? PVR2D_YUV420_2PLANE : PVR2D_ARGB8888; - GST_DEBUG_OBJECT (pvrvideosink, "begin"); g_mutex_lock (pvrvideosink->flow_lock); if (buffer == NULL) buffer = pvrvideosink->current_buffer; - if (buffer == NULL) { - g_mutex_unlock (pvrvideosink->flow_lock); - return; - } + if (buffer == NULL) + goto done; + + meta = gst_buffer_get_pvr_meta (buffer); + if (G_UNLIKELY (meta == NULL)) + goto no_pvr_meta; - caps = GST_BUFFER_CAPS (buffer); - src_mem = gst_ducati_buffer_get_meminfo ((GstDucatiBuffer *) buffer); + src_mem = meta->src_mem; p_blt_3d = dcontext->p_blt_info; - structure = gst_caps_get_structure (caps, 0); - ret = gst_structure_get_int (structure, "width", &video_width); - ret &= gst_structure_get_int (structure, "height", &video_height); - if (!ret) { - GST_ERROR_OBJECT (pvrvideosink, "Failed to get dimensions of the buffer"); - goto done; - } + video_width = GST_VIDEO_SINK_WIDTH (pvrvideosink); + video_height = GST_VIDEO_SINK_HEIGHT (pvrvideosink); g_mutex_lock (pvrvideosink->dcontext->x_lock); @@ -531,9 +579,7 @@ gst_pvrvideosink_blit (GstPVRVideoSink * pvrvideosink, GstBuffer * buffer) p_blt_3d->sDst.pSurfMemInfo = &dcontext->dst_mem; p_blt_3d->sDst.SurfOffset = 0; - p_blt_3d->sDst.Stride = - gst_video_format_get_row_stride (GST_VIDEO_FORMAT_BGRx, 0, - pvrvideosink->render_params.ui32Stride); + p_blt_3d->sDst.Stride = 4 * pvrvideosink->render_params.ui32Stride; p_blt_3d->sDst.Format = PVR2D_ARGB8888; p_blt_3d->sDst.SurfWidth = pvrvideosink->xwindow->width; p_blt_3d->sDst.SurfHeight = pvrvideosink->xwindow->height; @@ -545,56 +591,41 @@ gst_pvrvideosink_blit (GstPVRVideoSink * pvrvideosink, GstBuffer * buffer) p_blt_3d->sSrc.pSurfMemInfo = src_mem; p_blt_3d->sSrc.SurfOffset = 0; - p_blt_3d->sSrc.Stride = pvrvideosink->rowstride; + p_blt_3d->sSrc.Stride = GST_VIDEO_INFO_COMP_STRIDE (&pvrvideosink->info, 0); p_blt_3d->sSrc.Format = pvr_format; p_blt_3d->sSrc.SurfWidth = video_width; p_blt_3d->sSrc.SurfHeight = video_height; - p_blt_3d->rcSource.left = 0; - p_blt_3d->rcSource.top = 0; - p_blt_3d->rcSource.right = video_width; - p_blt_3d->rcSource.bottom = video_height; + /* If buffer has crop information, use that */ + if ((cropmeta = gst_buffer_get_video_crop_meta (buffer))) { + p_blt_3d->rcSource.left = cropmeta->x; + p_blt_3d->rcSource.top = cropmeta->y; + p_blt_3d->rcSource.right = cropmeta->x + cropmeta->width; + p_blt_3d->rcSource.bottom = cropmeta->y + cropmeta->height; + } else { + p_blt_3d->rcSource.left = 0; + p_blt_3d->rcSource.top = 0; + p_blt_3d->rcSource.right = video_width; + p_blt_3d->rcSource.bottom = video_height; + } p_blt_3d->hUseCode = NULL; - if (pvrvideosink->format == GST_VIDEO_FORMAT_NV12) + if (GST_VIDEO_INFO_FORMAT (&pvrvideosink->info) == GST_VIDEO_FORMAT_NV12) p_blt_3d->bDisableDestInput = TRUE; else /* blit fails for RGB without this... not sure why yet... */ p_blt_3d->bDisableDestInput = FALSE; + GST_DEBUG_OBJECT (pvrvideosink, "about to blit"); + pvr_error = PVR2DBlt3DExt (pvrvideosink->dcontext->pvr_context, dcontext->p_blt_info); - switch (pvr_error) { - case PVR2D_OK: - break; - case PVR2DERROR_DEVICE_UNAVAILABLE: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, device unavailable"); - goto done; - break; - case PVR2DERROR_INVALID_CONTEXT: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, invalid context"); - goto done; - break; - case PVR2DERROR_INVALID_PARAMETER: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, invalid parameter"); - goto done; - break; - case PVR2DERROR_HW_FEATURE_NOT_SUPPORTED: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, " - "hardware feature not supported"); - goto done; - break; - case PVR2DERROR_GENERIC_ERROR: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, generic error"); - goto done; - break; - default: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, " - "undefined error %d", pvr_error); - goto done; - break; + if (pvr_error != PVR2D_OK) { + GST_ERROR_OBJECT (pvrvideosink, "Failed to blit. Error : %s", + gst_pvr2d_error_get_string (pvr_error)); + goto done; } dcontext->wsegl_table->pfnWSEGL_SwapDrawable (dcontext->drawable_handle, 1); @@ -608,19 +639,35 @@ gst_pvrvideosink_blit (GstPVRVideoSink * pvrvideosink, GstBuffer * buffer) done: GST_DEBUG_OBJECT (pvrvideosink, "end"); g_mutex_unlock (pvrvideosink->flow_lock); + return; + + /* Error cases */ + +no_pvr_meta: + { + g_mutex_unlock (pvrvideosink->flow_lock); + GST_ERROR_OBJECT (pvrvideosink, "Got a buffer without GstPVRMeta"); + return; + } } static void gst_pvrvideosink_destroy_drawable (GstPVRVideoSink * pvrvideosink) { + GST_DEBUG_OBJECT (pvrvideosink, "dcontext : %p", pvrvideosink->dcontext); + if (pvrvideosink->dcontext != NULL) { - if (pvrvideosink->dcontext->drawable_handle) - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_DeleteDrawable (pvrvideosink->dcontext-> - drawable_handle); + if (pvrvideosink->dcontext->drawable_handle) { + GST_DEBUG_OBJECT (pvrvideosink, "Deleting Drawable (drawable_handle:%p)", + pvrvideosink->dcontext->drawable_handle); + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_DeleteDrawable (pvrvideosink->dcontext->drawable_handle); + } - pvrvideosink->dcontext->wsegl_table->pfnWSEGL_CloseDisplay (pvrvideosink-> - dcontext->display_handle); + GST_DEBUG_OBJECT (pvrvideosink, "Closing display (display_handle:%p)", + pvrvideosink->dcontext->display_handle); + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_CloseDisplay (pvrvideosink->dcontext->display_handle); } } @@ -641,9 +688,7 @@ gst_pvrvideosink_pvrfill_rectangle (GstPVRVideoSink * pvrvideosink, p_blt2d_info->BlitFlags = PVR2D_BLIT_DISABLE_ALL; p_blt2d_info->DstOffset = 0; p_blt2d_info->CopyCode = PVR2DROPclear; - p_blt2d_info->DstStride = - gst_video_format_get_row_stride (GST_VIDEO_FORMAT_BGRx, 0, - pvrvideosink->render_params.ui32Stride); + p_blt2d_info->DstStride = 4 * pvrvideosink->render_params.ui32Stride; p_blt2d_info->DstFormat = PVR2D_ARGB8888; p_blt2d_info->DstSurfWidth = pvrvideosink->xwindow->width; p_blt2d_info->DstSurfHeight = pvrvideosink->xwindow->height; @@ -654,35 +699,10 @@ gst_pvrvideosink_pvrfill_rectangle (GstPVRVideoSink * pvrvideosink, pvr_error = PVR2DBlt (pvrvideosink->dcontext->pvr_context, p_blt2d_info); - switch (pvr_error) { - case PVR2D_OK: - break; - case PVR2DERROR_DEVICE_UNAVAILABLE: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, device unavailable"); - goto done; - break; - case PVR2DERROR_INVALID_CONTEXT: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, invalid context"); - goto done; - break; - case PVR2DERROR_INVALID_PARAMETER: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, invalid parameter"); - goto done; - break; - case PVR2DERROR_HW_FEATURE_NOT_SUPPORTED: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, " - "hardware feature not supported"); - goto done; - break; - case PVR2DERROR_GENERIC_ERROR: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, generic error"); - goto done; - break; - default: - GST_ERROR_OBJECT (pvrvideosink, "Failed to blit, " - "undefined error %d", pvr_error); - goto done; - break; + if (pvr_error != PVR2D_OK) { + GST_ERROR_OBJECT (pvrvideosink, "Failed to blit. Error : %s", + gst_pvr2d_error_get_string (pvr_error)); + goto done; } dcontext->wsegl_table->pfnWSEGL_SwapDrawable (dcontext->drawable_handle, 1); @@ -744,112 +764,106 @@ static gboolean gst_pvrvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps) { GstPVRVideoSink *pvrvideosink; - gboolean ret = TRUE; + GstVideoInfo info; GstStructure *structure; - gint new_width, new_height; - const GValue *fps; - GstQuery *query; + GstBufferPool *oldpool, *newpool; pvrvideosink = GST_PVRVIDEOSINK (bsink); GST_DEBUG_OBJECT (pvrvideosink, - "sinkconnect possible caps with given caps %", caps); - - structure = gst_caps_get_structure (caps, 0); - - ret = gst_video_format_parse_caps_strided (caps, &pvrvideosink->format, - &new_width, &new_height, &pvrvideosink->rowstride); - if (pvrvideosink->rowstride == 0) - pvrvideosink->rowstride = - gst_video_format_get_row_stride (pvrvideosink->format, 0, new_width); - fps = gst_structure_get_value (structure, "framerate"); - ret &= (fps != NULL); - if (!ret) { - GST_ERROR_OBJECT (pvrvideosink, "problem at parsing caps"); - return FALSE; - } + "sinkconnect possible caps with given caps %" GST_PTR_FORMAT, caps); - if (pvrvideosink->current_caps) { - GST_DEBUG_OBJECT (pvrvideosink, "already have caps set"); - if (gst_caps_is_equal (pvrvideosink->current_caps, caps)) { - GST_DEBUG_OBJECT (pvrvideosink, "caps are equal!"); - return TRUE; - } - GST_DEBUG_OBJECT (pvrvideosink, "caps are different"); - } - - g_mutex_lock (pvrvideosink->pool_lock); - if (pvrvideosink->buffer_pool) { - if (!gst_caps_is_equal (pvrvideosink->buffer_pool->caps, caps)) { - GST_INFO_OBJECT (pvrvideosink, "in set caps, pool->caps != caps"); - gst_pvr_bufferpool_stop_running (pvrvideosink->buffer_pool, FALSE); - pvrvideosink->buffer_pool = NULL; - } - } - g_mutex_unlock (pvrvideosink->pool_lock); - - /* query to find if anyone upstream using these buffers has any - * minimum requirements: - */ - query = gst_query_new_buffers (caps); - if (gst_element_query (GST_ELEMENT (pvrvideosink), query)) { - gint min_buffers; - - gst_query_parse_buffers_count (query, &min_buffers); - - GST_DEBUG_OBJECT (pvrvideosink, "min_buffers=%d", min_buffers); - - /* XXX need to account for some buffers used by queue, etc.. probably - * queue should handle query, pass on to sink pad, and then add some - * number of buffers to the min, so this value is dynamic depending - * on the pipeline? - */ - if (min_buffers != -1) { - min_buffers += 3 + pvrvideosink->min_queued_bufs; - pvrvideosink->num_buffers_can_change = FALSE; - } + if (!gst_video_info_from_caps (&info, caps)) + goto invalid_format; - if (min_buffers > pvrvideosink->num_buffers) { - pvrvideosink->num_buffers = min_buffers; - } - } - gst_query_unref (query); + GST_VIDEO_SINK_WIDTH (pvrvideosink) = info.width; + GST_VIDEO_SINK_HEIGHT (pvrvideosink) = info.height; /* Notify application to set xwindow id now */ g_mutex_lock (pvrvideosink->flow_lock); if (!pvrvideosink->xwindow) { g_mutex_unlock (pvrvideosink->flow_lock); - gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (pvrvideosink)); + gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (pvrvideosink)); } else { g_mutex_unlock (pvrvideosink->flow_lock); } - GST_VIDEO_SINK_WIDTH (pvrvideosink) = new_width; - GST_VIDEO_SINK_HEIGHT (pvrvideosink) = new_height; g_mutex_lock (pvrvideosink->flow_lock); if (!pvrvideosink->xwindow) pvrvideosink->xwindow = gst_pvrvideosink_create_window (pvrvideosink, - new_width, new_height); + GST_VIDEO_SINK_WIDTH (pvrvideosink), + GST_VIDEO_SINK_HEIGHT (pvrvideosink)); g_mutex_unlock (pvrvideosink->flow_lock); - pvrvideosink->fps_n = gst_value_get_fraction_numerator (fps); - pvrvideosink->fps_d = gst_value_get_fraction_denominator (fps); + pvrvideosink->info = info; - pvrvideosink->current_caps = gst_caps_ref (caps); + /* After a resize, we want to redraw the borders in case the new frame size + * doesn't cover the same area */ + pvrvideosink->redraw_borders = TRUE; + + /* create a new pool for the new configuration */ + newpool = gst_pvr_buffer_pool_new (GST_ELEMENT_CAST (pvrvideosink)); + + /* PVR needs at least 3 buffers */ + structure = gst_buffer_pool_get_config (newpool); + gst_buffer_pool_config_set (structure, caps, GST_VIDEO_INFO_SIZE (&info), 3, + 0, 0, 15); + if (!gst_buffer_pool_set_config (newpool, structure)) + goto config_failed; + + oldpool = pvrvideosink->pool; + pvrvideosink->pool = newpool; + g_mutex_unlock (pvrvideosink->flow_lock); + + /* unref the old sink */ + if (oldpool) { + /* we don't deactivate, some elements might still be using it, it will + * be deactivated when the last ref is gone */ + gst_object_unref (oldpool); + } return TRUE; + +config_failed: + { + GST_ERROR_OBJECT (pvrvideosink, "failed to set config."); + g_mutex_unlock (pvrvideosink->flow_lock); + return FALSE; + } + +invalid_format: + { + GST_DEBUG_OBJECT (pvrvideosink, + "Could not locate image format from caps %" GST_PTR_FORMAT, caps); + return FALSE; + } } static GstCaps * -gst_pvrvideosink_getcaps (GstBaseSink * bsink) +gst_pvrvideosink_getcaps (GstBaseSink * bsink, GstCaps * filter) { GstPVRVideoSink *pvrvideosink; GstCaps *caps; + GST_DEBUG_OBJECT (bsink, "filter:%" GST_PTR_FORMAT, filter); + pvrvideosink = GST_PVRVIDEOSINK (bsink); - caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK - (pvrvideosink)->sinkpad)); + /* FIXME : If we have curently configured caps, we should return those + * intersected with the filter*/ + + caps = gst_pad_get_pad_template_caps (GST_BASE_SINK (pvrvideosink)->sinkpad); + if (filter) { + GstCaps *intersection; + + intersection = + gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (caps); + caps = intersection; + } + + GST_DEBUG_OBJECT (bsink, "Returning %" GST_PTR_FORMAT, caps); + return caps; } @@ -875,14 +889,8 @@ gst_pvrvideosink_change_state (GstElement * element, GstStateChange transition) gst_pvrvideosink_manage_event_thread (pvrvideosink); break; case GST_STATE_CHANGE_READY_TO_PAUSED: - g_mutex_lock (pvrvideosink->pool_lock); - pvrvideosink->pool_invalid = FALSE; - g_mutex_unlock (pvrvideosink->pool_lock); break; case GST_STATE_CHANGE_PAUSED_TO_READY: - g_mutex_lock (pvrvideosink->pool_lock); - pvrvideosink->pool_invalid = TRUE; - g_mutex_unlock (pvrvideosink->pool_lock); break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: break; @@ -896,8 +904,6 @@ gst_pvrvideosink_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PLAYING_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_READY: - pvrvideosink->fps_n = 0; - pvrvideosink->fps_d = 1; GST_VIDEO_SINK_WIDTH (pvrvideosink) = 0; GST_VIDEO_SINK_HEIGHT (pvrvideosink) = 0; break; @@ -924,185 +930,125 @@ gst_pvrvideosink_get_times (GstBaseSink * bsink, GstBuffer * buf, if (GST_BUFFER_DURATION_IS_VALID (buf)) { *end = *start + GST_BUFFER_DURATION (buf); } else { - if (pvrvideosink->fps_n > 0) { - *end = *start + - gst_util_uint64_scale_int (GST_SECOND, pvrvideosink->fps_d, - pvrvideosink->fps_n); + gint fps_n, fps_d; + fps_n = GST_VIDEO_INFO_FPS_N (&pvrvideosink->info); + fps_d = GST_VIDEO_INFO_FPS_D (&pvrvideosink->info); + if (fps_n > 0) { + *end = *start + gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n); } } } } static GstFlowReturn -gst_pvrvideosink_show_frame (GstBaseSink * vsink, GstBuffer * buf) +gst_pvrvideosink_show_frame (GstVideoSink * vsink, GstBuffer * buf) { - GstPVRVideoSink *pvrvideosink; - GstBuffer *newbuf = NULL; - g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR); - - pvrvideosink = GST_PVRVIDEOSINK (vsink); + GstPVRVideoSink *pvrvideosink = GST_PVRVIDEOSINK (vsink); + GstPVRMeta *meta; GST_DEBUG_OBJECT (pvrvideosink, "render buffer: %p", buf); - if (!GST_IS_BUFFER (buf)) { - GstFlowReturn ret; - - /* special case check for sub-buffers: In certain cases, places like - * GstBaseTransform, which might check that the buffer is writable - * before copying metadata, timestamp, and such, will find that the - * buffer has more than one reference to it. In these cases, they - * will create a sub-buffer with an offset=0 and length equal to the - * original buffer size. - * - * This could happen in two scenarios: (1) a tee in the pipeline, and - * (2) because the refcnt is incremented in gst_mini_object_free() - * before the finalize function is called, and decremented after it - * returns.. but returning this buffer to the buffer pool in the - * finalize function, could wake up a thread blocked in _buffer_alloc() - * which could run and get a buffer w/ refcnt==2 before the thread - * originally unref'ing the buffer returns from finalize function and - * decrements the refcnt back to 1! - */ - if (buf->parent && - (GST_BUFFER_DATA (buf) == GST_BUFFER_DATA (buf->parent)) && - (GST_BUFFER_SIZE (buf) == GST_BUFFER_SIZE (buf->parent))) { - GST_DEBUG_OBJECT (pvrvideosink, "I have a sub-buffer!"); - return gst_pvrvideosink_show_frame (vsink, buf->parent); - } - - GST_DEBUG_OBJECT (pvrvideosink, - "slow-path.. I got a %s so I need to memcpy", - g_type_name (G_OBJECT_TYPE (buf))); - - ret = gst_pvrvideosink_buffer_alloc (GST_BASE_SINK (vsink), - GST_BUFFER_OFFSET (buf), GST_BUFFER_SIZE (buf), GST_BUFFER_CAPS (buf), - &newbuf); - - if (GST_FLOW_OK != ret) { - GST_DEBUG_OBJECT (pvrvideosink, "dropping frame!!"); - return GST_FLOW_OK; - } - - memcpy (GST_BUFFER_DATA (newbuf), - GST_BUFFER_DATA (buf), - MIN (GST_BUFFER_SIZE (newbuf), GST_BUFFER_SIZE (buf))); + meta = gst_buffer_get_pvr_meta (buf); - GST_DEBUG_OBJECT (pvrvideosink, "render copied buffer: %p", newbuf); - - buf = newbuf; + if (G_UNLIKELY (meta == NULL)) { + meta = gst_buffer_add_pvr_meta (buf, GST_ELEMENT_CAST (pvrvideosink)); + if (meta == NULL) + goto meta_failure; } gst_pvrvideosink_blit (pvrvideosink, buf); - if (newbuf) { - gst_buffer_unref (newbuf); - } - return GST_FLOW_OK; -} +meta_failure: + { + GST_WARNING_OBJECT (pvrvideosink, "Failed to map incoming buffer"); + return GST_FLOW_ERROR; + } +} -/* Buffer management - * - * The buffer_alloc function must either return a buffer with given size and - * caps or create a buffer with different caps attached to the buffer. This - * last option is called reverse negotiation, ie, where the sink suggests a - * different format from the upstream peer. - * - * We try to do reverse negotiation when our geometry changes and we like a - * resized buffer. - */ -static GstFlowReturn -gst_pvrvideosink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size, - GstCaps * caps, GstBuffer ** buf) +static gboolean +gst_pvrvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query) { - GstPVRVideoSink *pvrvideosink; - GstDucatiBuffer *pvrvideo = NULL; - GstStructure *structure = NULL; - GstFlowReturn ret = GST_FLOW_OK; - gint width, height; + GstPVRVideoSink *pvrvideosink = (GstPVRVideoSink *) bsink; + GstBufferPool *pool; + GstStructure *config; + GstCaps *caps; + guint size; + gboolean need_pool; - pvrvideosink = GST_PVRVIDEOSINK (bsink); + gst_query_parse_allocation (query, &caps, &need_pool); - GST_DEBUG_OBJECT (pvrvideosink, "begin"); + if (caps == NULL) + goto no_caps; - if (G_UNLIKELY (!caps)) { - GST_WARNING_OBJECT (pvrvideosink, - "have no caps, doing fallback allocation"); - *buf = NULL; - ret = GST_FLOW_OK; - goto beach; - } + g_mutex_lock (pvrvideosink->flow_lock); + if ((pool = pvrvideosink->pool)) + gst_object_ref (pool); + g_mutex_unlock (pvrvideosink->flow_lock); - g_mutex_lock (pvrvideosink->pool_lock); - if (G_UNLIKELY (pvrvideosink->pool_invalid)) { - GST_DEBUG_OBJECT (pvrvideosink, "the pool is flushing"); - ret = GST_FLOW_WRONG_STATE; - g_mutex_unlock (pvrvideosink->pool_lock); - goto beach; - } else { - g_mutex_unlock (pvrvideosink->pool_lock); - } + if (pool != NULL) { + const GstCaps *pcaps; - GST_LOG_OBJECT (pvrvideosink, - "a buffer of %d bytes was requested with caps %" GST_PTR_FORMAT - " and offset %" G_GUINT64_FORMAT, size, caps, offset); - - /* get struct to see what is requested */ - structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "width", &width) || - !gst_structure_get_int (structure, "height", &height)) { - GST_WARNING_OBJECT (pvrvideosink, "invalid caps for buffer allocation %" - GST_PTR_FORMAT, caps); - ret = GST_FLOW_NOT_NEGOTIATED; - goto beach; - } + /* we had a pool, check caps */ + GST_DEBUG_OBJECT (pvrvideosink, "check existing pool caps"); + config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_get (config, &pcaps, &size, NULL, NULL, NULL, NULL); - g_mutex_lock (pvrvideosink->pool_lock); - /* initialize the buffer pool if not initialized yet */ - if (G_UNLIKELY (!pvrvideosink->buffer_pool || - pvrvideosink->buffer_pool->size != size)) { - if (pvrvideosink->buffer_pool) { - GST_INFO_OBJECT (pvrvideosink, "in buffer alloc, pool->size != size"); - gst_pvr_bufferpool_stop_running (pvrvideosink->buffer_pool, FALSE); + if (!gst_caps_is_equal (caps, pcaps)) { + GST_DEBUG_OBJECT (pvrvideosink, "pool has different caps"); + /* different caps, we can't use this pool */ + gst_object_unref (pool); + pool = NULL; } + } - GST_LOG_OBJECT (pvrvideosink, "Creating a buffer pool with %d buffers", - pvrvideosink->num_buffers); - if (!(pvrvideosink->buffer_pool = - gst_pvr_bufferpool_new (GST_ELEMENT (pvrvideosink), - caps, pvrvideosink->num_buffers, size, - pvrvideosink->dcontext->pvr_context))) { - g_mutex_unlock (pvrvideosink->pool_lock); - return GST_FLOW_ERROR; - } + if (pool == NULL && need_pool) { + GstVideoInfo info; + + GST_DEBUG_OBJECT (pvrvideosink, "create new pool"); + pool = gst_pvr_buffer_pool_new (GST_ELEMENT_CAST (pvrvideosink)); + + if (!gst_video_info_from_caps (&info, caps)) + goto invalid_caps; + + /* the normal size of a frame */ + size = info.size; + + config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_set (config, caps, size, 0, 0, 0, 0); + if (!gst_buffer_pool_set_config (pool, config)) + goto config_failed; } - pvrvideo = gst_pvr_bufferpool_get (pvrvideosink->buffer_pool, NULL); - g_mutex_unlock (pvrvideosink->pool_lock); + /* we need at least 3 buffers */ + gst_query_set_allocation_params (query, size, 3, 0, 0, 0, pool); - *buf = GST_BUFFER_CAST (pvrvideo); + /* we also support various metadata */ + gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API); -beach: - return ret; -} + gst_object_unref (pool); -/* Interfaces stuff */ + return TRUE; -static gboolean -gst_pvrvideosink_interface_supported (GstImplementsInterface * iface, - GType type) -{ - if (type == GST_TYPE_X_OVERLAY) - return TRUE; - else + /* ERRORS */ +no_caps: + { + GST_DEBUG_OBJECT (bsink, "no caps specified"); + return FALSE; + } +invalid_caps: + { + GST_DEBUG_OBJECT (bsink, "invalid caps specified"); + return FALSE; + } +config_failed: + { + GST_DEBUG_OBJECT (bsink, "failed setting config"); return FALSE; + } } -static void -gst_pvrvideosink_interface_init (GstImplementsInterfaceClass * klass) -{ - klass->supported = gst_pvrvideosink_interface_supported; -} +/* Interfaces stuff */ /* This function destroys a GstXWindow */ static void @@ -1129,9 +1075,9 @@ gst_pvrvideosink_xwindow_destroy (GstPVRVideoSink * pvrvideosink, } static void -gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) +gst_pvrvideosink_set_window_handle (GstVideoOverlay * overlay, guintptr id) { - XID xwindow_id = id; + XID window_handle = id; GstPVRVideoSink *pvrvideosink = GST_PVRVIDEOSINK (overlay); GstXWindow *xwindow = NULL; @@ -1140,7 +1086,7 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) g_mutex_lock (pvrvideosink->flow_lock); /* If we already use that window return */ - if (pvrvideosink->xwindow && (xwindow_id == pvrvideosink->xwindow->window)) { + if (pvrvideosink->xwindow && (window_handle == pvrvideosink->xwindow->window)) { g_mutex_unlock (pvrvideosink->flow_lock); return; } @@ -1153,14 +1099,6 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) return; } - /* Clear image pool as the images are unusable anyway */ - g_mutex_lock (pvrvideosink->pool_lock); - if (pvrvideosink->buffer_pool) { - gst_pvr_bufferpool_stop_running (pvrvideosink->buffer_pool, FALSE); - pvrvideosink->buffer_pool = NULL; - } - g_mutex_unlock (pvrvideosink->pool_lock); - /* If a window is there already we destroy it */ if (pvrvideosink->xwindow) { gst_pvrvideosink_xwindow_destroy (pvrvideosink, pvrvideosink->xwindow); @@ -1168,14 +1106,14 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) } /* If the xid is 0 we will create an internal one in buffer_alloc */ - if (xwindow_id != 0) { + if (window_handle != 0) { XWindowAttributes attr; WSEGLError glerror; WSEGLDrawableParams source_params; PVRSRV_CLIENT_MEM_INFO *client_mem_info; xwindow = g_new0 (GstXWindow, 1); - xwindow->window = xwindow_id; + xwindow->window = window_handle; /* Set the event we want to receive and create a GC */ g_mutex_lock (pvrvideosink->dcontext->x_lock); @@ -1203,9 +1141,9 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) g_mutex_unlock (pvrvideosink->dcontext->x_lock); glerror = - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_CreateWindowDrawable (pvrvideosink->dcontext-> - display_handle, pvrvideosink->dcontext->glconfig, + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_CreateWindowDrawable (pvrvideosink->dcontext->display_handle, + pvrvideosink->dcontext->glconfig, &(pvrvideosink->dcontext->drawable_handle), (NativeWindowType) xwindow->window, &(pvrvideosink->dcontext->rotation)); @@ -1215,9 +1153,9 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) return; } glerror = - pvrvideosink->dcontext-> - wsegl_table->pfnWSEGL_GetDrawableParameters (pvrvideosink->dcontext-> - drawable_handle, &source_params, &pvrvideosink->render_params); + pvrvideosink->dcontext->wsegl_table-> + pfnWSEGL_GetDrawableParameters (pvrvideosink->dcontext->drawable_handle, + &source_params, &pvrvideosink->render_params); client_mem_info = (PVRSRV_CLIENT_MEM_INFO *) pvrvideosink->render_params.hPrivateData; @@ -1231,7 +1169,7 @@ gst_pvrvideosink_set_window_handle (GstXOverlay * overlay, guintptr id) } static void -gst_pvrvideosink_expose (GstXOverlay * overlay) +gst_pvrvideosink_expose (GstVideoOverlay * overlay) { GstPVRVideoSink *pvrvideosink = GST_PVRVIDEOSINK (overlay); @@ -1239,7 +1177,7 @@ gst_pvrvideosink_expose (GstXOverlay * overlay) } static void -gst_pvrvideosink_set_event_handling (GstXOverlay * overlay, +gst_pvrvideosink_set_event_handling (GstVideoOverlay * overlay, gboolean handle_events) { GstPVRVideoSink *pvrvideosink = GST_PVRVIDEOSINK (overlay); @@ -1262,8 +1200,8 @@ gst_pvrvideosink_set_event_handling (GstXOverlay * overlay, } static void -gst_pvrvideosink_set_render_rectangle (GstXOverlay * overlay, gint x, gint y, - gint width, gint height) +gst_pvrvideosink_set_render_rectangle (GstVideoOverlay * overlay, gint x, + gint y, gint width, gint height) { GstPVRVideoSink *pvrvideosink = GST_PVRVIDEOSINK (overlay); @@ -1284,7 +1222,7 @@ gst_pvrvideosink_set_render_rectangle (GstXOverlay * overlay, gint x, gint y, } static void -gst_pvrvideosink_xoverlay_init (GstXOverlayClass * iface) +gst_pvrvideosink_videooverlay_init (GstVideoOverlayInterface * iface) { iface->set_window_handle = gst_pvrvideosink_set_window_handle; iface->expose = gst_pvrvideosink_expose; @@ -1338,11 +1276,72 @@ gst_pvrvideosink_get_property (GObject * object, guint prop_id, } } +void +gst_pvrvideosink_track_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer) +{ + GST_DEBUG_OBJECT (pvrsink, "Adding buffer %p to tracked buffers", buffer); + pvrsink->metabuffers = g_list_prepend (pvrsink->metabuffers, buffer); +} + +void +gst_pvrvideosink_untrack_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer) +{ + GST_DEBUG_OBJECT (pvrsink, "Removing buffer %p from tracked buffers", buffer); + pvrsink->metabuffers = g_list_remove_all (pvrsink->metabuffers, buffer); +} + +static void +gst_pvrvideosink_release_pvr_metas (GstPVRVideoSink * pvrsink) +{ + GstBuffer *buf; + GstPVRMeta *pvrmeta; + + GST_DEBUG_OBJECT (pvrsink, "Releasing pending PVR metas"); + + while (pvrsink->metabuffers) { + buf = (GstBuffer *) pvrsink->metabuffers->data; + + pvrmeta = gst_buffer_get_pvr_meta (buf); + if (pvrmeta) + gst_buffer_remove_meta (buf, (GstMeta *) pvrmeta); + } + + GST_DEBUG_OBJECT (pvrsink, "Done"); +} + +static void +gst_pvrvideosink_dcontext_free (GstDrawContext * dcontext) +{ + GST_DEBUG ("Freeing dcontext %p", dcontext); + + if (dcontext->p_blt_info) + g_free (dcontext->p_blt_info); + + if (dcontext->p_blt2d_info) + g_free (dcontext->p_blt2d_info); + + if (dcontext->x_lock) + g_mutex_lock (dcontext->x_lock); + if (dcontext->x_display) { + GST_LOG ("Closing display"); + XCloseDisplay (dcontext->x_display); + } + if (dcontext->x_lock) { + g_mutex_unlock (dcontext->x_lock); + g_mutex_free (dcontext->x_lock); + } + + g_free (dcontext); +} + static void gst_pvrvideosink_dcontext_clear (GstPVRVideoSink * pvrvideosink) { GstDrawContext *dcontext; + GST_DEBUG_OBJECT (pvrvideosink, "Clearing dcontext %p", + pvrvideosink->dcontext); + GST_OBJECT_LOCK (pvrvideosink); if (!pvrvideosink->dcontext) { GST_OBJECT_UNLOCK (pvrvideosink); @@ -1353,15 +1352,7 @@ gst_pvrvideosink_dcontext_clear (GstPVRVideoSink * pvrvideosink) pvrvideosink->dcontext = NULL; GST_OBJECT_UNLOCK (pvrvideosink); - if (dcontext->p_blt_info) - g_free (dcontext->p_blt_info); - - g_mutex_lock (dcontext->x_lock); - XCloseDisplay (dcontext->x_display); - g_mutex_unlock (dcontext->x_lock); - g_mutex_free (dcontext->x_lock); - - g_free (dcontext); + gst_pvrvideosink_dcontext_free (dcontext); } static void @@ -1369,6 +1360,8 @@ gst_pvrvideosink_reset (GstPVRVideoSink * pvrvideosink) { GThread *thread; + GST_DEBUG_OBJECT (pvrvideosink, "Resetting"); + GST_OBJECT_LOCK (pvrvideosink); pvrvideosink->running = FALSE; thread = pvrvideosink->event_thread; @@ -1379,23 +1372,24 @@ gst_pvrvideosink_reset (GstPVRVideoSink * pvrvideosink) g_thread_join (thread); if (pvrvideosink->current_buffer) { + GST_LOG_OBJECT (pvrvideosink, "Removing cached buffer"); gst_buffer_unref (pvrvideosink->current_buffer); pvrvideosink->current_buffer = NULL; } - g_mutex_lock (pvrvideosink->pool_lock); - pvrvideosink->pool_invalid = TRUE; - if (pvrvideosink->buffer_pool) { - gst_pvr_bufferpool_stop_running (pvrvideosink->buffer_pool, TRUE); - pvrvideosink->buffer_pool = NULL; + if (pvrvideosink->pool) { + GST_LOG_OBJECT (pvrvideosink, "Unreffing pool"); + gst_object_unref (pvrvideosink->pool); + pvrvideosink->pool = NULL; } - g_mutex_unlock (pvrvideosink->pool_lock); memset (&pvrvideosink->render_params, 0, sizeof (WSEGLDrawableParams)); pvrvideosink->render_rect.x = pvrvideosink->render_rect.y = 0; pvrvideosink->render_rect.w = pvrvideosink->render_rect.h = 0; pvrvideosink->have_render_rect = FALSE; + gst_pvrvideosink_release_pvr_metas (pvrvideosink); + gst_pvrvideosink_destroy_drawable (pvrvideosink); if (pvrvideosink->xwindow) { @@ -1419,10 +1413,6 @@ gst_pvrvideosink_finalize (GObject * object) g_mutex_free (pvrvideosink->flow_lock); pvrvideosink->flow_lock = NULL; } - if (pvrvideosink->pool_lock) { - g_mutex_free (pvrvideosink->pool_lock); - pvrvideosink->pool_lock = NULL; - } G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1432,19 +1422,11 @@ gst_pvrvideosink_init (GstPVRVideoSink * pvrvideosink) { pvrvideosink->running = FALSE; - pvrvideosink->fps_n = 0; - pvrvideosink->fps_d = 1; - pvrvideosink->flow_lock = g_mutex_new (); - pvrvideosink->pool_lock = g_mutex_new (); - pvrvideosink->buffer_pool = NULL; - pvrvideosink->pool_invalid = TRUE; + pvrvideosink->pool = NULL; pvrvideosink->keep_aspect = FALSE; pvrvideosink->current_caps = NULL; - pvrvideosink->num_buffers = DEFAULT_QUEUE_SIZE; - pvrvideosink->num_buffers_can_change = TRUE; - pvrvideosink->min_queued_bufs = DEFAULT_MIN_QUEUED_BUFS; pvrvideosink->dcontext = NULL; pvrvideosink->xwindow = NULL; pvrvideosink->redraw_borders = TRUE; @@ -1454,29 +1436,17 @@ gst_pvrvideosink_init (GstPVRVideoSink * pvrvideosink) } static void -gst_pvrvideosink_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details_simple (element_class, - "PVR Video sink", "Sink/Video", - "A PVR videosink", - "Luciana Fujii Pontello <luciana.fujii@collabora.co.uk"); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_pvrvideosink_sink_template_factory)); -} - -static void gst_pvrvideosink_class_init (GstPVRVideoSinkClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; GstBaseSinkClass *gstbasesink_class; + GstVideoSinkClass *videosink_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass; + videosink_class = (GstVideoSinkClass *) klass; parent_class = g_type_class_peek_parent (klass); @@ -1490,59 +1460,21 @@ gst_pvrvideosink_class_init (GstPVRVideoSinkClass * klass) "original aspect ratio", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_set_details_simple (gstelement_class, + "PVR Video sink", "Sink/Video", + "A PVR videosink", + "Luciana Fujii Pontello <luciana.fujii@collabora.co.uk"); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&gst_pvrvideosink_sink_template_factory)); + gstelement_class->change_state = gst_pvrvideosink_change_state; gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_pvrvideosink_setcaps); gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_pvrvideosink_getcaps); - gstbasesink_class->buffer_alloc = - GST_DEBUG_FUNCPTR (gst_pvrvideosink_buffer_alloc); + gstbasesink_class->propose_allocation = + GST_DEBUG_FUNCPTR (gst_pvrvideosink_propose_allocation); gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_pvrvideosink_get_times); - gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_pvrvideosink_show_frame); -} - -/* ============================================================= */ -/* */ -/* Public Methods */ -/* */ -/* ============================================================= */ - -/* =========================================== */ -/* */ -/* Object typing & Creation */ -/* */ -/* =========================================== */ - -GType -gst_pvrvideosink_get_type (void) -{ - static GType pvrvideosink_type = 0; - - if (!pvrvideosink_type) { - static const GTypeInfo pvrvideosink_info = { - sizeof (GstPVRVideoSinkClass), - gst_pvrvideosink_base_init, - NULL, - (GClassInitFunc) gst_pvrvideosink_class_init, - NULL, - NULL, - sizeof (GstPVRVideoSink), 0, (GInstanceInitFunc) gst_pvrvideosink_init, - }; - static const GInterfaceInfo iface_info = { - (GInterfaceInitFunc) gst_pvrvideosink_interface_init, NULL, NULL, - }; - static const GInterfaceInfo overlay_info = { - (GInterfaceInitFunc) gst_pvrvideosink_xoverlay_init, NULL, NULL, - }; - - pvrvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK, - "GstPVRVideoSink", &pvrvideosink_info, 0); - - g_type_add_interface_static (pvrvideosink_type, - GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info); - g_type_add_interface_static (pvrvideosink_type, GST_TYPE_X_OVERLAY, - &overlay_info); - } - - return pvrvideosink_type; + videosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_pvrvideosink_show_frame); } diff --git a/sys/pvr2d/gstpvrvideosink.h b/sys/pvr2d/gstpvrvideosink.h index 45f6a129e..f0b9df6a9 100644 --- a/sys/pvr2d/gstpvrvideosink.h +++ b/sys/pvr2d/gstpvrvideosink.h @@ -25,7 +25,6 @@ #include <gst/video/gstvideosink.h> #include <gst/video/video.h> -#include "gstpvrbufferpool.h" #include <string.h> #include <math.h> @@ -98,7 +97,6 @@ struct _GstXWindow * @fps_d: the framerate fraction denominator * @flow_lock: used to protect data flow routines from external calls such as * events from @event_thread or methods from the #GstXOverlay interface - * @pool_lock: used to protect the buffer pool * @x_lock: used to protect X calls * @buffer_pool: a list of #GstPVRVideoBuffer that could be reused at next buffer * allocation call @@ -115,20 +113,12 @@ struct _GstPVRVideoSink gboolean running; /* Framerate numerator and denominator */ - GstVideoFormat format; - gint fps_n; - gint fps_d; - gint rowstride; + GstVideoInfo info; GThread *event_thread; GMutex *flow_lock; - GMutex *pool_lock; - GstPvrBufferPool *buffer_pool; - gboolean pool_invalid; - gint num_buffers; - gboolean num_buffers_can_change; - gint min_queued_bufs; + GstBufferPool *pool; gboolean keep_aspect; @@ -143,6 +133,9 @@ struct _GstPVRVideoSink gboolean redraw_borders; GstBuffer *current_buffer; + /* List of buffer using GstPVRMeta on ourselves */ + GList *metabuffers; + WSEGLDrawableParams render_params; }; @@ -153,5 +146,8 @@ struct _GstPVRVideoSinkClass GType gst_pvrvideosink_get_type (void); +void gst_pvrvideosink_track_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer); +void gst_pvrvideosink_untrack_buffer (GstPVRVideoSink * pvrsink, GstBuffer * buffer); + G_END_DECLS #endif /* __GST_PVRVIDEOSINK_H__ */ diff --git a/sys/qcam/gstqcamsrc.c b/sys/qcam/gstqcamsrc.c index 2bd3a5855..76229ac76 100644 --- a/sys/qcam/gstqcamsrc.c +++ b/sys/qcam/gstqcamsrc.c @@ -148,8 +148,8 @@ gst_qcamsrc_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_static_pad_template (element_class, - &gst_qcamsrc_src_factory); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_qcamsrc_src_factory)); gst_element_class_set_details_simple (element_class, "QCam Source", "Source/Video", "Read from a QuickCam device", "Wim Taymans <wim.taymans@chello.be>"); diff --git a/sys/qtwrapper/audiodecoders.c b/sys/qtwrapper/audiodecoders.c index abb2541de..32f8e1d43 100644 --- a/sys/qtwrapper/audiodecoders.c +++ b/sys/qtwrapper/audiodecoders.c @@ -747,7 +747,8 @@ process_buffer_cb (ComponentInstance inAudioConverter, return noErr; } - GST_LOG_OBJECT (qtwrapper, "No remaining input data, returning NO_MORE_INPUT_DATA"); + GST_LOG_OBJECT (qtwrapper, + "No remaining input data, returning NO_MORE_INPUT_DATA"); return NO_MORE_INPUT_DATA; } @@ -970,7 +971,8 @@ qtwrapper_audio_decoder_base_init (QTWrapperAudioDecoderClass * klass) klass->sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, params->sinkcaps); gst_element_class_add_pad_template (element_class, klass->sinktempl); - gst_element_class_add_static_pad_template (element_class, &src_templ); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_templ)); /* Store class-global values */ klass->componentSubType = desc.componentSubType; diff --git a/sys/qtwrapper/videodecoders.c b/sys/qtwrapper/videodecoders.c index c532ef9bb..b2e58e968 100644 --- a/sys/qtwrapper/videodecoders.c +++ b/sys/qtwrapper/videodecoders.c @@ -171,7 +171,8 @@ qtwrapper_video_decoder_base_init (QTWrapperVideoDecoderClass * klass) GST_PAD_ALWAYS, params->sinkcaps); gst_element_class_add_pad_template (element_class, klass->sinktempl); - gst_element_class_add_static_pad_template (element_class, &src_templ); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_templ)); /* Store class-global values */ klass->component = params->component; diff --git a/sys/shm/gstshmsink.c b/sys/shm/gstshmsink.c index 3ebbc4752..605e79871 100644 --- a/sys/shm/gstshmsink.c +++ b/sys/shm/gstshmsink.c @@ -80,7 +80,8 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY); -GST_BOILERPLATE (GstShmSink, gst_shm_sink, GstBaseSink, GST_TYPE_BASE_SINK); +#define gst_shm_sink_parent_class parent_class +G_DEFINE_TYPE (GstShmSink, gst_shm_sink, GST_TYPE_BASE_SINK); static void gst_shm_sink_finalize (GObject * object); static void gst_shm_sink_set_property (GObject * object, guint prop_id, @@ -91,8 +92,6 @@ static void gst_shm_sink_get_property (GObject * object, guint prop_id, static gboolean gst_shm_sink_start (GstBaseSink * bsink); static gboolean gst_shm_sink_stop (GstBaseSink * bsink); static GstFlowReturn gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf); -static GstFlowReturn gst_shm_sink_buffer_alloc (GstBaseSink * sink, - guint64 offset, guint size, GstCaps * caps, GstBuffer ** out_buf); static gboolean gst_shm_sink_event (GstBaseSink * bsink, GstEvent * event); static gboolean gst_shm_sink_unlock (GstBaseSink * bsink); @@ -103,21 +102,7 @@ static gpointer pollthread_func (gpointer data); static guint signals[LAST_SIGNAL] = { 0 }; static void -gst_shm_sink_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_static_pad_template (element_class, &sinktemplate); - - gst_element_class_set_details_simple (element_class, - "Shared Memory Sink", - "Sink", - "Send data over shared memory to the matching source", - "Olivier Crete <olivier.crete@collabora.co.uk>"); -} - -static void -gst_shm_sink_init (GstShmSink * self, GstShmSinkClass * g_class) +gst_shm_sink_init (GstShmSink * self) { self->cond = g_cond_new (); self->size = DEFAULT_SIZE; @@ -129,9 +114,11 @@ static void gst_shm_sink_class_init (GstShmSinkClass * klass) { GObjectClass *gobject_class; + GstElementClass *gstelement_class; GstBaseSinkClass *gstbasesink_class; gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass; gobject_class->finalize = gst_shm_sink_finalize; @@ -144,8 +131,6 @@ gst_shm_sink_class_init (GstShmSinkClass * klass) gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_shm_sink_event); gstbasesink_class->unlock = GST_DEBUG_FUNCPTR (gst_shm_sink_unlock); gstbasesink_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_shm_sink_unlock_stop); - gstbasesink_class->buffer_alloc = - GST_DEBUG_FUNCPTR (gst_shm_sink_buffer_alloc); g_object_class_install_property (gobject_class, PROP_SOCKET_PATH, g_param_spec_string ("socket-path", @@ -188,6 +173,15 @@ gst_shm_sink_class_init (GstShmSinkClass * klass) GST_TYPE_SHM_SINK, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&sinktemplate)); + + gst_element_class_set_details_simple (gstelement_class, + "Shared Memory Sink", + "Sink", + "Send data over shared memory to the matching source", + "Olivier Crete <olivier.crete@collabora.co.uk>"); + GST_DEBUG_CATEGORY_INIT (shmsink_debug, "shmsink", 0, "Shared Memory Sink"); } @@ -408,13 +402,14 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf) { GstShmSink *self = GST_SHM_SINK (bsink); int rv; + GstMapInfo map; GST_OBJECT_LOCK (self); while (self->wait_for_connection && !self->clients) { g_cond_wait (self->cond, GST_OBJECT_GET_LOCK (self)); if (self->unlock) { GST_OBJECT_UNLOCK (self); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } } @@ -422,22 +417,24 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf) g_cond_wait (self->cond, GST_OBJECT_GET_LOCK (self)); if (self->unlock) { GST_OBJECT_UNLOCK (self); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } } - rv = sp_writer_send_buf (self->pipe, (char *) GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf)); + gst_buffer_map (buf, &map, GST_MAP_READ); + rv = sp_writer_send_buf (self->pipe, (char *) map.data, map.size, + GST_BUFFER_TIMESTAMP (buf)); + gst_buffer_unmap (buf, &map); if (rv == -1) { ShmBlock *block = NULL; gchar *shmbuf = NULL; while ((block = sp_writer_alloc_block (self->pipe, - GST_BUFFER_SIZE (buf))) == NULL) { + gst_buffer_get_size (buf))) == NULL) { g_cond_wait (self->cond, GST_OBJECT_GET_LOCK (self)); if (self->unlock) { GST_OBJECT_UNLOCK (self); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } } while (self->wait_for_connection && !self->clients) { @@ -445,13 +442,13 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf) if (self->unlock) { sp_writer_free_block (block); GST_OBJECT_UNLOCK (self); - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } } shmbuf = sp_writer_block_get_buf (block); - memcpy (shmbuf, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); - sp_writer_send_buf (self->pipe, shmbuf, GST_BUFFER_SIZE (buf), + gst_buffer_extract (buf, 0, shmbuf, gst_buffer_get_size (buf)); + sp_writer_send_buf (self->pipe, shmbuf, gst_buffer_get_size (buf), GST_BUFFER_TIMESTAMP (buf)); sp_writer_free_block (block); } @@ -461,6 +458,10 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf) return GST_FLOW_OK; } +#if 0 + +/* FIXME 0.11 implement some bufferpool support */ + static void gst_shm_sink_free_buffer (gpointer data) { @@ -516,6 +517,7 @@ gst_shm_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size, return GST_FLOW_OK; } +#endif static gpointer pollthread_func (gpointer data) diff --git a/sys/shm/gstshmsrc.c b/sys/shm/gstshmsrc.c index fe086b7ee..672f4f3a4 100644 --- a/sys/shm/gstshmsrc.c +++ b/sys/shm/gstshmsrc.c @@ -72,7 +72,8 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY); -GST_BOILERPLATE (GstShmSrc, gst_shm_src, GstPushSrc, GST_TYPE_PUSH_SRC); +#define gst_shm_src_parent_class parent_class +G_DEFINE_TYPE (GstShmSrc, gst_shm_src, GST_TYPE_PUSH_SRC); static void gst_shm_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -93,21 +94,6 @@ static void gst_shm_pipe_dec (GstShmPipe * pipe); // static guint gst_shm_src_signals[LAST_SIGNAL] = { 0 }; - -static void -gst_shm_src_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_static_pad_template (element_class, &srctemplate); - - gst_element_class_set_details_simple (element_class, - "Shared Memory Source", - "Source", - "Receive data from the shared memory sink", - "Olivier Crete <olivier.crete@collabora.co.uk>"); -} - static void gst_shm_src_class_init (GstShmSrcClass * klass) { @@ -145,11 +131,20 @@ gst_shm_src_class_init (GstShmSrcClass * klass) "True if the element cannot produce data in PAUSED", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&srctemplate)); + + gst_element_class_set_details_simple (element_class, + "Shared Memory Source", + "Source", + "Receive data from the shared memory sink", + "Olivier Crete <olivier.crete@collabora.co.uk>"); + GST_DEBUG_CATEGORY_INIT (shmsrc_debug, "shmsrc", 0, "Shared Memory Source"); } static void -gst_shm_src_init (GstShmSrc * self, GstShmSrcClass * g_class) +gst_shm_src_init (GstShmSrc * self) { self->poll = gst_poll_new (TRUE); gst_poll_fd_init (&self->pollfd); @@ -319,14 +314,14 @@ gst_shm_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) do { if (gst_poll_wait (self->poll, GST_CLOCK_TIME_NONE) < 0) { if (errno == EBUSY) - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed to read from shmsrc"), ("Poll failed on fd: %s", strerror (errno))); return GST_FLOW_ERROR; } if (self->unlocked) - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; if (gst_poll_fd_has_closed (self->poll, &self->pollfd)) { GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed to read from shmsrc"), @@ -362,11 +357,9 @@ gst_shm_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) gst_shm_pipe_inc (self->pipe); *outbuf = gst_buffer_new (); - GST_BUFFER_FLAG_SET (*outbuf, GST_BUFFER_FLAG_READONLY); - GST_BUFFER_DATA (*outbuf) = (guint8 *) buf; - GST_BUFFER_SIZE (*outbuf) = rv; - GST_BUFFER_MALLOCDATA (*outbuf) = (guint8 *) gsb; - GST_BUFFER_FREE_FUNC (*outbuf) = free_buffer; + gst_buffer_append_memory (*outbuf, + gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, + buf, rv, 0, rv, gsb, free_buffer)); return GST_FLOW_OK; } diff --git a/sys/vcd/vcdsrc.c b/sys/vcd/vcdsrc.c index 553e264cc..5ce58d870 100644 --- a/sys/vcd/vcdsrc.c +++ b/sys/vcd/vcdsrc.c @@ -99,7 +99,8 @@ gst_vcdsrc_base_init (gpointer g_class) "Source/File", "Asynchronous read from VCD disk", "Erik Walthinsen <omega@cse.ogi.edu>"); - gst_element_class_add_static_pad_template (element_class, &srctemplate); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&srctemplate)); } static void diff --git a/sys/vdpau/gstvdp/gstvdpdecoder.c b/sys/vdpau/gstvdp/gstvdpdecoder.c index a400a39d6..977f6e6b2 100644 --- a/sys/vdpau/gstvdp/gstvdpdecoder.c +++ b/sys/vdpau/gstvdp/gstvdpdecoder.c @@ -293,7 +293,6 @@ gst_vdp_decoder_base_init (gpointer g_class) GST_PAD_SRC, GST_PAD_ALWAYS, src_caps); gst_element_class_add_pad_template (element_class, src_template); - gst_object_unref (src_template); } static void diff --git a/sys/vdpau/gstvdpsink.c b/sys/vdpau/gstvdpsink.c index 27847bd18..5a5677eb4 100644 --- a/sys/vdpau/gstvdpsink.c +++ b/sys/vdpau/gstvdpsink.c @@ -1387,8 +1387,8 @@ gst_vdp_sink_base_init (gpointer g_class) "Sink/Video", "VDPAU Sink", "Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>"); - gst_element_class_add_static_pad_template (element_class, - &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } static void diff --git a/sys/vdpau/gstvdpvideopostprocess.c b/sys/vdpau/gstvdpvideopostprocess.c index 09e484409..ced168fec 100644 --- a/sys/vdpau/gstvdpvideopostprocess.c +++ b/sys/vdpau/gstvdpvideopostprocess.c @@ -1190,14 +1190,12 @@ gst_vdp_vpp_base_init (gpointer gclass) src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps); gst_element_class_add_pad_template (element_class, src_template); - gst_object_unref (src_template); /* SINK PAD */ sink_caps = gst_vdp_video_buffer_get_caps (FALSE, 0); sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps); gst_element_class_add_pad_template (element_class, sink_template); - gst_object_unref (sink_template); } /* initialize the vdpaumpegdecoder's class */ diff --git a/sys/vdpau/h264/gstvdph264dec.c b/sys/vdpau/h264/gstvdph264dec.c index 71893ca0b..ab5479794 100644 --- a/sys/vdpau/h264/gstvdph264dec.c +++ b/sys/vdpau/h264/gstvdph264dec.c @@ -872,7 +872,8 @@ gst_vdp_h264_dec_base_init (gpointer g_class) "Decode h264 stream with vdpau", "Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>"); - gst_element_class_add_static_pad_template (element_class, &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } static void diff --git a/sys/vdpau/mpeg/gstvdpmpegdec.c b/sys/vdpau/mpeg/gstvdpmpegdec.c index 87456eb78..96c04c8ce 100644 --- a/sys/vdpau/mpeg/gstvdpmpegdec.c +++ b/sys/vdpau/mpeg/gstvdpmpegdec.c @@ -626,7 +626,8 @@ gst_vdp_mpeg_dec_base_init (gpointer gclass) "Decode mpeg stream with vdpau", "Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>"); - gst_element_class_add_static_pad_template (element_class, &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } /* initialize the vdpaumpegdecoder's class */ diff --git a/sys/vdpau/mpeg/gstvdpmpegframe.c b/sys/vdpau/mpeg/gstvdpmpegframe.c index 54e1a3c28..a3e9060cf 100644 --- a/sys/vdpau/mpeg/gstvdpmpegframe.c +++ b/sys/vdpau/mpeg/gstvdpmpegframe.c @@ -36,7 +36,7 @@ gst_vdp_mpeg_frame_add_slice (GstVdpMpegFrame * mpeg_frame, GstBuffer * buf) if (!mpeg_frame->slices) mpeg_frame->slices = buf; else - mpeg_frame->slices = gst_buffer_join (mpeg_frame->slices, buf); + mpeg_frame->slices = gst_buffer_append (mpeg_frame->slices, buf); mpeg_frame->n_slices++; } diff --git a/sys/vdpau/mpeg4/gstvdpmpeg4dec.c b/sys/vdpau/mpeg4/gstvdpmpeg4dec.c index 4c1bcb8b3..2ecf434e1 100644 --- a/sys/vdpau/mpeg4/gstvdpmpeg4dec.c +++ b/sys/vdpau/mpeg4/gstvdpmpeg4dec.c @@ -445,8 +445,8 @@ gst_vdp_mpeg4_dec_base_init (gpointer gclass) "Decode mpeg4 stream with vdpau", "Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>"); - gst_element_class_add_static_pad_template (element_class, - &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } /* initialize the vdpaumpeg4decoder's class */ diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 8e515dc93..3a3d9e906 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -65,8 +65,8 @@ gst_wasapi_sink_base_init (gpointer gclass) { GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - gst_element_class_add_static_pad_template (element_class, - &sink_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); gst_element_class_set_details_simple (element_class, "WasapiSrc", "Sink/Audio", "Stream audio to an audio capture device through WASAPI", diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index 0ef642b08..a4100315b 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -69,7 +69,8 @@ gst_wasapi_src_base_init (gpointer gclass) { GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "WasapiSrc", "Source/Audio", "Stream audio from an audio capture device through WASAPI", diff --git a/sys/wininet/gstwininetsrc.c b/sys/wininet/gstwininetsrc.c index b21e3d0be..8104f7cea 100644 --- a/sys/wininet/gstwininetsrc.c +++ b/sys/wininet/gstwininetsrc.c @@ -83,7 +83,8 @@ gst_win_inet_src_base_init (gpointer gclass) { GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "Windows Network Source", "Source/Network", diff --git a/sys/winks/gstksvideodevice.c b/sys/winks/gstksvideodevice.c index dbd7f035b..957b874e9 100644 --- a/sys/winks/gstksvideodevice.c +++ b/sys/winks/gstksvideodevice.c @@ -1146,7 +1146,7 @@ error_cancel: if (error_str != NULL) *error_str = NULL; - return GST_FLOW_WRONG_STATE; + return GST_FLOW_FLUSHING; } error_get_result: { diff --git a/sys/winks/gstksvideosrc.c b/sys/winks/gstksvideosrc.c index 3f2b66914..897ff0c34 100644 --- a/sys/winks/gstksvideosrc.c +++ b/sys/winks/gstksvideosrc.c @@ -167,7 +167,6 @@ static void gst_ks_video_src_base_init (gpointer gclass) { GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); - GstPadTemplate *pad_template; gst_element_class_set_details_simple (element_class, "KsVideoSrc", "Source/Video", @@ -176,11 +175,9 @@ gst_ks_video_src_base_init (gpointer gclass) "Haakon Sporsheim <hakon.sporsheim@tandberg.com>\n" "Andres Colubri <andres.colubri@gmail.com>"); - pad_template = + gst_element_class_add_pad_template (element_class, gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - ks_video_get_all_caps ()); - gst_element_class_add_pad_template (element_class, pad_template); - gst_object_unref (pad_template); + ks_video_get_all_caps ())); } static void @@ -756,7 +753,7 @@ gst_ks_video_src_set_clock (GstElement * element, GstClock * clock) gst_ks_clock_provide_master_clock (priv->ksclock, clock); GST_OBJECT_UNLOCK (element); - return TRUE; + return GST_ELEMENT_CLASS (element)->set_clock (element, clock); } static GstCaps * diff --git a/sys/winscreencap/gstdx9screencapsrc.c b/sys/winscreencap/gstdx9screencapsrc.c index 029053d0d..5283376a1 100644 --- a/sys/winscreencap/gstdx9screencapsrc.c +++ b/sys/winscreencap/gstdx9screencapsrc.c @@ -101,7 +101,8 @@ gst_dx9screencapsrc_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "DirectX 9 screen capture source", "Source/Video", "Captures screen", diff --git a/sys/winscreencap/gstgdiscreencapsrc.c b/sys/winscreencap/gstgdiscreencapsrc.c index 3e0cd6f44..7658b2ea2 100644 --- a/sys/winscreencap/gstgdiscreencapsrc.c +++ b/sys/winscreencap/gstgdiscreencapsrc.c @@ -97,7 +97,8 @@ gst_gdiscreencapsrc_base_init (gpointer klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_static_pad_template (element_class, &src_template); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); gst_element_class_set_details_simple (element_class, "GDI screen capture source", "Source/Video", "Captures screen", "Haakon Sporsheim <hakon.sporsheim@tandberg.com>"); |