1 /* GStreamer
2  * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <gst/gst.h>
25 #include <string.h>
26 
27 #include "mxfessence.h"
28 
29 GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
30 #define GST_CAT_DEFAULT mxf_debug
31 
32 static GSList *_mxf_essence_element_handler_registry = NULL;
33 
34 void
mxf_essence_element_handler_register(const MXFEssenceElementHandler * handler)35 mxf_essence_element_handler_register (const MXFEssenceElementHandler * handler)
36 {
37   _mxf_essence_element_handler_registry =
38       g_slist_prepend (_mxf_essence_element_handler_registry,
39       (gpointer) handler);
40 }
41 
42 const MXFEssenceElementHandler *
mxf_essence_element_handler_find(const MXFMetadataTimelineTrack * track)43 mxf_essence_element_handler_find (const MXFMetadataTimelineTrack * track)
44 {
45   GSList *l;
46   const MXFEssenceElementHandler *ret = NULL;
47 
48   for (l = _mxf_essence_element_handler_registry; l; l = l->next) {
49     MXFEssenceElementHandler *current = l->data;
50 
51     if (current->handles_track (track)) {
52       ret = current;
53     }
54   }
55 
56   return ret;
57 }
58 
59 static GList *_essence_element_writer_registry = NULL;
60 static GPtrArray *_essence_element_writer_pad_templates = NULL;
61 
62 void
mxf_essence_element_writer_register(const MXFEssenceElementWriter * writer)63 mxf_essence_element_writer_register (const MXFEssenceElementWriter * writer)
64 {
65   _essence_element_writer_registry =
66       g_list_prepend (_essence_element_writer_registry, (gpointer) writer);
67 
68   if (!_essence_element_writer_pad_templates)
69     _essence_element_writer_pad_templates = g_ptr_array_new ();
70 
71   if (_essence_element_writer_pad_templates->len > 0 &&
72       g_ptr_array_index (_essence_element_writer_pad_templates,
73           _essence_element_writer_pad_templates->len - 1) == NULL)
74     g_ptr_array_remove_index (_essence_element_writer_pad_templates,
75         _essence_element_writer_pad_templates->len - 1);
76 
77   g_ptr_array_add (_essence_element_writer_pad_templates,
78       (gpointer) writer->pad_template);
79 }
80 
81 const GstPadTemplate **
mxf_essence_element_writer_get_pad_templates(void)82 mxf_essence_element_writer_get_pad_templates (void)
83 {
84   if (!_essence_element_writer_pad_templates
85       || _essence_element_writer_pad_templates->len == 0)
86     return NULL;
87 
88   if (g_ptr_array_index (_essence_element_writer_pad_templates,
89           _essence_element_writer_pad_templates->len - 1))
90     g_ptr_array_add (_essence_element_writer_pad_templates, NULL);
91 
92   return (const GstPadTemplate **) _essence_element_writer_pad_templates->pdata;
93 }
94 
95 const MXFEssenceElementWriter *
mxf_essence_element_writer_find(const GstPadTemplate * templ)96 mxf_essence_element_writer_find (const GstPadTemplate * templ)
97 {
98   GList *l = _essence_element_writer_registry;
99 
100   for (; l; l = l->next) {
101     MXFEssenceElementWriter *writer = l->data;
102 
103     if (writer->pad_template == templ)
104       return writer;
105   }
106 
107   return NULL;
108 }
109