1 /**
2  * MltFrame.cpp - MLT Wrapper
3  * Copyright (C) 2004-2015 Meltytech, LLC
4  * Author: Charles Yates <charles.yates@gmail.com>
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 #include "MltFrame.h"
22 #include "MltProducer.h"
23 using namespace Mlt;
24 
Frame()25 Frame::Frame() :
26 	Mlt::Properties( (mlt_properties)NULL ),
27 	instance( NULL )
28 {
29 }
30 
Frame(mlt_frame frame)31 Frame::Frame( mlt_frame frame ) :
32 	Mlt::Properties( (mlt_properties)NULL ),
33 	instance( frame )
34 {
35 	inc_ref( );
36 }
37 
Frame(Frame & frame)38 Frame::Frame( Frame &frame ) :
39 	Mlt::Properties( (mlt_properties)NULL ),
40 	instance( frame.instance )
41 {
42 	inc_ref( );
43 }
44 
Frame(const Frame & frame)45 Frame::Frame( const Frame &frame ) :
46 	Mlt::Properties( (mlt_properties)NULL ),
47 	instance( frame.instance )
48 {
49 	inc_ref( );
50 }
51 
~Frame()52 Frame::~Frame( )
53 {
54 	mlt_frame_close( instance );
55 }
56 
operator =(const Frame & frame)57 Frame& Frame::operator=( const Frame &frame )
58 {
59 	if (this != &frame)
60 	{
61 		mlt_frame_close( instance );
62 		instance = frame.instance;
63 		inc_ref( );
64 	}
65 	return *this;
66 }
67 
get_frame()68 mlt_frame Frame::get_frame( )
69 {
70 	return instance;
71 }
72 
get_properties()73 mlt_properties Frame::get_properties( )
74 {
75 	return mlt_frame_properties( get_frame( ) );
76 }
77 
get_image(mlt_image_format & format,int & w,int & h,int writable)78 uint8_t *Frame::get_image( mlt_image_format &format, int &w, int &h, int writable )
79 {
80 	uint8_t *image = NULL;
81 	if ( get_double( "consumer_aspect_ratio" ) == 0.0 )
82 		set( "consumer_aspect_ratio", 1.0 );
83 	mlt_frame_get_image( get_frame( ), &image, &format, &w, &h, writable );
84 	set( "format", format );
85 	set( "writable", writable );
86 	return image;
87 }
88 
fetch_image(mlt_image_format f,int w,int h,int writable)89 unsigned char *Frame::fetch_image( mlt_image_format f, int w, int h, int writable )
90 {
91 	uint8_t *image = NULL;
92 	if ( get_double( "consumer_aspect_ratio" ) == 0.0 )
93 		set( "consumer_aspect_ratio", 1.0 );
94 	mlt_frame_get_image( get_frame( ), &image, &f, &w, &h, writable );
95 	set( "format", f );
96 	set( "writable", writable );
97 	return image;
98 }
99 
get_audio(mlt_audio_format & format,int & frequency,int & channels,int & samples)100 void *Frame::get_audio( mlt_audio_format &format, int &frequency, int &channels, int &samples )
101 {
102 	void *audio = NULL;
103 	mlt_frame_get_audio( get_frame( ), &audio, &format, &frequency, &channels, &samples );
104 	return audio;
105 }
106 
get_waveform(int w,int h)107 unsigned char *Frame::get_waveform( int w, int h )
108 {
109 	return mlt_frame_get_waveform( get_frame( ), w, h );
110 }
111 
get_original_producer()112 Producer *Frame::get_original_producer( )
113 {
114 	return new Producer( mlt_frame_get_original_producer( get_frame( ) ) );
115 }
116 
get_unique_properties(Service & service)117 mlt_properties Frame::get_unique_properties( Service &service )
118 {
119 	return mlt_frame_unique_properties( get_frame(), service.get_service() );
120 }
121 
get_position()122 int Frame::get_position( )
123 {
124 	return mlt_frame_get_position( get_frame() );
125 }
126 
set_image(uint8_t * image,int size,mlt_destructor destroy)127 int Frame::set_image( uint8_t *image, int size, mlt_destructor destroy )
128 {
129 	return mlt_frame_set_image( get_frame(), image, size, destroy );
130 }
131 
set_alpha(uint8_t * alpha,int size,mlt_destructor destroy)132 int Frame::set_alpha( uint8_t *alpha, int size, mlt_destructor destroy )
133 {
134 	return mlt_frame_set_alpha( get_frame(), alpha, size, destroy );
135 }
136