experimental bktr(4) support, from freebsd

This commit is contained in:
jolan 2004-04-18 00:36:22 +00:00
parent 800605f870
commit f3327a9a04
9 changed files with 453 additions and 51 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.8 2003/12/06 13:43:08 espie Exp $
# $OpenBSD: Makefile,v 1.9 2004/04/18 00:36:22 jolan Exp $
COMMENT= "audio/video converter and streamer"
COMMENT= "audio/video converter and streamer with bktr(4) support"
DISTNAME= ffmpeg-0.4.8
PKGNAME= ffmpeg-0.4.8p0
CATEGORIES= graphics
PKGNAME= ${DISTNAME}p1
SV= ${DISTNAME:S/ffmpeg-0.//}
CATEGORIES= graphics x11
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=ffmpeg/}
HOMEPAGE= http://ffmpeg.sourceforge.net/
@ -16,8 +17,14 @@ PERMIT_DISTFILES_FTP= Yes
PERMIT_PACKAGE_CDROM= Yes
PERMIT_PACKAGE_FTP= Yes
LIB_DEPENDS= SDL.2.0::devel/sdl \
a52::audio/liba52 \
mp3lame.0.1::audio/lame \
vorbis.3.0,vorbisenc.2.0::audio/libvorbis \
NO_REGRESS= Yes # Possible to adapt with some work
USE_GMAKE= Yes
USE_X11= Yes
# It's either this or disable mmx so postprocess_template.c will build.
.if ${MACHINE_ARCH} == "i386"
@ -25,16 +32,39 @@ CFLAGS+=-fomit-frame-pointer
.endif
CONFIGURE_STYLE=simple
CONFIGURE_ARGS+=--cc=${CC} --make=gmake ${CONFIGURE_SHARED} \
--disable-ffserver --disable-opts --enable-pp
CONFIGURE_ENV+= CPPFLAGS="-I${LOCALBASE}/include"
CONFIGURE_ARGS+=${CONFIGURE_SHARED} \
--cc=${CC} \
--make=${MAKE_PROGRAM} \
--extra-cflags="-I${LOCALBASE}/include" \
--extra-ldflags="-L${LOCALBASE}/lib -L${X11BASE}/lib" \
--disable-opts \
--enable-pp \
--enable-mp3lame \
--enable-vorbis \
--enable-a52bin \
--disable-debug
SV= 0.4
MAKE_ENV+= LDFLAGS="-L${X11BASE}/lib -L${LOCALBASE}/lib"
pre-configure:
@perl -pi -e 's|_SV_|${SV}|g' ${WRKSRC}/configure
# bktr(4) support
.if ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "powerpc"
CONFIGURE_ARGS+=--disable-v4l
.endif
post-extract:
@cp ${FILESDIR}/grab_bsdbktr.c ${WRKSRC}/libavformat/
do-install:
${INSTALL_DATA_DIR} ${PREFIX}/share/doc/ffmpeg
${INSTALL_DATA_DIR} ${PREFIX}/share/doc/examples/ffmpeg
${INSTALL_DATA} ${WRKSRC}/doc/*.html ${PREFIX}/share/doc/ffmpeg
${INSTALL_DATA} ${WRKSRC}/doc/ffserver.conf \
${PREFIX}/share/doc/examples/ffmpeg
${INSTALL_MAN} ${WRKSRC}/doc/*.1 ${PREFIX}/man/man1
${INSTALL_PROGRAM} ${WRKBUILD}/ffmpeg ${PREFIX}/bin/ffmpeg
${INSTALL_PROGRAM} ${WRKBUILD}/ffplay ${PREFIX}/bin/ffplay
${INSTALL_PROGRAM} ${WRKBUILD}/ffserver ${PREFIX}/bin/ffserver
${INSTALL_DATA_DIR} ${PREFIX}/include/ffmpeg
${INSTALL_DATA_DIR} ${PREFIX}/include/postproc
${INSTALL_DATA} ${WRKSRC}/libavcodec/{avcodec,common}.h \

View File

@ -0,0 +1,315 @@
/* $OpenBSD: grab_bsdbktr.c,v 1.1 2004/04/18 00:36:22 jolan Exp $
*
* FreeBSD video grab interface
* Copyright (c) 2002 Steve O'Hara-Smith
* based on
* Linux video grab interface
* Copyright (c) 2000,2001 Gerard Lantau.
* and
* simple_grab.c Copyright (c) 1999 Roger Hardiman
*
* GPL virus inherited:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "avformat.h"
#include <dev/ic/bt8xx.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <signal.h>
typedef struct {
int fd;
int tuner_fd;
int frame_format; /* see VIDEO_PALETTE_xxx */
int width, height;
int frame_rate;
int frame_rate_base;
int64_t per_frame;
} VideoData;
const char *video_device = "/dev/bktr0";
#define PAL 1
#define PALBDGHI 1
#define NTSC 2
#define NTSCM 2
#define SECAM 3
#define PALN 4
#define PALM 5
#define NTSCJ 6
/* PAL is 768 x 576. NTSC is 640 x 480 */
#define PAL_HEIGHT 576
#define SECAM_HEIGHT 576
#define NTSC_HEIGHT 480
#ifndef VIDEO_FORMAT
#define VIDEO_FORMAT NTSC
#endif
static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2,
METEOR_DEV3, METEOR_DEV_SVIDEO };
static u_int8_t *video_buf;
static int nsignals = 0;
static void catchsignal(int signal)
{
nsignals++;
return;
}
static int bktr_init (const char *video_device, int width, int height,
int format, u_int8_t **video_buf, int *video_fd, int *tuner_fd,
int idev, double frequency)
{
struct meteor_geomet geo;
int h_max;
long ioctl_frequency;
char *arg;
int c;
struct sigaction act,old;
if (idev < 0 || idev > 4)
{
arg = getenv ("BKTR_DEV");
if (arg)
idev = atoi (arg);
if (idev < 0 || idev > 4)
idev = 0;
}
if (format < 1 || format > 6)
{
arg = getenv ("BKTR_FORMAT");
if (arg)
format = atoi (arg);
if (format < 1 || format > 6)
format = VIDEO_FORMAT;
}
if (frequency <= 0)
{
arg = getenv ("BKTR_FREQUENCY");
if (arg)
frequency = atof (arg);
if (frequency <= 0)
frequency = 0.0;
}
memset(&act,0,sizeof(act));
sigemptyset(&act.sa_mask);
act.sa_handler = catchsignal;
sigaction(SIGUSR1,&act,&old);
*tuner_fd = open ("/dev/tuner0", O_RDONLY);
if (*tuner_fd < 0) {
perror("Warning: Tuner not opened continuing");
}
*video_fd = open (video_device, O_RDONLY);
if (*video_fd < 0) {
perror (video_device);
return -1;
}
geo.rows = height;
geo.columns = width;
geo.frames = 1;
// geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12;
geo.oformat = METEOR_GEO_YUV_PACKED;
switch (format) {
case PAL: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break;
case PALN: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALN; break;
case PALM: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALM; break;
case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM; break;
case NTSC: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCM; break;
case NTSCJ: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCJ; break;
default: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break;
}
if (height <= h_max/2) {
geo.oformat |= METEOR_GEO_EVEN_ONLY;
}
if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) {
perror ("METEORSETGEO");
return -1;
}
if (ioctl(*video_fd, BT848SFMT, &c) < 0) {
perror ("BT848SFMT");
return -1;
}
c = bktr_dev[idev];
if (ioctl(*video_fd, METEORSINPUT, &c) < 0) {
perror ("METEORSINPUT");
return -1;
}
*video_buf = (u_int8_t *) mmap((caddr_t)0, width*height*2,
PROT_READ, MAP_SHARED, *video_fd, (off_t) 0);
if (*video_buf == MAP_FAILED) {
perror ("mmap");
return -1;
}
if (frequency != 0.0) {
ioctl_frequency = (unsigned long)(frequency*16);
if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency)<0)
perror("TVTUNER_SETFREQ");
}
c = METEOR_CAP_CONTINOUS;
ioctl(*video_fd, METEORCAPTUR, &c);
c = SIGUSR1;
ioctl (*video_fd, METEORSSIGNAL, &c);
return 0;
}
static void bktr_getframe(u_int64_t per_frame)
{
u_int64_t curtime;
static u_int64_t last_frame_time = 0;
curtime = av_gettime();
if (!last_frame_time
|| ((last_frame_time + per_frame) > curtime)) {
if (!usleep (last_frame_time + per_frame + per_frame/8 - curtime)) {
if (!nsignals)
printf ("\nSLEPT NO signals - %d microseconds late\n",
(int) (av_gettime() - last_frame_time - per_frame));
}
}
nsignals = 0;
last_frame_time = curtime;
}
void bf_memcpy (char *dest, char *src, int size)
{
while (size -= 2)
{
dest[0] = src[1];
dest[1] = src[0];
dest += 2;
src += 2;
}
}
/* note: we support only one picture read at a time */
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
VideoData *s = s1->priv_data;
int size, halfsize;
size = s->width * s->height;
halfsize = size << 1;
// if (av_new_packet(pkt, size + halfsize) < 0)
if (av_new_packet(pkt, size + size) < 0)
return -EIO;
bktr_getframe (s->per_frame);
pkt->pts = av_gettime() & ((1LL << 48) - 1);
bf_memcpy (pkt->data, video_buf, size + size);
// bf_memcpy (pkt->data, video_buf, size + halfsize);
// return size + halfsize;
return size + size;
}
static int grab_read_header (AVFormatContext *s1, AVFormatParameters *ap)
{
VideoData *s = s1->priv_data;
AVStream *st;
int width, height;
int frame_rate;
int frame_rate_base;
int format = -1;
if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
return -1;
width = ap->width;
height = ap->height;
frame_rate = ap->frame_rate;
frame_rate_base = ap->frame_rate_base;
st = av_new_stream(s1, 0);
if (!st)
return -ENOMEM;
s->width = width;
s->height = height;
s->frame_rate = frame_rate;
s->frame_rate_base = frame_rate_base;
s->per_frame = ((int64_t)1000000 * s->frame_rate_base) / s->frame_rate;
st->codec.codec_type = CODEC_TYPE_VIDEO;
// st->codec.pix_fmt = PIX_FMT_YUV420P;
st->codec.pix_fmt = PIX_FMT_YUV422;
st->codec.codec_id = CODEC_ID_RAWVIDEO;
st->codec.width = width;
st->codec.height = height;
st->codec.frame_rate = frame_rate;
st->codec.frame_rate_base = frame_rate_base;
av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in use */
if (ap->standard) {
if (!strcasecmp(ap->standard, "pal"))
format = PAL;
if (!strcasecmp(ap->standard, "secam"))
format = SECAM;
if (!strcasecmp(ap->standard, "ntsc"))
format = NTSC;
}
if (bktr_init (video_device, width, height, format, &video_buf,
&(s->fd), &(s->tuner_fd), -1, 0.0) < 0)
return -EIO;
return 0;
}
static int grab_read_close (AVFormatContext *s1)
{
VideoData *s = s1->priv_data;
int c = METEOR_CAP_STOP_CONT;
ioctl(s->fd, METEORCAPTUR, &c);
close(s->fd);
close(s->tuner_fd);
av_free(s);
return 0;
}
AVInputFormat video_grab_device_format = {
"video4linux",
"video grab",
sizeof(VideoData),
NULL,
grab_read_header,
grab_read_packet,
grab_read_close,
flags: AVFMT_NOFILE,
};
int video_grab_init(void)
{
av_register_input_format(&video_grab_device_format);
return 0;
}

