More corrections to frame position and audio/track handling
[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 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.
10 *
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.
15 *
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.
19 */
20
21 #include "filter_data.h"
22 #include <framework/mlt.h>
23
24 /** This filter should be used in conjuction with the data_show filter.
25 The concept of the data_feed is that it can be used to pass titles
26 or images to render on the frame, but doesn't actually do it
27 itself. data_feed imposes few rules on what's passed on and the
28 validity is confirmed in data_show before use.
29 */
30
31 /** Data queue destructor.
32 */
33
34 static void destroy_data_queue( void *arg )
35 {
36 if ( arg != NULL )
37 {
38 // Assign the correct type
39 mlt_deque queue = arg;
40
41 // Iterate through each item and destroy them
42 while ( mlt_deque_peek_front( queue ) != NULL )
43 mlt_properties_close( mlt_deque_pop_back( queue ) );
44
45 // Close the deque
46 mlt_deque_close( queue );
47 }
48 }
49
50 /** Filter processing.
51 */
52
53 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
54 {
55 // Get the filter properties
56 mlt_properties filter_properties = mlt_filter_properties( this );
57
58 // Get the frame properties
59 mlt_properties frame_properties = mlt_frame_properties( frame );
60
61 // Get the data queue
62 mlt_deque data_queue = mlt_properties_get_data( frame_properties, "data_queue", NULL );
63
64 // Create the data queue if it doesn't exist
65 if ( data_queue == NULL )
66 {
67 // Create the queue
68 data_queue = mlt_deque_init( );
69
70 // Assign it to the frame with the destructor
71 mlt_properties_set_data( frame_properties, "data_queue", data_queue, 0, destroy_data_queue, NULL );
72 }
73
74 // Now create the data feed
75 if ( data_queue != NULL )
76 {
77 // Get the in and out points of this filter
78 int in = mlt_filter_get_in( this );
79 int out = mlt_filter_get_out( this );
80
81 // Create a new data feed
82 mlt_properties feed = mlt_properties_new( );
83
84 // Get the type of the data feed
85 char *type = mlt_properties_get( filter_properties, "type" );
86
87 // Assign it the base properties
88 mlt_properties_set( feed, "id", mlt_properties_get( filter_properties, "_unique_id" ) );
89 mlt_properties_set( feed, "type", type );
90 mlt_properties_set_position( feed, "position", mlt_frame_get_position( frame ) );
91
92 // Assign in/out of service we're connected to
93 mlt_properties_set_position( feed, "in", mlt_properties_get_position( frame_properties, "in" ) );
94 mlt_properties_set_position( feed, "out", mlt_properties_get_position( frame_properties, "out" ) );
95
96 // Correct in/out to the filter if specified
97 if ( in != 0 )
98 mlt_properties_set_position( feed, "in", in );
99 if ( out != 0 )
100 mlt_properties_set_position( feed, "out", out );
101
102 // Pass the properties which start with a "feed." prefix
103 // Note that 'feed.text' in the filter properties becomes 'text' on the feed
104 mlt_properties_pass( feed, filter_properties, "feed." );
105
106 // Push it on to the queue
107 mlt_deque_push_back( data_queue, feed );
108 }
109
110 return frame;
111 }
112
113 /** Constructor for the filter.
114 */
115
116 mlt_filter filter_data_feed_init( char *arg )
117 {
118 // Create the filter
119 mlt_filter this = mlt_filter_new( );
120
121 // Initialise it
122 if ( this != NULL )
123 {
124 // Get the properties
125 mlt_properties properties = mlt_filter_properties( this );
126
127 // Assign the argument (default to titles)
128 mlt_properties_set( properties, "type", arg == NULL ? "titles" : arg );
129
130 // Specify the processing method
131 this->process = filter_process;
132 }
133
134 return this;
135 }
136