X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fhb.c;h=0541b9fa7d26e7b38c5abec59e61f15f48a1db14;hb=f93c2a10768843b2f8900695bb1ab276ffc168ab;hp=4f484208d005f1e2d51746bbd02716c74b3ec769;hpb=c0e795c30dffcb96c31a60737952d81c998d9a23;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/hb.c b/libhb/hb.c index 4f484208..0541b9fa 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -5,7 +5,7 @@ struct hb_handle_s { /* The "Check for update" thread */ int build; - char version[16]; + char version[32]; hb_thread_t * update_thread; /* This thread's only purpose is to check other threads' @@ -38,11 +38,18 @@ struct hb_handle_s /* For MacGui active queue increments each time the scan thread completes*/ int scanCount; + volatile int scan_die; + + /* Stash of persistent data between jobs, for stuff + like correcting frame count and framerate estimates + on multi-pass encodes where frames get dropped. */ + hb_interjob_t * interjob; }; hb_lock_t *hb_avcodec_lock; hb_work_object_t * hb_objects = NULL; +int hb_process_initialized = 0; static void thread_func( void * ); @@ -88,6 +95,16 @@ void hb_register( hb_work_object_t * w ) */ hb_handle_t * hb_init( int verbose, int update_check ) { + if (!hb_process_initialized) + { +#ifdef USE_PTHREAD +#if defined( _WIN32 ) || defined( __MINGW32__ ) + pthread_win32_process_attach_np(); +#endif +#endif + hb_process_initialized =1; + } + hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 ); uint64_t date; @@ -142,6 +159,8 @@ hb_handle_t * hb_init( int verbose, int update_check ) h->pause_lock = hb_lock_init(); + h->interjob = calloc( sizeof( hb_interjob_t ), 1 ); + /* libavcodec */ hb_avcodec_init(); @@ -150,14 +169,15 @@ hb_handle_t * hb_init( int verbose, int update_check ) h->die = 0; h->main_thread = hb_thread_init( "libhb", thread_func, h, HB_NORMAL_PRIORITY ); - hb_register( &hb_sync ); + hb_register( &hb_sync_video ); + hb_register( &hb_sync_audio ); hb_register( &hb_decmpeg2 ); hb_register( &hb_decvobsub ); hb_register( &hb_encvobsub ); hb_register( &hb_deccc608 ); + hb_register( &hb_decsrtsub ); hb_register( &hb_render ); hb_register( &hb_encavcodec ); - hb_register( &hb_encxvid ); hb_register( &hb_encx264 ); hb_register( &hb_enctheora ); hb_register( &hb_deca52 ); @@ -170,6 +190,7 @@ hb_handle_t * hb_init( int verbose, int update_check ) hb_register( &hb_encfaac ); hb_register( &hb_enclame ); hb_register( &hb_encvorbis ); + hb_register( &hb_muxer ); #ifdef __APPLE__ hb_register( &hb_encca_aac ); #endif @@ -247,14 +268,15 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) h->main_thread = hb_thread_init( "libhb", thread_func, h, HB_NORMAL_PRIORITY ); - hb_register( &hb_sync ); + hb_register( &hb_sync_video ); + hb_register( &hb_sync_audio ); hb_register( &hb_decmpeg2 ); hb_register( &hb_decvobsub ); hb_register( &hb_encvobsub ); hb_register( &hb_deccc608 ); + hb_register( &hb_decsrtsub ); hb_register( &hb_render ); hb_register( &hb_encavcodec ); - hb_register( &hb_encxvid ); hb_register( &hb_encx264 ); hb_register( &hb_enctheora ); hb_register( &hb_deca52 ); @@ -267,6 +289,7 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) hb_register( &hb_encfaac ); hb_register( &hb_enclame ); hb_register( &hb_encvorbis ); + hb_register( &hb_muxer ); #ifdef __APPLE__ hb_register( &hb_encca_aac ); #endif @@ -372,6 +395,8 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index, { hb_title_t * title; + h->scan_die = 0; + /* Clean up from previous scan */ hb_remove_previews( h ); while( ( title = hb_list_item( h->list_title, 0 ) ) ) @@ -381,8 +406,9 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index, } hb_log( "hb_scan: path=%s, title_index=%d", path, title_index ); - h->scan_thread = hb_scan_init( h, path, title_index, h->list_title, - preview_count, store_previews ); + h->scan_thread = hb_scan_init( h, &h->scan_die, path, title_index, + h->list_title, preview_count, + store_previews ); } /** @@ -421,14 +447,14 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, buf1 = av_malloc( avpicture_get_size( PIX_FMT_YUV420P, title->width, title->height ) ); buf2 = av_malloc( avpicture_get_size( PIX_FMT_YUV420P, title->width, title->height ) ); buf3 = av_malloc( avpicture_get_size( PIX_FMT_YUV420P, rgb_width, job->height ) ); - buf4 = av_malloc( avpicture_get_size( PIX_FMT_RGBA32, rgb_width, job->height ) ); + buf4 = av_malloc( avpicture_get_size( PIX_FMT_RGB32, rgb_width, job->height ) ); avpicture_fill( &pic_in, buf1, PIX_FMT_YUV420P, title->width, title->height ); avpicture_fill( &pic_deint, buf2, PIX_FMT_YUV420P, title->width, title->height ); avpicture_fill( &pic_scale, buf3, PIX_FMT_YUV420P, rgb_width, job->height ); - avpicture_fill( &pic_preview, buf4, PIX_FMT_RGBA32, + avpicture_fill( &pic_preview, buf4, PIX_FMT_RGB32, rgb_width, job->height ); // Allocate the AVPicture frames and fill in @@ -438,7 +464,7 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, hb_get_tempory_filename( h, filename, "%" PRIxPTR "%d", (intptr_t) title, picture ); - file = fopen( filename, "r" ); + file = fopen( filename, "rb" ); if( !file ) { hb_log( "hb_get_preview: fopen failed" ); @@ -464,7 +490,7 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, context = sws_getContext(title->width - (job->crop[2] + job->crop[3]), title->height - (job->crop[0] + job->crop[1]), PIX_FMT_YUV420P, - rgb_width, job->height, PIX_FMT_YUV420P, + job->width, job->height, PIX_FMT_YUV420P, swsflags, NULL, NULL, NULL); // Scale @@ -478,7 +504,7 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, // Get preview context context = sws_getContext(rgb_width, job->height, PIX_FMT_YUV420P, - rgb_width, job->height, PIX_FMT_RGBA32, + rgb_width, job->height, PIX_FMT_RGB32, swsflags, NULL, NULL, NULL); // Create preview @@ -634,7 +660,7 @@ void hb_set_anamorphic_size( hb_job_t * job, int cropped_width = title->width - job->crop[2] - job->crop[3] ; int cropped_height = title->height - job->crop[0] - job->crop[1] ; double storage_aspect = (double)cropped_width / (double)cropped_height; - int mod = job->anamorphic.modulus ? job->anamorphic.modulus : 16; + int mod = job->modulus ? job->modulus : 16; double aspect = title->aspect; int pixel_aspect_width = job->anamorphic.par_width; @@ -791,12 +817,24 @@ void hb_set_anamorphic_size( hb_job_t * job, } else { - /* We first need the display ar. - That's the source display width divided by the source height after cropping. - Then we multiple the output height by that to get the pixel aspect width, - and the pixel aspect height is the storage width.*/ - pixel_aspect_width = height * source_display_width / cropped_height; - pixel_aspect_height = width; + /* If we're doing ana 3 and not specifying a DAR, care needs to be taken. + This indicates a PAR is potentially being set by the interface. But + this is an output PAR, to correct a source, and it should not be assumed + that it properly creates a display aspect ratio when applied to the source, + which could easily be stored in a different resolution. */ + if( job->anamorphic.keep_display_aspect ) + { + /* We can ignore the possibility of a PAR change */ + pixel_aspect_width = height * ( (double)source_display_width / (double)cropped_height ); + pixel_aspect_height = width; + } + else + { + int output_display_width = width * (double)pixel_aspect_width / + (double)pixel_aspect_height; + pixel_aspect_width = output_display_width; + pixel_aspect_height = width; + } } /* Back to caller */ @@ -997,7 +1035,7 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) title_copy->list_subtitle = hb_list_init(); /* - * The following code is confusing, there are three ways in which + * The following code is confusing, there are two ways in which * we select subtitles and it depends on whether this is single or * two pass mode. * @@ -1005,17 +1043,13 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) * scans all subtitles of that language. The second pass does not * select any because they are set at the end of the first pass. * - * native_language may have a preferred language, in which case we - * may be switching the language we want for the subtitles in the - * first pass of a single pass, or the second pass of a two pass. - * * We may have manually selected a subtitle, in which case that is * selected in the first pass of a single pass, or the second of a * two pass. */ memset( audio_lang, 0, sizeof( audio_lang ) ); - if ( job->indepth_scan || job->native_language ) { + if ( job->indepth_scan ) { /* * Find the first audio language that is being encoded @@ -1028,35 +1062,6 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) break; } } - - /* - * In all cases switch the language if we need to to our native - * language. - */ - if( job->native_language ) - { - if( strncasecmp( job->native_language, audio_lang, - sizeof( audio_lang ) ) != 0 ) - { - - if( job->pass != 2 ) - { - hb_log( "Enabled subtitles in native language '%s', audio is in '%s'", - job->native_language, audio_lang); - } - /* - * The main audio track is not in our native language, so switch - * the subtitles to use our native language instead. - */ - strncpy( audio_lang, job->native_language, sizeof( audio_lang ) ); - } else { - /* - * native language is irrelevent, free it. - */ - free( job->native_language ); - job->native_language = NULL; - } - } } /* @@ -1068,7 +1073,8 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) { subtitle = hb_list_item( title->list_subtitle, i ); - if( strcmp( subtitle->iso639_2, audio_lang ) == 0 ) + if( strcmp( subtitle->iso639_2, audio_lang ) == 0 && + subtitle->source == VOBSUB ) { /* * Matched subtitle language with audio language, so @@ -1080,14 +1086,6 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); hb_list_add( title_copy->list_subtitle, subtitle_copy ); - if ( job->native_language ) { - /* - * With native language just select the - * first match in our langiage, not all of - * them. Subsequent ones are likely to be commentary - */ - break; - } } } } else { @@ -1095,57 +1093,17 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) * Not doing a subtitle scan in this pass, but maybe we are in the * first pass? */ - if( job->select_subtitle ) + if( job->pass != 1 ) { /* - * Don't add subtitles here, we'll add them via select_subtitle - * at the end of the subtitle_scan. - */ - } else { - /* - * Definitely not doing a subtitle scan. + * Copy all of them from the input job, to the title_copy/job_copy. */ - if( job->pass != 1 && job->native_language ) - { - /* - * We are not doing a subtitle scan but do want the - * native langauge subtitle selected, so select it - * for pass 0 or pass 2 of a two pass. - */ - for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) + for( i = 0; i < hb_list_count(job->list_subtitle); i++ ) { + if( ( subtitle = hb_list_item( job->list_subtitle, i ) ) ) { - subtitle = hb_list_item( title->list_subtitle, i ); - if( strcmp( subtitle->iso639_2, audio_lang ) == 0 ) - { - /* - * Matched subtitle language with audio language, so - * add this to our list to scan. - */ - subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); - memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); - hb_list_add( title_copy->list_subtitle, subtitle_copy ); - break; - } - } - } else { - /* - * Manually selected subtitles, in which case only - * bother adding them for pass 0 or pass 2 of a two - * pass. - */ - if( job->pass != 1 ) - { - /* - * Copy all of them from the input job, to the title_copy/job_copy. - */ - for( i = 0; i < hb_list_count(job->list_subtitle); i++ ) { - if( ( subtitle = hb_list_item( job->list_subtitle, i ) ) ) - { - subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); - memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); - hb_list_add( title_copy->list_subtitle, subtitle_copy ); - } - } + subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); + memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); + hb_list_add( title_copy->list_subtitle, subtitle_copy ); } } } @@ -1256,6 +1214,8 @@ void hb_pause( hb_handle_t * h ) hb_lock( h->pause_lock ); h->paused = 1; + hb_current_job( h )->st_pause_date = hb_get_date(); + hb_lock( h->state_lock ); h->state.state = HB_STATE_PAUSED; hb_unlock( h->state_lock ); @@ -1270,6 +1230,13 @@ void hb_resume( hb_handle_t * h ) { if( h->paused ) { +#define job hb_current_job( h ) + if( job->st_pause_date != -1 ) + { + job->st_paused += hb_get_date() - job->st_pause_date; + } +#undef job + hb_unlock( h->pause_lock ); h->paused = 0; } @@ -1290,6 +1257,20 @@ void hb_stop( hb_handle_t * h ) } /** + * Stops the conversion process. + * @param h Handle to hb_handle_t. + */ +void hb_scan_stop( hb_handle_t * h ) +{ + h->scan_die = 1; + + h->job_count = hb_count(h); + h->job_count_permanent = 0; + + hb_resume( h ); +} + +/** * Returns the state of the conversion process. * @param h Handle to hb_handle_t. * @param s Handle to hb_state_t which to copy the state data. @@ -1392,8 +1373,24 @@ static void thread_func( void * _h ) { hb_thread_close( &h->scan_thread ); - hb_log( "libhb: scan thread found %d valid title(s)", - hb_list_count( h->list_title ) ); + if ( h->scan_die ) + { + hb_title_t * title; + + hb_remove_previews( h ); + while( ( title = hb_list_item( h->list_title, 0 ) ) ) + { + hb_list_rem( h->list_title, title ); + hb_title_close( &title ); + } + + hb_log( "hb_scan: canceled" ); + } + else + { + hb_log( "libhb: scan thread found %d valid title(s)", + hb_list_count( h->list_title ) ); + } hb_lock( h->state_lock ); h->state.state = HB_STATE_SCANDONE; //originally state.state hb_unlock( h->state_lock ); @@ -1468,7 +1465,8 @@ void hb_set_state( hb_handle_t * h, hb_state_t * s ) hb_lock( h->pause_lock ); hb_lock( h->state_lock ); memcpy( &h->state, s, sizeof( hb_state_t ) ); - if( h->state.state == HB_STATE_WORKING ) + if( h->state.state == HB_STATE_WORKING || + h->state.state == HB_STATE_SEARCHING ) { /* XXX Hack */ if (h->job_count < 1) @@ -1487,3 +1485,9 @@ void hb_set_state( hb_handle_t * h, hb_state_t * s ) hb_unlock( h->state_lock ); hb_unlock( h->pause_lock ); } + +/* Passes a pointer to persistent data */ +hb_interjob_t * hb_interjob_get( hb_handle_t * h ) +{ + return h->interjob; +}