View File

@ -1,42 +1,28 @@
$OpenBSD: patch-configure,v 1.5 2003/11/04 07:50:19 jolan Exp $
$OpenBSD: patch-configure,v 1.6 2004/04/18 00:36:22 jolan Exp $
--- configure.orig 2003-09-28 10:26:39.000000000 -0500
+++ configure 2003-11-03 22:20:14.000000000 -0600
@@ -155,6 +155,15 @@ dv1394="no"
+++ configure 2004-02-26 21:20:18.000000000 -0600
@@ -155,6 +155,12 @@ dv1394="no"
make="gmake"
LDFLAGS="$LDFLAGS -export-dynamic"
;;
+OpenBSD)
+a52="no"
+audio_oss="no"
+dv1394="no"
+sdl="no" # not respected
+v4l="no"
+vhook="no"
+SLIBSUF=.so._SV_
+strip="echo"
+extralibs="$extralibs -lossaudio"
+source_path="`echo $0 | sed -e 's#/configure##'`"
+SLIBSUF=.so`grep '#define FFMPEG_VERSION ' $source_path/libavcodec/avcodec.h | cut -d '"' -f 2 | cut -d '0' -f 2`
+;;
BSD/OS)
v4l="no"
audio_oss="yes"
@@ -714,14 +723,14 @@ EOF
sdl_too_old=no
sdl=no
-if $cc -o $TMPE `sdl-config --cflags` $TMPC `sdl-config --libs` 2> /dev/null ; then
-_sdlversion=`sdl-config --version | sed 's/[^0-9]//g'`
-if test "$_sdlversion" -lt 121 ; then
-sdl_too_old=yes
-else
-sdl=yes
-fi
-fi
+#if $cc -o $TMPE `sdl-config --cflags` $TMPC `sdl-config --libs` 2> /dev/null ; then
+#_sdlversion=`sdl-config --version | sed 's/[^0-9]//g'`
+#if test "$_sdlversion" -lt 121 ; then
+#sdl_too_old=yes
+#else
+#sdl=yes
+#fi
+#fi
if test "$sdl" = "no" ; then
ffplay=no
@@ -276,9 +282,9 @@ for opt do
;;
--make=*) make=`echo $opt | cut -d '=' -f 2`
;;
- --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
+ --extra-cflags=*) CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
;;
- --extra-ldflags=*) LDFLAGS=${opt#--extra-ldflags=}
+ --extra-ldflags=*) LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
;;
--extra-libs=*) extralibs=${opt#--extra-libs=}
;;

View File

@ -1,6 +1,6 @@
$OpenBSD: patch-libavcodec_Makefile,v 1.5 2003/11/04 07:50:19 jolan Exp $
--- libavcodec/Makefile.orig 2003-08-24 17:29:50.000000000 -0500
+++ libavcodec/Makefile 2003-09-26 02:47:15.000000000 -0500
$OpenBSD: patch-libavcodec_Makefile,v 1.6 2004/04/18 00:36:22 jolan Exp $
--- libavcodec/Makefile.orig 2003-09-28 10:26:39.000000000 -0500
+++ libavcodec/Makefile 2004-02-24 23:43:07.000000000 -0600
@@ -142,6 +142,7 @@ OBJS := $(OBJS) $(ASM_OBJS)
LIB= $(LIBPREF)avcodec$(LIBSUF)
ifeq ($(BUILD_SHARED),yes)
@ -9,3 +9,12 @@ $OpenBSD: patch-libavcodec_Makefile,v 1.5 2003/11/04 07:50:19 jolan Exp $
endif
TESTS= imgresample-test dct-test motion-test fft-test
@@ -162,7 +163,7 @@ ifeq ($(CONFIG_WIN32),yes)
$(CC) $(SHFLAGS) -Wl,--output-def,$(@:.dll=.def) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS)
-lib /machine:i386 /def:$(@:.dll=.def)
else
- $(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS)
+ $(CC) $(LDFLAGS) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS)
endif
dsputil.o: dsputil.c dsputil.h

