X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fdv%2Fproducer_libdv.c;h=59e8c5f7c3a4fc23bbbe219bc02af1bc17646b06;hb=c8eb83155184ad2ac47a2802c913d9b81be8e452;hp=7d5fb25214245307bd013b5a3c755491030fb990;hpb=cdc142529076b33e4856a423547b9e93fb56330a;p=mlt diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 7d5fb252..59e8c5f7 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -3,25 +3,27 @@ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited * Author: Charles Yates * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "producer_libdv.h" +#include #include #include #include +#include + #include #include #include @@ -32,6 +34,9 @@ #include #include +#define FRAME_SIZE_525_60 10 * 150 * 80 +#define FRAME_SIZE_625_50 12 * 150 * 80 + /** To conserve resources, we maintain a stack of dv decoders. */ @@ -129,11 +134,11 @@ struct producer_libdv_s static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index ); static void producer_close( mlt_producer parent ); -static int producer_collect_info( producer_libdv this ); +static int producer_collect_info( producer_libdv this, mlt_profile profile ); -mlt_producer producer_libdv_init( char *filename ) +mlt_producer producer_libdv_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename ) { - producer_libdv this = calloc( sizeof( struct producer_libdv_s ), 1 ); + producer_libdv this = calloc( 1, sizeof( struct producer_libdv_s ) ); if ( filename != NULL && this != NULL && mlt_producer_init( &this->parent, this ) == 0 ) { @@ -151,19 +156,20 @@ mlt_producer producer_libdv_init( char *filename ) producer->get_frame = producer_get_frame; // If we have mov or dv, then we'll use an alternative producer - if ( strncasecmp( strrchr( filename, '.' ), ".avi", 4 ) == 0 || - strncasecmp( strrchr( filename, '.' ), ".dv", 3 ) == 0 || - strncasecmp( strrchr( filename, '.' ), ".mov", 4 ) == 0 ) + if ( strchr( filename, '.' ) != NULL && ( + strncasecmp( strrchr( filename, '.' ), ".avi", 4 ) == 0 || + strncasecmp( strrchr( filename, '.' ), ".mov", 4 ) == 0 ) ) { // Load via an alternative mechanism - this->alternative = mlt_factory_producer( "kino", filename ); + mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ); + this->alternative = mlt_factory_producer( profile, "kino", filename ); // If it's unavailable, then clean up if ( this->alternative == NULL ) destroy = 1; else mlt_properties_pass( properties, MLT_PRODUCER_PROPERTIES( this->alternative ), "" ); - this->is_pal = mlt_properties_get_int( properties, "fps" ) == 25; + this->is_pal = ( ( int ) mlt_producer_get_fps( producer ) ) == 25; } else { @@ -171,7 +177,7 @@ mlt_producer producer_libdv_init( char *filename ) this->fd = open( filename, O_RDONLY ); // Collect info - if ( this->fd == -1 || !producer_collect_info( this ) ) + if ( this->fd == -1 || !producer_collect_info( this, profile ) ) destroy = 1; } @@ -195,7 +201,6 @@ static int read_frame( int fd, uint8_t* frame_buf, int *isPAL ) if ( result ) { *isPAL = ( frame_buf[3] & 0x80 ); - if ( *isPAL ) { int diff = FRAME_SIZE_625_50 - FRAME_SIZE_525_60; @@ -206,7 +211,7 @@ static int read_frame( int fd, uint8_t* frame_buf, int *isPAL ) return result; } -static int producer_collect_info( producer_libdv this ) +static int producer_collect_info( producer_libdv this, mlt_profile profile ) { int valid = 0; @@ -220,6 +225,8 @@ static int producer_collect_info( producer_libdv this ) // If it looks like a valid frame, the get stats if ( valid ) { + double aspect_ratio; + // Get the properties mlt_properties properties = MLT_PRODUCER_PROPERTIES( &this->parent ); @@ -240,8 +247,8 @@ static int producer_collect_info( producer_libdv this ) this->frames_in_file = this->file_size / this->frame_size; // Calculate default in/out points - double fps = this->is_pal ? 25 : 30000.0 / 1001.0; - if ( mlt_properties_get_double( properties, "fps" ) == fps ) + int fps = 1000 * ( this->is_pal ? 25 : ( 30000.0 / 1001.0 ) ); + if ( ( int )( mlt_profile_fps( profile ) * 1000 ) == fps ) { if ( this->frames_in_file > 0 ) { @@ -257,8 +264,34 @@ static int producer_collect_info( producer_libdv this ) // Parse the header for meta info dv_parse_header( dv_decoder, dv_data ); - mlt_properties_set_double( properties, "aspect_ratio", - dv_format_wide( dv_decoder ) ? ( this->is_pal ? 118.0/81.0 : 40.0/33.0 ) : ( this->is_pal ? 59.0/54.0 : 10.0/11.0 ) ); + if ( this->is_pal ) + { + if ( dv_format_wide( dv_decoder ) ) + aspect_ratio = 64.0 / 45.0; + else + aspect_ratio = 16.0 / 15.0; + } + else + { + if ( dv_format_wide( dv_decoder ) ) + aspect_ratio = 32.0 / 27.0; + else + aspect_ratio = 8 / 9; + } + mlt_properties_set_double( properties, "aspect_ratio", aspect_ratio); + mlt_properties_set_int( properties, "meta.media.nb_streams", 2 ); + mlt_properties_set_int( properties, "video_index", 0 ); + mlt_properties_set( properties, "meta.media.0.stream.type", "video" ); + mlt_properties_set( properties, "meta.media.0.codec.name", "dvvideo" ); + mlt_properties_set( properties, "meta.media.0.codec.long_name", "DV (Digital Video)" ); + mlt_properties_set_int( properties, "audio_index", 1 ); + mlt_properties_set( properties, "meta.media.1.stream.type", "audio" ); + mlt_properties_set( properties, "meta.media.1.codec.name", "pcm_s16le" ); + mlt_properties_set( properties, "meta.media.1.codec.long_name", "signed 16-bit little-endian PCM" ); + mlt_properties_set_int( properties, "meta.media.width", 720 ); + mlt_properties_set_int( properties, "meta.media.height", this->is_pal ? 576 : 480 ); + mlt_properties_set_int( properties, "meta.media.frame_rate_num", this->is_pal? 25 : 30000 ); + mlt_properties_set_int( properties, "meta.media.frame_rate_den", this->is_pal? 1 : 1001 ); // Return the decoder dv_decoder_return( dv_decoder ); @@ -300,18 +333,18 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma // Parse the header for meta info dv_parse_header( decoder, dv_data ); - // Assign width and height from properties - *width = mlt_properties_get_int( properties, "width" ); - *height = mlt_properties_get_int( properties, "height" ); + // Assign width and height according to the frame + *width = 720; + *height = dv_data[ 3 ] & 0x80 ? 576 : 480; // Extract an image of the format requested - if ( *format == mlt_image_yuv422 ) + if ( *format != mlt_image_rgb24 ) { // Allocate an image uint8_t *image = mlt_pool_alloc( *width * ( *height + 1 ) * 2 ); // Pass to properties for clean up - mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL ); + mlt_frame_set_image( this, image, *width * ( *height + 1 ) * 2, mlt_pool_release ); // Decode the image pitches[ 0 ] = *width * 2; @@ -320,14 +353,15 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma // Assign result *buffer = image; + *format = mlt_image_yuv422; } - else if ( *format == mlt_image_rgb24 ) + else { // Allocate an image uint8_t *image = mlt_pool_alloc( *width * ( *height + 1 ) * 3 ); // Pass to properties for clean up - mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 3, ( mlt_destructor )mlt_pool_release, NULL ); + mlt_frame_set_image( this, image, *width * ( *height + 1 ) * 3, mlt_pool_release ); // Decode the frame pitches[ 0 ] = 720 * 3; @@ -336,6 +370,7 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma // Assign result *buffer = image; + *format = mlt_image_rgb24; } // Return the decoder @@ -344,7 +379,7 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma return 0; } -static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) +static int producer_get_audio( mlt_frame this, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) { int16_t *p; int i, j; @@ -365,20 +400,23 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma // Check that we have audio if ( decoder->audio->num_channels > 0 ) { + int size = *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ); + // Obtain required values *frequency = decoder->audio->frequency; *samples = decoder->audio->samples_this_frame; *channels = decoder->audio->num_channels; + *format = mlt_audio_s16; // Create a temporary workspace for ( i = 0; i < 4; i++ ) audio_channels[ i ] = mlt_pool_alloc( DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); // Create a workspace for the result - *buffer = mlt_pool_alloc( *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); + *buffer = mlt_pool_alloc( size ); // Pass the allocated audio buffer as a property - mlt_properties_set_data( properties, "audio", *buffer, *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), ( mlt_destructor )mlt_pool_release, NULL ); + mlt_frame_set_audio( this, *buffer, *format, size, mlt_pool_release ); // Decode the audio dv_decode_full_audio( decoder, dv_data, audio_channels ); @@ -425,7 +463,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i data = mlt_pool_alloc( FRAME_SIZE_625_50 ); // Create an empty frame - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); // Seek and fetch if ( this->fd != 0 && @@ -469,6 +507,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i mlt_properties_set_int( properties, "width", 720 ); mlt_properties_set_int( properties, "height", this->is_pal ? 576 : 480 ); mlt_properties_set_int( properties, "top_field_first", !this->is_pal ? 0 : ( data[ 5 ] & 0x07 ) == 0 ? 0 : 1 ); + mlt_properties_set_int( properties, "colorspace", 601 ); // Parse the header for meta info dv_parse_header( dv_decoder, data ); @@ -476,21 +515,30 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i mlt_properties_set_double( properties, "aspect_ratio", dv_format_wide( dv_decoder ) ? ( this->is_pal ? 118.0/81.0 : 40.0/33.0 ) : ( this->is_pal ? 59.0/54.0 : 10.0/11.0 ) ); - // Hmm - register audio callback - mlt_frame_push_audio( *frame, producer_get_audio ); - - // Push the quality string - mlt_frame_push_service( *frame, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "quality" ) ); + + mlt_properties_set_int( properties, "audio_frequency", dv_decoder->audio->frequency ); + mlt_properties_set_int( properties, "audio_channels", dv_decoder->audio->num_channels ); + + // Register audio callback + if ( mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "audio_index" ) > 0 ) + mlt_frame_push_audio( *frame, producer_get_audio ); - // Push the get_image method on to the stack - mlt_frame_push_get_image( *frame, producer_get_image ); + if ( mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "video_index" ) > -1 ) + { + // Push the quality string + mlt_frame_push_service( *frame, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "quality" ) ); + + // Push the get_image method on to the stack + mlt_frame_push_get_image( *frame, producer_get_image ); + } // Return the decoder dv_decoder_return( dv_decoder ); } // Update timecode on the frame we're creating - mlt_frame_set_position( *frame, mlt_producer_position( producer ) ); + if ( *frame != NULL ) + mlt_frame_set_position( *frame, mlt_producer_position( producer ) ); // Calculate the next timecode mlt_producer_prepare_next( producer );