cdbfcce24311a5c8bec99fd913759e61061584b1
[platform/upstream/gstreamer.git] / ext / ttml / subtitlemeta.c
1 /* GStreamer
2  * Copyright (C) <2015> British Broadcasting Corporation
3  *   Author: Chris Bass <dash@rd.bbc.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * SECTION:gstsubtitlemeta
23  * @title: GstSubtitleMeta
24  * @short_description: Metadata class for timed-text subtitles.
25  *
26  * The GstSubtitleMeta class enables the layout and styling information needed
27  * to render subtitle text to be attached to a #GstBuffer containing that text.
28  */
29
30 #include "subtitlemeta.h"
31
32 GType
33 gst_subtitle_meta_api_get_type (void)
34 {
35   static volatile GType type;
36   static const gchar *tags[] = { "memory", NULL };
37
38   if (g_once_init_enter (&type)) {
39     GType _type = gst_meta_api_type_register ("GstSubtitleMetaAPI", tags);
40     g_once_init_leave (&type, _type);
41   }
42   return type;
43 }
44
45 gboolean
46 gst_subtitle_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
47 {
48   GstSubtitleMeta *subtitle_meta = (GstSubtitleMeta *) meta;
49
50   subtitle_meta->regions = NULL;
51   return TRUE;
52 }
53
54 void
55 gst_subtitle_meta_free (GstMeta * meta, GstBuffer * buffer)
56 {
57   GstSubtitleMeta *subtitle_meta = (GstSubtitleMeta *) meta;
58
59   if (subtitle_meta->regions)
60     g_ptr_array_unref (subtitle_meta->regions);
61 }
62
63 const GstMetaInfo *
64 gst_subtitle_meta_get_info (void)
65 {
66   static const GstMetaInfo *subtitle_meta_info = NULL;
67
68   if (g_once_init_enter (&subtitle_meta_info)) {
69     const GstMetaInfo *meta =
70         gst_meta_register (GST_SUBTITLE_META_API_TYPE, "GstSubtitleMeta",
71         sizeof (GstSubtitleMeta), gst_subtitle_meta_init,
72         gst_subtitle_meta_free, (GstMetaTransformFunction) NULL);
73     g_once_init_leave (&subtitle_meta_info, meta);
74   }
75   return subtitle_meta_info;
76 }
77
78 /**
79  * gst_buffer_add_subtitle_meta:
80  * @buffer: (transfer none): #GstBuffer holding subtitle text, to which
81  * subtitle metadata should be added.
82  * @regions: (transfer full): A #GPtrArray of #GstSubtitleRegions.
83  *
84  * Attaches subtitle metadata to a #GstBuffer.
85  *
86  * Returns: A pointer to the added #GstSubtitleMeta if successful; %NULL if
87  * unsuccessful.
88  */
89 GstSubtitleMeta *
90 gst_buffer_add_subtitle_meta (GstBuffer * buffer, GPtrArray * regions)
91 {
92   GstSubtitleMeta *meta;
93
94   g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
95   g_return_val_if_fail (regions != NULL, NULL);
96
97   meta = (GstSubtitleMeta *) gst_buffer_add_meta (buffer,
98       GST_SUBTITLE_META_INFO, NULL);
99
100   meta->regions = regions;
101   return meta;
102 }