summaryrefslogtreecommitdiff
path: root/src/encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoder.cc')
-rw-r--r--src/encoder.cc93
1 files changed, 44 insertions, 49 deletions
diff --git a/src/encoder.cc b/src/encoder.cc
index ee60a8f..fc19921 100644
--- a/src/encoder.cc
+++ b/src/encoder.cc
@@ -34,13 +34,10 @@ Encoder::Encoder(Error* err,
{
errobj = err;
- sprintf(ip, gip);
+ strcpy(ip, gip);
port = gport;
memset(cpr, 0, sizeof(cpr));
- printf("[ip: %s]\n", ip);
- printf("[port: %d]\n", port);
-
sem = gsem;
queue = gqueue;
mutex = gmutex;
@@ -67,95 +64,93 @@ Encoder::~Encoder()
}
-void Encoder::setCpr(char *newcpr)
-{
- sprintf(cpr, newcpr);
-}
-
-
void Encoder::encode()
{
DVFrame *f;
+ printf("0\n");
while(*running) {
+ printf("1\n");
sem_wait(sem);
- /*
+ printf("2\n");
pthread_mutex_lock(mutex);
- while((f = queue->pop())) delete f;
+ f = queue->pop();
pthread_mutex_unlock(mutex);
-
- while(record) {
- sem_wait(sem);
- */
+
+ printf("3\n");
+ if((f && record) ||
+ (freeze_request != freeze_value) ||
+ (shoot_request != shoot_value)) {
+ n_header h;
- pthread_mutex_lock(mutex);
- f = queue->pop();
- pthread_mutex_unlock(mutex);
+ h.header_type = DATA_HEADER;
+ sprintf(h.header.h_data.cpr, cpr);
+ h.header.h_data.freeze = (freeze_request != freeze_value);
+ h.header.h_data.snapshot = (shoot_request != shoot_value);
+ h.header.h_data.record = record;
+
+ if(freeze_request != freeze_value) freeze_value = freeze_request;
+ if(shoot_request != shoot_value) shoot_value = shoot_request;
- if((f && record) || (freeze_request != freeze_value) || (shoot_request != shoot_value)) {
- fprintf(stderr, "Rec!\n");
- n_header h;
-
- h.header_type = DATA_HEADER;
- sprintf(h.header.h_data.cpr, cpr);
- h.header.h_data.freeze = (freeze_request != freeze_value);
- h.header.h_data.snapshot = (shoot_request != shoot_value);
- h.header.h_data.record = record;
-
- if(freeze_request != freeze_value) freeze_value = freeze_request;
- if(shoot_request != shoot_value) shoot_value = shoot_request;
-
- n->sendPackage(&h, f->frame, sizeof(f->frame));
- }
-
- if(f) delete f;
- //}
+ n->sendPackage(&h, f->frame, sizeof(f->frame));
+ }
+
+ if(f) delete f;
}
pthread_exit(NULL);
}
+
+void Encoder::setCpr(char *newcpr)
+{
+ strcpy(cpr, newcpr);
+}
+
+
void Encoder::freeze()
{
if(!s) {
- s = new Socket(port);
+ s = new Socket(port, errobj);
s->sconnect(ip);
- n = new Network(s);
+ n = new Network(s, errobj);
}
- freeze_request = 1 - freeze_request;
+ if(!errobj->hasError()) freeze_request = 1 - freeze_request;
}
+
void Encoder::shoot()
{
if(!s) {
- s = new Socket(port);
+ s = new Socket(port, errobj);
s->sconnect(ip);
- n = new Network(s);
+ n = new Network(s, errobj);
}
- shoot_request = 1 - shoot_request;
+ if(!errobj->hasError()) shoot_request = 1 - shoot_request;
}
+
void Encoder::run() {
encode();
}
+
void Encoder::start() {
- printf("GO!\n");
if(!s) {
- s = new Socket(port);
+ s = new Socket(port, errobj);
s->sconnect(ip);
- n = new Network(s);
+ n = new Network(s, errobj);
}
- record = 1;
+ if(!errobj->hasError()) record = 1;
}
+
void Encoder::stop() {
- printf("STOP!\n");
+ record = 0;
if(s) {
if(n) delete n;
delete s;
s = NULL;
n = NULL;
}
- record = 0;
}