2 * mlt_tractor.c -- tractor service class
3 * Copyright (C) 2003-2004 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 "mlt_tractor.h"
24 #include "mlt_frame.h"
25 #include "mlt_multitrack.h"
31 /** Private structure.
36 struct mlt_producer_s parent
;
40 /** Forward references to static methods.
43 static int producer_get_frame( mlt_producer
this, mlt_frame_ptr frame
, int track
);
45 /** Constructor for the tractor.
47 TODO: thread this service...
50 mlt_tractor
mlt_tractor_init( )
52 mlt_tractor
this = calloc( sizeof( struct mlt_tractor_s
), 1 );
55 mlt_producer producer
= &this->parent
;
56 if ( mlt_producer_init( producer
, this ) == 0 )
58 producer
->get_frame
= producer_get_frame
;
59 mlt_properties_set( mlt_producer_properties( producer
), "resource", "<tractor>" );
60 mlt_properties_set( mlt_producer_properties( producer
), "mlt_type", "producer" );
61 mlt_properties_set( mlt_producer_properties( producer
), "mlt_service", "tractor" );
72 /** Get the service object associated to the tractor.
75 mlt_service
mlt_tractor_service( mlt_tractor
this )
77 return mlt_producer_service( &this->parent
);
80 /** Get the producer object associated to the tractor.
83 mlt_producer
mlt_tractor_producer( mlt_tractor
this )
88 /** Get the properties object associated to the tractor.
91 mlt_properties
mlt_tractor_properties( mlt_tractor
this )
93 return mlt_producer_properties( &this->parent
);
96 /** Connect the tractor.
99 int mlt_tractor_connect( mlt_tractor
this, mlt_service producer
)
101 int ret
= mlt_service_connect_producer( mlt_tractor_service( this ), producer
, 0 );
103 // This is the producer we're going to connect to
105 this->producer
= producer
;
110 /** Get the next frame.
112 TODO: This should be reading a pump being populated by the thread...
115 static int producer_get_frame( mlt_producer parent
, mlt_frame_ptr frame
, int track
)
117 mlt_tractor
this = parent
->child
;
119 // We only respond to the first track requests
120 if ( track
== 0 && this->producer
!= NULL
)
125 mlt_frame temp
= NULL
;
126 mlt_frame store
[ 10 ];
129 // Get the properties of the parent producer
130 mlt_properties properties
= mlt_producer_properties( parent
);
132 // Try to obtain the multitrack associated to the tractor
133 mlt_multitrack multitrack
= mlt_properties_get_data( properties
, "multitrack", NULL
);
135 // If we don't have one, we're in trouble...
136 if ( multitrack
!= NULL
)
138 mlt_producer target
= mlt_multitrack_producer( multitrack
);
139 mlt_producer_seek( target
, mlt_producer_frame( parent
) );
140 mlt_producer_set_speed( target
, mlt_producer_get_speed( parent
) );
144 fprintf( stderr
, "tractor without a multitrack!!\n" );
147 // Loop through each of the tracks we're harvesting
148 for ( i
= 0; !done
; i
++ )
150 // Get a frame from the producer
151 mlt_service_get_frame( this->producer
, &temp
, i
);
153 // Check for last track
154 done
= mlt_properties_get_int( mlt_frame_properties( temp
), "last_track" );
157 if ( done
&& looking
)
159 // Use this as output if we don't have one already
162 else if ( ( !mlt_frame_is_test_card( temp
) || !mlt_frame_is_test_audio( temp
) ) && looking
&&
163 mlt_producer_frame( parent
) == mlt_frame_get_position( temp
) )
170 // We store all other frames for now
171 store
[ count
++ ] = temp
;
175 // Now place all the unused frames on to the properties (will be destroyed automatically)
178 mlt_properties frame_properties
= mlt_frame_properties( *frame
);
180 sprintf( label
, "tractor_%d", count
);
181 while ( mlt_properties_get_data( frame_properties
, label
, NULL
) != NULL
)
182 strcat( label
, "+" );
183 mlt_properties_set_data( frame_properties
, label
, store
[ count
], 0, ( mlt_destructor
)mlt_frame_close
, NULL
);
186 // Prepare the next frame
187 mlt_producer_prepare_next( parent
);
189 // Indicate our found status
194 // Generate a test card
195 *frame
= mlt_frame_init( );
200 /** Close the tractor.
203 void mlt_tractor_close( mlt_tractor
this )
205 mlt_producer_close( &this->parent
);