]> git.sesse.net Git - nageru/blobdiff - input_mapping.cpp
Release Nageru 1.7.2.
[nageru] / input_mapping.cpp
index 4b28a592dec5b8c7d9b4cc865e81c9361067573e..45b60095e5af99cadecb01cb88389478974d5cc7 100644 (file)
@@ -1,18 +1,40 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include "input_mapping.h"
 
-#include <google/protobuf/text_format.h>
-#include <google/protobuf/io/zero_copy_stream.h>
+#include <assert.h>
+#include <fcntl.h>
 #include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/text_format.h>
+#include <stdio.h>
+#include <set>
+#include <utility>
 
 #include "audio_mixer.h" 
-#include "input_mapping.h"
 #include "state.pb.h"
 
 using namespace std;
 using namespace google::protobuf;
 
+string spec_to_string(DeviceSpec device_spec)
+{
+       char buf[256];
+
+       switch (device_spec.type) {
+       case InputSourceType::SILENCE:
+               return "<silence>";
+       case InputSourceType::CAPTURE_CARD:
+               snprintf(buf, sizeof(buf), "Capture card %u", device_spec.index);
+               return buf;
+       case InputSourceType::ALSA_INPUT:
+               snprintf(buf, sizeof(buf), "ALSA input %u", device_spec.index);
+               return buf;
+       case InputSourceType::FFMPEG_VIDEO_INPUT:
+               snprintf(buf, sizeof(buf), "FFmpeg input %u", device_spec.index);
+               return buf;
+       default:
+               assert(false);
+       }
+}
+
 bool save_input_mapping_to_file(const map<DeviceSpec, DeviceInfo> &devices, const InputMapping &input_mapping, const string &filename)
 {
        InputMappingProto mapping_proto;
@@ -84,10 +106,15 @@ bool load_input_mapping_from_file(const map<DeviceSpec, DeviceInfo> &devices, co
                case DeviceSpecProto::SILENCE:
                        device_mapping.push_back(DeviceSpec{InputSourceType::SILENCE, 0});
                        break;
+               case DeviceSpecProto::FFMPEG_VIDEO_INPUT:
                case DeviceSpecProto::CAPTURE_CARD: {
                        // First see if there's a card that matches on both index and name.
-                       DeviceSpec spec{InputSourceType::CAPTURE_CARD, unsigned(device_proto.index())};
+                       DeviceSpec spec;
+                       spec.type = (device_proto.type() == DeviceSpecProto::CAPTURE_CARD) ?
+                               InputSourceType::CAPTURE_CARD : InputSourceType::FFMPEG_VIDEO_INPUT;
+                       spec.index = unsigned(device_proto.index());
                        assert(devices.count(spec));
+
                        const DeviceInfo &dev = devices.find(spec)->second;
                        if (remaining_devices.count(spec) &&
                            dev.display_name == device_proto.display_name()) {