1 /**
2 * MltFilter.cpp - MLT Wrapper
3 * Copyright (C) 2004-2019 Meltytech, LLC
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include "MltFilter.h"
23 #include "MltProfile.h"
24 using namespace Mlt;
25
Filter()26 Filter::Filter()
27 : Service()
28 , instance(nullptr)
29 {
30 }
31
Filter(Profile & profile,const char * id,const char * arg)32 Filter::Filter( Profile& profile, const char *id, const char *arg ) :
33 Filter( profile.get_profile(), id, arg )
34 {
35 }
36
Filter(mlt_profile profile,const char * id,const char * arg)37 Filter::Filter( mlt_profile profile, const char *id, const char *arg ) :
38 instance( NULL )
39 {
40 if ( arg != NULL )
41 {
42 instance = mlt_factory_filter( profile, id, arg );
43 }
44 else
45 {
46 if ( strchr( id, ':' ) )
47 {
48 char *temp = strdup( id );
49 char *arg = strchr( temp, ':' ) + 1;
50 *( arg - 1 ) = '\0';
51 instance = mlt_factory_filter( profile, temp, arg );
52 free( temp );
53 }
54 else
55 {
56 instance = mlt_factory_filter( profile, id, NULL );
57 }
58 }
59 }
60
Filter(Service & filter)61 Filter::Filter( Service &filter ) :
62 instance( NULL )
63 {
64 if ( filter.type( ) == mlt_service_filter_type )
65 {
66 instance = ( mlt_filter )filter.get_service( );
67 inc_ref( );
68 }
69 }
70
Filter(Filter & filter)71 Filter::Filter( Filter &filter ) :
72 Mlt::Service( filter ),
73 instance( filter.get_filter( ) )
74 {
75 inc_ref( );
76 }
77
Filter(const Filter & filter)78 Filter::Filter( const Filter &filter ) :
79 Filter( const_cast<Filter&>(filter) )
80 {
81 }
82
Filter(mlt_filter filter)83 Filter::Filter( mlt_filter filter ) :
84 instance( filter )
85 {
86 inc_ref( );
87 }
88
~Filter()89 Filter::~Filter( )
90 {
91 mlt_filter_close( instance );
92 }
93
operator =(const Filter & filter)94 Filter &Filter::operator=(const Filter &filter)
95 {
96 if (this != &filter)
97 {
98 mlt_filter_close( instance );
99 instance = filter.instance;
100 inc_ref( );
101 }
102 return *this;
103 }
104
get_filter()105 mlt_filter Filter::get_filter( )
106 {
107 return instance;
108 }
109
get_service()110 mlt_service Filter::get_service( )
111 {
112 return mlt_filter_service( get_filter( ) );
113 }
114
connect(Service & service,int index)115 int Filter::connect( Service &service, int index )
116 {
117 return mlt_filter_connect( get_filter( ), service.get_service( ), index );
118 }
119
set_in_and_out(int in,int out)120 void Filter::set_in_and_out( int in, int out )
121 {
122 mlt_filter_set_in_and_out( get_filter( ), in, out );
123 }
124
get_in()125 int Filter::get_in( )
126 {
127 return mlt_filter_get_in( get_filter( ) );
128 }
129
get_out()130 int Filter::get_out( )
131 {
132 return mlt_filter_get_out( get_filter( ) );
133 }
134
get_length()135 int Filter::get_length( )
136 {
137 return mlt_filter_get_length( get_filter( ) );
138 }
139
get_length2(Frame & frame)140 int Filter::get_length2( Frame &frame )
141 {
142 return mlt_filter_get_length2( get_filter( ), frame.get_frame() );
143 }
144
get_track()145 int Filter::get_track( )
146 {
147 return mlt_filter_get_track( get_filter( ) );
148 }
149
get_position(Frame & frame)150 int Filter::get_position( Frame &frame )
151 {
152 return mlt_filter_get_position( get_filter( ), frame.get_frame( ) );
153 }
154
get_progress(Frame & frame)155 double Filter::get_progress( Frame &frame )
156 {
157 return mlt_filter_get_progress( get_filter( ), frame.get_frame( ) );
158 }
159
process(Frame & frame)160 void Filter::process( Frame &frame )
161 {
162 mlt_filter_process( get_filter( ), frame.get_frame() );
163 }
164