summaryrefslogtreecommitdiff
path: root/src/dv1394.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-05-14 14:24:34 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-05-14 14:24:34 +0200
commit0ff825e0e6fe5fc7238e3964d24779a07cb53518 (patch)
tree7b47a9fe58a09e12ed99fdfacc84fff198ce5ce1 /src/dv1394.cc
parent29ae5ac36d4ffc520232ff393b2455130ec0227e (diff)
Split miav server and client apart. Port client to Qt4. Replace libraw1994 with libiec61883. Add unit tests for multiplexer and fix some bugs in it.
Diffstat (limited to 'src/dv1394.cc')
-rw-r--r--src/dv1394.cc150
1 files changed, 44 insertions, 106 deletions
diff --git a/src/dv1394.cc b/src/dv1394.cc
index 270da2e..fe06a4d 100644
--- a/src/dv1394.cc
+++ b/src/dv1394.cc
@@ -24,14 +24,8 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
#include "dv1394.h"
-#ifdef USE_GUI
-
-#include "dv.h"
-
-
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
@@ -39,76 +33,31 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include <sys/poll.h>
+#include "dv.h"
-
-/**
- * Callback function for the firewire interface.
- */
-static int raw_reader( raw1394handle_t handle, int channel, size_t length, quadlet_t *data )
+static int write_frame(unsigned char *data, int len, int complete,
+ void *callback_data)
{
- static char *framedata = NULL;
-
- // Only process packets with reasonable length.
- if ( length > 16 )
- {
- unsigned char * p = ( unsigned char* ) & data[ 3 ];
- int section_type = p[ 0 ] >> 5; // section type is in bits 5 - 7
- int dif_sequence = p[ 1 ] >> 4; // dif sequence number is in bits 4 - 7
- int dif_block = p[ 2 ];
-
- if ( section_type == 0 && dif_sequence == 0 )
- {
- if ( framedata != NULL )
- {
- raw1394_set_userdata(handle, (void *)framedata);
- framedata = NULL;
- }
- }
-
- if(!framedata)
- {
- framedata = (char *)malloc(DVPACKAGE_SIZE); // dvframe.h
- if(!framedata)
- {
- // We're fucked
- fprintf(stderr, "Framedata allocation error: %s.\n", strerror( errno ) ); fflush(stderr);
- exit(1);
- }
- }
-
- switch ( section_type )
- {
- case 0: // 1 Header block
- // p[3] |= 0x80; // hack to force PAL data
- memcpy( framedata + dif_sequence * 150 * 80, p, 480 );
- break;
-
- case 1: // 2 Subcode blocks
- memcpy( framedata + dif_sequence * 150 * 80 + ( 1 + dif_block ) * 80, p, 480 );
- break;
-
- case 2: // 3 VAUX blocks
- memcpy( framedata + dif_sequence * 150 * 80 + ( 3 + dif_block ) * 80, p, 480 );
- break;
-
- case 3: // 9 Audio blocks interleaved with video
- memcpy( framedata + dif_sequence * 150 * 80 + ( 6 + dif_block * 16 ) * 80, p, 480 );
- break;
-
- case 4: // 135 Video blocks interleaved with audio
- memcpy( framedata + dif_sequence * 150 * 80 + ( 7 + ( dif_block / 15 ) + dif_block ) * 80, p, 480 );
- break;
-
- default: // we can't handle any other data
- break;
- }
- }
- return 0;
+ class dv1394 *dv = (class dv1394*)callback_data;
+
+ if (complete == 0) {
+ fprintf (stderr, "Error: incomplete frame received!\n");
+ return 0;
+ }
+ //return (fwrite (data, len, 1, f) < 1) ? -1 : 0;
+ unsigned char *ptr = (unsigned char *)malloc(len);
+ memcpy(ptr, data, len);
+
+ dv->ptr = ptr;
+
+ return 1;
}
dv1394::dv1394(Info *i, int p, int c)
{
+ printf("dv1394::dv1394()\n");
info = i;
port = p;
channel = c;
@@ -116,60 +65,49 @@ dv1394::dv1394(Info *i, int p, int c)
dv1394::~dv1394()
{
+ printf("dv1394::~dv1394()\n");
+ iec61883_dv_fb_close (frame);
// Close firewire connection.
- if(handle) raw1394_destroy_handle(handle);
+ if(handle) raw1394_destroy_handle (handle);
}
bool dv1394::connect()
{
- int n_ports;
- struct raw1394_portinfo pinf[ 16 ];
+ printf("dv1394::connect()\n");
- // Get handle to firewire channels
- handle = raw1394_new_handle();
- if(!handle) {
- info->error("raw1394 - failed to get handle: %s.", strerror( errno ) );
- return false;
- }
+ handle = raw1394_new_handle_on_port(port);
+ printf(" handle: %p\n", handle);
- // how many adapters are hooked in?
- if((n_ports = raw1394_get_port_info(handle, pinf, 16)) < 0 ) {
- info->error("raw1394 - failed to get port info: %s.", strerror( errno ) );
- raw1394_destroy_handle(handle);
- handle = NULL;
- return false;
- }
+ frame = iec61883_dv_fb_init(handle, write_frame, this);
+ printf(" frame: %p\n", frame);
- // Tell raw1394 which host adapter to use
- if(raw1394_set_port(handle, port) < 0 ) {
- info->error("raw1394 - failed to set port: %s.", strerror( errno ) );
- raw1394_destroy_handle(handle);
- handle = NULL;
+ if(frame && iec61883_dv_fb_start(frame, channel) == 0) {
+ // ok
+ printf("frame ok\n");
+ } else {
+ // fail
+ printf("frame fail\n");
return false;
- }
+ }
- raw1394_set_iso_handler( handle, channel, raw_reader);
- raw1394_set_userdata( handle, ( void* ) NULL);
- raw1394_start_iso_rcv( handle, channel);
-
return true;
}
unsigned char *dv1394::readFrame()
{
- // Firewire port not correctly opened.
- if(!handle) return NULL;
-
- unsigned char *ptr;
- while(1) {
- raw1394_loop_iterate(handle);
- ptr = (unsigned char *)raw1394_get_userdata(handle);
- if(ptr) {
- raw1394_set_userdata(handle, NULL);
- break;
+ struct pollfd pfd;
+ pfd.fd = raw1394_get_fd(handle);
+ pfd.events = POLLIN | POLLPRI;
+ pfd.revents = 0;
+
+ ptr = NULL;
+
+ while(ptr == NULL) {
+ if(poll (&pfd, 1, 50) > 0 && (pfd.revents & POLLIN)) {
+ raw1394_loop_iterate(handle);
}
}
+
return ptr;
}
-#endif/*USE_GUI*/