View File

@ -1,6 +1,15 @@
$OpenBSD: patch-libavformat_Makefile,v 1.5 2003/11/04 07:50:19 jolan Exp $
$OpenBSD: patch-libavformat_Makefile,v 1.6 2004/04/18 00:36:22 jolan Exp $
--- libavformat/Makefile.orig 2003-09-28 10:26:40.000000000 -0500
+++ libavformat/Makefile 2003-11-03 22:20:14.000000000 -0600
+++ libavformat/Makefile 2004-02-24 21:12:13.000000000 -0600
@@ -32,7 +32,7 @@ OBJS+= avio.o aviobuf.o file.o
OBJS+= framehook.o
ifeq ($(CONFIG_VIDEO4LINUX),yes)
-OBJS+= grab.o
+OBJS+= grab_bsdbktr.o
endif
ifeq ($(CONFIG_DV1394),yes)
@@ -65,6 +65,7 @@ endif
LIB= $(LIBPREF)avformat$(LIBSUF)
ifeq ($(BUILD_SHARED),yes)

View File

@ -0,0 +1,24 @@
$OpenBSD: patch-libavformat_audio_c,v 1.1 2004/04/18 00:36:22 jolan Exp $
--- libavformat/audio.c.orig 2003-09-28 10:26:40.000000000 -0500
+++ libavformat/audio.c 2004-02-24 22:02:33.000000000 -0600
@@ -21,7 +21,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#if defined(__OpenBSD__)
+#include <soundcard.h>
+#else
#include <sys/soundcard.h>
+#endif
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -49,7 +53,7 @@ static int audio_open(AudioData *s, int
/* open linux audio device */
if (!audio_device)
- audio_device = "/dev/dsp";
+ audio_device = "/dev/audio";
if (is_output)
audio_fd = open(audio_device, O_WRONLY);

View File

@ -1,2 +1,17 @@
FFmpeg is a complete solution to record, convert and stream audio and
video. It includes libavcodec, the leading audio/video codec library.
bktr(4) support (i386/powerpc only) may be controlled through the
following environment variables:
BKTR_DEV={0|1|2|3|4}: Selects device input (tuner, camera, ...)
BKTR_FORMAT={1|2|3|4|5|6}:
1 PAL
2 NTSC
3 SECAM
4 PALN
5 PALM
6 NTSCJ
BKTR_FREQUENCY=xxx.yy: Sets frequency in MHz

View File

@ -1,4 +1,4 @@
@comment $OpenBSD: PFRAG.shared,v 1.6 2003/11/04 07:50:19 jolan Exp $
lib/libavcodec.so.0.4
lib/libavformat.so.0.4
@comment $OpenBSD: PFRAG.shared,v 1.7 2004/04/18 00:36:22 jolan Exp $
lib/libavcodec.so.4.8
lib/libavformat.so.4.8
DYNLIBDIR(%D/lib)

View File

@ -1,5 +1,7 @@
@comment $OpenBSD: PLIST,v 1.3 2003/12/06 13:38:09 espie Exp $
@comment $OpenBSD: PLIST,v 1.4 2004/04/18 00:36:22 jolan Exp $
bin/ffmpeg
bin/ffplay
bin/ffserver
include/ffmpeg/avcodec.h
include/ffmpeg/avformat.h
include/ffmpeg/avio.h
@ -10,6 +12,18 @@ include/ffmpeg/rtspcodes.h
include/postproc/postprocess.h
lib/libavcodec.a
lib/libavformat.a
man/man1/ffmpeg.1
man/man1/ffplay.1
man/man1/ffserver.1
share/doc/examples/ffmpeg/ffserver.conf
share/doc/ffmpeg/faq.html
share/doc/ffmpeg/ffmpeg-doc.html
share/doc/ffmpeg/ffplay-doc.html
share/doc/ffmpeg/ffserver-doc.html
share/doc/ffmpeg/hooks.html
%%SHARED%%
@dirrm share/doc/ffmpeg
@dirrm share/doc/examples/ffmpeg
@dirrm share/doc/examples
@dirrm include/postproc
@dirrm include/ffmpeg