]> git.sesse.net Git - mlt/blob - src/mlt++/MltProducer.cpp
add mlt_producer_seek_time and mlt_producer_frame_time
[mlt] / src / mlt++ / MltProducer.cpp
1 /**
2  * MltProducer.cpp - MLT Wrapper
3  * Copyright (C) 2004-2005 Charles Yates
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 "MltProducer.h"
22 #include "MltFilter.h"
23 #include "MltProfile.h"
24 #include "MltEvent.h"
25 #include "MltConsumer.h"
26 using namespace Mlt;
27
28 Producer::Producer( ) :
29         instance( NULL ),
30         parent_( NULL )
31 {
32 }
33
34 Producer::Producer( Profile& profile, const char *id, const char *service ) :
35         instance( NULL ),
36         parent_( NULL )
37 {
38         if ( id != NULL && service != NULL )
39                 instance = mlt_factory_producer( profile.get_profile(), id, service );
40         else
41                 instance = mlt_factory_producer( profile.get_profile(), NULL, id != NULL ? id : service );
42 }
43
44 Producer::Producer( Service &producer ) :
45         instance( NULL ),
46         parent_( NULL )
47 {
48         mlt_service_type type = producer.type( );
49         if ( type == producer_type || type == playlist_type || 
50                  type == tractor_type || type == multitrack_type )
51         {
52                 instance = ( mlt_producer )producer.get_service( );
53                 inc_ref( );
54         }
55 }
56
57 Producer::Producer( mlt_producer producer ) :
58         instance( producer ),
59         parent_( NULL )
60 {
61         inc_ref( );
62 }
63
64 Producer::Producer( Producer &producer ) :
65         Mlt::Service( producer ),
66         instance( producer.get_producer( ) ),
67         parent_( NULL )
68 {
69         inc_ref( );
70 }
71
72 Producer::Producer( Producer *producer ) :
73         instance( producer != NULL ? producer->get_producer( ) : NULL ),
74         parent_( NULL )
75 {
76         if ( is_valid( ) )
77                 inc_ref( );
78 }
79
80 Producer::~Producer( )
81 {
82         delete parent_;
83         mlt_producer_close( instance );
84         instance = NULL;
85 }
86
87 mlt_producer Producer::get_producer( )
88 {
89         return instance;
90 }
91
92 mlt_producer Producer::get_parent( )
93 {
94         return get_producer( ) != NULL && mlt_producer_cut_parent( get_producer( ) ) != NULL ? mlt_producer_cut_parent( get_producer( ) ) : get_producer( );
95 }
96
97 Producer &Producer::parent( )
98 {
99         if ( is_cut( ) && parent_ == NULL )
100                 parent_ = new Producer( get_parent( ) );
101         return parent_ == NULL ? *this : *parent_;
102 }
103
104 mlt_service Producer::get_service( )
105 {
106         return mlt_producer_service( get_producer( ) );
107 }
108         
109 int Producer::seek( int position )
110 {
111         return mlt_producer_seek( get_producer( ), position );
112 }
113
114 int Producer::seek( const char *time )
115 {
116         return mlt_producer_seek_time( get_producer( ), time );
117 }
118
119 int Producer::position( )
120 {
121         return mlt_producer_position( get_producer( ) );
122 }
123
124 int Producer::frame( )
125 {
126         return mlt_producer_frame( get_producer( ) );
127 }
128
129 char* Producer::frame_time( mlt_time_format format )
130 {
131         return mlt_producer_frame_time( get_producer(), format );
132 }
133
134 int Producer::set_speed( double speed )
135 {
136         return mlt_producer_set_speed( get_producer( ), speed );
137 }
138
139 int Producer::pause()
140 {
141         int result = 0;
142
143         if ( get_speed() != 0 )
144         {
145                 Consumer consumer( ( mlt_consumer ) mlt_service_consumer( get_service( ) ) );
146                 Event *event = consumer.setup_wait_for( "consumer-sdl-paused" );
147                 
148                 result = mlt_producer_set_speed( get_producer( ), 0 );
149                 if ( result == 0 && consumer.is_valid() && !consumer.is_stopped() )
150                         consumer.wait_for( event );
151                 delete event;
152         }
153         
154         return result;
155 }
156
157 double Producer::get_speed( )
158 {
159         return mlt_producer_get_speed( get_producer( ) );
160 }
161
162 double Producer::get_fps( )
163 {
164         return mlt_producer_get_fps( get_producer( ) );
165 }
166
167 int Producer::set_in_and_out( int in, int out )
168 {
169         return mlt_producer_set_in_and_out( get_producer( ), in, out );
170 }
171
172 int Producer::get_in( )
173 {
174         return mlt_producer_get_in( get_producer( ) );
175 }
176
177 int Producer::get_out( )
178 {
179         return mlt_producer_get_out( get_producer( ) );
180 }
181
182 int Producer::get_length( )
183 {
184         return mlt_producer_get_length( get_producer( ) );
185 }
186
187 char* Producer::get_length_time( mlt_time_format format )
188 {
189         return mlt_producer_get_length_time( get_producer( ), format );
190 }
191
192 int Producer::get_playtime( )
193 {
194         return mlt_producer_get_playtime( get_producer( ) );
195 }
196
197 Producer *Producer::cut( int in, int out )
198 {
199         mlt_producer producer = mlt_producer_cut( get_producer( ), in, out );
200         Producer *result = new Producer( producer );
201         mlt_producer_close( producer );
202         return result;
203 }
204
205 bool Producer::is_cut( )
206 {
207         return mlt_producer_is_cut( get_producer( ) ) != 0;
208 }
209
210 bool Producer::is_blank( )
211 {
212         return mlt_producer_is_blank( get_producer( ) ) != 0;
213 }
214
215 bool Producer::same_clip( Producer &that )
216 {
217         return mlt_producer_cut_parent( get_producer( ) ) == mlt_producer_cut_parent( that.get_producer( ) );
218 }
219
220 bool Producer::runs_into( Producer &that )
221 {
222         return same_clip( that ) && get_out( ) == ( that.get_in( ) - 1 );
223 }
224
225 void Producer::optimise( )
226 {
227         mlt_producer_optimise( get_producer( ) );
228 }
229
230 int Producer::clear( )
231 {
232         return mlt_producer_clear( get_producer( ) );
233 }