mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-01 12:19:28 +00:00
- Detect PAL by CIP header rather than the DSF bit in the DV header.
Some DVcam(ex. Panasonic NV-DS1 DV camcorder) doesn't seems to set this bit even if it's for PAL. Fix the DSF bit for such cases so that we can send back the stream to the DVcam without problem. Problem Reported by: Richard Tobin <richard@cogsci.ed.ac.uk> - Make the number of bulkxfer packets(NPACKET_T) and the number of packets write at once(TNBUF) to be different values. I observe some block noise for large TNBUF. - Show the detection of NTSC or PAL. - Pad with 0xff rather than 0x00 for broken frames. - Bzero hdr[0]. - Remove unused code.
This commit is contained in:
parent
a506dcda3d
commit
2932d7d58b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111112
@ -54,6 +54,8 @@
|
||||
#include <dev/firewire/firewire.h>
|
||||
#include <dev/firewire/iec68113.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#define FIX_FRAME 1
|
||||
|
||||
struct frac {
|
||||
int n,d;
|
||||
@ -71,6 +73,8 @@ struct frac pad_rate[2] = {
|
||||
{203, 2997}, /* = (8000 - 29.97 * 250)/(29.97 * 250) */
|
||||
{1, 15}, /* = (8000 - 25 * 300)/(25 * 300) */
|
||||
};
|
||||
char *system_name[] = {"NTSC", "PAL"};
|
||||
int frame_rate[] = {30, 25};
|
||||
|
||||
#define PSIZE 512
|
||||
#define DSIZE 480
|
||||
@ -78,8 +82,9 @@ struct frac pad_rate[2] = {
|
||||
|
||||
#define NPACKET_R 256
|
||||
#define NPACKET_T 255
|
||||
#define NEMPTY 20
|
||||
#define BUFSIZE (PSIZE * NPACKET_R)
|
||||
#define TNBUF 100 /* XXX too large value causes block noise */
|
||||
#define NEMPTY 10 /* depends on TNBUF */
|
||||
#define RBUFSIZE (PSIZE * NPACKET_R)
|
||||
#define MAXBLOCKS (300)
|
||||
#define CYCLE_FRAC 0xc00
|
||||
|
||||
@ -93,14 +98,14 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
struct fw_pkt *pkt;
|
||||
char *pad, *buf;
|
||||
u_int32_t *ptr;
|
||||
int len, tlen, npad, fd, k, m, vec, pal, nb;
|
||||
int len, tlen, npad, fd, k, m, vec, system = -1, nb;
|
||||
int nblocks[] = {250 /* NTSC */, 300 /* PAL */};
|
||||
struct iovec wbuf[NPACKET_R];
|
||||
|
||||
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660);
|
||||
buf = (char *)malloc(BUFSIZE);
|
||||
buf = (char *)malloc(RBUFSIZE);
|
||||
pad = (char *)malloc(DSIZE*MAXBLOCKS);
|
||||
bzero(pad, DSIZE*MAXBLOCKS);
|
||||
memset(pad, 0xff, DSIZE*MAXBLOCKS);
|
||||
bzero(wbuf, sizeof(wbuf));
|
||||
|
||||
bufreq.rx.nchunk = NCHUNK;
|
||||
@ -124,7 +129,7 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
#if 0
|
||||
tlen = 0;
|
||||
while ((len = read(d, buf + tlen, PSIZE
|
||||
/*BUFSIZE - tlen*/)) > 0) {
|
||||
/* RBUFSIZE - tlen */)) > 0) {
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
fprintf(stderr, "(EAGAIN)\n");
|
||||
@ -135,11 +140,11 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
err(1, "read failed");
|
||||
}
|
||||
tlen += len;
|
||||
if ((BUFSIZE - tlen) < PSIZE)
|
||||
if ((RBUFSIZE - tlen) < PSIZE)
|
||||
break;
|
||||
};
|
||||
#else
|
||||
tlen = len = read(d, buf, BUFSIZE);
|
||||
tlen = len = read(d, buf, RBUFSIZE);
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
fprintf(stderr, "(EAGAIN)\n");
|
||||
@ -154,7 +159,7 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
ptr = (u_int32_t *) buf;
|
||||
again:
|
||||
pkt = (struct fw_pkt *) ptr;
|
||||
#if 0
|
||||
#if DEBUG
|
||||
fprintf(stderr, "%08x %08x %08x %08x\n",
|
||||
htonl(ptr[0]), htonl(ptr[1]),
|
||||
htonl(ptr[2]), htonl(ptr[3]));
|
||||
@ -163,7 +168,7 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
if (ciph->fmt != CIP_FMT_DVCR)
|
||||
errx(1, "unknown format 0x%x", ciph->fmt);
|
||||
ptr = (u_int32_t *) (ciph + 1); /* skip cip header */
|
||||
#if 0
|
||||
#if DEBUG
|
||||
if (ciph->fdf.dv.cyc != 0xffff && k == 0) {
|
||||
fprintf(stderr, "0x%04x\n", ntohs(ciph->fdf.dv.cyc));
|
||||
}
|
||||
@ -175,18 +180,22 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
(char *)dv < (char *)(ptr + ciph->len);
|
||||
dv+=6) {
|
||||
|
||||
#if 0
|
||||
#if DEBUG
|
||||
fprintf(stderr, "(%d,%d) ", dv->sct, dv->dseq);
|
||||
#endif
|
||||
if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) {
|
||||
#if 0
|
||||
fprintf(stderr, "%d(%d) ", k, m);
|
||||
#else
|
||||
if (system < 0) {
|
||||
system = ciph->fdf.dv.fs;
|
||||
printf("%s\n", system_name[system]);
|
||||
}
|
||||
|
||||
/* Fix DSF bit */
|
||||
if (system == 1 &&
|
||||
(dv->payload[0] & DV_DSF_12) == 0)
|
||||
dv->payload[0] |= DV_DSF_12;
|
||||
nb = nblocks[system];
|
||||
fprintf(stderr, "%d", k%10);
|
||||
#endif
|
||||
pal = ((dv->payload[0] & DV_DSF_12) != 0);
|
||||
nb = nblocks[pal];
|
||||
#if 1
|
||||
#if FIX_FRAME
|
||||
if (m > 0 && m != nb) {
|
||||
/* padding bad frame */
|
||||
npad = ((nb - m) % nb);
|
||||
@ -204,7 +213,8 @@ dvrecv(int d, char *filename, char ich, int count)
|
||||
}
|
||||
#endif
|
||||
k++;
|
||||
if (k % 30 == 0) { /* every second */
|
||||
if (k % frame_rate[system] == 0) {
|
||||
/* every second */
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
fflush(stderr);
|
||||
@ -241,16 +251,16 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
struct dvdbc *dv;
|
||||
struct fw_pkt *pkt;
|
||||
int len, tlen, header, fd, frames, packets, vec, offset, nhdr, i;
|
||||
int system=0, pad_acc, cycle_acc, cycle, f_cycle, f_frac;
|
||||
struct iovec wbuf[NPACKET_T*2 + NEMPTY];
|
||||
int system=-1, pad_acc, cycle_acc, cycle, f_cycle, f_frac;
|
||||
struct iovec wbuf[TNBUF*2 + NEMPTY];
|
||||
char *pbuf;
|
||||
u_int32_t iso_data, iso_empty, hdr[NPACKET_T + NEMPTY][3];
|
||||
u_int32_t iso_data, iso_empty, hdr[TNBUF + NEMPTY][3];
|
||||
struct ciphdr *ciph;
|
||||
struct timeval start, end;
|
||||
double rtime;
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
pbuf = (char *)malloc(DSIZE * NPACKET_T);
|
||||
pbuf = (char *)malloc(DSIZE * TNBUF);
|
||||
bzero(wbuf, sizeof(wbuf));
|
||||
|
||||
bufreq.rx.nchunk = 0;
|
||||
@ -269,6 +279,7 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
if( ioctl(d, FW_STSTREAM, &isoreq) < 0)
|
||||
err(1, "ioctl");
|
||||
|
||||
iso_data = 0;
|
||||
pkt = (struct fw_pkt *) &iso_data;
|
||||
pkt->mode.stream.len = htons(DSIZE + sizeof(struct ciphdr));
|
||||
pkt->mode.stream.sy = 0;
|
||||
@ -278,32 +289,31 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
pkt = (struct fw_pkt *) &iso_empty;
|
||||
pkt->mode.stream.len = htons(sizeof(struct ciphdr));
|
||||
|
||||
bzero(hdr[0], sizeof(hdr[0]));
|
||||
hdr[0][0] = iso_data;
|
||||
ciph = (struct ciphdr *)&hdr[0][1];
|
||||
ciph->src = 0;
|
||||
ciph->src = 0; /* XXX */
|
||||
ciph->len = 120;
|
||||
ciph->dbc = 0;
|
||||
ciph->eoh1 = 1;
|
||||
ciph->fdf.dv.cyc = 0xffff;
|
||||
|
||||
for (i = 1; i < NPACKET_T; i++) {
|
||||
for (i = 1; i < TNBUF; i++) {
|
||||
bcopy(hdr[0], hdr[i], sizeof(hdr[0]));
|
||||
}
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
#if 0
|
||||
#if DEBUG
|
||||
fprintf(stderr, "%08x %08x %08x\n",
|
||||
htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2]));
|
||||
#endif
|
||||
frames = 0;
|
||||
packets = 0;
|
||||
pad_acc = 0;
|
||||
cycle = 1;
|
||||
cycle_acc = frame_cycle[system].d * cycle;
|
||||
while (1) {
|
||||
tlen = 0;
|
||||
while (tlen < DSIZE * NPACKET_T) {
|
||||
len = read(fd, pbuf + tlen, DSIZE * NPACKET_T - tlen);
|
||||
while (tlen < DSIZE * TNBUF) {
|
||||
len = read(fd, pbuf + tlen, DSIZE * TNBUF - tlen);
|
||||
if (len <= 0) {
|
||||
if (tlen > 0)
|
||||
break;
|
||||
@ -316,7 +326,6 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
tlen += len;
|
||||
}
|
||||
vec = 0;
|
||||
count = 0;
|
||||
offset = 0;
|
||||
nhdr = 0;
|
||||
next:
|
||||
@ -324,19 +333,24 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
#if 0
|
||||
header = (dv->sct == 0 && dv->dseq == 0);
|
||||
#else
|
||||
header = (packets % npackets[system] == 0);
|
||||
header = (packets == 0 || packets % npackets[system] == 0);
|
||||
#endif
|
||||
|
||||
ciph = (struct ciphdr *)&hdr[nhdr][1];
|
||||
if (header) {
|
||||
if (system < 0) {
|
||||
system = ((dv->payload[0] & DV_DSF_12) != 0);
|
||||
printf("%s\n", system_name[system]);
|
||||
cycle = 1;
|
||||
cycle_acc = frame_cycle[system].d * cycle;
|
||||
}
|
||||
fprintf(stderr, "%d", frames % 10);
|
||||
frames ++;
|
||||
if (count > 0 && frames > count)
|
||||
break;
|
||||
if (frames % 30 == 0)
|
||||
if (frames % frame_rate[system] == 0)
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
system = ((dv->payload[0] & DV_DSF_12) != 0);
|
||||
f_cycle = (cycle_acc / frame_cycle[system].d) & 0xf;
|
||||
f_frac = (cycle_acc % frame_cycle[system].d
|
||||
* CYCLE_FRAC) / frame_cycle[system].d;
|
||||
@ -394,40 +408,3 @@ dvsend(int d, char *filename, char ich, int count)
|
||||
frames, rtime, frames/rtime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int ch;
|
||||
int fd;
|
||||
char devname[] = "/dev/fw0";
|
||||
|
||||
while ((ch = getopt(argc, argv, "I:")) != -1){
|
||||
switch(ch) {
|
||||
case 'I':
|
||||
strcpy(devname, optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
fd = open(devname, O_RDWR);
|
||||
if (fd < 0)
|
||||
err(1, "open");
|
||||
dvrec(fd, argv[0], (TAG<<6) | CHANNEL, atoi(argv[1]));
|
||||
close(fd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user