Merge ../mlt
[melted] / 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 "config.h"
22
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include "kino_wrapper.h"
27 #include "filehandler.h"
28
29 extern "C"
30 {
31
32 #include <framework/mlt_pool.h>
33
34 struct kino_wrapper_s
35 {
36 FileHandler *handler;
37 int is_pal;
38 };
39
40 kino_wrapper kino_wrapper_init( )
41 {
42 kino_wrapper self = ( kino_wrapper )malloc( sizeof( kino_wrapper_s ) );
43 if ( self != NULL )
44 self->handler = NULL;
45 return self;
46 }
47
48 int kino_wrapper_open( kino_wrapper self, char *src )
49 {
50 if ( self != NULL )
51 {
52 // Rough file determination based on file type
53 if ( strncasecmp( strrchr( src, '.' ), ".avi", 4 ) == 0 )
54 self->handler = new AVIHandler( );
55 else if ( strncasecmp( strrchr( src, '.' ), ".dv", 3 ) == 0 || strncasecmp( strrchr( src, '.' ), ".dif", 4 ) == 0 )
56 self->handler = new RawHandler( );
57 #ifdef HAVE_LIBQUICKTIME
58 else if ( strncasecmp( strrchr( src, '.' ), ".mov", 4 ) == 0 )
59 self->handler = new QtHandler( );
60 #endif
61
62 // Open the file if we have a handler
63 if ( self->handler != NULL )
64 if ( !self->handler->Open( src ) )
65 self = NULL;
66
67 // Check the first frame to see if it's PAL or NTSC
68 if ( self != NULL && self->handler != NULL )
69 {
70 uint8_t *data = ( uint8_t * )mlt_pool_alloc( 144000 );
71 if ( self->handler->GetFrame( data, 0 ) == 0 )
72 self->is_pal = data[3] & 0x80;
73 else
74 self = NULL;
75 mlt_pool_release( data );
76 }
77 }
78
79 return kino_wrapper_is_open( self );
80 }
81
82 int kino_wrapper_get_frame_count( kino_wrapper self )
83 {
84 return self != NULL && self->handler != NULL ? self->handler->GetTotalFrames( ) : 0;
85 }
86
87 int kino_wrapper_is_open( kino_wrapper self )
88 {
89 return self != NULL && self->handler != NULL ? self->handler->FileIsOpen( ) : 0;
90 }
91
92 int kino_wrapper_is_pal( kino_wrapper self )
93 {
94 return self != NULL ? self->is_pal : 0;
95 }
96
97 int kino_wrapper_get_frame( kino_wrapper self, uint8_t *data, int index )
98 {
99 return self != NULL && self->handler != NULL ? !self->handler->GetFrame( data, index ) : 0;
100 }
101
102 void kino_wrapper_close( kino_wrapper self )
103 {
104 if ( self )
105 delete self->handler;
106 free( self );
107 }
108
109 }
110
111