summaryrefslogtreecommitdiff
path: root/src/dv1394.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv1394.cc')
-rw-r--r--src/dv1394.cc94
1 files changed, 63 insertions, 31 deletions
diff --git a/src/dv1394.cc b/src/dv1394.cc
index ea702a6..8d62605 100644
--- a/src/dv1394.cc
+++ b/src/dv1394.cc
@@ -26,42 +26,22 @@
#include <config.h>
#include "dv1394.h"
-init {
- // FIXME: Read port and channel data from config.
- int port = 0;
- int channel = 63; // 63 is default channel... sucks.
+#include "dv.h"
- int n_ports;
- struct raw1394_portinfo pinf[ 16 ];
- raw1394handle_t handle;
-
- // Get handle to firewire channels
- handle = raw1394_new_handle();
- if(!handle) {
- fprintf( stderr, "raw1394 - failed to get handle: %s.\n", strerror( errno ) );
- exit( EXIT_FAILURE );
- }
-
- // how many adapters are hook in?
- if((n_ports = raw1394_get_port_info(handle, pinf, 16)) < 0 ) {
- fprintf( stderr, "raw1394 - failed to get port info: %s.\n", strerror( errno ) );
- raw1394_destroy_handle( handle );
- exit( EXIT_FAILURE );
- }
- // Tell raw1394 which host adapter to use
- if(raw1394_set_port(handle, port) < 0 ) {
- errobj->pushError("Error while opening codec for input stream.");
- fprintf( stderr, "raw1394 - failed to set port: %s.\n", strerror( errno ) );
- exit( EXIT_FAILURE );
- }
+#include <stdlib.h>
+#include <memory.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
- raw1394_set_iso_handler( handle, channel, raw_reader);
- raw1394_set_userdata( handle, ( void* ) NULL);
- raw1394_start_iso_rcv( handle, channel);
-}
+/**
+ * Callback function for the firewire interface.
+ */
static int raw_reader( raw1394handle_t handle, int channel, size_t length, quadlet_t *data )
{
static char *framedata = NULL;
@@ -122,3 +102,55 @@ static int raw_reader( raw1394handle_t handle, int channel, size_t length, quadl
}
return 0;
}
+
+dv1394::dv1394(Error *e, int port, int channel)
+{
+ errobj = e;
+ int n_ports;
+ struct raw1394_portinfo pinf[ 16 ];
+
+ // Get handle to firewire channels
+ handle = raw1394_new_handle();
+ if(!handle) {
+ fprintf( stderr, "raw1394 - failed to get handle: %s.\n", strerror( errno ) );
+ exit( EXIT_FAILURE );
+ }
+
+ // how many adapters are hooked in?
+ if((n_ports = raw1394_get_port_info(handle, pinf, 16)) < 0 ) {
+ fprintf( stderr, "raw1394 - failed to get port info: %s.\n", strerror( errno ) );
+ raw1394_destroy_handle( handle );
+ exit( EXIT_FAILURE );
+ }
+
+ // Tell raw1394 which host adapter to use
+ if(raw1394_set_port(handle, port) < 0 ) {
+ errobj->pushError("Error while opening codec for input stream.");
+ fprintf( stderr, "raw1394 - failed to set port: %s.\n", strerror( errno ) );
+ exit( EXIT_FAILURE );
+ }
+
+ raw1394_set_iso_handler( handle, channel, raw_reader);
+ raw1394_set_userdata( handle, ( void* ) NULL);
+ raw1394_start_iso_rcv( handle, channel);
+
+}
+
+dv1394::~dv1394()
+{
+}
+
+unsigned char *dv1394::readFrame()
+{
+ unsigned char *ptr;
+ while(1) {
+ raw1394_loop_iterate(handle);
+ ptr = (unsigned char *)raw1394_get_userdata(handle);
+ if(ptr) {
+ raw1394_set_userdata(handle, NULL);
+ break;
+ }
+ }
+ return ptr;
+}
+