X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fvorbis%2Fproducer_vorbis.c;h=30c718fe4aead2a33cb3ed5b675a4c10c3c3a20d;hb=e3aa100d0d719e166f747c773484b7a9ad1c3dd4;hp=d69fc82a75501870267bd6c4bb087ad9c466c58e;hpb=a5b82fc0a3bb42bd849c8c82e3418402cc2fe9d9;p=melted diff --git a/src/modules/vorbis/producer_vorbis.c b/src/modules/vorbis/producer_vorbis.c index d69fc82..30c718f 100644 --- a/src/modules/vorbis/producer_vorbis.c +++ b/src/modules/vorbis/producer_vorbis.c @@ -3,25 +3,23 @@ * 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 */ -// Local header files -#include "producer_vorbis.h" - // MLT Header files +#include #include // vorbis Header files @@ -31,15 +29,45 @@ // System header files #include #include +#include // Forward references. -static int producer_open( mlt_producer this, char *file ); +static int producer_open( mlt_producer this, mlt_profile profile, char *file ); static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ); +/** Structure for metadata reading +*/ + +typedef struct _sw_metadata sw_metadata; + +struct _sw_metadata { + char * name; + char * content; +}; + +static sw_metadata *vorbis_metadata_from_str (char * str) +{ + sw_metadata * meta = NULL; + int i; + + for (i = 0; str[i]; i++) { + str[i] = tolower(str[i]); + if (str[i] == '=') { + str[i] = '\0'; + meta = malloc (sizeof (sw_metadata)); + meta->name = malloc( strlen(str) + 18 ); + sprintf(meta->name, "meta.attr.%s.markup", str); + meta->content = strdup (&str[i+1]); + break; + } + } + return meta; +} + /** Constructor for libvorbis. */ -mlt_producer producer_vorbis_init( char *file ) +mlt_producer producer_vorbis_init( mlt_profile profile, mlt_service_type type, const char *id, char *file ) { mlt_producer this = NULL; @@ -62,7 +90,7 @@ mlt_producer producer_vorbis_init( char *file ) this->get_frame = producer_get_frame; // Open the file - if ( producer_open( this, file ) != 0 ) + if ( producer_open( this, profile, file ) != 0 ) { // Clean up mlt_producer_close( this ); @@ -92,7 +120,7 @@ static void producer_file_close( void *file ) /** Open the file. */ -static int producer_open( mlt_producer this, char *file ) +static int producer_open( mlt_producer this, mlt_profile profile, char *file ) { // FILE pointer for file FILE *input = fopen( file, "r" ); @@ -118,13 +146,23 @@ static int producer_open( mlt_producer this, char *file ) // Assign the ov structure mlt_properties_set_data( properties, "ogg_vorbis_file", ov, 0, producer_file_close, NULL ); + // Read metadata + sw_metadata * metadata = NULL; + char **ptr = ov_comment(ov, -1)->user_comments; + while(*ptr) { + metadata = vorbis_metadata_from_str (*ptr); + if (metadata != NULL) + mlt_properties_set(properties, metadata->name, metadata->content); + ++ptr; + } + if ( ov_seekable( ov ) ) { // Get the length of the file double length = ov_time_total( ov, -1 ); // We will treat everything with the producer fps - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_profile_fps( profile ); // Set out and length of file mlt_properties_set_position( properties, "out", ( length * fps ) - 1 ); @@ -134,6 +172,13 @@ static int producer_open( mlt_producer this, char *file ) vorbis_info *vi = ov_info( ov, -1 ); mlt_properties_set_int( properties, "frequency", (int) vi->rate ); mlt_properties_set_int( properties, "channels", vi->channels ); + + // Set some media metadata + mlt_properties_set_int( properties, "meta.media.nb_streams", 1 ); + mlt_properties_set_int( properties, "audio_index", 0 ); + mlt_properties_set( properties, "meta.media.0.stream.type", "audio" ); + mlt_properties_set( properties, "meta.media.0.codec.name", "vorbis" ); + mlt_properties_set( properties, "meta.media.0.codec.long_name", "Vorbis" ); } } else @@ -154,14 +199,7 @@ static int producer_open( mlt_producer this, char *file ) static double producer_time_of_frame( mlt_producer this, mlt_position position ) { - // Get the properties - mlt_properties properties = MLT_PRODUCER_PROPERTIES( this ); - - // Obtain the fps - double fps = mlt_properties_get_double( properties, "fps" ); - - // Do the calc - return ( double )position / fps; + return ( double )position / mlt_producer_get_fps( this ); } /** Get the audio from a frame. @@ -188,7 +226,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form mlt_position expected = mlt_properties_get_position( properties, "audio_expected" ); // Get the fps for this producer - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_producer_get_fps( this ); // Get the vorbis info vorbis_info *vi = ov_info( ov, -1 ); @@ -309,7 +347,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ) { // Create an empty frame - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) ); // Update timecode on the frame we're creating mlt_frame_set_position( *frame, mlt_producer_position( this ) );