]> git.sesse.net Git - mlt/commitdiff
producer hold, experimental ac3 audio support
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 22 Mar 2004 12:31:40 +0000 (12:31 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 22 Mar 2004 12:31:40 +0000 (12:31 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@226 d19143bc-622f-0410-bfdd-b5b2a6649095

12 files changed:
src/modules/avformat/producer_avformat.c
src/modules/core/producer_colour.c
src/modules/dv/consumer_libdv.c
src/modules/fezzik/Makefile
src/modules/fezzik/configure
src/modules/fezzik/factory.c
src/modules/fezzik/producer_hold.c [new file with mode: 0644]
src/modules/fezzik/producer_hold.h [new file with mode: 0644]
src/modules/resample/filter_resample.c
src/tests/dan.c
src/tests/pango.c
src/tests/pixbuf.c

index b5f7f62e816d4ff1c83e07af009c94bc546859d6..0f3a5597e5ca65c0c48beebb637ce94fe4b060b0 100644 (file)
@@ -758,7 +758,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        pthread_mutex_lock( &avformat_mutex );
 
        // Check for resample and create if necessary
-       if ( resample == NULL )
+       if ( resample == NULL && codec_context->channels <= 2 )
        {
                // Create the resampler
                resample = audio_resample_init( *channels, codec_context->channels, *frequency, codec_context->sample_rate );
@@ -766,6 +766,11 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                // And store it on properties
                mlt_properties_set_data( properties, "audio_resample", resample, 0, ( mlt_destructor )audio_resample_close, NULL );
        }
+       else if ( resample == NULL )
+       {
+               *channels = codec_context->channels;
+               *frequency = codec_context->sample_rate;
+       }
 
        // Check for audio buffer and create if necessary
        if ( audio_buffer == NULL )
@@ -827,7 +832,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                uint8_t *ptr = pkt.data;
                        int data_size;
 
-                       // We only deal with video from the selected video_index
+                       // We only deal with audio from the selected audio_index
                        while ( ptr != NULL && ret >= 0 && pkt.stream_index == index && len > 0 )
                        {
                                // Decode the audio
@@ -844,9 +849,15 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
 
                                if ( data_size > 0 )
                                {
-                                       int size_out = audio_resample( resample, &audio_buffer[ audio_used * *channels ], temp, data_size / ( codec_context->channels * sizeof( int16_t ) ) );
-
-                                       audio_used += size_out;
+                                       if ( resample != NULL )
+                                       {
+                                               audio_used += audio_resample( resample, &audio_buffer[ audio_used * *channels ], temp, data_size / ( codec_context->channels * sizeof( int16_t ) ) );
+                                       }
+                                       else
+                                       {
+                                               memcpy( &audio_buffer[ audio_used * *channels ], temp, data_size );
+                                               audio_used += data_size / ( codec_context->channels * sizeof( int16_t ) );
+                                       }
 
                                        // Handle ignore
                                        while ( ignore && audio_used > *samples )
index 43d019dc50c922ab47934629b3fc2de96059d95d..415b595eed325fb018affda975f003e64e2ad532 100644 (file)
@@ -193,6 +193,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", 1 );
+               mlt_properties_set_int( properties, "aspect_ratio", 1 );
 
                // colour is an alias for resource
                // CY: Do we really need this?
index 1ca825f7ce908cf17c76831864273536dab406de..b7714920165c43bae5e1064cbc0eb3ed12ab5e40 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * producer_libdv.c -- a DV encoder based on libdv
+ * consumer_libdv.c -- a DV encoder based on libdv
  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
  *
index b2c9368e44ce5cf3eae4a5eaab7067adaa69fe1a..b0e98f7e2911af683bd2677dbd99baf98fdc6097 100644 (file)
@@ -2,7 +2,8 @@
 TARGET = ../libmltfezzik.so
 
 OBJS = factory.o \
-          producer_fezzik.o 
+          producer_fezzik.o \
+          producer_hold.o 
 
 CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
 
index 057604207113bef5a4f7ec904877da2c54261276..b7880adde7e2fe31a27290f26fea17f2c93963e7 100755 (executable)
@@ -5,6 +5,7 @@ then
 
 cat << EOF >> ../producers.dat
 fezzik                 libmltfezzik.so
+hold                   libmltfezzik.so
 EOF
 
 fi
index f37316f9562b6262166ae435c2e75c966335b71a..c7e5cca74dada00d8122130a5e05243f78438253 100644 (file)
 #include <string.h>
 
 #include "producer_fezzik.h"
+#include "producer_hold.h"
 
 void *mlt_create_producer( char *id, void *arg )
 {
        if ( !strcmp( id, "fezzik" ) )
                return producer_fezzik_init( arg );
+       if ( !strcmp( id, "hold" ) )
+               return producer_hold_init( arg );
        return NULL;
 }
 
diff --git a/src/modules/fezzik/producer_hold.c b/src/modules/fezzik/producer_hold.c
new file mode 100644 (file)
index 0000000..d2ce7f8
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * producer_hold.c -- frame holding producer
+ * 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 program 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.
+ *
+ * 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.
+ */
+
+#include "producer_hold.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <framework/mlt.h>
+
+// Forward references
+static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index );
+
+/** Constructor for the frame holding producer. Basically, all this producer does is
+       provide a producer wrapper for the requested producer, allows the specifcation of
+       the frame required and will then repeatedly obtain that frame for each get_frame
+       and get_image requested.
+*/
+
+mlt_producer producer_hold_init( char *arg )
+{
+       // Construct a new holding producer
+       mlt_producer this = mlt_producer_new( );
+
+       // Construct the requested producer via fezzik
+       mlt_producer producer = mlt_factory_producer( "fezzik", arg );
+
+       // Initialise the frame holding capabilities
+       if ( this != NULL && producer != NULL )
+       {
+               // Get the properties of this producer
+               mlt_properties properties = mlt_producer_properties( this );
+
+               // Store the producer
+               mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
+
+               // Set frame, in, out and length for this producer
+               mlt_properties_set_position( properties, "frame", 0 );
+               mlt_properties_set_position( properties, "in", 0 );
+               mlt_properties_set_position( properties, "out", 25 );
+               mlt_properties_set_position( properties, "length", 15000 );
+
+               // Override the get_frame method
+               this->get_frame = producer_get_frame;
+       }
+       else
+       {
+               // Clean up (not sure which one failed, can't be bothered to find out, so close both)
+               mlt_producer_close( this );
+               mlt_producer_close( producer );
+
+               // Make sure we return NULL
+               this = NULL;
+       }
+
+       // Return this producer
+       return this;
+}
+
+static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
+{
+       // Get the properties of the frame
+       mlt_properties properties = mlt_frame_properties( frame );
+
+       // Obtain the real frame
+       mlt_frame real_frame = mlt_frame_pop_service( frame );
+
+       // We want distorted to ensure we don't hit the resize filter twice
+       mlt_properties_set_int( properties, "distort", 1 );
+
+       // Get the image from the real frame
+       mlt_frame_get_image( real_frame, buffer, format, width, height, writable );
+
+       // Set the values obtained on the frame
+       mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
+       mlt_properties_set_int( properties, "width", *width );
+       mlt_properties_set_int( properties, "height", *height );
+
+       // We'll deinterlace on the downstream deinterlacer
+       mlt_properties_set_int( mlt_frame_properties( real_frame ), "consumer_deinterlace", 1 );
+
+       // All done
+       return 0;
+}
+
+static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index )
+{
+       // Get the properties of this producer
+       mlt_properties properties = mlt_producer_properties( this );
+
+       // Construct a new frame
+       *frame = mlt_frame_init( );
+
+       // If we have a frame, then stack the producer itself and the get_image method
+       if ( *frame != NULL )
+       {
+               // Define the real frame
+               mlt_frame real_frame = NULL;
+
+               // Get the producer
+               mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
+
+               // Get the frame position requested
+               mlt_position position = mlt_properties_get_position( properties, "frame" );
+
+               // Seek the producer to the correct place
+               mlt_producer_seek( producer, position );
+
+               // Get the real frame
+               mlt_service_get_frame( mlt_producer_service( producer ), &real_frame, index );
+
+               // Ensure that the real frame gets wiped
+               mlt_properties_set_data( mlt_frame_properties( *frame ), "real_frame", real_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
+
+               // Stack the real frame and method
+               mlt_frame_push_service( *frame, real_frame );
+               mlt_frame_push_service( *frame, producer_get_image );
+
+               // Ensure that the consumer sees what the real frame has
+               mlt_properties_pass( mlt_frame_properties( *frame ), mlt_frame_properties( real_frame ), "" );
+
+               // Mirror the properties of the frame
+               mlt_properties_mirror( mlt_frame_properties( *frame ), mlt_frame_properties( real_frame ) );
+       }
+
+       // Move to the next position
+       mlt_producer_prepare_next( this );
+
+       return 0;
+}
diff --git a/src/modules/fezzik/producer_hold.h b/src/modules/fezzik/producer_hold.h
new file mode 100644 (file)
index 0000000..d80a9e2
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * producer_hold.h -- a frame holding producer
+ * 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 program 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.
+ *
+ * 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.
+ */
+
+#ifndef _PRODUCER_HOLD_H_
+#define _PRODUCER_HOLD_H_
+
+#include <framework/mlt_producer.h>
+
+extern mlt_producer producer_hold_init( char *args );
+
+#endif
index 57f9aadcc21304c470f9d597ede022f24107a66d..adfe0670c1dd96bdca7668fdc4c4fde5d2a60721 100644 (file)
@@ -58,11 +58,9 @@ static int resample_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Duplicate channels as necessary
        if ( channels_avail < *channels )
        {
-               int size = *channels * *samples * 2;
+               int size = *channels * *samples * sizeof( int16_t );
                int16_t *new_buffer = mlt_pool_alloc( size );
                
-               mlt_properties_set_data( properties, "audio", new_buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
-               
                // Duplicate the existing channels
                for ( i = 0; i < *samples; i++ )
                {
@@ -74,10 +72,31 @@ static int resample_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                        }
                }
                
+               // Update the audio buffer now - destroys the old
+               mlt_properties_set_data( properties, "audio", new_buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
+               
+               *buffer = new_buffer;
+       }
+       else if ( channels_avail > *channels )
+       {
+               // Nasty hack for ac3 5.1 audio - may be a cause of failure?
+               int size = *channels * *samples * sizeof( int16_t );
+               int16_t *new_buffer = mlt_pool_alloc( size );
+               
+               // Drop all but the first *channels
+               for ( i = 0; i < *samples; i++ )
+               {
+                       new_buffer[ ( i * *channels ) + 0 ] = (*buffer)[ ( i * channels_avail ) + 2 ];
+                       new_buffer[ ( i * *channels ) + 1 ] = (*buffer)[ ( i * channels_avail ) + 3 ];
+               }
+
+               // Update the audio buffer now - destroys the old
+               mlt_properties_set_data( properties, "audio", new_buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
+               
                *buffer = new_buffer;
        }
 
-       // Return now if now work to do
+       // Return now if no work to do
        if ( output_rate == *frequency )
                return 0;
 
index 051fb3985f57d8fcb76bdb88f1734557f328d8e0..3488768d253e4f2e234093d65e40d471ad60fcaa 100644 (file)
@@ -21,7 +21,7 @@ int main( int argc, char **argv )
                file2 = argv[ 2 ];
 
        // Start the consumer...
-       int vstd = mlt_video_standard_ntsc;
+       //int vstd = mlt_video_standard_ntsc;
        //mlt_consumer consumer = mlt_factory_consumer( "bluefish", &vstd );
        //mlt_consumer consumer = mlt_factory_consumer( "sdl", NULL );
        mlt_consumer consumer = consumer_libdv_init( NULL );
index fb56113e5c1b3bfe386d053e86d482e36709cbe0..fb5e19a039b75bcde3916e1b2098379d3c442cb4 100644 (file)
@@ -33,7 +33,6 @@ int main( int argc, char **argv )
        mlt_playlist pl2 = mlt_playlist_init();
        mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
        mlt_playlist_append( pl2, title );
-       mlt_properties_set_int( mlt_producer_properties( title ), "video_standard", mlt_video_standard_pal );
        mlt_properties_set( mlt_producer_properties( title ), "font", "Sans Bold 36" );
        mlt_properties_set( mlt_producer_properties( title ), "text", text );
        mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f );
index 64a23b72ec915cbd13923c6543a36f4421048b51..fd0f0b636423177e6e2b18f42010b0957fcc0c64 100644 (file)
@@ -33,7 +33,6 @@ int main( int argc, char **argv )
        mlt_playlist pl2 = mlt_playlist_init();
        mlt_producer overlay = mlt_factory_producer( "pixbuf", file2 );
        mlt_playlist_append( pl2, overlay );
-       mlt_properties_set_int( mlt_producer_properties( overlay ), "video_standard", mlt_video_standard_pal );
        mlt_properties_set_int( mlt_producer_properties( overlay ), "x", 600 );
        mlt_properties_set_int( mlt_producer_properties( overlay ), "y", 460 );
        mlt_properties_set_double( mlt_producer_properties( overlay ), "mix", 0.8 );