]> git.sesse.net Git - mlt/blobdiff - src/modules/avformat/producer_avformat.c
Fix compile warning about planar_to_interleaved() unused.
[mlt] / src / modules / avformat / producer_avformat.c
index da4dcb2d21f793f0b050fa115a62f288efe06862..9068f0815448160b12cb5dab19f2b11046af99e2 100644 (file)
@@ -959,7 +959,7 @@ static int seek_video( producer_avformat self, mlt_position position,
                                timestamp -= 2 / av_q2d( self->video_time_base );
                        if ( timestamp < 0 )
                                timestamp = 0;
-                       mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "seeking timestamp %"PRId64" position %d expected %d last_pos %"PRId64"\n",
+                       mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "seeking timestamp %"PRId64" position " MLT_POSITION_FMT " expected "MLT_POSITION_FMT" last_pos %"PRId64"\n",
                                timestamp, position, self->video_expected, self->last_position );
 
                        // Seek to the timestamp
@@ -1426,6 +1426,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                                pthread_mutex_unlock( &self->packets_mutex );
                                                goto exit_get_image;
                                        }
+                                       if ( !self->seekable && mlt_properties_get_int( properties, "exit_on_disconnect" ) )
+                                       {
+                                               mlt_log_fatal( MLT_PRODUCER_SERVICE(producer), "Exiting with error due to disconnected source.\n" );
+                                               exit( EXIT_FAILURE );
+                                       }
                                }
                        }
                        pthread_mutex_unlock( &self->packets_mutex );
@@ -1811,8 +1816,7 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p
                if ( mlt_properties_get( properties, "force_fps" ) )
                {
                        AVRational force_fps = av_d2q( mlt_properties_get_double( properties, "force_fps" ), 1024 );
-                       self->video_time_base.num *= frame_rate.num * force_fps.den;
-                       self->video_time_base.den *= frame_rate.den * force_fps.num;
+                       self->video_time_base = av_mul_q( stream->time_base, av_div_q( frame_rate, force_fps ) );
                        frame_rate = force_fps;
                }
                mlt_properties_set_int( properties, "meta.media.frame_rate_num", frame_rate.num );
@@ -2006,31 +2010,33 @@ static int sample_bytes( AVCodecContext *context )
 #endif
 }
 
-static void planar_to_interleaved( uint8_t *dest, uint8_t *src, int samples, int channels, int bytes_per_sample )
+#if LIBAVCODEC_VERSION_MAJOR >= 55
+static void planar_to_interleaved( uint8_t *dest, AVFrame *src, int samples, int channels, int bytes_per_sample )
 {
        int s, c;
        for ( s = 0; s < samples; s++ )
        {
                for ( c = 0; c < channels; c++ )
                {
-                       memcpy( dest, src + ( c * samples + s ) * bytes_per_sample, bytes_per_sample );
+                       memcpy( dest, &src->data[c][s * bytes_per_sample], bytes_per_sample );
                        dest += bytes_per_sample;
                }
        }
 }
-
-static void planar_to_interleaved2( uint8_t *dest, AVFrame *src, int samples, int channels, int bytes_per_sample )
+#else
+static void planar_to_interleaved( uint8_t *dest, uint8_t *src, int samples, int channels, int bytes_per_sample )
 {
        int s, c;
        for ( s = 0; s < samples; s++ )
        {
                for ( c = 0; c < channels; c++ )
                {
-                       memcpy( dest, &src->data[c][s * bytes_per_sample], bytes_per_sample );
+                       memcpy( dest, src + ( c * samples + s ) * bytes_per_sample, bytes_per_sample );
                        dest += bytes_per_sample;
                }
        }
 }
+#endif
 
 static int decode_audio( producer_avformat self, int *ignore, AVPacket pkt, int channels, int samples, double timecode, double fps )
 {
@@ -2102,7 +2108,7 @@ static int decode_audio( producer_avformat self, int *ignore, AVPacket pkt, int
                        case AV_SAMPLE_FMT_S32P:
                        case AV_SAMPLE_FMT_FLTP:
 #if LIBAVCODEC_VERSION_MAJOR >= 55
-                               planar_to_interleaved2( dest, self->audio_frame, convert_samples, codec_context->channels, sizeof_sample );
+                               planar_to_interleaved( dest, self->audio_frame, convert_samples, codec_context->channels, sizeof_sample );
 #else
                                planar_to_interleaved( dest, decode_buffer, convert_samples, codec_context->channels, sizeof_sample );
 #endif
@@ -2285,8 +2291,10 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                                }
                                else if ( ret < 0 )
                                {
-                                       mlt_log_verbose( MLT_PRODUCER_SERVICE(self->parent), "av_read_frame returned error %d inside get_audio\n", ret );
-                                       if ( !self->seekable && mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( self->parent ), "reconnect" ) )
+                                       mlt_producer producer = self->parent;
+                                       mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
+                                       mlt_log_verbose( MLT_PRODUCER_SERVICE(producer), "av_read_frame returned error %d inside get_audio\n", ret );
+                                       if ( !self->seekable && mlt_properties_get_int( properties, "reconnect" ) )
                                        {
                                                // Try to reconnect to live sources by closing context and codecs,
                                                // and letting next call to get_frame() reopen.
@@ -2294,6 +2302,11 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                                                pthread_mutex_unlock( &self->packets_mutex );
                                                goto exit_get_audio;
                                        }
+                                       if ( !self->seekable && mlt_properties_get_int( properties, "exit_on_disconnect" ) )
+                                       {
+                                               mlt_log_fatal( MLT_PRODUCER_SERVICE(producer), "Exiting with error due to disconnected source.\n" );
+                                               exit( EXIT_FAILURE );
+                                       }
                                }
                        }
                        pthread_mutex_unlock( &self->packets_mutex );
@@ -2526,14 +2539,11 @@ static void producer_set_up_audio( producer_avformat self, mlt_frame frame )
                                audio_codec_init( self, index, properties );
                }
        }
-       else if ( context && index > -1 && audio_codec_init( self, index, properties ) )
+       else if ( context && index > -1 && index < MAX_AUDIO_STREAMS &&
+               audio_codec_init( self, index, properties ) )
        {
-               // Set the frame properties
-               if ( index < MAX_AUDIO_STREAMS )
-               {
-                       mlt_properties_set_int( frame_properties, "audio_frequency", self->audio_codec[ index ]->sample_rate );
-                       mlt_properties_set_int( frame_properties, "audio_channels", self->audio_codec[ index ]->channels );
-               }
+               mlt_properties_set_int( frame_properties, "audio_frequency", self->audio_codec[ index ]->sample_rate );
+               mlt_properties_set_int( frame_properties, "audio_channels", self->audio_codec[ index ]->channels );
        }
        if ( context && index > -1 )
        {