]> git.sesse.net Git - mlt/blob - src/modules/kino/kino_wrapper.cc
Avoid unnecessary compilation when running "./configure; make; make install" multiple...
[mlt] / src / modules / kino / kino_wrapper.cc
1 /*
2  * kino_wrapper.cc -- c wrapper for kino file handler
3  * Copyright (C) 2005 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@gmail.com>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <cstring>
22 #include <cstdlib>
23
24 #include "kino_wrapper.h"
25 #include "filehandler.h"
26
27 extern "C" 
28 {
29
30 #include <framework/mlt_pool.h>
31
32 struct kino_wrapper_s
33 {
34         FileHandler *handler;
35         int is_pal;
36 };
37
38 kino_wrapper kino_wrapper_init( )
39 {
40         kino_wrapper self = ( kino_wrapper )malloc( sizeof( kino_wrapper_s ) );
41         if ( self != NULL )
42                 self->handler = NULL;
43         return self;
44 }
45
46 int kino_wrapper_open( kino_wrapper self, char *src )
47 {
48         if ( self != NULL )
49         {
50                 // Rough file determination based on file type
51                 if ( strncasecmp( strrchr( src, '.' ), ".avi", 4 ) == 0 )
52                         self->handler = new AVIHandler( );
53                 else if ( strncasecmp( strrchr( src, '.' ), ".dv", 3 ) == 0 || strncasecmp( strrchr( src, '.' ), ".dif", 4 ) == 0 )
54                         self->handler = new RawHandler( );
55                 #ifdef HAVE_LIBQUICKTIME
56                 else if ( strncasecmp( strrchr( src, '.' ), ".mov", 4 ) == 0 )
57                         self->handler = new QtHandler( );
58                 #endif
59
60                 // Open the file if we have a handler
61                 if ( self->handler != NULL )
62                         if ( !self->handler->Open( src ) )
63                                 self = NULL;
64
65                 // Check the first frame to see if it's PAL or NTSC
66                 if ( self != NULL && self->handler != NULL )
67                 {
68                         uint8_t *data = ( uint8_t * )mlt_pool_alloc( 144000 );
69                         if ( self->handler->GetFrame( data, 0 ) == 0 )
70                                 self->is_pal = data[3] & 0x80;
71                         else
72                                 self = NULL;
73                         mlt_pool_release( data );
74                 }
75         }
76
77         return kino_wrapper_is_open( self );
78 }
79
80 int kino_wrapper_get_frame_count( kino_wrapper self )
81 {
82         return self != NULL && self->handler != NULL ? self->handler->GetTotalFrames( ) : 0;
83 }
84
85 int kino_wrapper_is_open( kino_wrapper self )
86 {
87         return self != NULL && self->handler != NULL ? self->handler->FileIsOpen( ) : 0;
88 }
89
90 int kino_wrapper_is_pal( kino_wrapper self )
91 {
92         return self != NULL ? self->is_pal : 0;
93 }
94
95 int kino_wrapper_get_frame( kino_wrapper self, uint8_t *data, int index )
96 {
97         return self != NULL && self->handler != NULL ? !self->handler->GetFrame( data, index ) : 0;
98 }
99
100 void kino_wrapper_close( kino_wrapper self )
101 {
102         if ( self )
103                 delete self->handler;
104         free( self );
105 }
106
107 }
108
109