Constness changes
[melted] / src / modules / core / filter_data_feed.c
1 /*
2 * filter_data_feed.c -- data feed filter
3 * Copyright (C) 2004-2005 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <framework/mlt.h>
24
25 /** This filter should be used in conjuction with the data_show filter.
26 The concept of the data_feed is that it can be used to pass titles
27 or images to render on the frame, but doesn't actually do it
28 itself. data_feed imposes few rules on what's passed on and the
29 validity is confirmed in data_show before use.
30 */
31
32 /** Data queue destructor.
33 */
34
35 static void destroy_data_queue( void *arg )
36 {
37 if ( arg != NULL )
38 {
39 // Assign the correct type
40 mlt_deque queue = arg;
41
42 // Iterate through each item and destroy them
43 while ( mlt_deque_peek_front( queue ) != NULL )
44 mlt_properties_close( mlt_deque_pop_back( queue ) );
45
46 // Close the deque
47 mlt_deque_close( queue );
48 }
49 }
50
51 /** Filter processing.
52 */
53
54 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
55 {
56 // Get the filter properties
57 mlt_properties filter_properties = MLT_FILTER_PROPERTIES( this );
58
59 // Get the frame properties
60 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
61
62 // Get the data queue
63 mlt_deque data_queue = mlt_properties_get_data( frame_properties, "data_queue", NULL );
64
65 // Get the type of the data feed
66 char *type = mlt_properties_get( filter_properties, "type" );
67
68 // Get the in and out points of this filter
69 int in = mlt_filter_get_in( this );
70 int out = mlt_filter_get_out( this );
71
72 // Create the data queue if it doesn't exist
73 if ( data_queue == NULL )
74 {
75 // Create the queue
76 data_queue = mlt_deque_init( );
77
78 // Assign it to the frame with the destructor
79 mlt_properties_set_data( frame_properties, "data_queue", data_queue, 0, destroy_data_queue, NULL );
80 }
81
82 // Now create the data feed
83 if ( data_queue != NULL && type != NULL && !strcmp( type, "attr_check" ) )
84 {
85 int i = 0;
86 int count = mlt_properties_count( frame_properties );
87
88 for ( i = 0; i < count; i ++ )
89 {
90 char *name = mlt_properties_get_name( frame_properties, i );
91
92 // Only deal with meta.attr.name values here - these should have a value of 1 to be considered
93 // Additional properties of the form are meta.attr.name.property are passed down on the feed
94 if ( !strncmp( name, "meta.attr.", 10 ) && strchr( name + 10, '.' ) == NULL && mlt_properties_get_int( frame_properties, name ) == 1 )
95 {
96 // Temp var to hold name + '.' for pass method
97 char temp[ 132 ];
98
99 // Create a new data feed
100 mlt_properties feed = mlt_properties_new( );
101
102 // Assign it the base properties
103 mlt_properties_set( feed, "id", mlt_properties_get( filter_properties, "_unique_id" ) );
104 mlt_properties_set( feed, "type", strrchr( name, '.' ) + 1 );
105 mlt_properties_set_position( feed, "position", mlt_frame_get_position( frame ) );
106
107 // Assign in/out of service we're connected to
108 mlt_properties_set_position( feed, "in", mlt_properties_get_position( frame_properties, "in" ) );
109 mlt_properties_set_position( feed, "out", mlt_properties_get_position( frame_properties, "out" ) );
110
111 // Pass all meta properties
112 sprintf( temp, "%s.", name );
113 mlt_properties_pass( feed, frame_properties, temp );
114
115 // Push it on to the queue
116 mlt_deque_push_back( data_queue, feed );
117
118 // Make sure this attribute only gets processed once
119 mlt_properties_set_int( frame_properties, name, 0 );
120 }
121 }
122 }
123 else if ( data_queue != NULL )
124 {
125 // Create a new data feed
126 mlt_properties feed = mlt_properties_new( );
127
128 // Assign it the base properties
129 mlt_properties_set( feed, "id", mlt_properties_get( filter_properties, "_unique_id" ) );
130 mlt_properties_set( feed, "type", type );
131 mlt_properties_set_position( feed, "position", mlt_frame_get_position( frame ) );
132
133 // Assign in/out of service we're connected to
134 mlt_properties_set_position( feed, "in", mlt_properties_get_position( frame_properties, "in" ) );
135 mlt_properties_set_position( feed, "out", mlt_properties_get_position( frame_properties, "out" ) );
136
137 // Correct in/out to the filter if specified
138 if ( in != 0 )
139 mlt_properties_set_position( feed, "in", in );
140 if ( out != 0 )
141 mlt_properties_set_position( feed, "out", out );
142
143 // Pass the properties which start with a "feed." prefix
144 // Note that 'feed.text' in the filter properties becomes 'text' on the feed
145 mlt_properties_pass( feed, filter_properties, "feed." );
146
147 // Push it on to the queue
148 mlt_deque_push_back( data_queue, feed );
149 }
150
151 return frame;
152 }
153
154 /** Constructor for the filter.
155 */
156
157 mlt_filter filter_data_feed_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
158 {
159 // Create the filter
160 mlt_filter this = mlt_filter_new( );
161
162 // Initialise it
163 if ( this != NULL )
164 {
165 // Get the properties
166 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
167
168 // Assign the argument (default to titles)
169 mlt_properties_set( properties, "type", arg == NULL ? "titles" : arg );
170
171 // Specify the processing method
172 this->process = filter_process;
173 }
174
175 return this;
176 }
177