diff options
author | deva <deva> | 2005-05-02 10:35:23 +0000 |
---|---|---|
committer | deva <deva> | 2005-05-02 10:35:23 +0000 |
commit | 6d7b4b50ca9f159b9c422d6e7668c33ddd7992a1 (patch) | |
tree | 1fbbac941bc90c4676ad1e97c2d38ab9ae32f862 /src/decoder.cc | |
parent | 6018769717141e28ed5eb84b2cfb3449f3e7334d (diff) |
Fixed wrongly showed snapshot thumbnails.
Diffstat (limited to 'src/decoder.cc')
-rw-r--r-- | src/decoder.cc | 80 |
1 files changed, 80 insertions, 0 deletions
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*/ |