diff --git a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.cpp b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.cpp index 8e90cd5152..580433841b 100644 --- a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.cpp +++ b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.cpp @@ -24,6 +24,102 @@ #include #include "gstdwrite-utils.h" +GType +gst_dwrite_subtitle_meta_api_get_type (void) +{ + static GType type = 0; + static const gchar *tags[] = { NULL, }; + + GST_DWRITE_CALL_ONCE_BEGIN { + type = gst_meta_api_type_register ("GstDWriteSubtitleMetaAPI", tags); + } GST_DWRITE_CALL_ONCE_END; + + return type; +} + +static gboolean +gst_dwrite_subtitle_meta_init (GstMeta * meta, gpointer params, + GstBuffer * buffer) +{ + GstDWriteSubtitleMeta *m = (GstDWriteSubtitleMeta *) meta; + + m->stream = NULL; + m->subtitle = NULL; + + return TRUE; +} + +static void +gst_dwrite_subtitle_meta_free (GstMeta * meta, GstBuffer * buffer) +{ + GstDWriteSubtitleMeta *m = (GstDWriteSubtitleMeta *) meta; + + if (m->stream) + gst_object_unref (m->stream); + + if (m->subtitle) + gst_buffer_unref (m->subtitle); +} + +static gboolean +gst_dwrite_subtitle_meta_transform (GstBuffer * dest, GstMeta * meta, + GstBuffer * buffer, GQuark type, gpointer data) +{ + GstDWriteSubtitleMeta *dmeta, *smeta; + + if (GST_META_TRANSFORM_IS_COPY (type)) { + smeta = (GstDWriteSubtitleMeta *) meta; + + dmeta = gst_buffer_add_dwrite_subtitle_meta (dest, + smeta->stream, smeta->subtitle); + if (!dmeta) + return FALSE; + } else { + return FALSE; + } + + return TRUE; +} + +const GstMetaInfo * +gst_dwrite_subtitle_meta_get_info (void) +{ + static const GstMetaInfo *info = NULL; + + GST_DWRITE_CALL_ONCE_BEGIN { + info = gst_meta_register (GST_DWRITE_SUBTITLE_META_API_TYPE, + "GstDWriteSubtitleMeta", + sizeof (GstDWriteSubtitleMeta), + gst_dwrite_subtitle_meta_init, + gst_dwrite_subtitle_meta_free, gst_dwrite_subtitle_meta_transform); + } + GST_DWRITE_CALL_ONCE_END; + + return info; +} + +GstDWriteSubtitleMeta * +gst_buffer_add_dwrite_subtitle_meta (GstBuffer * buffer, GstStream * stream, + GstBuffer * subtitle) +{ + GstDWriteSubtitleMeta *meta; + + g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL); + g_return_val_if_fail (GST_IS_STREAM (stream), NULL); + g_return_val_if_fail (GST_IS_BUFFER (subtitle), NULL); + + meta = (GstDWriteSubtitleMeta *) gst_buffer_add_meta (buffer, + GST_DWRITE_SUBTITLE_META_INFO, NULL); + + if (!meta) + return NULL; + + meta->stream = (GstStream *) gst_object_ref (stream); + meta->subtitle = gst_buffer_ref (subtitle); + + return meta; +} + gboolean gst_dwrite_is_windows_10_or_greater (void) { diff --git a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h index 6c3ada6b00..185aebe3d0 100644 --- a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h +++ b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h @@ -21,6 +21,8 @@ #include +G_BEGIN_DECLS + #define GST_DWRITE_CAPS \ GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY "," \ GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, \ @@ -31,7 +33,29 @@ GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, GST_VIDEO_FORMATS_ALL) ";" \ GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) -G_BEGIN_DECLS +typedef struct +{ + GstMeta meta; + + GstStream *stream; + GstBuffer *subtitle; + + /*< private >*/ + gpointer _gst_reserved[GST_PADDING]; +} GstDWriteSubtitleMeta; + +GType gst_dwrite_subtitle_meta_api_get_type (void); +#define GST_DWRITE_SUBTITLE_META_API_TYPE (gst_dwrite_subtitle_meta_api_get_type()) + +const GstMetaInfo * gst_dwrite_subtitle_meta_get_info (void); +#define GST_DWRITE_SUBTITLE_META_INFO (gst_dwrite_subtitle_meta_get_info()) + +#define gst_buffer_get_dwrite_subtitle_meta(b) \ + ((GstDWriteSubtitleMeta *) gst_buffer_get_meta((b), GST_DWRITE_SUBTITLE_META_API_TYPE)) + +GstDWriteSubtitleMeta * gst_buffer_add_dwrite_subtitle_meta (GstBuffer * buffer, + GstStream * stream, + GstBuffer * subtitle); gboolean gst_dwrite_is_windows_10_or_greater (void);