From 7f172339fdcdeb0393c1a296da95acb6fc57d3b8 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Thu, 23 Jan 2003 10:33:16 +0000 Subject: [PATCH] grab device is in AVFormatParameter (at least better than global variable) Originally committed as revision 1499 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/audio.c | 11 ++++++----- libavformat/avformat.h | 6 ++---- libavformat/beosaudio.cpp | 3 --- libavformat/dv1394.c | 7 +++++-- libavformat/grab.c | 4 ++++ libavformat/utils.c | 2 -- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libavformat/audio.c b/libavformat/audio.c index 4fa155c85d..05055a1781 100644 --- a/libavformat/audio.c +++ b/libavformat/audio.c @@ -28,8 +28,6 @@ #include #include -const char *audio_device = "/dev/dsp"; - #define AUDIO_BLOCK_SIZE 4096 typedef struct { @@ -43,13 +41,16 @@ typedef struct { int buffer_ptr; } AudioData; -static int audio_open(AudioData *s, int is_output) +static int audio_open(AudioData *s, int is_output, const char *audio_device) { int audio_fd; int tmp, err; char *flip = getenv("AUDIO_FLIP_LEFT"); /* open linux audio device */ + if (!audio_device) + audio_device = "/dev/dsp"; + if (is_output) audio_fd = open(audio_device, O_WRONLY); else @@ -155,7 +156,7 @@ static int audio_write_header(AVFormatContext *s1) st = s1->streams[0]; s->sample_rate = st->codec.sample_rate; s->channels = st->codec.channels; - ret = audio_open(s, 1); + ret = audio_open(s, 1, NULL); if (ret < 0) { return -EIO; } else { @@ -217,7 +218,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) s->sample_rate = ap->sample_rate; s->channels = ap->channels; - ret = audio_open(s, 0); + ret = audio_open(s, 0, ap->device); if (ret < 0) { av_free(st); return -EIO; diff --git a/libavformat/avformat.h b/libavformat/avformat.h index e67001c81b..9b00eba471 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -61,6 +61,8 @@ typedef struct AVFormatParameters { int height; enum PixelFormat pix_fmt; struct AVImageFormat *image_format; + int channel; /* used to select dv channel */ + const char *device; /* video4linux, audio or DV device */ } AVFormatParameters; #define AVFMT_NOFILE 0x0001 /* no file should be opened */ @@ -381,10 +383,6 @@ int audio_init(void); /* DV1394 */ int dv1394_init(void); -extern int dv1394_channel; - -extern const char *video_device; -extern const char *audio_device; #ifdef HAVE_AV_CONFIG_H int strstart(const char *str, const char *val, const char **ptr); diff --git a/libavformat/beosaudio.cpp b/libavformat/beosaudio.cpp index a1ae0a53c8..d2a52800e6 100644 --- a/libavformat/beosaudio.cpp +++ b/libavformat/beosaudio.cpp @@ -34,9 +34,6 @@ extern "C" { /* enable performance checks */ //#define PERF_CHECK -//const char *audio_device = "/dev/dsp"; -const char *audio_device = "beosaudio:"; - /* Pipes are 4k in BeOS IIRC */ #define AUDIO_BLOCK_SIZE 4096 //#define AUDIO_BLOCK_SIZE 2048 diff --git a/libavformat/dv1394.c b/libavformat/dv1394.c index 8515160545..f0b5e8d5ee 100644 --- a/libavformat/dv1394.c +++ b/libavformat/dv1394.c @@ -76,6 +76,7 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap { struct dv1394_data *dv = context->priv_data; AVStream *st; + const char *video_device; st = av_new_stream(context, 0); if (!st) @@ -83,14 +84,16 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap dv->width = DV1394_WIDTH; dv->height = DV1394_HEIGHT; - dv->channel = dv1394_channel; + dv->channel = ap->channel; dv->frame_rate = 30; dv->frame_size = DV1394_NTSC_FRAME_SIZE; /* Open and initialize DV1394 device */ - + video_device = ap->device; + if (!video_device) + video_device = "/dev/dv1394/0"; dv->fd = open(video_device, O_RDONLY); if (dv->fd < 0) { perror("Failed to open DV interface"); diff --git a/libavformat/grab.c b/libavformat/grab.c index 263c2946b9..1c6eafb6c4 100644 --- a/libavformat/grab.c +++ b/libavformat/grab.c @@ -62,6 +62,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) int ret, frame_rate; int desired_palette; struct video_audio audio; + const char *video_device; if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0) return -1; @@ -78,6 +79,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) s->height = height; s->frame_rate = frame_rate; + video_device = ap->device; + if (!video_device) + video_device = "/dev/video"; video_fd = open(video_device, O_RDWR); if (video_fd < 0) { perror(video_device); diff --git a/libavformat/utils.c b/libavformat/utils.c index 4ebca7daec..f811b2c628 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -41,8 +41,6 @@ AVInputFormat *first_iformat; AVOutputFormat *first_oformat; AVImageFormat *first_image_format; -const char *video_device = "none"; - void av_register_input_format(AVInputFormat *format) { AVInputFormat **p;