]> git.sesse.net Git - mlt/blobdiff - src/modules/vorbis/producer_vorbis.c
Fix compile error on Windows.
[mlt] / src / modules / vorbis / producer_vorbis.c
index 60166524a7fefcf67f4f5da7e2eef6e72a4acf1e..920108627f500d495535dadf00d1080b17e61a0e 100644 (file)
@@ -21,6 +21,7 @@
 // MLT Header files
 #include <framework/mlt_producer.h>
 #include <framework/mlt_frame.h>
+#include <framework/mlt_profile.h>
 
 // vorbis Header files
 #include <vorbis/codec.h>
@@ -32,7 +33,7 @@
 #include <ctype.h>
 
 // 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 
@@ -90,7 +91,7 @@ mlt_producer producer_vorbis_init( mlt_profile profile, mlt_service_type type, c
                        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 );
@@ -120,7 +121,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" );
@@ -151,8 +152,14 @@ static int producer_open( mlt_producer this, char *file )
                        char **ptr = ov_comment(ov, -1)->user_comments;
                        while(*ptr) {
                                metadata = vorbis_metadata_from_str (*ptr);
-                               if (metadata != NULL)
+                               if (metadata != NULL) {
                                        mlt_properties_set(properties, metadata->name, metadata->content);
+                                       if (metadata->name)
+                                               free(metadata->name);
+                                       if (metadata->content)
+                                               free(metadata->content);
+                                       free(metadata);
+                               }
                                ++ptr;
                        }
 
@@ -162,7 +169,7 @@ static int producer_open( mlt_producer this, char *file )
                        double length = ov_time_total( ov, -1 );
 
                                // We will treat everything with the producer fps
-                               double fps = mlt_producer_get_fps( this );
+                               double fps = mlt_profile_fps( profile );
 
                                // Set out and length of file
                                mlt_properties_set_position( properties, "out", ( length * fps ) - 1 );
@@ -170,8 +177,15 @@ static int producer_open( mlt_producer this, char *file )
 
                                // Get the vorbis info
                                vorbis_info *vi = ov_info( ov, -1 );
-                               mlt_properties_set_int( properties, "frequency", (int) vi->rate );
-                               mlt_properties_set_int( properties, "channels", vi->channels );
+                               mlt_properties_set_int( properties, "audio_frequency", (int) vi->rate );
+                               mlt_properties_set_int( properties, "audio_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
@@ -198,13 +212,10 @@ static double producer_time_of_frame( mlt_producer this, mlt_position position )
 /** Get the audio from a frame.
 */
 
-static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
+static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
 {
-       // Get the properties from the frame
-       mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
-
        // Obtain the frame number of this frame
-       mlt_position position = mlt_properties_get_position( frame_properties, "vorbis_position" );
+       mlt_position position = mlt_frame_original_position( frame );
 
        // Get the producer 
        mlt_producer this = mlt_frame_pop_audio( frame );
@@ -212,6 +223,8 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Get the producer properties
        mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( this ) );
+
        // Get the ogg vorbis file
        OggVorbis_File *ov = mlt_properties_get_data( properties, "ogg_vorbis_file", NULL );
 
@@ -298,7 +311,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                        {
                                ignore --;
                                audio_used -= *samples;
-                               memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * sizeof( int16_t ) );
+                               memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * sizeof( int16_t ) * *channels );
                                *samples = mlt_sample_calculator( fps, *frequency, expected ++ );
                        }
                }
@@ -306,11 +319,14 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                // Now handle the audio if we have enough
                if ( audio_used >= *samples )
                {
-                       *buffer = mlt_pool_alloc( *samples * *channels * sizeof( int16_t ) );
-                       memcpy( *buffer, audio_buffer, *samples * *channels * sizeof( int16_t ) );
+                       int size = *samples * *channels * sizeof( int16_t );
+
+                       *format = mlt_audio_s16;
+                       *buffer = mlt_pool_alloc( size );
+                       memcpy( *buffer, audio_buffer, size );
                        audio_used -= *samples;
                        memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * *channels * sizeof( int16_t ) );
-                       mlt_properties_set_data( frame_properties, "audio", *buffer, 0, mlt_pool_release, NULL );
+                       mlt_frame_set_audio( frame, *buffer, *format, size, mlt_pool_release );
                }
                else
                {
@@ -331,6 +347,8 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Regardless of speed, we expect to get the next frame (cos we ain't too bright)
        mlt_properties_set_position( properties, "audio_expected", position + 1 );
 
+       mlt_service_unlock( MLT_PRODUCER_SERVICE( this ) );
+
        return 0;
 }
 
@@ -345,16 +363,12 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
        // Update timecode on the frame we're creating
        mlt_frame_set_position( *frame, mlt_producer_position( this ) );
 
-       // Set the position of this producer
-       mlt_properties frame_properties = MLT_FRAME_PROPERTIES( *frame );
-       mlt_properties_set_position( frame_properties, "vorbis_position", mlt_producer_frame( this ) );
-
        // Set up the audio
        mlt_frame_push_audio( *frame, this );
        mlt_frame_push_audio( *frame, producer_get_audio );
 
        // Pass audio properties to the frame
-       mlt_properties_pass_list( frame_properties, MLT_PRODUCER_PROPERTIES( this ), "frequency, channels" );
+       mlt_properties_pass_list( MLT_FRAME_PROPERTIES(*frame), MLT_PRODUCER_PROPERTIES( this ), "frequency, channels" );
 
        // Calculate the next timecode
        mlt_producer_prepare_next( this );