From 6a36015c99012637999d62e44c9dc5b84337ea9f Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Mon, 17 Dec 2018 16:37:46 -0500
Subject: [PATCH] video_input: fallback to default if no video

When streaming a file with no video (music, for example), fall back to
the default device instead of cutting video altogether.

Change-Id: I0b30abff5339a38c6e5ed6c3b65d2cf49fa9104a
---
 src/media/video/video_input.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/media/video/video_input.cpp b/src/media/video/video_input.cpp
index 620f490cbe..237235fa0b 100644
--- a/src/media/video/video_input.cpp
+++ b/src/media/video/video_input.cpp
@@ -488,6 +488,16 @@ VideoInput::initFile(std::string path)
         return false;
     }
 
+    // check if file has video, fall back to default device if none
+    // FIXME the way this is done is hackish, but it can't be done in createDecoder because that
+    // would break the promise returned in switchInput
+    DeviceParams p;
+    p.input = path;
+    auto dec = std::make_unique<MediaDecoder>();
+    if (dec->openInput(p) < 0 || dec->setupFromVideoData() < 0) {
+        return initCamera(ring::getVideoDeviceMonitor().getDefaultDevice());
+    }
+
     clearOptions();
     emulateRate_ = true;
     decOpts_.input = path;
-- 
GitLab