Date: Sat, 04 Apr 1998 13:25:15 -0800 From: Amancio Hasty <hasty@rah.star-gate.com> To: Luigi Rizzo <luigi@labinfo.iet.unipi.it> Cc: multimedia@FreeBSD.ORG Subject: Re: problems with signals on capture with bt848 driver Message-ID: <199804042125.NAA29768@rah.star-gate.com> In-Reply-To: Your message of "Sat, 04 Apr 1998 14:45:24 %2B0200." <199804041245.OAA29386@labinfo.iet.unipi.it>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
Try this small program. It uses signals to determine when to write
a frame to disk.
Have Fun,
Amancio
[-- Attachment #2 --]
/* Capture yuv frames suitable for mpeg encoode
* it captures yuv12 frames to a file
*/
/* Copyright (c) 1997 Amancio Hasty
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Amancio Hasty
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <machine/ioctl_meteor.h>
#include <signal.h>
/* number of frames to capture */
#define FRAMES 300
/* height and width of the picuture */
#define ROWS 240
#define COLS 320
/* stuff for the driver */
#define SIZE (ROWS * COLS * 2)
typedef unsigned char uint8;
typedef signed char int8;
static uint8 *yuv_data;
static int8 *ue, *uo, *ve, *vo;
extern int errno;
static frames = -1;
u_int * pyuv_ ;
u_int * frame_ ;
int framesize_ ;
int bt848;
int scratch_file;
sig_t done() {
close(bt848);
close(scratch_file);
printf("captured %d frames \n", frames);
exit(0);
}
sig_t do_write() {
int o;
int j;
char file_name[128];
char buffer[ROWS*COLS*2];
if (frames < 0) {
if ((scratch_file =
open("scratch", O_RDWR | O_CREAT | O_TRUNC,0644)) < 0) {
printf("temp file scratch open failed: %d\n", errno);
exit(1);
}
}
if (frames < FRAMES ) {
frames++;
write(scratch_file, pyuv_, framesize_ + (framesize_ >> 2 ) * 2);
return;
}
close(bt848);
close(scratch_file);
exit(0);
}
main(int ac, char **av)
{
struct meteor_geomet geo;
int o,c,r;
volatile u_int* py ;
volatile u_int* pu ;
volatile u_int* pv ;
u_int* lum ;
u_int* uoff ;
u_int* voff ;
int row, col, numc, i;
char file_name[30];
char *cmd;
int c_opt = 3, h_opt = 320, v_opt = 240, f_opt = 1000;
for (i = 1 ; i < ac; i+=2) {
cmd = av[i];
if ( strcmp(cmd, "-c") == 0) {
c_opt = atoi(av[i+1]);
} else if ( strcmp(cmd, "-h") == 0) {
h_opt = atoi(av[i+1]);
} else if ( strcmp(cmd, "-v") == 0){
v_opt = atoi(av[i+1]);
}else if ( strcmp(cmd, "-f") == 0 ) {
f_opt = atoi(av[i+1]);
}
}
frame_ = (u_int *) malloc(ROWS*COLS*4);
framesize_ = ROWS * COLS;
if ((bt848 = open("/dev/bktr0", O_RDONLY)) < 0) {
printf("open failed: %d\n", errno);
exit(1);
}
/* set up the capture type and size */
geo.rows = ROWS;
geo.columns = COLS;
geo.frames = 1;
geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12
| METEOR_GEO_EVEN_ONLY;
if (ioctl(bt848, METEORSETGEO, &geo) < 0) {
printf("ioctl failed: %d\n", errno);
exit(1);
}
c = METEOR_INPUT_DEV1;
if (ioctl(bt848, METEORSINPUT, &c) < 0) {
printf("ioctl failed: %d\n", errno);
exit(1);
}
pyuv_ = (u_int *)mmap((caddr_t)0,SIZE,PROT_READ,0, bt848, (off_t)0);
if ((int) pyuv_ == -1) return (0);
frames = -1;
c = 31;
ioctl(bt848, METEORSSIGNAL, &c);
signal(31, (sig_t) do_write);
signal(SIGINT, (sig_t) done);
c = METEOR_CAP_CONTINOUS ;
ioctl(bt848, METEORCAPTUR, &c);
while (frames < (FRAMES+2)) {};
close(bt848);
exit(0);
}
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199804042125.NAA29768>
