2 * producer_kino.c -- a DV file format parser
3 * Copyright (C) 2005 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
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.
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.
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.
22 #include <framework/mlt_producer.h>
23 #include <framework/mlt_frame.h>
24 #include <framework/mlt_deque.h>
25 #include <framework/mlt_factory.h>
26 #include "kino_wrapper.h"
28 /* NB: This is an abstract producer - it provides no codec support whatsoever. */
30 #define FRAME_SIZE_525_60 10 * 150 * 80
31 #define FRAME_SIZE_625_50 12 * 150 * 80
33 typedef struct producer_kino_s *producer_kino;
35 struct producer_kino_s
37 struct mlt_producer_s parent;
41 static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
42 static void producer_close( mlt_producer parent );
44 mlt_producer producer_kino_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename )
46 kino_wrapper wrapper = kino_wrapper_init( );
48 if ( kino_wrapper_open( wrapper, filename ) )
50 producer_kino this = calloc( sizeof( struct producer_kino_s ), 1 );
52 if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
54 mlt_producer producer = &this->parent;
55 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
56 double fps = kino_wrapper_is_pal( wrapper ) ? 25 : 30000.0 / 1001.0;
59 this->wrapper = wrapper;
61 // Pass wrapper properties (frame rate, count etc)
62 mlt_properties_set_position( properties, "length", kino_wrapper_get_frame_count( wrapper ) );
63 mlt_properties_set_position( properties, "in", 0 );
64 mlt_properties_set_position( properties, "out", kino_wrapper_get_frame_count( wrapper ) - 1 );
65 mlt_properties_set_double( properties, "real_fps", fps );
66 mlt_properties_set( properties, "resource", filename );
68 // Register transport implementation with the producer
69 producer->close = ( mlt_destructor )producer_close;
71 // Register our get_frame implementation with the producer
72 producer->get_frame = producer_get_frame;
74 // Return the producer
80 kino_wrapper_close( wrapper );
85 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
87 producer_kino this = producer->child;
88 uint8_t *data = mlt_pool_alloc( FRAME_SIZE_625_50 );
90 // Obtain the current frame number
91 uint64_t position = mlt_producer_frame( producer );
93 // Create an empty frame
94 *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
97 if ( kino_wrapper_get_frame( this->wrapper, data, position ) )
99 // Get the frames properties
100 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
102 // Determine if we're PAL or NTSC
103 int is_pal = kino_wrapper_is_pal( this->wrapper );
106 mlt_properties_set_data( properties, "dv_data", data, FRAME_SIZE_625_50, ( mlt_destructor )mlt_pool_release, NULL );
108 // Update other info on the frame
109 mlt_properties_set_int( properties, "width", 720 );
110 mlt_properties_set_int( properties, "height", is_pal ? 576 : 480 );
111 mlt_properties_set_int( properties, "top_field_first", is_pal ? 0 : ( data[ 5 ] & 0x07 ) == 0 ? 0 : 1 );
115 mlt_pool_release( data );
118 // Update timecode on the frame we're creating
119 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
121 // Calculate the next timecode
122 mlt_producer_prepare_next( producer );
127 static void producer_close( mlt_producer parent )
129 if ( parent != NULL )
132 producer_kino this = parent->child;
136 kino_wrapper_close( this->wrapper );
139 parent->close = NULL;
140 mlt_producer_close( parent );