summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-06-16 21:28:57 +0000
committerdeva <deva>2005-06-16 21:28:57 +0000
commite0592745a40dae2e14e5b6d9226f41a293ababc9 (patch)
treeb3640c07fd6af71aa01bed384613ffda6c03bf41
parentc397f2dcdc399b43cf150f8000e711fc20613deb (diff)
Rewrote thread object
Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to growing server queue)
-rw-r--r--src/camera.cc16
-rw-r--r--src/camera.h7
-rw-r--r--src/decoder.cc7
-rw-r--r--src/decoder.h7
-rw-r--r--src/encoder.cc7
-rw-r--r--src/encoder.h10
-rw-r--r--src/frame.cc9
-rw-r--r--src/frame.h13
-rw-r--r--src/mainwindow.cc53
-rw-r--r--src/mainwindow.h11
-rw-r--r--src/miav_daemon.cc8
-rw-r--r--src/mov_encoder.cc75
-rw-r--r--src/mov_encoder.h10
-rw-r--r--src/mov_encoder_thread.cc32
-rw-r--r--src/mov_encoder_thread.h13
-rw-r--r--src/mov_encoder_writer.cc77
-rw-r--r--src/mov_encoder_writer.h7
-rw-r--r--src/player.cc7
-rw-r--r--src/player.h9
-rw-r--r--src/thread.cc20
-rw-r--r--src/thread.h19
21 files changed, 326 insertions, 91 deletions
diff --git a/src/camera.cc b/src/camera.cc
index 52fe0b8..a9a0982 100644
--- a/src/camera.cc
+++ b/src/camera.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.18 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.17 2005/05/25 13:11:42 deva
*
* Made unfreeze close connection, when no recording is done.
@@ -133,21 +138,24 @@ void Camera::connect(const char *ip, const int port)
}
*/
- pthread_create (&decodetid, NULL, thread_run, decoder);
+ // pthread_create (&decodetid, NULL, thread_run, decoder);
+ decoder->run();
/*
if(errorstatus->hasError()) {
errorstatus->pushError("Camera initialization failed (decoder thread).");
return;
}
*/
- pthread_create (&encodetid, NULL, thread_run, encoder);
+ // pthread_create (&encodetid, NULL, thread_run, encoder);
+ encoder->run();
/*
if(errorstatus->hasError()) {
errorstatus->pushError("Camera initialization failed (encoder thread).");
return;
}
*/
- pthread_create (&playertid, NULL, thread_run, player);
+ // pthread_create (&playertid, NULL, thread_run, player);
+ player->run();
/*
if(errorstatus->hasError()) {
errorstatus->pushError("Camera initialization failed (player thread).");
@@ -162,9 +170,11 @@ Camera::~Camera()
// Signal to the threads to stop
running = 0;
+ /* // FIXME: Add some way to stop a thread object
pthread_join(decodetid, NULL);
pthread_join(playertid, NULL);
pthread_join(encodetid, NULL);
+ */
delete decoder;
delete encoder;
diff --git a/src/camera.h b/src/camera.h
index a495149..0ffdc3a 100644
--- a/src/camera.h
+++ b/src/camera.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.13 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.12 2005/05/16 16:00:56 deva
*
* Lots of stuff!
@@ -104,9 +109,11 @@ private:
Info *info;
bool initialized;
+ /* // No need for these anymore
pthread_t playertid;
pthread_t decodetid;
pthread_t encodetid;
+ */
volatile int running;
Encoder *encoder;
diff --git a/src/decoder.cc b/src/decoder.cc
index 404fc5f..5704347 100644
--- a/src/decoder.cc
+++ b/src/decoder.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.33 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.32 2005/06/09 11:00:03 deva
* Added daemon code, and cleaned up using -Wall and -Werror
*
@@ -218,7 +223,7 @@ void Decoder::decode()
sem_post(encode_sem);
}
-void Decoder::run() {
+void Decoder::thread_main() {
decode();
fprintf(stderr, "Decoder thread stopped.\n"); fflush(stderr);
}
diff --git a/src/decoder.h b/src/decoder.h
index 247124a..8606880 100644
--- a/src/decoder.h
+++ b/src/decoder.h
@@ -38,6 +38,11 @@
/*
* $Log$
+ * Revision 1.15 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.14 2005/05/25 13:11:42 deva
*
* Made unfreeze close connection, when no recording is done.
@@ -91,7 +96,7 @@ public:
pthread_mutex_t *gmutex,
volatile int *grunning);
~Decoder();
- void run();
+ void thread_main();
void freeze();
void unfreeze();
diff --git a/src/encoder.cc b/src/encoder.cc
index f16a754..9bc6b56 100644
--- a/src/encoder.cc
+++ b/src/encoder.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.29 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.28 2005/05/25 13:11:42 deva
*
* Made unfreeze close connection, when no recording is done.
@@ -240,7 +245,7 @@ void Encoder::shoot()
}
-void Encoder::run() {
+void Encoder::thread_main() {
encode();
if(s) {
if(n) delete n;
diff --git a/src/encoder.h b/src/encoder.h
index 2054f92..7eb1c87 100644
--- a/src/encoder.h
+++ b/src/encoder.h
@@ -38,6 +38,11 @@
/*
* $Log$
+ * Revision 1.13 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.12 2005/05/03 08:31:59 deva
* Removed the error object, and replaced it with a more generic info object.
*
@@ -63,6 +68,8 @@
#ifndef __RTVIDEOREC_ENCODER_H
#define __RTVIDEOREC_ENCODER_H
+#include "thread.h"
+
#include "info.h"
#include <stdio.h>
@@ -73,7 +80,6 @@
#include "miav.h"
#include "util.h"
#include "package.h"
-#include "thread.h"
#include "frame.h"
#include "queue.h"
@@ -104,7 +110,7 @@ public:
void freeze();
void shoot();
- void run();
+ void thread_main();
// AVFormatContext *fc;
sem_t *sem;
diff --git a/src/frame.cc b/src/frame.cc
index c6a2848..e204a2b 100644
--- a/src/frame.cc
+++ b/src/frame.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.9 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.8 2005/06/02 20:45:01 deva
*
* Added clear button
@@ -56,7 +61,7 @@
Frame::Frame(unsigned char *d, int sz)
{
- if(sz) data = (unsigned char *)malloc(sz);
+ if(sz) data = new unsigned char[sz];
if(sz && d) memcpy(data, d, sz);
size = sz;
number = 0;
@@ -64,7 +69,7 @@ Frame::Frame(unsigned char *d, int sz)
Frame::~Frame()
{
- free(data);
+ delete data;
data = NULL;
size = 0;
}
diff --git a/src/frame.h b/src/frame.h
index 8734924..3300fff 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.8 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.7 2005/05/25 13:11:42 deva
*
* Made unfreeze close connection, when no recording is done.
@@ -63,13 +68,6 @@ public:
Frame(unsigned char *d, int sz);
~Frame();
- /*
- // Smaller frame number is higher priority
- bool operator<(const Frame& f) const {
- return number > f.number;
- }
- */
-
unsigned char *data;
int size;
@@ -82,6 +80,7 @@ public:
#include <functional>
+// Method for use, when comparing Frames in priority queue.
template <typename T>
struct frame_priority : std::binary_function<T, T, bool> {
bool operator() (const T& a, const T& b) const {
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 1493506..0b1343e 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.33 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.32 2005/06/15 08:41:49 deva
* *** empty log message ***
*
@@ -119,7 +124,7 @@ MainWindow::MainWindow(QApplication *qApp, QWidget* parent, const char* name )
{
info = new InfoGui(qApp, this, config);
- info->log("Starting MIaV.");
+ info->log("Starting MIaV v. %s.", VERSION);
video_width = config->readInt("video_width");
video_height = config->readInt("video_height");
@@ -254,17 +259,17 @@ void MainWindow::createGui()
btn_cpr->setPixmap(*pix_cpr);
QObject::connect( btn_cpr, SIGNAL(clicked()), this, SLOT(cpr_clicked()) );
// Will also be connected in the MGUI code
- g1->addWidget(btn_cpr, 1, 1);
+ g1->addWidget(btn_cpr, 1, 2);
lbl_name = createLabel("", 18, 2);
g1->addMultiCellWidget ( lbl_name, 2, 2, 0, 2);
-
+/*
btn_clear = createButton("Clear", 8, 3);
// btn_clear->setPixmap(*pix_clear);
QObject::connect( btn_clear, SIGNAL(clicked()), this, SLOT(clear_clicked()) );
// Will also be connected in the MGUI code
g1->addWidget(btn_clear, 1, 2);
-
+*/
// Rec + Shot + Freeze buttons
btn_rec = createButton("", 8, 3);
btn_rec->setPixmap(*pix_record);
@@ -292,6 +297,16 @@ void MainWindow::createGui()
// g2->addWidget(img_history[i]);
}
+ // FIXME: Create button like the other buttons
+ btn_clear = new QPushButton("Clear", gb);
+ btn_clear->setFont( QFont( "Arial", (int)(unit * 3 / 2), QFont::Bold ) );
+ btn_clear->setFixedHeight((int)(unit * 3));
+
+ // btn_clear->setPixmap(*pix_clear);
+ QObject::connect( btn_clear, SIGNAL(clicked()), this, SLOT(clear_clicked()) );
+ // Will also be connected in the MGUI code
+
+
// Statusbar
status = new QStatusBar(this);
status->setSizeGripEnabled(FALSE);
@@ -378,21 +393,28 @@ void MainWindow::message(char *msg)
info->log("Message: %s", msg);
}
-void MainWindow::clear_clicked()
+void MainWindow::clear()
{
info->log("Clearing screen.");
+ // History widgets
+ QImage dummy_resized = pix_dummy->smoothScale(240, 192);
+
+ for(int i = 0; i < NUM_HISTORY; i++) {
+ img_history[i]->setPixmap(dummy_resized);
+ }
+
+ lbl_name->setText("");
+ lbl_cpr->setText("");
+}
+
+void MainWindow::clear_clicked()
+{
if(MessageBox(this,
TXT_ASK_CLEAR_SCREEN_TITLE,
TXT_ASK_CLEAR_SCREEN,
TYPE_YES_NO,
ICON_QUESTION).exec() == MSG_YES) {
-
- // History widgets
- QImage dummy_resized = pix_dummy->smoothScale(240, 192);
-
- for(int i = 0; i < NUM_HISTORY; i++) {
- img_history[i]->setPixmap(dummy_resized);
- }
+ clear();
}
}
@@ -416,6 +438,8 @@ void MainWindow::cpr_clicked()
strcpy(oldname, lbl_name->text().ascii());
strcpy(oldcpr, lbl_cpr->text().ascii());
+ clear();
+
// Create and call the CPRQueryDialog.
CPRQueryDialog dlg(lbl_cpr, lbl_name, this, TXT_CPRDLG_TITLE, status);
@@ -427,6 +451,11 @@ void MainWindow::cpr_clicked()
} else {
// Change CPR camera.
info->log("New CPR %s (old %s).", (char*)lbl_cpr->text().ascii(), oldcpr);
+ strcpy(oldname, lbl_name->text().ascii());
+ strcpy(oldcpr, lbl_cpr->text().ascii());
+ clear();
+ lbl_name->setText(oldname);
+ lbl_cpr->setText(oldcpr);
camera->setCpr((char*)lbl_cpr->text().ascii());
}
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 790097e..d4c4c5b 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.16 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.15 2005/06/02 20:45:01 deva
*
* Added clear button
@@ -100,8 +105,8 @@ using namespace std;
Optagelsen standses ved tryk på den røde cirkel med gul streg over."
#define TXT_TIME "Tid:"
#define TXT_QUEUELENGTH "Buffer størelse:"
-#define TXT_ASK_CLEAR_SCREEN_TITLE "Tøm billedlisten"
-#define TXT_ASK_CLEAR_SCREEN "Er du sikker på at du vil tømme billedlisten?"
+#define TXT_ASK_CLEAR_SCREEN_TITLE "Fjerne data fra skærmen?"
+#define TXT_ASK_CLEAR_SCREEN "Er du sikker på at du vil dataene fra skærmen (billeder, CPR nummer og navn)?"
/**
* Images
@@ -138,6 +143,8 @@ public slots:
void taskbar_update();
private:
+ void clear();
+
Info *info;
void createGui();
diff --git a/src/miav_daemon.cc b/src/miav_daemon.cc
index d59d7ec..520a2fb 100644
--- a/src/miav_daemon.cc
+++ b/src/miav_daemon.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.4 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.3 2005/06/14 13:47:09 deva
* *** empty log message ***
*
@@ -69,7 +74,8 @@ int MiavDaemon::daemon_main()
signal(SIGCLD, SIG_IGN); // Ved SIGCHILD til IGNORE maa wait/waitpid ikke kaldes
// (ellers kommer der kernel-brok)
- info.log("Listening on port %d", port);
+ info.info("Starting MIaV server v. %s", VERSION);
+ info.info("Listening on port %d", port);
Socket *socket = new Socket(port, &info);
while(1) {
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index d422f87..908e857 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.30 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.29 2005/06/14 18:58:35 deva
* *** empty log message ***
*
@@ -143,7 +148,9 @@ MovEncoder::MovEncoder(sem_t *r_sem,
/////////LIBFAME STUFF///////////
// Allocate the output buffer.
- fame_buffer = new unsigned char [FAME_BUFFER_SIZE];
+
+// fame_buffer = new unsigned char [FAME_BUFFER_SIZE];
+
/*
// Open output file
f=fopen(filename, "wb");
@@ -272,7 +279,7 @@ MovEncoder::~MovEncoder()
fclose(f);
}
*/
- delete [] fame_buffer;
+ // delete [] fame_buffer;
delete [] yuv.y;
delete [] yuv.u;
delete [] yuv.v;
@@ -370,7 +377,54 @@ void MovEncoder::encode_audio(Frame *dvframe)
}
// this runs in a thread
-void MovEncoder::run()
+void MovEncoder::thread_main()
+{
+ info->info("MovEncoder::run");
+
+ FrameVector *item;
+ Frame *in_frame;
+ Frame *out_frame;
+
+ while(running) {
+ sem_wait(input_sem);
+
+ // Lock inout mutex
+ pthread_mutex_lock(input_mutex);
+ item = inputqueue->front();
+ inputqueue->pop();
+ pthread_mutex_unlock(input_mutex);
+ // Unlock input mutex
+
+ if(item) {
+ for(unsigned int cnt = 0; cnt < item->size(); cnt++) {
+ in_frame = item->at(cnt);
+ out_frame = encode(in_frame);
+ out_frame->number = in_frame->number;
+
+ delete in_frame;
+
+ // Lock output mutex
+ pthread_mutex_lock(output_mutex);
+ outputqueue->push(out_frame);
+ pthread_mutex_unlock(output_mutex);
+ // Unlock output mutex
+
+ // Kick frame writer
+ sem_post(output_sem);
+ }
+
+ delete item;
+
+ // Kick reader
+ sem_post(read_sem);
+ }
+ }
+
+ info->info("MovEncoder::stop");
+}
+
+/*
+void MovEncoder::thread_main()
{
info->info("MovEncoder::run");
@@ -384,8 +438,10 @@ void MovEncoder::run()
// Lock inout mutex
pthread_mutex_lock(input_mutex);
if(inputqueue->size() == 0) {
- info->error("Dammit... Empty queue in MovEncoder.");
+ info->warn("Empty queue in MovEncoder (This should not happen).");
pthread_mutex_unlock(input_mutex);
+ // Kick reader
+ sem_post(read_sem);
continue;
}
item = inputqueue->front();
@@ -394,7 +450,9 @@ void MovEncoder::run()
// Unlock input mutex
if(!item) {
- info->warn("Empty block detected.");
+ info->warn("Empty block detected (This should not happen).");
+ // Kick reader
+ sem_post(read_sem);
continue;
}
@@ -410,13 +468,18 @@ void MovEncoder::run()
outputqueue->push(out_frame);
pthread_mutex_unlock(output_mutex);
// Unlock output mutex
+
+ // Kick frame writer
+ sem_post(output_sem);
}
delete item;
+ // Kick reader
sem_post(read_sem);
- sem_post(output_sem);
}
info->info("MovEncoder::stop");
}
+
+ */
diff --git a/src/mov_encoder.h b/src/mov_encoder.h
index f006daa..918768b 100644
--- a/src/mov_encoder.h
+++ b/src/mov_encoder.h
@@ -36,6 +36,11 @@
/*
* $Log$
+ * Revision 1.12 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.11 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -100,7 +105,7 @@ public:
~MovEncoder();
Frame* encode(Frame *frame);
- void run();
+ void thread_main();
volatile bool running;
@@ -124,10 +129,11 @@ private:
void encode_audio(Frame *frame);
// libFAME encoder
- unsigned char *fame_buffer;
+ // unsigned char *fame_buffer;
fame_parameters_t fame_par;
fame_context_t *fame_context;
fame_yuv_t yuv;
+ unsigned char fame_buffer[FAME_BUFFER_SIZE];
// libdv decoder
dv_decoder_t *dvdecoder;
diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc
index 600a351..49ba24c 100644
--- a/src/mov_encoder_thread.cc
+++ b/src/mov_encoder_thread.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.12 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.11 2005/06/14 18:58:35 deva
* *** empty log message ***
*
@@ -96,19 +101,21 @@ MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
pthread_mutex_init (&output_mutex, NULL);
writer = new MovEncoderWriter(cpr, outputqueue, &out_sem, &output_mutex, info);
- writer_tid = new pthread_t;
- pthread_create (writer_tid, NULL, thread_run, writer);
+ writer->run();
+ // writer_tid = new pthread_t;
+ //pthread_create (writer_tid, NULL, thread_run, writer);
for(int cnt = 0; cnt < threads; cnt++) {
- encs.push_back(new MovEncoder(&read_sem,
+ MovEncoder *movenc = new MovEncoder(&read_sem,
inputqueue, &in_sem, &input_mutex,
outputqueue, &out_sem, &output_mutex,
- info));
- tids.push_back(new pthread_t);
- pthread_create (tids[cnt], NULL, thread_run, encs[cnt]);
+ info);
+ movenc->run();
+ encs.push_back(movenc);
+ // tids.push_back(new pthread_t);
+ // pthread_create (tids[cnt], NULL, thread_run, encs[cnt]);
}
- current_frame = 0;
frame_number = 0;
}
@@ -133,11 +140,11 @@ MovEncoderThread::~MovEncoderThread()
// They should be exited now, so we can delete them.
for(int cnt = 0; cnt < threads; cnt++) {
- pthread_join(*tids[cnt], NULL);
+ // pthread_join(*tids[cnt], NULL);
delete encs[cnt];
- delete tids[cnt];
+ // delete tids[cnt];
}
-
+
// Tell the writer to stop
writer->running = false;
@@ -145,8 +152,8 @@ MovEncoderThread::~MovEncoderThread()
sem_post(&out_sem);
// Destroy the thread
- pthread_join(*writer_tid, NULL);
- delete writer_tid;
+ // pthread_join(*writer_tid, NULL);
+ // delete writer_tid;
// delete the writer (end thereby close the file)
delete writer;
@@ -193,7 +200,6 @@ void MovEncoderThread::encode(Frame* frame)
sem_post(&in_sem);
// Start new block
- current_frame = 0;
block = new FrameVector;
}
diff --git a/src/mov_encoder_thread.h b/src/mov_encoder_thread.h
index 330e6e6..a4d334d 100644
--- a/src/mov_encoder_thread.h
+++ b/src/mov_encoder_thread.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.8 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.7 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -64,9 +69,6 @@
#include <fcntl.h>
#include <unistd.h>
-#include <pthread.h>
-#include <semaphore.h>
-
#include <vector>
using namespace std;
@@ -99,17 +101,16 @@ private:
pthread_mutex_t output_mutex;
// Used for encoder switching
- int current_frame;
unsigned int frame_number;
unsigned int num_frames_in_block;
MovEncoderWriter *writer;
- pthread_t* writer_tid;
+ // pthread_t* writer_tid;
int threads;
vector<MovEncoder*> encs;
- vector<pthread_t*> tids;
+ // vector<pthread_t*> tids;
};
#endif/*__MIAV_MOV_ENCODER_THREAD_H__*/
diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc
index bd4fb56..a10d671 100644
--- a/src/mov_encoder_writer.cc
+++ b/src/mov_encoder_writer.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.6 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.5 2005/06/14 18:58:35 deva
* *** empty log message ***
*
@@ -117,45 +122,76 @@ MovEncoderWriter::~MovEncoderWriter()
delete file;
}
-//#define TEST_SIZE
-#ifdef TEST_SIZE
- #define BLOCK_SIZE 1024*1024
- #define TIMES 10
- static void *buf = NULL;
-#endif
-
-void MovEncoderWriter::run()
+void MovEncoderWriter::thread_main()
{
info->info("MovEncoderWriter::run");
-#ifdef TEST_SIZE
- if(!buf) buf = malloc(BLOCK_SIZE);
-#endif
-
Frame *frame;
while(running) {
sem_wait(sem);
+ // Lock output mutex
+ pthread_mutex_lock(mutex);
+ frame = queue->top();
+ if(frame && frame->number == frame_number) queue->pop();
+ pthread_mutex_unlock(mutex);
+ // Unlock output mutex
+
+ while(frame && (frame->number == frame_number)) {
+ int ret;
+
+ ret = file->Write(frame->data, frame->size);
+
+ delete frame;
+
+ if(ret == -1) return;
+
+ frame_number++;
+
+ // Lock output mutex
+ pthread_mutex_lock(mutex);
+ frame = queue->top();
+ if(frame && frame->number == frame_number) queue->pop();
+ pthread_mutex_unlock(mutex);
+ // Unlock output mutex
+ }
+ }
+
+ info->info("MovEncoderWriter::stop");
+}
+
+/*
+void MovEncoderWriter::thread_main()
+{
+ unsigned int howdeep = 0;
+ info->info("MovEncoderWriter::run");
+
+ Frame *frame;
+
+ while(running) {
+ sem_wait(sem);
+ howdeep++;
+
+ // Lock output mutex
pthread_mutex_lock(mutex);
if(queue->size() == 0) {
- // info->warn("MovEncoderWriter::run() encountered an empty queue.");
+ info->warn("1MovEncoderWriter encountered an empty queue (This shouldn't happen).");
+ // Unlock output mutex
pthread_mutex_unlock(mutex);
continue;
}
frame = queue->top();
if(frame->number == frame_number) queue->pop();
pthread_mutex_unlock(mutex);
+ // Unlock output mutex
- while(frame->number == frame_number) {
+ while((frame->number == frame_number) && howdeep) {
+ howdeep--;
int ret;
-#ifdef TEST_SIZE
- for(int cnt = 0; cnt < TIMES; cnt++) ret = file->Write(buf, BLOCK_SIZE);
-#else
ret = file->Write(frame->data, frame->size);
-#endif
delete frame;
@@ -166,9 +202,9 @@ void MovEncoderWriter::run()
// Lock output mutex
pthread_mutex_lock(mutex);
if(queue->size() == 0) {
- //info->warn("MovEncoderWriter::run() encountered an empty queue.");
+ info->warn("2MovEncoderWriter encountered an empty queue (This shouldn't happen).");
pthread_mutex_unlock(mutex);
- break;
+ continue;
}
frame = queue->top();
if(frame->number == frame_number) queue->pop();
@@ -179,3 +215,4 @@ void MovEncoderWriter::run()
info->info("MovEncoderWriter::stop");
}
+*/
diff --git a/src/mov_encoder_writer.h b/src/mov_encoder_writer.h
index 4ed144f..6419b25 100644
--- a/src/mov_encoder_writer.h
+++ b/src/mov_encoder_writer.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.4 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.3 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -63,7 +68,7 @@ public:
Info *info);
~MovEncoderWriter();
- void run();
+ void thread_main();
volatile bool running;
diff --git a/src/player.cc b/src/player.cc
index 051c910..8e39fa5 100644
--- a/src/player.cc
+++ b/src/player.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.25 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.24 2005/06/09 11:00:03 deva
* Added daemon code, and cleaned up using -Wall and -Werror
*
@@ -207,7 +212,7 @@ void Player::player()
if(frame) delete frame;
}
-void Player::run()
+void Player::thread_main()
{
player();
fprintf(stderr, "Player thread stopped.\n"); fflush(stderr);
diff --git a/src/player.h b/src/player.h
index e516a33..fb7d9c9 100644
--- a/src/player.h
+++ b/src/player.h
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.8 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.7 2005/05/03 08:31:59 deva
* Removed the error object, and replaced it with a more generic info object.
*
@@ -56,8 +61,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <semaphore.h>
-#include <pthread.h>
#include <SDL/SDL.h>
//#include <avformat.h>
@@ -88,7 +91,7 @@ public:
void start();
void stop();
- void run();
+ void thread_main();
private:
Info *info;
diff --git a/src/thread.cc b/src/thread.cc
index 1d59f74..e38774e 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.4 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.3 2005/05/03 08:31:59 deva
* Removed the error object, and replaced it with a more generic info object.
*
@@ -43,8 +48,19 @@
#include "thread.h"
#include <stdio.h>
-void* thread_run(void *data) {
+static void* thread_run(void *data) {
Thread *t = (Thread*)data;
- t->run();
+ t->thread_main();
return NULL;
}
+
+Thread::Thread()
+{}
+
+Thread::~Thread()
+{}
+
+void Thread::run()
+{
+ pthread_create (&tid, NULL, thread_run, this);
+}
diff --git a/src/thread.h b/src/thread.h
index 8f7bd41..b7f3f98 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.4 2005/06/16 21:28:57 deva
+ * Rewrote thread object
+ * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
+ * growing server queue)
+ *
* Revision 1.3 2005/05/03 08:31:59 deva
* Removed the error object, and replaced it with a more generic info object.
*
@@ -48,11 +53,15 @@
class Thread {
public:
- Thread() {}
- virtual ~Thread() {}
- virtual void run() = 0;
-};
+ Thread();
+ virtual ~Thread();
+
+ void run();
-void* thread_run(void *data);
+ virtual void thread_main() = 0;
+
+private:
+ pthread_t tid;
+};
#endif/*__THREAD_H__*/