CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxVLCRecorder.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include <cxVLCRecorder.h>
34 
35 #include <QFileInfo>
36 
37 #include <QProcess>
38 #include "cxLogger.h"
39 
40 namespace cx
41 {
42 
43 VLCRecorder* VLCRecorder::mTheInstance = NULL;
45 
47 {
48  if(mTheInstance == NULL)
49  {
50  mTheInstance = new VLCRecorder();
51  }
52  return mTheInstance;
53 }
54 
56 {
58 }
59 
61 {
62  delete mTheInstance;
63  mTheInstance = NULL;
64 }
65 
66 VLCRecorder::VLCRecorder() :
67  mCommandLine(new ProcessWrapper("VLC")), mVLCPath("")
68 {
69  this->findVLCApplication();
70 }
71 
72 VLCRecorder::~VLCRecorder()
73 {}
74 
76 {
77  return QFile::exists(mVLCPath);
78 }
79 
80 void VLCRecorder::findVLCApplication(QStringList suggestedVLCLocations)
81 {
82  suggestedVLCLocations.push_front(this->getVLCDefaultLocation());
83  foreach(QString path, suggestedVLCLocations)
84  {
85  if(this->isValidVLC(path))
86  {
87  this->setVLCPath(path);
88  return;
89  }
90  }
91 }
92 
94 {
95  return mCommandLine->isRunning();
96 }
97 
99 {
100  return mCommandLine->waitForStarted(msecs);
101 }
102 
104 {
105  return mCommandLine->waitForFinished(msecs);
106 }
107 
109 {
110  return mVLCPath;
111 }
112 
113 void VLCRecorder::startRecording(QString saveFile)
114 {
115  if(this->hasVLCApplication())
116  mCommandLine->launch("\""+mVLCPath+"\""+this->getVLCDefaultRecorderArguments(saveFile));
117  else
118  reportError("VLC not found.");
119 }
120 
122 {
123  QString quit = "quit\n";
124  mCommandLine->write(quit.toStdString().c_str());
125 }
126 
127 void VLCRecorder::setVLCPath(QString path)
128 {
129  mVLCPath = path;
130  report("Found valid VLC application: "+mVLCPath);
131 }
132 
133 bool VLCRecorder::isValidVLC(QString vlcPath)
134 {
135  QFileInfo info(vlcPath);
136  if(info.exists() && !QString::compare(info.baseName(), "vlc", Qt::CaseInsensitive))
137  return true;
138  return false;
139 }
140 
141 QString VLCRecorder::getVLCDefaultLocation()
142 {
143  QString defaultLocation("");
144 #ifdef CX_WINDOWS
145  defaultLocation = "C:/Program Files (x86)/VideoLAN/VLC/vlc.exe";
146 #endif
147 #ifdef CX_APPLE
148  defaultLocation = "/Applications/VLC.app/Contents/MacOS/VLC";
149 #endif
150 #ifdef CX_LINUX
151  defaultLocation = "/usr/bin/vlc";
152 #endif
153  return defaultLocation;
154 }
155 
156 QString VLCRecorder::getVLCDefaultRecorderArguments(QString saveFile)
157 {
158  QString defaultArguements("");
159 #ifdef CX_WINDOWS
160  saveFile = saveFile.replace("/", "\\");
161  defaultArguements = " -I luacli screen:// :screen-fps=10.000000 :live-caching=300 :sout=#transcode{vcodec=h264,acodec=none}:file{dst="+saveFile+"} :sout-keep ";
162 #endif
163 #ifdef CX_APPLE
164  defaultArguements = " -I cli screen:// \":sout=#transcode{vcodec=h264,vb=800,fps=10,scale=1,acodec=none}:duplicate{dst=standard{access=file,mux=mp4,dst="+saveFile+"}}\"";
165 #endif
166 #ifdef CX_LINUX
167  defaultArguements = " -I cli screen:// :screen-fps=10.000000 :live-caching=300 \":sout=#transcode{vcodec=h264,vb=0,fps=10,scale=0,acodec=none}:file{dst="+saveFile+"}\" :sout-keep";
168 #endif
169  return defaultArguements;
170 }
171 
172 } /* namespace cx */
static VLCRecorder * getInstance()
bool waitForFinished(int msecs=30000)
void reportError(QString msg)
Definition: cxLogger.cpp:92
Lets you use the third party application VLC to record a video of the screen.
Definition: cxVLCRecorder.h:63
bool waitForStarted(int msecs=30000)
void startRecording(QString saveFile)
static void initialize()
static void shutdown()
void findVLCApplication(QStringList suggestedVLCLocations=QStringList())
void report(QString msg)
Definition: cxLogger.cpp:90
bool hasVLCApplication()
QString getVLCPath()
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.