Cleanup license declarations and remove dv1394d references.
[melted] / src / modules / vorbis / producer_vorbis.c
index 46cae76..0094822 100644 (file)
@@ -3,19 +3,19 @@
  * 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
 static int producer_open( mlt_producer this, 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.
 */
 
@@ -53,7 +82,7 @@ mlt_producer producer_vorbis_init( char *file )
                if ( mlt_producer_init( this, NULL ) == 0 )
                {
                        // Get the properties
-                       mlt_properties properties = mlt_producer_properties( this );
+                       mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
                        // Set the resource property (required for all producers)
                        mlt_properties_set( properties, "resource", file );
@@ -113,11 +142,21 @@ static int producer_open( mlt_producer this, char *file )
                if ( error == 0 )
                {
                        // Get the properties
-                       mlt_properties properties = mlt_producer_properties( this );
+                       mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
                        // 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
@@ -129,6 +168,11 @@ static int producer_open( mlt_producer this, char *file )
                                // Set out and length of file
                                mlt_properties_set_position( properties, "out", ( length * fps ) - 1 );
                                mlt_properties_set_position( properties, "length", ( length * fps ) );
+
+                               // 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 );
                        }
                }
                else
@@ -150,7 +194,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 );
+       mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
        // Obtain the fps
        double fps = mlt_properties_get_double( properties, "fps" );
@@ -165,16 +209,16 @@ static double producer_time_of_frame( mlt_producer this, mlt_position position )
 static int producer_get_audio( mlt_frame frame, int16_t **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 );
+       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" );
 
        // Get the producer 
-       mlt_producer this = mlt_properties_get_data( frame_properties, "vorbis_producer", NULL );
+       mlt_producer this = mlt_frame_pop_audio( frame );
 
        // Get the producer properties
-       mlt_properties properties = mlt_producer_properties( this );
+       mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
        // Get the ogg vorbis file
        OggVorbis_File *ov = mlt_properties_get_data( properties, "ogg_vorbis_file", NULL );
@@ -278,7 +322,6 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                }
                else
                {
-                       frame->get_audio = NULL;
                        mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
                        audio_used = 0;
                }
@@ -289,7 +332,6 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        else
        {
                // Get silence and don't touch the context
-               frame->get_audio = NULL;
                *samples = mlt_sample_calculator( fps, *frequency, position );
                mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
        }
@@ -300,21 +342,6 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        return 0;
 }
 
-/** Set up audio handling.
-*/
-
-static void producer_set_up_audio( mlt_producer this, mlt_frame frame )
-{
-       // Get the properties
-       mlt_properties properties = mlt_frame_properties( frame );
-
-       // Set the audio method
-       frame->get_audio = producer_get_audio;
-
-       // Set the producer on the frame
-       mlt_properties_set_data( properties, "vorbis_producer", this, 0, NULL, NULL );
-}
-
 /** Our get frame implementation.
 */
 
@@ -327,10 +354,15 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
        mlt_frame_set_position( *frame, mlt_producer_position( this ) );
 
        // Set the position of this producer
-       mlt_properties_set_position( mlt_frame_properties( *frame ), "vorbis_position", mlt_producer_position( this ) );
+       mlt_properties frame_properties = MLT_FRAME_PROPERTIES( *frame );
+       mlt_properties_set_position( frame_properties, "vorbis_position", mlt_producer_frame( this ) );
 
        // Set up the audio
-       producer_set_up_audio( this, *frame );
+       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" );
 
        // Calculate the next timecode
        mlt_producer_prepare_next( this );