Cleanup license declarations and remove dv1394d references.
[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 "filter_data.h"
24 #include <framework/mlt.h>
25
26 /** This filter should be used in conjuction with the data_show filter.
27 The concept of the data_feed is that it can be used to pass titles
28 or images to render on the frame, but doesn't actually do it
29 itself. data_feed imposes few rules on what's passed on and the
30 validity is confirmed in data_show before use.
31 */
32
33 /** Data queue destructor.
34 */
35
36 static void destroy_data_queue( void *arg )
37 {
38 if ( arg != NULL )
39 {
40 // Assign the correct type
41 mlt_deque queue = arg;
42
43 // Iterate through each item and destroy them
44 while ( mlt_deque_peek_front( queue ) != NULL )
45 mlt_properties_close( mlt_deque_pop_back( queue ) );
46
47 // Close the deque
48 mlt_deque_close( queue );
49 }
50 }
51
52 /** Filter processing.
53 */
54
55 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
56 {
57 // Get the filter properties
58 mlt_properties filter_properties = MLT_FILTER_PROPERTIES( this );
59
60 // Get the frame properties
61 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
62
63 // Get the data queue
64 mlt_deque data_queue = mlt_properties_get_data( frame_properties, "data_queue", NULL );
65
66 // Get the type of the data feed
67 char *type = mlt_properties_get( filter_properties, "type" );
68
69 // Get the in and out points of this filter
70 int in = mlt_filter_get_in( this );
71 int out = mlt_filter_get_out( this );
72
73 // Create the data queue if it doesn't exist
74 if ( data_queue == NULL )
75 {
76 // Create the queue
77 data_queue = mlt_deque_init( );
78
79 // Assign it to the frame with the destructor
80 mlt_properties_set_data( frame_properties, "data_queue", data_queue, 0, destroy_data_queue, NULL );
81 }
82
83 // Now create the data feed
84 if ( data_queue != NULL && type != NULL && !strcmp( type, "attr_check" ) )
85 {
86 int i = 0;
87 int count = mlt_properties_count( frame_properties );
88
89 for ( i = 0; i < count; i ++ )
90 {
91 char *name = mlt_properties_get_name( frame_properties, i );
92
93 // Only deal with meta.attr.name values here - these should have a value of 1 to be considered
94 // Additional properties of the form are meta.attr.name.property are passed down on the feed
95 if ( !strncmp( name, "meta.attr.", 10 ) && strchr( name + 10, '.' ) == NULL && mlt_properties_get_int( frame_properties, name ) == 1 )
96 {
97 // Temp var to hold name + '.' for pass method
98 char temp[ 132 ];
99
100 // Create a new data feed
101 mlt_properties feed = mlt_properties_new( );
102
103 // Assign it the base properties
104 mlt_properties_set( feed, "id", mlt_properties_get( filter_properties, "_unique_id" ) );
105 mlt_properties_set( feed, "type", strrchr( name, '.' ) + 1 );
106 mlt_properties_set_position( feed, "position", mlt_frame_get_position( frame ) );
107
108 // Assign in/out of service we're connected to
109 mlt_properties_set_position( feed, "in", mlt_properties_get_position( frame_properties, "in" ) );
110 mlt_properties_set_position( feed, "out", mlt_properties_get_position( frame_properties, "out" ) );
111
112 // Pass all meta properties
113 sprintf( temp, "%s.", name );
114 mlt_properties_pass( feed, frame_properties, temp );
115
116 // Push it on to the queue
117 mlt_deque_push_back( data_queue, feed );
118
119 // Make sure this attribute only gets processed once
120 mlt_properties_set_int( frame_properties, name, 0 );
121 }
122 }
123 }
124 else if ( data_queue != NULL )
125 {
126 // Create a new data feed
127 mlt_properties feed = mlt_properties_new( );
128
129 // Assign it the base properties
130 mlt_properties_set( feed, "id", mlt_properties_get( filter_properties, "_unique_id" ) );
131 mlt_properties_set( feed, "type", type );
132 mlt_properties_set_position( feed, "position", mlt_frame_get_position( frame ) );
133
134 // Assign in/out of service we're connected to
135 mlt_properties_set_position( feed, "in", mlt_properties_get_position( frame_properties, "in" ) );
136 mlt_properties_set_position( feed, "out", mlt_properties_get_position( frame_properties, "out" ) );
137
138 // Correct in/out to the filter if specified
139 if ( in != 0 )
140 mlt_properties_set_position( feed, "in", in );
141 if ( out != 0 )
142 mlt_properties_set_position( feed, "out", out );
143
144 // Pass the properties which start with a "feed." prefix
145 // Note that 'feed.text' in the filter properties becomes 'text' on the feed
146 mlt_properties_pass( feed, filter_properties, "feed." );
147
148 // Push it on to the queue
149 mlt_deque_push_back( data_queue, feed );
150 }
151
152 return frame;
153 }
154
155 /** Constructor for the filter.
156 */
157
158 mlt_filter filter_data_feed_init( char *arg )
159 {
160 // Create the filter
161 mlt_filter this = mlt_filter_new( );
162
163 // Initialise it
164 if ( this != NULL )
165 {
166 // Get the properties
167 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
168
169 // Assign the argument (default to titles)
170 mlt_properties_set( properties, "type", arg == NULL ? "titles" : arg );
171
172 // Specify the processing method
173 this->process = filter_process;
174 }
175
176 return this;
177 }
178