summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cprquerydialog.cc7
-rw-r--r--src/decoder.cc6
-rw-r--r--src/dv1394.cc24
-rw-r--r--src/error.cc46
-rw-r--r--src/error.h4
-rw-r--r--src/mainwindow.cc19
-rw-r--r--src/miav.cc7
-rw-r--r--src/miav_config.cc7
-rw-r--r--src/miav_config.h4
10 files changed, 67 insertions, 59 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 39ba80a..b23a966 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@
AM_CXXFLAGS := $(CXXFLAGS) $(EXTRA_CXXFLAGS) -I../include $(QT_CXXFLAGS) \
-DPIXMAPS=\"$(datadir)/pixmaps\" \
- -DETC=\"$(datadir)/miav\" \
+ -DETC=\"$(prefix)/etc/miav\" \
-I/usr/include/ffmpeg
bin_PROGRAMS = miav
diff --git a/src/cprquerydialog.cc b/src/cprquerydialog.cc
index 07a4df6..8420b4d 100644
--- a/src/cprquerydialog.cc
+++ b/src/cprquerydialog.cc
@@ -39,16 +39,15 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
: QDialog(parent, name, TRUE)
{
setCaption(name);
- MiavConfig cfg("cprquery.conf");
lbl_name = lname;
lbl_cpr = lcpr;
statusbar = status;
//Read configuration
- CPR_HOST = cfg.readString("cpr_host");
- CPR_PORT = cfg.readInt("cpr_port");
- CPR_TIMEOUT = cfg.readInt("cpr_timeout");
+ CPR_HOST = config->readString("cpr_host");
+ CPR_PORT = config->readInt("cpr_port");
+ CPR_TIMEOUT = config->readInt("cpr_timeout");
cpr[0] = '\0';
internalCpr[0] = '\0';
diff --git a/src/decoder.cc b/src/decoder.cc
index 7b4720e..9798b03 100644
--- a/src/decoder.cc
+++ b/src/decoder.cc
@@ -59,7 +59,7 @@ Decoder::~Decoder()
void Decoder::decode()
{
- dv1394 dv_stream = dv1394(); // Use default port and channel.
+ dv1394 dv_stream = dv1394(errobj); // Use default port and channel.
while(*running) {
uint8_t *ptr;
@@ -67,7 +67,9 @@ void Decoder::decode()
SDL_Event user_event;
// Read a dvframe
- Frame *frame = new Frame(dv_stream.readFrame(), DVPACKAGE_SIZE);
+ ptr = dv_stream.readFrame();
+ if(!ptr) return; // No frame read. (Due to firewire error)
+ Frame *frame = new Frame(ptr, DVPACKAGE_SIZE);
pthread_mutex_lock(mutex);
encode_queue->push(frame);
diff --git a/src/dv1394.cc b/src/dv1394.cc
index 339d192..d4912e4 100644
--- a/src/dv1394.cc
+++ b/src/dv1394.cc
@@ -69,6 +69,7 @@ static int raw_reader( raw1394handle_t handle, int channel, size_t length, quadl
if(!framedata)
{
// We're fucked
+ // errobj->pushError("Were fucked: %s.\n", strerror( errno ) );
exit(1);
}
}
@@ -112,24 +113,24 @@ dv1394::dv1394(Error *e, int port, int channel)
// Get handle to firewire channels
handle = raw1394_new_handle();
if(!handle) {
- // errobj->pushError("");
- fprintf( stderr, "raw1394 - failed to get handle: %s.\n", strerror( errno ) );
- exit( EXIT_FAILURE );
+ errobj->pushError("raw1394 - failed to get handle: %s.", strerror( errno ) );
+ return;
}
// how many adapters are hooked in?
if((n_ports = raw1394_get_port_info(handle, pinf, 16)) < 0 ) {
- // errobj->pushError("");
- fprintf( stderr, "raw1394 - failed to get port info: %s.\n", strerror( errno ) );
- raw1394_destroy_handle( handle );
- exit( EXIT_FAILURE );
+ errobj->pushError("raw1394 - failed to get port info: %s.", strerror( errno ) );
+ raw1394_destroy_handle(handle);
+ handle = NULL;
+ return;
}
// Tell raw1394 which host adapter to use
if(raw1394_set_port(handle, port) < 0 ) {
- // errobj->pushError("");
- fprintf( stderr, "raw1394 - failed to set port: %s.\n", strerror( errno ) );
- exit( EXIT_FAILURE );
+ errobj->pushError("raw1394 - failed to set port: %s.", strerror( errno ) );
+ raw1394_destroy_handle(handle);
+ handle = NULL;
+ return;
}
raw1394_set_iso_handler( handle, channel, raw_reader);
@@ -146,6 +147,9 @@ dv1394::~dv1394()
unsigned char *dv1394::readFrame()
{
+ // Firewiare port not correctly opened.
+ if(!handle) return NULL;
+
unsigned char *ptr;
while(1) {
raw1394_loop_iterate(handle);
diff --git a/src/error.cc b/src/error.cc
index 4e3f045..34c8e33 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -22,42 +22,30 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
#include <config.h>
#include "error.h"
+#include <stdio.h>
+#include <stdarg.h>
+
Error::Error()
{
// Initialize
lastError = NULL;
-
pthread_mutex_init (&mutex, NULL);
}
+
Error::~Error()
{
}
-/*
- pthread_mutex_lock(&mutex);
- // ... do something
- pthread_mutex_unlock(&mutex);
-
- */
bool Error::hasError()
{
return lastError != NULL;
}
-/* // Perhaps!
-string Error::popAllErrorStrings()
-{
- string le = lastError;
- removeError();
- return le;
-}
-*/
string Error::popErrorString()
{
@@ -72,30 +60,30 @@ string Error::popErrorString()
return le;
}
-void Error::pushError(char* errstr)
+
+void Error::pushError(char *fmt, ...)
{
- pthread_mutex_lock(&mutex);
- printf("New Error: [%s]\n", errstr);
+ char buf[1024];
- _err_entry *err = new _err_entry;
+ pthread_mutex_lock(&mutex);
- err->errstr = errstr;
- err->prev = lastError;
- lastError = err;
- pthread_mutex_unlock(&mutex);
-}
+ va_list argp;
+ va_start(argp, fmt);
+ fprintf(stderr, "New Error: [");
+ vfprintf(stderr, fmt, argp);
+ fprintf(stderr, "]\n"); fflush(stderr);
+ vsprintf(buf, fmt, argp);
+ va_end(argp);
-void Error::pushError(string &errstr)
-{
- pthread_mutex_lock(&mutex);
_err_entry *err = new _err_entry;
- err->errstr = errstr;
+ err->errstr = string(buf);
err->prev = lastError;
lastError = err;
pthread_mutex_unlock(&mutex);
}
+
void Error::removeAllErrors()
{
while(lastError) popErrorString();
diff --git a/src/error.h b/src/error.h
index a7e6b29..4c88505 100644
--- a/src/error.h
+++ b/src/error.h
@@ -52,8 +52,8 @@ public:
string popErrorString();
// Set methods
- void pushError(char* errstr);
- void pushError(string &errstr);
+ void pushError(char* fmt, ...);
+ // void pushError(string &errstr);
void removeAllErrors();
private:
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 9c049ac..d68820b 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -52,19 +52,18 @@
MainWindow::MainWindow( QWidget* parent, const char* name )
: QWidget( parent, name, WStyle_Customize | WStyle_NoBorder )
{
- error = new Error();
- MiavConfig cfg("miav.conf", error);
- video_width = cfg.readInt("video_width");
- video_height = cfg.readInt("video_height");
+ Error *error = config->getErrorObj();
+ video_width = config->readInt("video_width");
+ video_height = config->readInt("video_height");
- int resolution_w = cfg.readInt("pixel_width");
- int resolution_h = cfg.readInt("pixel_height");
+ int resolution_w = config->readInt("pixel_width");
+ int resolution_h = config->readInt("pixel_height");
while(error->hasError()) {
show();
MessageBox(this, TXT_ERROR_TITLE, error->popErrorString().c_str(),
TYPE_OK, ICON_ERROR).exec();
}
- unit = ((float)resolution_w / (float)(cfg.readFloat("screensize") * 3.1f));
+ unit = ((float)resolution_w / (float)(config->readFloat("screensize") * 3.1f));
move(0,0);
resize(resolution_w, resolution_h);
@@ -102,8 +101,8 @@ MainWindow::MainWindow( QWidget* parent, const char* name )
show();
camera = new Camera();
- camera->connect(cfg.readString("server_addr")->c_str(),
- cfg.readInt("server_port"));
+ camera->connect(config->readString("server_addr")->c_str(),
+ config->readInt("server_port"));
cam_error = camera->errorObject();
while(cam_error->hasError()) {
@@ -120,7 +119,7 @@ MainWindow::MainWindow( QWidget* parent, const char* name )
MainWindow::~MainWindow()
{
- if(camera) delete camera;
+ delete camera;
delete btn_cpr;
}
diff --git a/src/miav.cc b/src/miav.cc
index c441dca..eedeb7e 100644
--- a/src/miav.cc
+++ b/src/miav.cc
@@ -30,9 +30,11 @@
#ifdef USE_GUI
#include <qapplication.h>
#include "mainwindow.h"
-#include <miav.h>
+#include "miav.h"
#endif /* USE_GUI */
+#include "miav_config.h"
+
#include <stdio.h>
enum {
@@ -103,6 +105,9 @@ int server(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
+ Error conferr;
+ config = new MiavConfig(ETC"/miav.conf", &conferr);
+
int mode = MODE_GRAB;
if(argc < 2) {
diff --git a/src/miav_config.cc b/src/miav_config.cc
index 8a9307d..c0acfb8 100644
--- a/src/miav_config.cc
+++ b/src/miav_config.cc
@@ -26,6 +26,8 @@
#include <config.h>
#include "miav_config.h"
+MiavConfig *config;
+
MiavConfig::MiavConfig(char *file, Error* err)
{
error = err;
@@ -254,3 +256,8 @@ _cfg *MiavConfig::findNode(char* node)
if(error) error->pushError(errbuf);
return NULL;
}
+
+Error* MiavConfig::getErrorObj()
+{
+ return error;
+}
diff --git a/src/miav_config.h b/src/miav_config.h
index 45eab0c..c621af2 100644
--- a/src/miav_config.h
+++ b/src/miav_config.h
@@ -51,6 +51,8 @@ public:
string *readString(char *node);
float readFloat(char *node);
+ Error* getErrorObj();
+
private:
string emptyString;
Error* error;
@@ -63,4 +65,6 @@ private:
_cfg *configs;
};
+extern MiavConfig *config;
+
#endif/*__MIAV_MIAV_CONFIG_H__*/