port iso examples to rawiso API

git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@147 53a565d1-3bb7-0310-b661-cf11e63c67ab
This commit is contained in:
ddennedy 2004-11-18 05:24:13 +00:00
parent d5902a8715
commit eb9b08bd5c
4 changed files with 110 additions and 66 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ Version 1.1.0:
- deprecate old isochronous API.
- move API comment documentation to header and reformat header comments as
kernel-doc (use linux/scripts/kernel-doc to extract and format them).
- updated tools/dumpiso and tools/sendiso to new isochronous API.
Version 0.10:

View File

@ -146,7 +146,7 @@ int raw1394_iso_xmit_init(raw1394handle_t handle,
* @max_packet_size: largest packet you need to handle, in bytes (not including
* the isochronous header)
* @channel: isochronous channel to receive
* @speed: speed at which to receive
* @mode: bufferfill or packet per buffer mode
* @irq_interval: maximum latency of wake-ups, in packets
* (-1 if you don't care)
*

View File

@ -1,3 +1,13 @@
/*
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
*
* Copyright (C) 1999,2000 Andreas Bombe
*
* This library is licensed under the GNU Lesser General Public License (LGPL),
* version 2.1 or later. See the file COPYING.LIB in the distribution for
* details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@ -7,13 +17,14 @@
#include "../src/raw1394.h"
#define BUFFER 1000
#define PACKET_MAX 4096
u_int64_t listen_channels;
unsigned long which_port;
char *filename;
int file;
int done;
enum raw1394_iso_dma_recv_mode mode = RAW1394_DMA_DEFAULT;
void usage_exit(int exitcode)
{
@ -70,6 +81,8 @@ void parse_args(int argc, char **argv)
optarg);
usage_exit(1);
}
} else {
mode = RAW1394_DMA_PACKET_PER_BUFFER;
}
if (chan2 < chan1) {
@ -160,28 +173,38 @@ void open_dumpfile()
write_header();
}
int iso_packet_handler(raw1394handle_t handle, int channel, size_t length,
quadlet_t *data)
static enum raw1394_iso_disposition
iso_handler(raw1394handle_t handle, unsigned char *data,
unsigned int length, unsigned char channel,
unsigned char tag, unsigned char sy, unsigned int cycle,
unsigned int dropped)
{
int ret;
static unsigned int count;
static unsigned int counter = 0;
count++;
fprintf(stderr, "\r%u", count);
fflush(stderr);
if (++counter % 1000 == 0)
fprintf(stderr, "\r%uK packets", counter/1000);
/* write header */
write(file, &length, sizeof(length));
write(file, &channel, sizeof(channel));
write(file, &tag, sizeof(tag));
write(file, &sy, sizeof(sy));
sy = 0;
write(file, &sy, sizeof(sy));
while (length) {
ret = write(file, data, length);
if (ret < 0) {
perror("data write");
exit(1);
return RAW1394_ISO_ERROR;
}
length -= ret;
data = (quadlet_t *)(((char *)data) + ret);
data += ret;
}
return 0;
return RAW1394_ISO_OK;
}
int main(int argc, char **argv)
@ -221,16 +244,24 @@ int main(int argc, char **argv)
open_dumpfile();
for (i = 0; i < 64; i++) {
if (!(listen_channels & 1ULL << i)) continue;
if (mode == RAW1394_DMA_DEFAULT) {
raw1394_iso_multichannel_recv_init(handle, iso_handler,
BUFFER, 2048, -1); /* >2048 makes rawiso stall! */
raw1394_iso_recv_set_channel_mask(handle, listen_channels);
raw1394_set_iso_handler(handle, i, iso_packet_handler);
raw1394_start_iso_rcv(handle, i);
} else for (i = 0; i < 64; i++) {
if (!(listen_channels & 1ULL << i))
continue;
raw1394_iso_recv_init(handle, iso_handler, BUFFER, PACKET_MAX,
i, mode, -1);
}
raw1394_iso_recv_start(handle, -1, -1, 0);
/* This should actually do something with the done variable, and set up
signal handlers. */
while (!done) raw1394_loop_iterate(handle);
while (raw1394_loop_iterate(handle) == 0);
fprintf(stderr, "\n");
raw1394_iso_shutdown(handle);
raw1394_destroy_handle(handle);
return 0;
}

View File

@ -18,6 +18,8 @@
#include "../src/raw1394.h"
#define BUFFER 1000
#define PACKET_MAX 4096
unsigned long which_port;
char *filename;
@ -86,15 +88,15 @@ void parse_args(int argc, char **argv)
switch (speed) {
case 1:
case 100:
speed = 0;
speed = RAW1394_ISO_SPEED_100;
break;
case 2:
case 200:
speed = 1;
speed = RAW1394_ISO_SPEED_200;
break;
case 4:
case 400:
speed = 2;
speed = RAW1394_ISO_SPEED_400;
break;
default:
fprintf(stderr,
@ -134,66 +136,72 @@ void parse_args(int argc, char **argv)
if (argc) filename = *argv;
}
static int dec_int_callback(raw1394handle_t unused, void *counter, raw1394_errcode_t unused_errcode)
{
(*(int *)counter)--;
return 0;
}
static int pend_req;
#define BUF_SIZE 65536
#define BUF_OVER BUF_SIZE
#define BUF_SIZE 4096
#define BUF_HEAD 8
void send_file_once(raw1394handle_t handle, int file)
{
int count, i, ret;
unsigned channel, tag, sy;
size_t length;
static char buffer[BUF_SIZE + BUF_OVER];
static struct raw1394_reqhandle rh = {
dec_int_callback,
&pend_req
};
static char buffer[BUF_SIZE + BUF_HEAD];
static unsigned int counter = 0;
static int inited = 0;
while (1) {
while (pend_req > 30) raw1394_loop_iterate(handle);
count = read(file, buffer, BUF_SIZE);
count = read(file, buffer, BUF_HEAD);
if (count < 0) {
perror("read");
exit(1);
}
if (count < 4) return;
if (count < BUF_HEAD)
return;
i = 0;
while (i < count) {
length = (buffer[i] << 8) | buffer[i + 1];
channel = buffer[i + 2] & 0x3f;
tag = buffer[i + 2] >> 6;
sy = buffer[i + 3] & 0xf;
i += 4;
while (i + length > count) {
ret = read(file, buffer + BUF_SIZE,
i + length - BUF_SIZE);
length = ((unsigned int *)buffer)[i];
channel = buffer[i + 4];
tag = buffer[i + 5];
sy = buffer[i + 6];
i += BUF_HEAD;
while (count < length + BUF_HEAD) {
ret = read(file, buffer + count,
length - count + BUF_HEAD);
if (ret < 0) {
perror("read");
exit(1);
}
if (ret < 0) {
perror("read");
exit(1);
if (ret == 0) return;
count += ret;
}
raw1394_start_iso_write(handle, channel, tag, sy,
speed, length,
(quadlet_t *)(buffer + i),
(unsigned long)&rh);
i += length;
pend_req++;
if (ret == 0)
return;
count += ret;
}
if (inited == 0) {
/*
fprintf(stderr, "transmitting first packet with length "
"%d on channel %d with tag %d and sy %d\n",
length, channel, tag, sy);
*/
ret = raw1394_iso_xmit_init(handle, NULL, BUFFER,
PACKET_MAX, channel, speed, -1);
if (ret < 0) {
perror("raw1394_iso_xmit_init");
exit(1);
}
raw1394_iso_xmit_start(handle, -1, -1);
inited = 1;
}
if (++counter % 1000 == 0)
fprintf(stderr, "\r%uK packets", counter/1000);
ret = raw1394_iso_xmit_write(handle, &buffer[i],
length, tag, sy);
if (ret < 0) {
perror("\nraw1394_iso_xmit_write");
exit(1);
}
}
}
@ -299,5 +307,9 @@ int main(int argc, char **argv)
if (filename)
send_iso_file(handle);
fprintf(stderr, "\n");
raw1394_iso_shutdown(handle);
raw1394_destroy_handle(handle);
return 0;
}