From: Good Guy Date: Sat, 4 May 2019 02:48:21 +0000 (-0600) Subject: add hw_dev preference, opts file var, tweak hw GPU xfer err msg X-Git-Tag: 2019-08~58 X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=97552ff95c1bf20be9192b8101f61de5490eff20;p=goodguy%2Fcinelerra.git add hw_dev preference, opts file var, tweak hw GPU xfer err msg --- diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index b22f9935..9f13ec0d 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -33,6 +33,7 @@ #include "libmjpeg.h" #include "mainerror.h" #include "mwindow.h" +#include "preferences.h" #include "vframe.h" #ifdef FFMPEG3 @@ -263,7 +264,6 @@ FFStream::FFStream(FFMPEG *ffmpeg, AVStream *st, int fidx) seek_pos = curr_pos = 0; seeked = 1; eof = 0; reading = writing = 0; - hw_dev = 0; hw_pixfmt = AV_PIX_FMT_NONE; hw_device_ctx = 0; flushed = 0; @@ -1001,8 +1001,10 @@ FFVideoStream::~FFVideoStream() AVHWDeviceType FFVideoStream::decode_hw_activate() { AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE; - const char *hw_dev = getenv("CIN_HW_DEV"); - if( hw_dev ) { + const char *hw_dev = ffmpeg->opt_hw_dev; + if( !hw_dev ) hw_dev = getenv("CIN_HW_DEV"); + if( !hw_dev ) hw_dev = ffmpeg->ff_hw_dev(); + if( hw_dev && *hw_dev && strcmp(_("none"), hw_dev) ) { type = av_hwdevice_find_type_by_name(hw_dev); if( type == AV_HWDEVICE_TYPE_NONE ) { fprintf(stderr, "Device type %s is not supported.\n", hw_dev); @@ -1243,7 +1245,8 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame * } AVPixelFormat pix_fmt = (AVPixelFormat)ip->format; - if( pix_fmt == ((FFVideoStream *)this)->hw_pixfmt ) { + FFVideoStream *vid =(FFVideoStream *)this; + if( pix_fmt == vid->hw_pixfmt ) { int ret = 0; if( !sw_frame && !(sw_frame=av_frame_alloc()) ) ret = AVERROR(ENOMEM); @@ -1253,7 +1256,8 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame * pix_fmt = (AVPixelFormat)ip->format; } if( ret < 0 ) { - ff_err(ret, "Error retrieving data from GPU to CPU\n"); + eprintf(_("Error retrieving data from GPU to CPU\nfile: %s\n"), + vid->ffmpeg->fmt_ctx->url); return -1; } } @@ -1267,7 +1271,8 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame * int ret = sws_scale(convert_ctx, ip->data, ip->linesize, 0, ip->height, ipic->data, ipic->linesize); if( ret < 0 ) { - ff_err(ret, "FFVideoConvert::convert_picture_frame: sws_scale() failed\n"); + ff_err(ret, "FFVideoConvert::convert_picture_frame: sws_scale() failed\nfile: %s\n", + vid->ffmpeg->fmt_ctx->url); return -1; } return 0; @@ -1446,6 +1451,7 @@ FFMPEG::FFMPEG(FileBase *file_base) opt_duration = -1; opt_video_filter = 0; opt_audio_filter = 0; + opt_hw_dev = 0; fflags = 0; char option_path[BCTEXTLEN]; set_option_path(option_path, "%s", "ffmpeg.opts"); @@ -1465,6 +1471,7 @@ FFMPEG::~FFMPEG() av_dict_free(&opts); delete [] opt_video_filter; delete [] opt_audio_filter; + delete [] opt_hw_dev; } int FFMPEG::check_sample_rate(AVCodec *codec, int sample_rate) @@ -1910,6 +1917,8 @@ int FFMPEG::read_options(FILE *fp, const char *options, AVDictionary *&opts) opt_video_filter = cstrdup(val); else if( !strcmp(key, "audio_filter") ) opt_audio_filter = cstrdup(val); + else if( !strcmp(key, "cin_hw_dev") ) + opt_hw_dev = cstrdup(val); else if( !strcmp(key, "loglevel") ) set_loglevel(val); else @@ -3002,6 +3011,11 @@ int FFMPEG::ff_cpus() return file_base->file->cpus; } +const char *FFMPEG::ff_hw_dev() +{ + return &file_base->file->preferences->use_hw_dev[0]; +} + int FFVideoStream::create_filter(const char *filter_spec, AVCodecParameters *avpar) { avfilter_register_all(); diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h index 9656bf39..15659944 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.h +++ b/cinelerra-5.1/cinelerra/ffmpeg.h @@ -132,7 +132,6 @@ public: int reading, writing; int seeked, eof; - const char *hw_dev; int hw_pixfmt; AVBufferRef *hw_device_ctx; @@ -326,6 +325,7 @@ public: double opt_duration; char *opt_video_filter; char *opt_audio_filter; + char *opt_hw_dev; char file_format[BCTEXTLEN]; int fflags; @@ -388,6 +388,7 @@ public: int ff_video_mpeg_color_range(int stream); int ff_cpus(); + const char *ff_hw_dev(); void dump_context(AVCodecContext *ctx); }; diff --git a/cinelerra-5.1/cinelerra/performanceprefs.C b/cinelerra-5.1/cinelerra/performanceprefs.C index 5c35553f..cb19f905 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.C +++ b/cinelerra-5.1/cinelerra/performanceprefs.C @@ -73,6 +73,11 @@ void PerformancePrefs::create_objects() int y0 = y; win = add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default)); maxw = win->get_w(); + int x1 = x + xmargin4; + win = add_subwindow(new BC_Title(x1, y + 5, _("Use HW Device:"))); + x1 += win->get_w() + 5; + PrefsUseHWDev *use_hw_dev = new PrefsUseHWDev(pwindow, this, x1, y); + use_hw_dev->create_objects(); int y1 = y += 30; win = add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:"))); @@ -88,11 +93,11 @@ void PerformancePrefs::create_objects() preroll->create_objects(); y += 30; - int x1 = x + xmargin4; + x1 = x + xmargin4; BC_Title *smp_title = new BC_Title(x1, y + 5, _("Project SMP cpus:")); add_subwindow(smp_title); - int x2 = x1 + smp_title->get_w() + 5; - PrefsProjectSMP *proj_smp = new PrefsProjectSMP(pwindow, this, x2, y); + x1 += smp_title->get_w() + 5; + PrefsProjectSMP *proj_smp = new PrefsProjectSMP(pwindow, this, x1, y); proj_smp->create_objects(); PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y); @@ -317,6 +322,31 @@ int CICacheSize::handle_event() } +PrefsUseHWDev::PrefsUseHWDev(PreferencesWindow *pwindow, + PerformancePrefs *subwindow, int x, int y) + : BC_PopupTextBox(subwindow,0,0,x,y,100,80,LISTBOX_TEXT) +{ + this->pwindow = pwindow; +} + +void PrefsUseHWDev::create_objects() +{ + BC_PopupTextBox::create_objects(); + hw_dev_names.append(new BC_ListBoxItem(_("none"))); + hw_dev_names.append(new BC_ListBoxItem("vaapi")); + hw_dev_names.append(new BC_ListBoxItem("vdpau")); + hw_dev_names.append(new BC_ListBoxItem("")); + update_list(&hw_dev_names); + update(&pwindow->thread->preferences->use_hw_dev[0]); +} + +int PrefsUseHWDev::handle_event() +{ + strncpy(&pwindow->thread->preferences->use_hw_dev[0], + get_text(), sizeof(pwindow->thread->preferences->use_hw_dev)); + return 1; +} + PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, diff --git a/cinelerra-5.1/cinelerra/performanceprefs.h b/cinelerra-5.1/cinelerra/performanceprefs.h index 61d43a5d..3e00f9d8 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.h +++ b/cinelerra-5.1/cinelerra/performanceprefs.h @@ -46,6 +46,7 @@ public: int hot_node; CICacheSize *cache_size; + PerfsUseHWDev *use_hw_dev; enum { @@ -337,5 +338,17 @@ public: PreferencesWindow *pwindow; }; +class PrefsUseHWDev : public BC_PopupTextBox +{ +public: + PrefsUseHWDev(PreferencesWindow *pwindow, + PerformancePrefs *subwindow, int x, int y); + void create_objects(); + int handle_event(); + + PreferencesWindow *pwindow; + ArrayList hw_dev_names; +}; + #endif diff --git a/cinelerra-5.1/cinelerra/performanceprefs.inc b/cinelerra-5.1/cinelerra/performanceprefs.inc index db081535..f034704c 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.inc +++ b/cinelerra-5.1/cinelerra/performanceprefs.inc @@ -44,5 +44,6 @@ class PrefsRenderFarmSortNodes; class PrefsRenderFarmReset; class PrefsRenderFarmWatchdog; class CICacheSize; +class PerfsUseHWDev; #endif diff --git a/cinelerra-5.1/cinelerra/preferences.C b/cinelerra-5.1/cinelerra/preferences.C index 6e7ffc91..75768b65 100644 --- a/cinelerra-5.1/cinelerra/preferences.C +++ b/cinelerra-5.1/cinelerra/preferences.C @@ -86,6 +86,7 @@ Preferences::Preferences() project_smp = processors = calculate_processors(0); real_processors = calculate_processors(1); ffmpeg_marker_indexes = 1; + memset(&use_hw_dev, 0, sizeof(use_hw_dev)); warn_indexes = 1; warn_version = 1; bd_warn_root = 1; @@ -205,6 +206,7 @@ void Preferences::copy_from(Preferences *that) processors = that->processors; real_processors = that->real_processors; ffmpeg_marker_indexes = that->ffmpeg_marker_indexes; + strcpy(use_hw_dev, &that->use_hw_dev[0]); warn_indexes = that->warn_indexes; warn_version = that->warn_version; bd_warn_root = that->bd_warn_root; @@ -346,6 +348,8 @@ int Preferences::load_defaults(BC_Hash *defaults) project_smp = defaults->get("PROJECT_SMP", project_smp); force_uniprocessor = defaults->get("FORCE_UNIPROCESSOR", force_uniprocessor); ffmpeg_marker_indexes = defaults->get("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes); + memset(&use_hw_dev, 0, sizeof(use_hw_dev)); + defaults->get("USE_HW_DEV", use_hw_dev); warn_indexes = defaults->get("WARN_INDEXES", warn_indexes); warn_version = defaults->get("WARN_VERSION", warn_version); bd_warn_root = defaults->get("BD_WARN_ROOT", bd_warn_root); @@ -487,6 +491,7 @@ int Preferences::save_defaults(BC_Hash *defaults) defaults->update("PROJECT_SMP", project_smp); defaults->update("FORCE_UNIPROCESSOR", force_uniprocessor); defaults->update("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes); + defaults->update("USE_HW_DEV", use_hw_dev); defaults->update("WARN_INDEXES", warn_indexes); defaults->update("WARN_VERSION", warn_version); defaults->update("BD_WARN_ROOT", bd_warn_root); diff --git a/cinelerra-5.1/cinelerra/preferences.h b/cinelerra-5.1/cinelerra/preferences.h index 7f63bced..6a8f174a 100644 --- a/cinelerra-5.1/cinelerra/preferences.h +++ b/cinelerra-5.1/cinelerra/preferences.h @@ -112,6 +112,8 @@ public: int real_processors; // ffmpeg builds marker indexes as it builds idx files int ffmpeg_marker_indexes; +// ffmpeg hw_dev driver probe name + char use_hw_dev[BCSTRLEN]; // warning int warn_indexes; int warn_version;