From: lilo_booter Date: Tue, 25 Oct 2005 07:26:52 +0000 (+0000) Subject: src/modules/core/consumer_null.c X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=bd2707bb370eda9cae39e22b5e89b9096474cd7d;p=melted src/modules/core/consumer_null.c src/modules/sdl/consumer_sdl.c + Terminate on pause functionality src/modules/motion_est/filter_autotrack_rectangle.c + Ensures that tracked area remains valid (out of bounds was causing core dumps) ? Currently, width/height is preserved on boundaries, but maybe it should shrink/grow? git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@856 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/modules/core/consumer_null.c b/src/modules/core/consumer_null.c index d2abe19..96183fd 100644 --- a/src/modules/core/consumer_null.c +++ b/src/modules/core/consumer_null.c @@ -80,6 +80,7 @@ static int consumer_start( mlt_consumer this ) // Set the running state mlt_properties_set_int( properties, "running", 1 ); + mlt_properties_set_int( properties, "joined", 0 ); // Create the thread pthread_create( thread, NULL, consumer_thread, this ); @@ -96,13 +97,14 @@ static int consumer_stop( mlt_consumer this ) mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Check that we're running - if ( mlt_properties_get_int( properties, "running" ) ) + if ( !mlt_properties_get_int( properties, "joined" ) ) { // Get the thread pthread_t *thread = mlt_properties_get_data( properties, "thread", NULL ); // Stop the thread mlt_properties_set_int( properties, "running", 0 ); + mlt_properties_set_int( properties, "joined", 1 ); // Wait for termination pthread_join( *thread, NULL ); @@ -132,15 +134,23 @@ static void *consumer_thread( void *arg ) // Get the properties mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + // Convenience functionality + int terminate_on_pause = mlt_properties_get_int( properties, "terminate_on_pause" ); + int terminated = 0; + // Frame and size mlt_frame frame = NULL; // Loop while running - while( mlt_properties_get_int( properties, "running" ) ) + while( !terminated && mlt_properties_get_int( properties, "running" ) ) { // Get the frame frame = mlt_consumer_rt_frame( this ); + // Check for termination + if ( terminate_on_pause && frame != NULL ) + terminated = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ) == 0.0; + // Check that we have a frame to work with if ( frame != NULL ) { @@ -151,6 +161,7 @@ static void *consumer_thread( void *arg ) } // Indicate that the consumer is stopped + mlt_properties_set_int( properties, "running", 0 ); mlt_consumer_stopped( this ); return NULL; diff --git a/src/modules/motion_est/filter_autotrack_rectangle.c b/src/modules/motion_est/filter_autotrack_rectangle.c index a54faa7..60d8660 100644 --- a/src/modules/motion_est/filter_autotrack_rectangle.c +++ b/src/modules/motion_est/filter_autotrack_rectangle.c @@ -40,7 +40,9 @@ void caculate_motion( struct motion_vector_s *vectors, int macroblock_width, int macroblock_height, int mv_buffer_width, - int method ) + int method, + int width, + int height ) { @@ -90,6 +92,18 @@ void caculate_motion( struct motion_vector_s *vectors, boundry->x -= (double)average2_x / (double)n; boundry->y -= (double)average2_y / (double)n; + + if ( boundry->x < 0 ) + boundry->x = 0; + + if ( boundry->y < 0 ) + boundry->y = 0; + + if ( boundry->x + boundry->w > width ) + boundry->x = width - boundry->w; + + if ( boundry->y + boundry->h > height ) + boundry->y = height - boundry->h; } // Image stack(able) method @@ -136,7 +150,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format int macroblock_width = mlt_properties_get_int( frame_properties, "motion_est.macroblock_width" ); int mv_buffer_width = *width / macroblock_width; - caculate_motion( vectors, &boundry, macroblock_width, macroblock_height, mv_buffer_width, method ); + caculate_motion( vectors, &boundry, macroblock_width, macroblock_height, mv_buffer_width, method, *width, *height ); // Make the geometry object a real boy @@ -168,6 +182,11 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format mlt_properties_set( MLT_FILTER_PROPERTIES( obscure ), "end", geom ); } + if( mlt_properties_get_int( filter_properties, "collect" ) == 1 ) + { + printf( "%d,%d,%d,%d\n", (int)boundry.x, (int)boundry.y, (int)boundry.w, (int)boundry.h ); + fflush( stdout ); + } return error; } diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index bcd69a0..5879187 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -683,6 +683,10 @@ static void *consumer_thread( void *arg ) // Get the consumer mlt_consumer consumer = &this->parent; + // Convenience functionality + int terminate_on_pause = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "terminate_on_pause" ); + int terminated = 0; + // Video thread pthread_t thread; @@ -696,11 +700,15 @@ static void *consumer_thread( void *arg ) struct timespec tm = { 0, 100000 }; // Loop until told not to - while( this->running ) + while( !terminated && this->running ) { // Get a frame from the attached producer frame = mlt_consumer_rt_frame( consumer ); + // Check for termination + if ( terminate_on_pause && frame != NULL ) + terminated = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ) == 0.0; + // Ensure that we have a frame if ( frame != NULL ) { @@ -737,6 +745,8 @@ static void *consumer_thread( void *arg ) } } + this->running = 0; + // Kill the video thread if ( init_video == 0 ) {