add hw_dev preference, opts file var, tweak hw GPU xfer err msg
authorGood Guy <good1.2guy@gmail.com>
Sat, 4 May 2019 02:48:21 +0000 (20:48 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sat, 4 May 2019 02:48:21 +0000 (20:48 -0600)
cinelerra-5.1/cinelerra/ffmpeg.C
cinelerra-5.1/cinelerra/ffmpeg.h
cinelerra-5.1/cinelerra/performanceprefs.C
cinelerra-5.1/cinelerra/performanceprefs.h
cinelerra-5.1/cinelerra/performanceprefs.inc
cinelerra-5.1/cinelerra/preferences.C
cinelerra-5.1/cinelerra/preferences.h

index b22f993578105b15cb8b3738d5557c4280c2de64..9f13ec0d3cf8c5593bf04cf366ff9c9dcfa7d2c9 100644 (file)
@@ -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();
index 9656bf3970914db5ab27dee24dc2d91188bec8bf..15659944c9b3ef57ae599e2eac3527099b438db0 100644 (file)
@@ -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);
 };
 
index 5c35553f1d9f5c93e7aaadf690ee822cde8920da..cb19f905672c1664f54e5e52edcbf78b93b2f5f0 100644 (file)
@@ -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,
index 61d43a5d49cfe1891dab260e603ac853c68b12b5..3e00f9d8e828cb6269441d7865e29033f9ccf1db 100644 (file)
@@ -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<BC_ListBoxItem *> hw_dev_names;
+};
+
 
 #endif
index db081535d91bc7e8462b7a1377c72da01e8cd30d..f034704c535b17178a8d283270f5a2ecc59142d9 100644 (file)
@@ -44,5 +44,6 @@ class PrefsRenderFarmSortNodes;
 class PrefsRenderFarmReset;
 class PrefsRenderFarmWatchdog;
 class CICacheSize;
+class PerfsUseHWDev;
 
 #endif
index 6e7ffc914d72f2a3bc33c9737cbc81f84a27dcd0..75768b65ea42e4afe925b7548a81891d2ac1e692 100644 (file)
@@ -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);
index 7f63bcedcd43867520ed40ff9c7341b06e730ff3..6a8f174a3933791b37d39b8f72fdc170d7318a49 100644 (file)
@@ -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;