1 /**
2 * MltChain.cpp - Chain wrapper
3 * Copyright (C) 2020 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 "MltChain.h"
21
22 using namespace Mlt;
23
Chain()24 Chain::Chain( ) :
25 instance( nullptr )
26 {
27 }
28
Chain(Profile & profile,const char * id,const char * service)29 Chain::Chain( Profile& profile, const char *id, const char *service ) :
30 instance( mlt_chain_init( profile.get_profile() ) )
31 {
32 Mlt::Producer source( profile, id, service );
33 mlt_chain_set_source( instance, source.get_producer() );
34 }
35
Chain(Profile & profile)36 Chain::Chain( Profile& profile ) :
37 instance( mlt_chain_init( profile.get_profile() ) )
38 {
39 }
40
Chain(mlt_chain chain)41 Chain::Chain( mlt_chain chain ) :
42 instance( chain )
43 {
44 inc_ref( );
45 }
46
Chain(Chain & chain)47 Chain::Chain( Chain& chain ) :
48 Mlt::Producer( chain ),
49 instance( chain.get_chain( ) )
50 {
51 inc_ref( );
52 }
53
Chain(Chain * chain)54 Chain::Chain( Chain* chain ) :
55 Mlt::Producer( chain ),
56 instance( chain != NULL ? chain->get_chain( ) : NULL )
57 {
58 if ( is_valid( ) )
59 inc_ref( );
60 }
61
Chain(Service & chain)62 Chain::Chain( Service& chain ) :
63 instance( NULL )
64 {
65 if ( chain.type( ) == mlt_service_chain_type )
66 {
67 instance = ( mlt_chain )chain.get_service( );
68 inc_ref( );
69 }
70 }
71
~Chain()72 Chain::~Chain( )
73 {
74 mlt_chain_close( instance );
75 instance = nullptr;
76 }
77
get_chain()78 mlt_chain Chain::get_chain( )
79 {
80 return instance;
81 }
82
get_producer()83 mlt_producer Chain::get_producer( )
84 {
85 return MLT_CHAIN_PRODUCER( instance );
86 }
87
set_source(Mlt::Producer & source)88 void Chain::set_source( Mlt::Producer& source )
89 {
90 mlt_chain_set_source( instance, source.get_producer() );
91 }
92
get_source()93 Mlt::Producer Chain::get_source( )
94 {
95 return Mlt::Producer( mlt_chain_get_source(instance) );
96 }
97
attach(Mlt::Link & link)98 int Chain::attach( Mlt::Link& link )
99 {
100 return mlt_chain_attach( instance, link.get_link() );
101 }
102
detach(Mlt::Link & link)103 int Chain::detach( Mlt::Link& link )
104 {
105 return mlt_chain_detach( instance, link.get_link() );
106 }
107
link_count() const108 int Chain::link_count() const
109 {
110 return mlt_chain_link_count( instance );
111 }
112
move_link(int from,int to)113 bool Chain::move_link( int from, int to )
114 {
115 return (bool)mlt_chain_move_link( instance, from, to );
116 }
117
link(int index)118 Mlt::Link* Chain::link( int index )
119 {
120 mlt_link result = mlt_chain_link( instance, index );
121 return result == NULL ? NULL : new Link( result );
122
123 }
124