From: handbrake Date: Fri, 8 Feb 2013 03:55:16 +0000 (+0000) Subject: Replace some code with platform independent X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=179959002020b51490dbb78b05fb4534d4de9fa1;p=handbrake Replace some code with platform independent Remove some useless code git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/opencl@5243 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/libhb/common.c b/libhb/common.c index bf2da46b6..b5d296dee 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -1739,7 +1739,6 @@ static void job_setup( hb_job_t * job, hb_title_t * title ) job->list_attachment = hb_attachment_list_copy( title->list_attachment ); job->metadata = hb_metadata_copy( title->metadata ); - job->use_hw_decode = 0; } static void job_clean( hb_job_t * job ) @@ -2968,18 +2967,4 @@ int hb_use_dxva( hb_title_t * title ) || title->video_codec_param == AV_CODEC_ID_MPEG4 ) && title->opaque_priv ); } -int hb_get_gui_info(hb_gui_t * gui, int option) -{ - if ( option == 1 ) - return gui->use_hwd; - else if ( option == 2 ) - return gui->use_opencl; - else - return gui->title_scan; -} -void hb_set_gui_info(hb_gui_t *gui, int hwd, int opencl, int titlescan) -{ - gui->use_hwd = hwd; - gui->use_opencl = opencl; - gui->title_scan = titlescan; -} + diff --git a/libhb/common.h b/libhb/common.h index 3fc4b22aa..0bc196d3a 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -147,15 +147,7 @@ int hb_subtitle_can_burn( int source ); int hb_subtitle_can_pass( int source, int mux ); hb_attachment_t *hb_attachment_copy(const hb_attachment_t *src); -int hb_get_gui_info(hb_gui_t *gui, int option); -void hb_set_gui_info(hb_gui_t *gui, int hwd, int opencl, int titlescan); -struct hb_gui_s -{ - int use_hwd; - int use_opencl; - int title_scan; -}; -hb_gui_t hb_gui; +int hb_gui_use_hwd_flag; hb_list_t *hb_attachment_list_copy(const hb_list_t *src); void hb_attachment_close(hb_attachment_t **attachment); @@ -442,7 +434,6 @@ struct hb_job_s // to non-I frames). int use_opencl;/* 0 is disable use of opencl. 1 is enable use of opencl */ int use_hwd; - int use_hw_decode; #ifdef __LIBHB__ /* Internal data */ @@ -951,7 +942,6 @@ extern hb_work_object_t hb_encca_aac; extern hb_work_object_t hb_encca_haac; extern hb_work_object_t hb_encavcodeca; extern hb_work_object_t hb_reader; -extern hb_work_object_t hb_decavcodecv_accl; #define HB_FILTER_OK 0 #define HB_FILTER_DELAY 1 diff --git a/libhb/cropscale.c b/libhb/cropscale.c index e0a3e2af3..168b09358 100644 --- a/libhb/cropscale.c +++ b/libhb/cropscale.c @@ -14,6 +14,7 @@ struct hb_filter_private_s { + hb_job_t * job; int width_in; int height_in; int pix_fmt; @@ -62,6 +63,7 @@ static int hb_crop_scale_init( hb_filter_object_t * filter, hb_filter_private_t * pv = filter->private_data; // TODO: add pix format option to settings + pv->job = init->job; pv->pix_fmt_out = init->pix_fmt; pv->width_in = init->width; pv->height_in = init->height; @@ -69,7 +71,8 @@ static int hb_crop_scale_init( hb_filter_object_t * filter, pv->height_out = init->height; #ifdef USE_OPENCL pv->use_dxva = init->use_dxva; - if ( hb_get_gui_info(&hb_gui, 2) ) + + if ( pv->job->use_opencl ) { pv->title_width = init->title_width; pv->title_height = init->title_height; @@ -114,7 +117,8 @@ static int hb_crop_scale_info( hb_filter_object_t * filter, memcpy( info->out.crop, pv->crop, sizeof( int[4] ) ); #ifdef USE_OPENCL - if ( hb_get_gui_info(&hb_gui, 2) ) + + if ( pv->job->use_opencl ) { int cropped_width = pv->title_width - ( pv->crop[2] + pv->crop[3] ); int cropped_height = pv->title_height - ( pv->crop[0] + pv->crop[1] ); @@ -158,7 +162,8 @@ static void hb_crop_scale_close( hb_filter_object_t * filter ) return; } #ifdef USE_OPENCL - if ( hb_get_gui_info(&hb_gui, 2) && pv->os) + + if ( pv->job->use_opencl && pv->os ) { CL_FREE( pv->os->h_in_buf ); CL_FREE( pv->os->h_out_buf ); @@ -217,7 +222,8 @@ static hb_buffer_t* crop_scale( hb_filter_private_t * pv, hb_buffer_t * in ) pv->crop[0], pv->crop[2] ); #ifdef USE_OPENCL - if ( hb_get_gui_info(&hb_gui, 2) ) + + if ( pv->job->use_opencl ) { int w = in->f.width - ( pv->crop[2] + pv->crop[3] ); int h = in->f.height - ( pv->crop[0] + pv->crop[1] ); diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 43457720a..71c089016 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -40,7 +40,6 @@ #include "hb.h" #include "hbffmpeg.h" -#include "audio_remap.h" #include "audio_resample.h" #ifdef USE_HWD @@ -543,7 +542,8 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv, AVFrame *frame ) { hb_buffer_t *buf; int ww, hh; - if( (w > pv->job->width || h > pv->job->height) && (hb_get_gui_info(&hb_gui, 2) == 1) ) + + if( (w > pv->job->width || h > pv->job->height) && (pv->job->use_opencl) ) { buf = hb_video_buffer_init( pv->job->width, pv->job->height ); ww = pv->job->width; @@ -559,7 +559,7 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv, AVFrame *frame ) { pv->dst_frame = malloc( ww * hh * 3 / 2 ); } - if( hb_va_extract( pv->dxva2, pv->dst_frame, frame, pv->job->width, pv->job->height, pv->job->title->crop, pv->os ) == HB_WORK_ERROR ) + if( hb_va_extract( pv->dxva2, pv->dst_frame, frame, pv->job->width, pv->job->height, pv->job->title->crop, pv->os, pv->job->use_opencl ) == HB_WORK_ERROR ) { hb_log( "hb_va_Extract failed!!!!!!" ); } @@ -1124,7 +1124,7 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job ) || (w->codec_param==AV_CODEC_ID_VC1) || (w->codec_param==AV_CODEC_ID_WMV3) || (w->codec_param==AV_CODEC_ID_MPEG4)) - && pv->job && job->use_hw_decode) + && pv->job && job->use_hwd && hb_use_dxva( pv->title ) ) { pv->dxva2 = hb_va_create_dxva2( pv->dxva2, w->codec_param ); if( pv->dxva2 && pv->dxva2->do_job==HB_WORK_OK ) @@ -1579,19 +1579,6 @@ hb_work_object_t hb_decavcodecv = .info = decavcodecvInfo, .bsinfo = decavcodecvBSInfo }; -#ifdef USE_HWD -hb_work_object_t hb_decavcodecv_accl = -{ - .id = WORK_DECAVCODECVACCL, - .name = "Video hardware decoder (libavcodec)", - .init = decavcodecvInit, - .work = decavcodecvWork, - .close = decavcodecClose, - .flush = decavcodecvFlush, - .info = decavcodecvInfo, - .bsinfo = decavcodecvBSInfo -}; -#endif static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data, int size, int64_t pts) { diff --git a/libhb/hb.c b/libhb/hb.c index 0dbe8f528..fca34bacc 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -484,9 +484,6 @@ hb_handle_t * hb_init( int verbose, int update_check ) #endif hb_register( &hb_encavcodeca ); hb_register( &hb_reader ); -#ifdef USE_HWD - hb_register( &hb_decavcodecv_accl ); -#endif return h; } @@ -585,9 +582,6 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) #endif hb_register( &hb_encavcodeca ); hb_register( &hb_reader ); -#ifdef USE_HWD - hb_register( &hb_decavcodecv_accl ); -#endif return h; } diff --git a/libhb/internal.h b/libhb/internal.h index 79ed86f89..81cc8680f 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -417,8 +417,7 @@ enum WORK_ENCAVCODEC_AUDIO, WORK_MUX, WORK_READER, - WORK_DECPGSSUB, - WORK_DECAVCODECVACCL + WORK_DECPGSSUB }; extern hb_filter_object_t hb_filter_detelecine; diff --git a/libhb/openclwrapper.c b/libhb/openclwrapper.c index 2371c2167..8b7cb09b9 100644 --- a/libhb/openclwrapper.c +++ b/libhb/openclwrapper.c @@ -15,11 +15,13 @@ #include #include #include -#include #include "openclwrapper.h" #include "openclkernels.h" //#define USE_EXTERNAL_KERNEL +#ifdef SYS_MINGW +#include +#endif #if defined(__APPLE__) #include @@ -571,7 +573,9 @@ int hb_init_opencl_env( GPUEnv *gpu_info ) CL_QUEUE_THREAD_HANDLE_AMD, sizeof(handle), &handle, NULL ) == CL_SUCCESS && handle != INVALID_HANDLE_VALUE ) { +#ifdef SYS_MINGW SetThreadPriority( handle, THREAD_PRIORITY_TIME_CRITICAL ); +#endif } return 0; diff --git a/libhb/scale_kernel.c b/libhb/scale_kernel.c index 4d0b285c3..ab8e7867b 100644 --- a/libhb/scale_kernel.c +++ b/libhb/scale_kernel.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "scale.h" #include "openclwrapper.h" diff --git a/libhb/stream.c b/libhb/stream.c index 3ae2b1951..402bdee7a 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -611,7 +611,7 @@ static int hb_stream_get_type(hb_stream_t *stream) if ( fread(buf, 1, sizeof(buf), stream->file_handle) == sizeof(buf) ) { #ifdef USE_HWD - if ( hb_get_gui_info(&hb_gui, 1) ) + if ( hb_gui_use_hwd_flag == 1 ) return 0; #endif int psize; diff --git a/libhb/vadxva2.c b/libhb/vadxva2.c index 548dfe144..081bb5652 100644 --- a/libhb/vadxva2.c +++ b/libhb/vadxva2.c @@ -692,7 +692,7 @@ void hb_init_filter( cl_mem src, int srcwidth, int srcheight, uint8_t* dst, int * nv12 to yuv with opencl and with C reference * scale with opencl */ -int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w, int job_h, int *crop, hb_oclscale_t *os ) +int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w, int job_h, int *crop, hb_oclscale_t *os, int use_opencl ) { LPDIRECT3DSURFACE9 d3d = (LPDIRECT3DSURFACE9)(uintptr_t)frame->data[3]; @@ -716,7 +716,7 @@ int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w lock.Pitch, }; #ifdef USE_OPENCL - if( ( dxva2->width > job_w || dxva2->height > job_h ) && (TestGPU() == 0) && (hb_get_gui_info(&hb_gui, 2) == 1)) + if( ( dxva2->width > job_w || dxva2->height > job_h ) && (TestGPU() == 0) && (use_opencl)) { hb_ocl_nv12toyuv( plane, lock.Pitch, dxva2->width, dxva2->height, crop, dxva2 ); diff --git a/libhb/vadxva2.h b/libhb/vadxva2.h index eeab5bec8..bb1a3778a 100644 --- a/libhb/vadxva2.h +++ b/libhb/vadxva2.h @@ -204,7 +204,7 @@ static const hb_dx_mode_t dxva2_modes[] = }; int hb_va_get_frame_buf( hb_va_dxva2_t *dxva2, AVCodecContext *p_context, AVFrame *frame ); -int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w, int job_h, int *crop, hb_oclscale_t *os ); +int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w, int job_h, int *crop, hb_oclscale_t *os, int use_opencl ); enum PixelFormat hb_ffmpeg_get_format( AVCodecContext *, const enum PixelFormat * ); hb_va_dxva2_t *hb_va_create_dxva2( hb_va_dxva2_t *dxva2, int codec_id ); void hb_va_new_dxva2( hb_va_dxva2_t *dxva2, AVCodecContext *p_context ); diff --git a/libhb/work.c b/libhb/work.c index 4791c7dfd..dc50d502b 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -1020,13 +1020,7 @@ static void do_job( hb_job_t * job ) title->video_codec_param = AV_CODEC_ID_MPEG2VIDEO; } #endif -#ifdef USE_HWD - if ( /*job->use_opencl &&*/ hb_use_dxva( title ) && job->use_hwd ) - { - //vcodec = WORK_DECAVCODECVACCL; - job->use_hw_decode = 1; - } -#endif + hb_list_add( job->list_work, ( w = hb_get_work( vcodec ) ) ); w->codec_param = title->video_codec_param; w->fifo_in = job->fifo_mpeg2; diff --git a/test/test.c b/test/test.c index 15d3447d7..57156c726 100644 --- a/test/test.c +++ b/test/test.c @@ -261,7 +261,7 @@ int main( int argc, char ** argv ) titleindex = 0; } - hb_set_gui_info(&hb_gui, use_hwd, use_opencl, titleindex); + hb_gui_use_hwd_flag = use_hwd; hb_scan( h, input, titleindex, preview_count, store_previews, min_title_duration * 90000LL ); /* Wait... */