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"
29 /** Private structure.
34 struct mlt_service_s parent
;
38 /** Forward references to static methods.
41 static int service_get_frame( mlt_service
this, mlt_frame_ptr frame
, int track
);
43 /** Constructor for the tractor.
45 TODO: thread this service...
48 mlt_tractor
mlt_tractor_init( )
50 mlt_tractor
this = calloc( sizeof( struct mlt_tractor_s
), 1 );
53 mlt_service service
= &this->parent
;
54 if ( mlt_service_init( service
, this ) == 0 )
56 service
->get_frame
= service_get_frame
;
67 /** Get the service object associated to the tractor.
70 mlt_service
mlt_tractor_service( mlt_tractor
this )
75 /** Connect the tractor.
78 int mlt_tractor_connect( mlt_tractor
this, mlt_service producer
)
80 int ret
= mlt_service_connect_producer( &this->parent
, producer
, 0 );
84 // This is the producer we're going to connect to
85 this->producer
= producer
;
91 /** Get the next frame.
93 TODO: This should be reading a pump being populated by the thread...
96 static int service_get_frame( mlt_service parent
, mlt_frame_ptr frame
, int track
)
98 mlt_tractor
this = parent
->child
;
100 // We only respond to the first track requests
101 if ( track
== 0 && this->producer
!= NULL
)
108 // Loop through each of the tracks we're harvesting
109 for ( i
= 0; !done
; i
++ )
111 // Get a frame from the producer
112 mlt_service_get_frame( this->producer
, &temp
, i
);
114 // Check for last track
115 done
= mlt_properties_get_int( mlt_frame_properties( temp
), "last_track" );
118 if ( done
&& looking
)
120 // Use this as output if we don't have one already
123 else if ( !mlt_frame_is_test_card( temp
) && looking
)
125 // This is the one we want and we can stop looking
131 // We discard all other frames
132 mlt_frame_close( temp
);
136 // Indicate our found status
141 // Generate a test card
142 *frame
= mlt_frame_init( );
147 /** Close the tractor.
150 void mlt_tractor_close( mlt_tractor
this )
152 mlt_service_close( &this->parent
);