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