mirror of
https://github.com/vale981/Taevitas
synced 2025-03-04 17:11:40 -05:00
A bit more refactoring.
This commit is contained in:
parent
a5dc215ffb
commit
7e07d7b954
5 changed files with 107 additions and 99 deletions
|
@ -57,38 +57,6 @@ void CameraManager::connectCamera( int index ) {
|
|||
camera_index = index;
|
||||
}
|
||||
|
||||
void CameraManager::camConnectEvent( void * pParameter, unsigned int serialNumber ) {
|
||||
static_cast<CameraManager *>( pParameter )->cameraConnected();
|
||||
}
|
||||
|
||||
void CameraManager::camDisconnectEvent( void * pParameter, unsigned int serialNumber ) {
|
||||
CameraManager * cam = static_cast<CameraManager *>( pParameter );
|
||||
FlyCapture2::CameraInfo info;
|
||||
|
||||
cam->camera.GetCameraInfo( &info );
|
||||
bool current = ( serialNumber == info.serialNumber );
|
||||
|
||||
cam->cameraDisconnected( current );
|
||||
}
|
||||
|
||||
void CameraManager::stopCapture() {
|
||||
if ( !is_capturing )
|
||||
return;
|
||||
|
||||
grabber->stopCapturing();
|
||||
|
||||
Error error = camera.StopCapture();
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
grabber->wait();
|
||||
|
||||
|
||||
is_capturing = false;
|
||||
}
|
||||
|
||||
void CameraManager::startCapture() {
|
||||
// Don't capture twice!
|
||||
if ( is_capturing )
|
||||
|
@ -113,3 +81,35 @@ void CameraManager::startCapture() {
|
|||
grabber = tmpG;
|
||||
is_capturing = true;
|
||||
}
|
||||
|
||||
void CameraManager::stopCapture() {
|
||||
if ( !is_capturing )
|
||||
return;
|
||||
|
||||
grabber->stopCapturing();
|
||||
|
||||
Error error = camera.StopCapture();
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
grabber->wait();
|
||||
|
||||
|
||||
is_capturing = false;
|
||||
}
|
||||
|
||||
void CameraManager::camConnectEvent( void * pParameter, unsigned int serialNumber ) {
|
||||
static_cast<CameraManager *>( pParameter )->cameraConnected();
|
||||
}
|
||||
|
||||
void CameraManager::camDisconnectEvent( void * pParameter, unsigned int serialNumber ) {
|
||||
CameraManager * cam = static_cast<CameraManager *>( pParameter );
|
||||
FlyCapture2::CameraInfo info;
|
||||
|
||||
cam->camera.GetCameraInfo( &info );
|
||||
bool current = ( serialNumber == info.serialNumber );
|
||||
|
||||
cam->cameraDisconnected( current );
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ class CameraManager : public QObject {
|
|||
explicit CameraManager( QObject * parent = 0 );
|
||||
~CameraManager();
|
||||
|
||||
// Connect camera from index. Once successfull it emits the cameraConnected signal.
|
||||
// Emits Error signal in case of an error.
|
||||
void connectCamera( int );
|
||||
|
||||
// Starts capturing images. When an image has been captured, the signal frameCaptured is emited.
|
||||
// Throws FlyCapture2::Error
|
||||
void startCapture();
|
||||
|
@ -40,22 +44,24 @@ class CameraManager : public QObject {
|
|||
return num_cameras;
|
||||
}
|
||||
|
||||
// Connect camera from index. Once successfull it emits the cameraConnected signal.
|
||||
// Emits Error signal in case of an error.
|
||||
void connectCamera( int );
|
||||
|
||||
bool isCapturing() {
|
||||
return is_capturing;
|
||||
}
|
||||
|
||||
FlyCapture2::CallbackHandle handleC;
|
||||
FlyCapture2::CallbackHandle handleD;
|
||||
|
||||
private:
|
||||
FlyCapture2::Camera camera;
|
||||
FlyCapture2::FC2Config cam_config;
|
||||
FlyCapture2::BusManager bus_mgr;
|
||||
|
||||
FlyCapture2::CallbackHandle handleC;
|
||||
FlyCapture2::CallbackHandle handleD;
|
||||
|
||||
// Capture Thread
|
||||
ImageGrabber * grabber;
|
||||
|
||||
// Status Variable
|
||||
bool is_capturing;
|
||||
|
||||
unsigned int num_cameras;
|
||||
|
||||
// GUID of the camera, which is currently being used
|
||||
|
@ -64,12 +70,7 @@ class CameraManager : public QObject {
|
|||
// Index of the current camera
|
||||
int camera_index;
|
||||
|
||||
// State Variable
|
||||
bool is_capturing;
|
||||
|
||||
// Capture Thread
|
||||
ImageGrabber * grabber;
|
||||
|
||||
// Event Handlers
|
||||
static void camConnectEvent( void * pParameter, unsigned int serialNumber );
|
||||
static void camDisconnectEvent( void * pParameter, unsigned int serialNumber );
|
||||
|
||||
|
@ -77,6 +78,7 @@ class CameraManager : public QObject {
|
|||
void frameCaptured( FlyCapture2::Image * image ) const;
|
||||
void cameraConnected();
|
||||
void cameraDisconnected( bool current );
|
||||
|
||||
void captureError( FlyCapture2::Error err );
|
||||
};
|
||||
|
||||
|
|
|
@ -295,6 +295,9 @@ void MainWindow::startStopRecording() {
|
|||
return;
|
||||
}
|
||||
|
||||
// If changed through corrections.
|
||||
ui->projectName->setText( recorder.getRecName() );
|
||||
|
||||
if ( !camMan.isCapturing() ) {
|
||||
try {
|
||||
camMan.startCapture();
|
||||
|
|
|
@ -25,17 +25,6 @@ Recorder::~Recorder() {
|
|||
stopRecording();
|
||||
}
|
||||
|
||||
void Recorder::setProjectDir( QString &p_dir ) {
|
||||
QFileInfo pDirInfo( p_dir );
|
||||
if ( !pDirInfo.isDir() || !pDirInfo.isWritable() ) {
|
||||
throw RecorderError( RecorderError::INVALID_PROJECT_DIRECTORY );
|
||||
return;
|
||||
}
|
||||
|
||||
baseDir = QDir( p_dir );
|
||||
pDirSet = true;
|
||||
}
|
||||
|
||||
void Recorder::newRecording( QString r_name ) {
|
||||
stopRecording();
|
||||
|
||||
|
@ -99,6 +88,31 @@ void Recorder::newRecording( QString r_name ) {
|
|||
is_recording = true;
|
||||
}
|
||||
|
||||
void Recorder::stopRecording() {
|
||||
if ( is_recording ) {
|
||||
// Stop Recorder
|
||||
Error err = recorder.AVIClose();
|
||||
if ( err != PGRERROR_OK ) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
|
||||
is_recording = false;
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void Recorder::setProjectDir( QString &p_dir ) {
|
||||
QFileInfo pDirInfo( p_dir );
|
||||
if ( !pDirInfo.isDir() || !pDirInfo.isWritable() ) {
|
||||
throw RecorderError( RecorderError::INVALID_PROJECT_DIRECTORY );
|
||||
return;
|
||||
}
|
||||
|
||||
baseDir = QDir( p_dir );
|
||||
pDirSet = true;
|
||||
}
|
||||
|
||||
bool Recorder::restoreRecording() {
|
||||
bool ok;
|
||||
|
||||
|
@ -138,30 +152,6 @@ RecorderError Recorder::verifyRecDir() {
|
|||
return RecorderError( RecorderError::OK );
|
||||
}
|
||||
|
||||
void Recorder::stopRecording() {
|
||||
if ( is_recording ) {
|
||||
// Stop Recorder
|
||||
Error err = recorder.AVIClose();
|
||||
if ( err != PGRERROR_OK ) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
|
||||
is_recording = false;
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void Recorder::cleanup() {
|
||||
// Reset Everything
|
||||
if ( !is_recording ) {
|
||||
frame_n = 0;
|
||||
time_c = 0;
|
||||
append = false;
|
||||
delete statFile;
|
||||
}
|
||||
}
|
||||
|
||||
void Recorder::appendFrame( FlyCapture2::Image * image ) {
|
||||
write_lock.lock();
|
||||
qDebug() << "Writing Frame...";
|
||||
|
@ -199,3 +189,13 @@ void Recorder::appendFrame( FlyCapture2::Image * image ) {
|
|||
emit frameSaved( image );
|
||||
write_lock.unlock();
|
||||
}
|
||||
|
||||
void Recorder::cleanup() {
|
||||
// Reset Everything
|
||||
if ( !is_recording ) {
|
||||
frame_n = 0;
|
||||
time_c = 0;
|
||||
append = false;
|
||||
delete statFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,23 +68,31 @@ class Recorder : public QObject {
|
|||
// stops the recording, cleans up, throws FlyCapture2::Error
|
||||
void stopRecording();
|
||||
|
||||
void setProjectDir( QString &p_dir );
|
||||
QString getProjectDir() {
|
||||
return baseDir.absolutePath();
|
||||
}
|
||||
|
||||
QString getRecName() {
|
||||
return recName;
|
||||
}
|
||||
|
||||
bool isRecording() {
|
||||
return is_recording;
|
||||
}
|
||||
|
||||
int frameNumber() const {
|
||||
return frame_n;
|
||||
}
|
||||
|
||||
double timeCaptured() const {
|
||||
return time_c;
|
||||
}
|
||||
|
||||
QString getRecName() {
|
||||
return recName;
|
||||
}
|
||||
|
||||
unsigned int getFrameRate() {
|
||||
return options.frameRate;
|
||||
}
|
||||
|
||||
void setProjectDir( QString &p_dir );
|
||||
void setFrameRate( unsigned int frame_rate ) {
|
||||
options.frameRate = frame_rate;
|
||||
}
|
||||
|
@ -97,14 +105,6 @@ class Recorder : public QObject {
|
|||
return capture_frames;
|
||||
}
|
||||
|
||||
int frameNumber() const {
|
||||
return frame_n;
|
||||
}
|
||||
|
||||
double timeCaptured() const {
|
||||
return time_c;
|
||||
}
|
||||
|
||||
public slots:
|
||||
// Append a frame to the recording,
|
||||
void appendFrame( FlyCapture2::Image * image );
|
||||
|
@ -118,7 +118,14 @@ class Recorder : public QObject {
|
|||
FlyCapture2::AVIOption options;
|
||||
FlyCapture2::TIFFOption frame_options;
|
||||
|
||||
// Basic state Variable, because AVIRecorder doesn't provide it.
|
||||
// lock the appendFrame function.
|
||||
QMutex write_lock;
|
||||
|
||||
// Indicates wether the project directorie is set.
|
||||
bool pDirSet;
|
||||
|
||||
// basic state Variable, because AVIRecorder doesn't provide it.
|
||||
// Well it does, but it is boring to look it up.
|
||||
bool is_recording;
|
||||
|
||||
// append to existing files
|
||||
|
@ -131,6 +138,7 @@ class Recorder : public QObject {
|
|||
int frame_n;
|
||||
double time_c;
|
||||
|
||||
// recording config
|
||||
QDir baseDir;
|
||||
QDir record_dir;
|
||||
QString recName;
|
||||
|
@ -147,11 +155,6 @@ class Recorder : public QObject {
|
|||
// reset Status, only if not recording (is_recording == false).
|
||||
void cleanup();
|
||||
|
||||
// lock the appendFrame function.
|
||||
QMutex write_lock;
|
||||
|
||||
bool pDirSet;
|
||||
|
||||
signals:
|
||||
void frameSaved( FlyCapture2::Image * image );
|
||||
void writeError( FlyCapture2::Error err );
|
||||
|
|
Loading…
Add table
Reference in a new issue