diff options
Diffstat (limited to 'src/camera.cc')
-rw-r--r-- | src/camera.cc | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/camera.cc b/src/camera.cc index 0ba3da9..9e9fd82 100644 --- a/src/camera.cc +++ b/src/camera.cc @@ -34,13 +34,14 @@ Camera::Camera() void Camera::connect(const char *ip, const int port) { errorstatus = new Error(); + initialized = false; pthread_mutex_init (&mutex, NULL); //mutex = PTHREAD_MUTEX_INITIALIZER; - + /* AVFormatContext *ifmtctx; AVFormatContext *ofmtctx; - + */ running = 1; int channel = 0; @@ -63,8 +64,10 @@ void Camera::connect(const char *ip, const int port) player_queue, &mutex, &running); - // ifmtctx = decoder->fc; - if(!decoder->fc) return; + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (decoder)."); + return; + } encoder = new Encoder(errorstatus, ip, port, @@ -72,17 +75,38 @@ void Camera::connect(const char *ip, const int port) encode_queue, &mutex, &running); - ofmtctx = encoder->fc; + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (encoder)."); + return; + } player = new Player(errorstatus, &running, &player_sem, player_queue, &mutex); + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (player)."); + return; + } pthread_create (&decodetid, NULL, thread_run, decoder); + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (decoder thread)."); + return; + } pthread_create (&encodetid, NULL, thread_run, encoder); + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (encoder thread)."); + return; + } pthread_create (&playertid, NULL, thread_run, player); + if(errorstatus->hasError()) { + errorstatus->pushError("Camera initialization failed (player thread)."); + return; + } + + initialized = true; } Camera::~Camera() @@ -110,36 +134,46 @@ Camera::~Camera() void Camera::setCpr(char *newcpr) { - encoder->setCpr(newcpr); + if(initialized) encoder->setCpr(newcpr); + else errorstatus->pushError("Camera not initialized."); + } void Camera::start() { - encoder->start(); + if(initialized) encoder->start(); + else errorstatus->pushError("Camera not initialized."); } void Camera::stop() { - encoder->stop(); + if(initialized) encoder->stop(); + else errorstatus->pushError("Camera not initialized."); } void Camera::freeze() { // FIXME: Ensure they freeze the same frame, i.e. the player - // shows the same frame that is actually fronzen on the server. - player->stop(); - encoder->freeze(); + // shows the same frame that is actually frozen on the server. + if(initialized) { + player->stop(); + encoder->freeze(); + } else { + errorstatus->pushError("Camera not initialized."); + } } void Camera::unfreeze() { - player->start(); + if(initialized) player->start(); + else errorstatus->pushError("Camera not initialized."); } void Camera::snapshot() { - encoder->shoot(); + if(initialized) encoder->shoot(); + else errorstatus->pushError("Camera not initialized."); } Error *Camera::errorObject() |