fprintf( stderr, "...\n" );
}
+static void on_fatal_error( mlt_properties owner, mlt_consumer consumer )
+{
+ mlt_consumer_stop( consumer );
+ exit( EXIT_FAILURE );
+}
+
int main( int argc, char **argv )
{
int i;
mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) );
// Start the consumer
+ mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error );
mlt_consumer_start( consumer );
// Transport functionality
#include <framework/mlt_frame.h>
#include <framework/mlt_profile.h>
#include <framework/mlt_log.h>
+#include <framework/mlt_events.h>
// System header files
#include <stdio.h>
this->start = consumer_start;
this->stop = consumer_stop;
this->is_stopped = consumer_is_stopped;
+
+ mlt_events_register( properties, "consumer-fatal-error", NULL );
}
// Return this
if ( pkt.size > 0 )
{
if ( av_interleaved_write_frame( oc, &pkt ) )
- mlt_log_error( MLT_CONSUMER_SERVICE( this ), "error writing audio frame %d\n", frames - 1 );
+ {
+ mlt_log_fatal( MLT_CONSUMER_SERVICE( this ), "error writing audio frame\n" );
+ mlt_events_fire( properties, "consumer-fatal-error", NULL );
+ goto on_fatal_error;
+ }
}
mlt_log_debug( MLT_CONSUMER_SERVICE( this ), " frame_size %d\n", codec->frame_size );
// Write video
if ( mlt_deque_count( queue ) )
{
- int out_size, ret;
+ int out_size, ret = 0;
AVCodecContext *c;
frame = mlt_deque_pop_front( queue );
}
}
frame_count++;
+ if ( ret )
+ {
+ mlt_log_fatal( MLT_CONSUMER_SERVICE( this ), "error writing video frame\n" );
+ mlt_events_fire( properties, "consumer-fatal-error", NULL );
+ goto on_fatal_error;
+ }
mlt_frame_close( frame );
}
else
pkt.data = audio_outbuf;
if ( av_interleaved_write_frame( oc, &pkt ) != 0 )
{
- mlt_log_error( MLT_CONSUMER_SERVICE( this ), "%s: error writing flushed audio frame\n", __FILE__ );
- break;
+ mlt_log_fatal( MLT_CONSUMER_SERVICE( this ), "error writing flushed audio frame\n" );
+ mlt_events_fire( properties, "consumer-fatal-error", NULL );
+ goto on_fatal_error;
}
}
// write the compressed frame in the media file
if ( av_interleaved_write_frame( oc, &pkt ) != 0 )
{
- mlt_log_error( MLT_CONSUMER_SERVICE(this), "error writing flushed video frame\n" );
- break;
+ mlt_log_fatal( MLT_CONSUMER_SERVICE(this), "error writing flushed video frame\n" );
+ mlt_events_fire( properties, "consumer-fatal-error", NULL );
+ goto on_fatal_error;
}
// Dual pass logging
if ( mlt_properties_get_data( properties, "_logfile", NULL ) && c->stats_out )
}
}
+on_fatal_error:
+
// Write the trailer, if any
av_write_trailer( oc );