summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera.cc5
-rw-r--r--src/decoder.cc80
-rw-r--r--src/decoder.h8
-rw-r--r--src/encoder.cc56
-rw-r--r--src/encoder.h7
5 files changed, 101 insertions, 55 deletions
diff --git a/src/camera.cc b/src/camera.cc
index a35cf9c..c1720b9 100644
--- a/src/camera.cc
+++ b/src/camera.cc
@@ -27,6 +27,9 @@
*/
/*
* $Log$
+ * Revision 1.12 2005/05/02 10:35:23 deva
+ * Fixed wrongly showed snapshot thumbnails.
+ *
* Revision 1.11 2005/05/02 09:58:43 deva
*
* Fixed initial values of the stae bools.
@@ -195,7 +198,7 @@ void Camera::snapshot(unsigned char *rgb)
{
if(initialized) {
decoder->shoot(rgb);
- encoder->shoot(rgb);
+ encoder->shoot();
} else {
errorstatus->pushError("Camera not initialized.");
}
diff --git a/src/decoder.cc b/src/decoder.cc
index ac076a4..214e8bc 100644
--- a/src/decoder.cc
+++ b/src/decoder.cc
@@ -25,6 +25,9 @@
*/
/*
* $Log$
+ * Revision 1.24 2005/05/02 10:35:23 deva
+ * Fixed wrongly showed snapshot thumbnails.
+ *
* Revision 1.23 2005/05/02 09:58:43 deva
*
* Fixed initial values of the stae bools.
@@ -44,6 +47,13 @@
#include <fcntl.h>
#include <errno.h>
*/
+
+#include <time.h>
+
+// Use libdv
+#include <libdv/dv.h>
+#include <libdv/dv_types.h>
+
#include <SDL/SDL.h>
#include "dv1394.h"
@@ -67,13 +77,18 @@ Decoder::Decoder(Error* err,
player_queue = gplayer_queue;
mutex = gmutex;
running = grunning;
+
b_shoot = false;
b_freeze = false;
b_record = false; // Initially no recording is done.
+
+ pthread_mutex_init (&shot_mutex, NULL);
+ shot = NULL;
}
Decoder::~Decoder()
{
+ pthread_mutex_destroy(&shot_mutex);
}
void Decoder::decode()
@@ -99,6 +114,19 @@ void Decoder::decode()
b_freeze = false;
local_record = b_record;
+ if(b_shoot) {
+ pthread_mutex_lock(&shot_mutex);
+ if(!shot) shot = new Frame(ptr, DVPACKAGE_SIZE);
+ pthread_mutex_unlock(&shot_mutex);
+ }
+
+ if(b_freeze) {
+ pthread_mutex_lock(&shot_mutex);
+ if(shot) delete shot;
+ shot = new Frame(ptr, DVPACKAGE_SIZE);
+ pthread_mutex_unlock(&shot_mutex);
+ }
+
Frame *eframe = new Frame(ptr, DVPACKAGE_SIZE);
eframe->shoot = local_shoot;
eframe->freeze = local_freeze;
@@ -147,7 +175,26 @@ void Decoder::freeze()
*/
void Decoder::shoot(unsigned char *rgb)
{
+ struct timespec ts;
+
b_shoot = true;
+
+ // Wait for shot to be taken
+ while(1) {
+ pthread_mutex_lock(&shot_mutex);
+ if(shot) {
+ getScreenshot(shot, rgb);
+ delete shot;
+ shot = NULL;
+ pthread_mutex_unlock(&shot_mutex);
+ return;
+ }
+ pthread_mutex_unlock(&shot_mutex);
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000L; // 100ms
+ nanosleep(&ts, NULL);
+ }
}
/*
@@ -166,5 +213,38 @@ void Decoder::stop(n_savestate save)
b_record = false;
}
+void Decoder::getScreenshot(Frame *frame, unsigned char *rgb)
+{
+ unsigned char *pixels[3];
+ int pitches[3];
+
+ pixels[ 0 ] = rgb;
+ pixels[ 1 ] = NULL;
+ pixels[ 2 ] = NULL;
+
+ pitches[ 0 ] = 720 * 4;
+ pitches[ 1 ] = 0;
+ pitches[ 2 ] = 0;
+
+ dv_decoder_t *decoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
+ decoder->quality = DV_QUALITY_BEST;
+
+ dv_parse_header(decoder, frame->data);
+
+ decoder->system = e_dv_system_625_50; // PAL lines, PAL framerate
+ decoder->sampling = e_dv_sample_422; // 4 bytes y, 2 bytes u, 2 bytes v
+ decoder->std = e_dv_std_iec_61834;
+ decoder->num_dif_seqs = 12;
+
+ // libdv img decode to rgb
+ dv_decode_full_frame(decoder,
+ frame->data,
+ e_dv_color_bgr0,
+ pixels,
+ pitches);
+
+ dv_decoder_free(decoder);
+}
+
#endif /*USE_GUI*/
diff --git a/src/decoder.h b/src/decoder.h
index cc1ac22..13a7f39 100644
--- a/src/decoder.h
+++ b/src/decoder.h
@@ -24,6 +24,9 @@
*/
/*
* $Log$
+ * Revision 1.10 2005/05/02 10:35:23 deva
+ * Fixed wrongly showed snapshot thumbnails.
+ *
* Revision 1.9 2005/05/02 09:50:22 deva
* Rewrote freeze, shoot and record flags, from encoder to frame.
*
@@ -68,6 +71,11 @@ public:
void stop(n_savestate save);
private:
+ void getScreenshot(Frame *frame, unsigned char *rgb);
+
+ pthread_mutex_t shot_mutex;
+ Frame* shot;
+
volatile bool b_freeze;
volatile bool b_shoot;
volatile bool b_record;
diff --git a/src/encoder.cc b/src/encoder.cc
index fd7b8a2..e6cbb92 100644
--- a/src/encoder.cc
+++ b/src/encoder.cc
@@ -25,6 +25,9 @@
*/
/*
* $Log$
+ * Revision 1.24 2005/05/02 10:35:23 deva
+ * Fixed wrongly showed snapshot thumbnails.
+ *
* Revision 1.23 2005/05/02 10:18:51 deva
* Preserve network connection when a frozen frame exists, even though no recording is done.
*
@@ -54,12 +57,6 @@
#include "encoder.h"
-#include <time.h>
-
-// Use libdv
-#include <libdv/dv.h>
-#include <libdv/dv_types.h>
-
Encoder::Encoder(Error* err,
const char *gip,
const int gport,
@@ -180,7 +177,7 @@ void Encoder::freeze()
* Set the shoot bit in the network header on the current frame.
* return the decodet (rgba) version af that frame, for thumbnail show.
*/
-void Encoder::shoot(unsigned char *rgb)
+void Encoder::shoot()
{
/*
if(!s) {
@@ -190,7 +187,7 @@ void Encoder::shoot(unsigned char *rgb)
}
*/
// if(!errobj->hasError()) shoot_request = 1 - shoot_request;
- getScreenshot(rgb);
+ // getScreenshot(rgb);
}
@@ -250,47 +247,4 @@ void Encoder::stop(n_savestate save) {
*/
}
-
-void Encoder::getScreenshot(unsigned char *rgb)
-{
- Frame *frame;
-
- unsigned char *pixels[3];
- int pitches[3];
-
- pixels[ 0 ] = rgb;
- pixels[ 1 ] = NULL;
- pixels[ 2 ] = NULL;
-
- pitches[ 0 ] = 720 * 4;
- pitches[ 1 ] = 0;
- pitches[ 2 ] = 0;
-
- dv_decoder_t *decoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
- decoder->quality = DV_QUALITY_BEST;
-
- frame = queue->peek();
- if(!frame) {
- memset(rgb, 0, sizeof(rgb));
- fprintf(stderr, "Queue is empty\n"); fflush(stderr);
- return;
- }
-
- dv_parse_header(decoder, frame->data);
-
- decoder->system = e_dv_system_625_50; // PAL lines, PAL framerate
- decoder->sampling = e_dv_sample_422; // 4 bytes y, 2 bytes u, 2 bytes v
- decoder->std = e_dv_std_iec_61834;
- decoder->num_dif_seqs = 12;
-
- // libdv img decode to rgb
- dv_decode_full_frame(decoder,
- frame->data,
- e_dv_color_bgr0,
- pixels,
- pitches);
-
- dv_decoder_free(decoder);
-}
-
#endif /*USE_GUI*/
diff --git a/src/encoder.h b/src/encoder.h
index 1912261..80552ef 100644
--- a/src/encoder.h
+++ b/src/encoder.h
@@ -24,6 +24,9 @@
*/
/*
* $Log$
+ * Revision 1.11 2005/05/02 10:35:23 deva
+ * Fixed wrongly showed snapshot thumbnails.
+ *
* Revision 1.10 2005/05/02 10:18:51 deva
* Preserve network connection when a frozen frame exists, even though no recording is done.
*
@@ -82,7 +85,7 @@ public:
void stop(n_savestate save);
void freeze();
- void shoot(unsigned char *rgb);
+ void shoot();
void run();
@@ -93,8 +96,6 @@ public:
volatile int *running;
private:
- void getScreenshot(unsigned char *rgb);
-
Error *errobj;
int port;