Fraxinus  16.5.0-fx-rc9
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  connect(mCommandLine->getProcess(), &QProcess::stateChanged, this, &VLCRecorder::stateChanged);
70  this->findVLCApplication();
71 }
72 
73 VLCRecorder::~VLCRecorder()
74 {}
75 
77 {
78  return QFile::exists(mVLCPath);
79 }
80 
81 void VLCRecorder::findVLCApplication(QStringList suggestedVLCLocations)
82 {
83  suggestedVLCLocations.push_front(this->getVLCDefaultLocation());
84  foreach(QString path, suggestedVLCLocations)
85  {
86  if(this->isValidVLC(path))
87  {
88  this->setVLCPath(path);
89  return;
90  }
91  }
92 }
93 
95 {
96  return mCommandLine->isRunning();
97 }
98 
100 {
101  return mCommandLine->waitForStarted(msecs);
102 }
103 
105 {
106  return mCommandLine->waitForFinished(msecs);
107 }
108 
110 {
111  return mVLCPath;
112 }
113 
114 void VLCRecorder::startRecording(QString saveFile)
115 {
116  if(this->hasVLCApplication())
117  mCommandLine->launch("\""+mVLCPath+"\""+this->getVLCDefaultRecorderArguments(saveFile));
118  else
119  reportError("VLC not found.");
120 }
121 
123 {
124  QString quit = "quit\n";
125  mCommandLine->write(quit.toStdString().c_str());
126 }
127 
128 void VLCRecorder::setVLCPath(QString path)
129 {
130  mVLCPath = path;
131  report("Found valid VLC application: "+mVLCPath);
132 }
133 
134 bool VLCRecorder::isValidVLC(QString vlcPath)
135 {
136  QFileInfo info(vlcPath);
137  if(info.exists() && !QString::compare(info.baseName(), "vlc", Qt::CaseInsensitive))
138  return true;
139  return false;
140 }
141 
142 QString VLCRecorder::getVLCDefaultLocation()
143 {
144  QString defaultLocation("");
145 #ifdef CX_WINDOWS
146  defaultLocation = "C:/Program Files (x86)/VideoLAN/VLC/vlc.exe";
147 #endif
148 #ifdef CX_APPLE
149  defaultLocation = "/Applications/VLC.app/Contents/MacOS/VLC";
150 #endif
151 #ifdef CX_LINUX
152  defaultLocation = "/usr/bin/vlc";
153 #endif
154  return defaultLocation;
155 }
156 
157 QString VLCRecorder::getVLCDefaultRecorderArguments(QString saveFile)
158 {
159  QString defaultArguements("");
160 #ifdef CX_WINDOWS
161  saveFile = saveFile.replace("/", "\\");
162  defaultArguements = " -I luacli screen:// :screen-fps=10.000000 :live-caching=300 :sout=#transcode{vcodec=h264,acodec=none}:file{dst="+saveFile+"} :sout-keep ";
163 #endif
164 #ifdef CX_APPLE
165  CX_LOG_WARNING("VLC 2.2.1 fails on Mac. VLC version 2.1.2 works.");
166  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+"}}\"";
167 #endif
168 #ifdef CX_LINUX
169  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";
170 #endif
171  return defaultArguements;
172 }
173 
174 } /* 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()
#define CX_LOG_WARNING
Definition: cxLogger.h:113
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.