|
From: Tapio V. <aa...@us...> - 2010-08-12 15:40:10
|
Module: performous
Branch: portaudio
Commit: 50f43a7b2d262320ca55ae2654e4cc539ee2b0af
Author: Tapio Vierros <tap...@gm...>
Date: Wed Aug 11 19:02:48 2010 +0300
Allow configuring which webcam to use.
---
data/schema.xml | 7 +++++++
game/screen_sing.cc | 4 ++--
game/webcam.cc | 12 +++++++++---
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 1eea68e..2352133 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -124,6 +124,13 @@ to save the current settings to XML.
<long>Performous can try to use webcam as a background video. You can disable it if it annoys you.</long>
</locale>
</entry>
+ <entry name="graphic/webcamid" type="int" value="-1">
+ <limits min="-1" max="9" step="1" />
+ <locale name="C">
+ <short>Webcam id</short>
+ <long>Use -1 to autodetect or a number starting from 0 to choose specific device.</long>
+ </locale>
+ </entry>
<entry name="graphic/3d_notes" type="bool" value="true">
<locale name="C">
<short>3D notes</short>
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index dd822f3..e4ea994 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -59,7 +59,7 @@ void ScreenSing::enter() {
}
// Initialize webcam
if (config["graphic/webcam"].b() && Webcam::enabled()) {
- m_cam.reset(new Webcam());
+ m_cam.reset(new Webcam(config["graphic/webcamid"].i()));
}
// Load video
if (!m_song->video.empty() && config["graphic/video"].b()) {
@@ -253,7 +253,7 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_w) dispInFlash(++config["game/pitch"]); // Toggle pitch wave
// Toggle webcam
if (key == SDLK_a && Webcam::enabled()) {
- if (!m_cam) m_cam.reset(new Webcam()); // Initialize if we haven't done that already
+ if (!m_cam) m_cam.reset(new Webcam(config["graphic/webcamid"].i())); // Initialize if we haven't done that already
if (m_cam) { dispInFlash(++config["graphic/webcam"]); m_cam->pause(!config["graphic/webcam"].b()); }
}
// Latency settings
diff --git a/game/webcam.cc b/game/webcam.cc
index e29ca66..aff3c8a 100644
--- a/game/webcam.cc
+++ b/game/webcam.cc
@@ -18,8 +18,14 @@ Webcam::Webcam(int cam_id):
// Initialize the capture device
m_capture = cvCaptureFromCAM(cam_id);
if (!m_capture) {
- std::cout << "Could not initialize webcam capturing!" << std::endl;
- return;
+ if (cam_id != -1) {
+ std::cout << "Webcam id " << cam_id << " failed, trying autodetecting...";
+ m_capture = cvCaptureFromCAM(-1);
+ }
+ if (!m_capture) {
+ std::cout << "Could not initialize webcam capturing!" << std::endl;
+ return;
+ }
}
// Initialize the video writer
#ifdef SAVE_WEBCAM_VIDEO
@@ -27,7 +33,7 @@ Webcam::Webcam(int cam_id):
int framew = cvGetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_WIDTH);
int frameh = cvGetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_HEIGHT);
int codec = CV_FOURCC('P','I','M','1'); // MPEG-1
- std::string out_file((getHomeDir() / std::string("/performous-webcam_out.mpg")).string());
+ std::string out_file((getHomeDir() / std::string("performous-webcam_out.mpg")).string());
m_writer = cvCreateVideoWriter(out_file.c_str(), codec, fps > 0 ? fps : 30.0f, cvSize(framew,frameh));
if (!m_writer) std::cout << "Could not initialize webcam video saving!" << std::endl;
#endif
|