]> git.sesse.net Git - mlt/blobdiff - src/modules/vorbis/producer_vorbis.c
Fix short forward seeking in vorbis producer.
[mlt] / src / modules / vorbis / producer_vorbis.c
index 3e2218cd977b1aecceaef8f9565ea442cc518113..b5a12c4e365a85e685122397c61911c3038821b7 100644 (file)
@@ -3,26 +3,25 @@
  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
  *
- * 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 <framework/mlt_producer.h>
 #include <framework/mlt_frame.h>
+#include <framework/mlt_profile.h>
 
 // vorbis Header files
 #include <vorbis/codec.h>
 // System header files
 #include <stdlib.h>
 #include <string.h>
+#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 
@@ -68,7 +68,7 @@ static sw_metadata *vorbis_metadata_from_str (char * str)
 /** 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;
 
@@ -91,7 +91,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 );
@@ -121,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" );
@@ -163,7 +163,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_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 );
@@ -173,6 +173,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
@@ -193,20 +200,13 @@ 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.
 */
 
-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 );
@@ -227,7 +227,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 );
@@ -306,7 +306,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 ++ );
                        }
                }
@@ -314,11 +314,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
                {
@@ -348,7 +351,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 ) );