CustusX  22.04-rc5
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include <cxVLCRecorder.h>
13 
14 #include <QFileInfo>
15 
16 #include <QProcess>
17 #include "cxLogger.h"
18 
19 namespace cx
20 {
21 
22 VLCRecorder* VLCRecorder::mTheInstance = NULL;
24 
26 {
27  if(mTheInstance == NULL)
28  {
29  mTheInstance = new VLCRecorder();
30  }
31  return mTheInstance;
32 }
33 
35 {
37 }
38 
40 {
41  delete mTheInstance;
42  mTheInstance = NULL;
43 }
44 
45 VLCRecorder::VLCRecorder() :
46  mCommandLine(new ProcessWrapper("VLC")), mVLCPath("")
47 {
48  connect(mCommandLine->getProcess(), &QProcess::stateChanged, this, &VLCRecorder::stateChanged);
49  this->findVLCApplication();
50 }
51 
52 VLCRecorder::~VLCRecorder()
53 {}
54 
56 {
57  return QFile::exists(mVLCPath);
58 }
59 
60 void VLCRecorder::findVLCApplication(QStringList suggestedVLCLocations)
61 {
62  suggestedVLCLocations.push_front(this->getVLCDefaultLocation());
63  foreach(QString path, suggestedVLCLocations)
64  {
65  if(this->isValidVLC(path))
66  {
67  this->setVLCPath(path);
68  return;
69  }
70  }
71 }
72 
74 {
75  return mCommandLine->isRunning();
76 }
77 
79 {
80  return mCommandLine->waitForStarted(msecs);
81 }
82 
84 {
85  return mCommandLine->waitForFinished(msecs);
86 }
87 
89 {
90  return mVLCPath;
91 }
92 
93 void VLCRecorder::startRecording(QString saveFile)
94 {
95  if(this->hasVLCApplication())
96  mCommandLine->launch("\""+mVLCPath+"\""+this->getVLCDefaultRecorderArguments(saveFile));
97  else
98  reportError("VLC not found.");
99 }
100 
102 {
103  QString quit = "quit\n";
104  mCommandLine->write(quit.toStdString().c_str());
105 }
106 
107 void VLCRecorder::setVLCPath(QString path)
108 {
109  mVLCPath = path;
110  report("Found valid VLC application: "+mVLCPath);
111 }
112 
113 bool VLCRecorder::isValidVLC(QString vlcPath)
114 {
115  QFileInfo info(vlcPath);
116  if(info.exists() && !QString::compare(info.baseName(), "vlc", Qt::CaseInsensitive))
117  return true;
118  return false;
119 }
120 
121 QString VLCRecorder::getVLCDefaultLocation()
122 {
123  QString defaultLocation("");
124 #ifdef CX_WINDOWS
125  defaultLocation = "C:/Program Files (x86)/VideoLAN/VLC/vlc.exe";
126 #endif
127 #ifdef CX_APPLE
128  defaultLocation = "/Applications/VLC.app/Contents/MacOS/VLC";
129 #endif
130 #ifdef CX_LINUX
131  defaultLocation = "/usr/bin/vlc";
132 #endif
133  return defaultLocation;
134 }
135 
136 QString VLCRecorder::getVLCDefaultRecorderArguments(QString saveFile)
137 {
138  QString defaultArguements("");
139 #ifdef CX_WINDOWS
140  saveFile = saveFile.replace("/", "\\");
141  defaultArguements = " -I luacli screen:// :screen-fps=10.000000 :live-caching=300 :sout=#transcode{vcodec=h264,acodec=none}:file{dst="+saveFile+"} :sout-keep ";
142 #endif
143 #ifdef CX_APPLE
144  CX_LOG_WARNING("VLC 2.2.1 fails on Mac. VLC version 2.1.2 works.");
145  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+"}}\"";
146 #endif
147 #ifdef CX_LINUX
148  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";
149 #endif
150  return defaultArguements;
151 }
152 
153 } /* namespace cx */
static VLCRecorder * getInstance()
bool waitForFinished(int msecs=30000)
void reportError(QString msg)
Definition: cxLogger.cpp:71
Lets you use the third party application VLC to record a video of the screen.
Definition: cxVLCRecorder.h:42
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:69
bool compare(T1 const &lhs, T2 const &rhs)
Definition: catch.hpp:1060
bool hasVLCApplication()
QString getVLCPath()
#define CX_LOG_WARNING
Definition: cxLogger.h:98
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.
Namespace for all CustusX production code.