]> git.sesse.net Git - nageru/commitdiff
Allow changing FFmpeg URL from the context menu.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 23 Apr 2018 18:09:04 +0000 (20:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 23 Apr 2018 18:09:04 +0000 (20:09 +0200)
ffmpeg_capture.cpp
ffmpeg_capture.h
glwidget.cpp
mixer.cpp
mixer.h

index a0904dc3eb2f48881152cce24152274455eb1693..b7db50c5513beea1376b70031d608cab6059c154 100644 (file)
@@ -282,9 +282,15 @@ void FFmpegCapture::producer_thread_func()
        pthread_setname_np(pthread_self(), thread_name);
 
        while (!producer_thread_should_quit.should_quit()) {
-               string pathname = search_for_file(filename);
-               if (filename.empty()) {
-                       fprintf(stderr, "%s not found, sleeping one second and trying again...\n", filename.c_str());
+               string filename_copy;
+               {
+                       lock_guard<mutex> lock(filename_mu);
+                       filename_copy = filename;
+               }
+
+               string pathname = search_for_file(filename_copy);
+               if (pathname.empty()) {
+                       fprintf(stderr, "%s not found, sleeping one second and trying again...\n", filename_copy.c_str());
                        send_disconnected_frame();
                        producer_thread_should_quit.sleep_for(seconds(1));
                        continue;
index 336f6bd253ae25945843d672eae7c1bda915091b..8a513df971fa20f2cba71e25ac603242b9be3be3 100644 (file)
@@ -77,6 +77,19 @@ public:
                producer_thread_should_quit.wakeup();
        }
 
+       std::string get_filename() const
+       {
+               std::lock_guard<std::mutex> lock(filename_mu);
+               return filename;
+       }
+
+       void change_filename(const std::string &new_filename)
+       {
+               std::lock_guard<std::mutex> lock(filename_mu);
+               filename = new_filename;
+               should_interrupt = true;
+       }
+
        // Will stop the stream even if it's hung on blocking I/O.
        void disconnect()
        {
@@ -215,6 +228,7 @@ private:
        static int interrupt_cb_thunk(void *unique);
        int interrupt_cb();
 
+       mutable std::mutex filename_mu;
        std::string description, filename;
        uint16_t timecode = 0;
        unsigned width, height;
index 7caee374becc777d2af42575d58427bac5848d6b..c3e82dacc07b5e9827ea66e218c5023628dbfcfd 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <QAction>
 #include <QActionGroup>
+#include <QInputDialog>
 #include <QList>
 #include <QMenu>
 #include <QPoint>
@@ -239,7 +240,15 @@ void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos)
        // --- The choices in the next few options depend a lot on which card is active ---
 
        bool has_auto_mode = false;
-       if (!is_ffmpeg) {
+       QAction *change_url_action = nullptr;
+       if (is_ffmpeg) {
+               // Add a menu to change the source URL if we're an FFmpeg card.
+               // (The theme can still override.)
+               if (global_mixer->card_is_ffmpeg(current_card)) {
+                       change_url_action = new QAction("Change source filename/URL…", &menu);
+                       menu.addAction(change_url_action);
+               }
+       } else {
                // Add a submenu for selecting video input, with an action for each input.
                QMenu video_input_submenu;
                QActionGroup video_input_group(&video_input_submenu);
@@ -341,6 +350,17 @@ void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos)
        QAction *selected_item = menu.exec(global_pos);
        if (audio_source_action != nullptr && selected_item == audio_source_action) {
                global_audio_mixer->set_simple_input(current_card);
+       } else if (change_url_action != nullptr && selected_item == change_url_action) {
+               // NOTE: We can't use “this” as parent, since the dialog would inherit our style sheet.
+               bool ok;
+               const string url = global_mixer->get_ffmpeg_filename(current_card);
+               QString new_url = QInputDialog::getText(window(), tr("Change URL"),
+                       tr("Enter new filename/URL for the given video input:"), QLineEdit::Normal,
+                               QString::fromStdString(url), &ok);
+               // FIXME prefill the input
+               if (ok) {
+                       global_mixer->set_ffmpeg_filename(current_card, new_url.toStdString());
+               }
        } else if (selected_item == master_clock_action) {
                global_mixer->set_master_clock(signal_num);
        } else if (selected_item != nullptr) {
index 73a59d5a3a0745b60e5e327cb866895f30f3ac11..5cee30005faee349e8023396b9cd5f98d5072316 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -1587,6 +1587,17 @@ map<uint32_t, VideoMode> Mixer::get_available_output_video_modes() const
        return cards[desired_output_card_index].output->get_available_video_modes();
 }
 
+string Mixer::get_ffmpeg_filename(unsigned card_index) const
+{
+       assert(card_index >= num_cards && card_index < num_cards + num_video_inputs);
+       return ((FFmpegCapture *)(cards[card_index].capture.get()))->get_filename();
+}
+
+void Mixer::set_ffmpeg_filename(unsigned card_index, const string &filename) {
+       assert(card_index >= num_cards && card_index < num_cards + num_video_inputs);
+       ((FFmpegCapture *)(cards[card_index].capture.get()))->change_filename(filename);
+}
+
 Mixer::OutputChannel::~OutputChannel()
 {
        if (has_current_frame) {
diff --git a/mixer.h b/mixer.h
index 03a51636a2cee982c9b46bb643921c2fe77cffde..5a3e203dc9dc0dd5f02c6eb2c100364313521291 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -374,6 +374,10 @@ public:
                cards[card_index].capture->set_audio_input(input);
        }
 
+       std::string get_ffmpeg_filename(unsigned card_index) const;
+
+       void set_ffmpeg_filename(unsigned card_index, const std::string &filename);
+
        void change_x264_bitrate(unsigned rate_kbit) {
                video_encoder->change_x264_bitrate(rate_kbit);
        }