2 * filter_data_feed.c -- data feed filter
3 * Copyright (C) 2004-2005 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "filter_data.h"
24 #include <framework/mlt.h>
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.
33 /** Data queue destructor.
36 static void destroy_data_queue( void *arg
)
40 // Assign the correct type
41 mlt_deque queue
= arg
;
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
) );
48 mlt_deque_close( queue
);
52 /** Filter processing.
55 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
57 // Get the filter properties
58 mlt_properties filter_properties
= MLT_FILTER_PROPERTIES( this );
60 // Get the frame properties
61 mlt_properties frame_properties
= MLT_FRAME_PROPERTIES( frame
);
64 mlt_deque data_queue
= mlt_properties_get_data( frame_properties
, "data_queue", NULL
);
66 // Get the type of the data feed
67 char *type
= mlt_properties_get( filter_properties
, "type" );
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 );
73 // Create the data queue if it doesn't exist
74 if ( data_queue
== NULL
)
77 data_queue
= mlt_deque_init( );
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
);
83 // Now create the data feed
84 if ( data_queue
!= NULL
&& type
!= NULL
&& !strcmp( type
, "attr_check" ) )
87 int count
= mlt_properties_count( frame_properties
);
90 for ( i
= 0; i
< count
; i
++ )
92 char *name
= mlt_properties_get_name( frame_properties
, i
);
93 if ( !strncmp( name
, "meta.attr.", 10 ) && strstr( name
, ".inactive" ) == NULL
)
95 char *value
= mlt_properties_get( frame_properties
, name
);
96 sprintf( inactive
, "%s.inactive", name
);
97 if ( value
!= NULL
&& mlt_properties_get_int( frame_properties
, inactive
) == 0 )
99 // Create a new data feed
100 mlt_properties feed
= mlt_properties_new( );
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
) );
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" ) );
111 // Assign the value to the feed
112 mlt_properties_set( feed
, "markup", value
);
114 // Push it on to the queue
115 mlt_deque_push_back( data_queue
, feed
);
120 else if ( data_queue
!= NULL
)
122 // Create a new data feed
123 mlt_properties feed
= mlt_properties_new( );
125 // Assign it the base properties
126 mlt_properties_set( feed
, "id", mlt_properties_get( filter_properties
, "_unique_id" ) );
127 mlt_properties_set( feed
, "type", type
);
128 mlt_properties_set_position( feed
, "position", mlt_frame_get_position( frame
) );
130 // Assign in/out of service we're connected to
131 mlt_properties_set_position( feed
, "in", mlt_properties_get_position( frame_properties
, "in" ) );
132 mlt_properties_set_position( feed
, "out", mlt_properties_get_position( frame_properties
, "out" ) );
134 // Correct in/out to the filter if specified
136 mlt_properties_set_position( feed
, "in", in
);
138 mlt_properties_set_position( feed
, "out", out
);
140 // Pass the properties which start with a "feed." prefix
141 // Note that 'feed.text' in the filter properties becomes 'text' on the feed
142 mlt_properties_pass( feed
, filter_properties
, "feed." );
144 // Push it on to the queue
145 mlt_deque_push_back( data_queue
, feed
);
151 /** Constructor for the filter.
154 mlt_filter
filter_data_feed_init( char *arg
)
157 mlt_filter
this = mlt_filter_new( );
162 // Get the properties
163 mlt_properties properties
= MLT_FILTER_PROPERTIES( this );
165 // Assign the argument (default to titles)
166 mlt_properties_set( properties
, "type", arg
== NULL ?
"titles" : arg
);
168 // Specify the processing method
169 this->process
= filter_process
;