null pointer check in end_playlist
[melted] / src / modules / avformat / producer_avformat.c
index 773632a..0f3a559 100644 (file)
@@ -41,6 +41,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 static int avformat_initialised = 0;
 static pthread_mutex_t avformat_mutex;
 
+#if 0
 void *av_malloc( unsigned int size )
 {
        return mlt_pool_alloc( size );
@@ -55,6 +56,7 @@ void av_free( void *ptr )
 {
        return mlt_pool_release( ptr );
 }
+#endif
 
 /** Constructor for libavformat.
 */
@@ -230,7 +232,7 @@ static int producer_open( mlt_producer this, char *file )
                {
                        mrl[0] = 0;
                        char *name = strdup( ++mrl );
-                       char *value = strchr( name, '=' );
+                       char *value = strchr( name, ':' );
                        if ( value )
                        {
                                value[0] = 0;
@@ -297,7 +299,7 @@ static int producer_open( mlt_producer this, char *file )
                        // Store selected audio and video indexes on properties
                        mlt_properties_set_int( properties, "audio_index", audio_index );
                        mlt_properties_set_int( properties, "video_index", video_index );
-
+                       
                        // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later)
                        if ( audio_index != -1 && video_index != -1 )
                        {
@@ -377,7 +379,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        mlt_position expected = mlt_properties_get_position( properties, "video_expected" );
 
        // Calculate the real time code
-       double real_timecode = producer_time_of_frame( this, position ) + mlt_properties_get_double( properties, "_v_pts_offset" );
+       double real_timecode = producer_time_of_frame( this, position );
 
        // Get the video stream
        AVStream *stream = context->streams[ index ];
@@ -490,14 +492,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                if ( got_picture )
                                {
                                        if ( pkt.pts != AV_NOPTS_VALUE && pkt.pts != 0  )
-                                       {
-                                               if ( current_time == 0 )
-                                               {
-                                                       mlt_properties_set_double( properties, "_v_pts_offset", ( double )( pkt.pts / 1000000 ) );
-                                                       real_timecode += pkt.pts / 1000000;
-                                               }
                                                current_time = ( double )pkt.pts / 1000000.0;
-                                       }
                                        else
                                                current_time = real_timecode;
 
@@ -763,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 );
@@ -771,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 )
@@ -832,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
@@ -849,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 )