diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | cfg-mplayer.h | 6 | ||||
-rwxr-xr-x | configure | 55 | ||||
-rw-r--r-- | stream/stream_radio.c | 138 | ||||
-rw-r--r-- | stream/tv.c | 24 | ||||
-rw-r--r-- | stream/tvi_v4l.c | 1910 |
6 files changed, 7 insertions, 2127 deletions
@@ -136,7 +136,6 @@ SRCS_COMMON-$(TV_DSHOW) += stream/tvi_dshow.c \ loader/dshow/guids.c \ loader/dshow/mediatype.c \ -SRCS_COMMON-$(TV_V4L1) += stream/tvi_v4l.c stream/audio_in.c SRCS_COMMON-$(TV_V4L2) += stream/tvi_v4l2.c stream/audio_in.c SRCS_COMMON-$(VCD) += stream/stream_vcd.c SRCS_COMMON-$(VSTREAM) += stream/stream_vstream.c diff --git a/cfg-mplayer.h b/cfg-mplayer.h index bce30e12b1..716eb9aca9 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -121,12 +121,12 @@ const m_option_t tvopts_conf[]={ {"hue", &stream_tv_defaults.hue, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, {"saturation", &stream_tv_defaults.saturation, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, {"gain", &stream_tv_defaults.gain, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL}, -#if defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW) +#if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW) {"buffersize", &stream_tv_defaults.buffer_size, CONF_TYPE_INT, CONF_RANGE, 16, 1024, NULL}, {"amode", &stream_tv_defaults.amode, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL}, {"volume", &stream_tv_defaults.volume, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, #endif -#if defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2) +#if defined(CONFIG_TV_V4L2) {"bass", &stream_tv_defaults.bass, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, {"treble", &stream_tv_defaults.treble, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, {"balance", &stream_tv_defaults.balance, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, @@ -139,7 +139,7 @@ const m_option_t tvopts_conf[]={ #ifdef CONFIG_ALSA {"alsa", &stream_tv_defaults.alsa, CONF_TYPE_FLAG, 0, 0, 1, NULL}, #endif /* CONFIG_ALSA */ -#endif /* defined(CONFIG_TV_V4L) || defined(CONFIG_TV_V4L2) */ +#endif /* defined(CONFIG_TV_V4L2) */ {"adevice", &stream_tv_defaults.adevice, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"tdevice", &stream_tv_defaults.teletext.device, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"tpage", &stream_tv_defaults.teletext.page, CONF_TYPE_INT, CONF_RANGE, 100, 899, NULL}, @@ -304,7 +304,6 @@ Optional features: --disable-radio-v4l2 disable Video4Linux2 radio interface [autodetect] --disable-radio-bsdbt848 disable BSD BT848 radio interface [autodetect] --disable-tv disable TV interface (TV/DVB grabbers) [enable] - --disable-tv-v4l1 disable Video4Linux TV interface [autodetect] --disable-tv-v4l2 disable Video4Linux2 TV interface [autodetect] --disable-tv-bsdbt848 disable BSD BT848 interface [autodetect] --disable-pvr disable Video4Linux2 MPEG PVR [autodetect] @@ -508,11 +507,9 @@ _win32dll=no _select=yes _radio=no _radio_capture=no -_radio_v4l=auto _radio_v4l2=auto _radio_bsdbt848=auto _tv=yes -_tv_v4l1=auto _tv_v4l2=auto _tv_bsdbt848=auto _tv_dshow=auto @@ -772,8 +769,6 @@ for ac_option do --disable-tv) _tv=no ;; --enable-tv-bsdbt848) _tv_bsdbt848=yes ;; --disable-tv-bsdbt848) _tv_bsdbt848=no ;; - --enable-tv-v4l1) _tv_v4l1=yes ;; - --disable-tv-v4l1) _tv_v4l1=no ;; --enable-tv-v4l2) _tv_v4l2=yes ;; --disable-tv-v4l2) _tv_v4l2=no ;; --enable-tv-dshow) _tv_dshow=yes ;; @@ -782,8 +777,6 @@ for ac_option do --enable-radio-capture) _radio_capture=yes ;; --disable-radio-capture) _radio_capture=no ;; --disable-radio) _radio=no ;; - --enable-radio-v4l) _radio_v4l=yes ;; - --disable-radio-v4l) _radio_v4l=no ;; --enable-radio-v4l2) _radio_v4l2=yes ;; --disable-radio-v4l2) _radio_v4l2=no ;; --enable-radio-bsdbt848) _radio_bsdbt848=yes ;; @@ -1754,9 +1747,9 @@ if test "$_pthreads" = yes ; then def_threads='#define HAVE_THREADS 1' extra_cflags="$extra_cflags $THREAD_CFLAGS" else - res_comment="v4l, v4l2, ao_nas, win32 loader disabled" + res_comment="v4l2, ao_nas, win32 loader disabled" def_pthreads='#undef HAVE_PTHREADS' - _nas=no ; _tv_v4l1=no ; _tv_v4l2=no + _nas=no ; _tv_v4l2=no mingw32 || _win32dll=no fi echores "$_pthreads" @@ -3725,26 +3718,6 @@ fi echores "$_tv_dshow" -echocheck "Video 4 Linux TV interface" -if test "$_tv_v4l1" = auto ; then - _tv_v4l1=no - if test "$_tv" = yes && linux ; then - header_check_broken sys/time.h linux/videodev.h && _tv_v4l1=yes - fi -fi -if test "$_tv_v4l1" = yes ; then - _audio_input=yes - _tv_v4l=yes - def_tv_v4l='#define CONFIG_TV_V4L 1' - def_tv_v4l1='#define CONFIG_TV_V4L1 1' - inputmodules="tv-v4l $inputmodules" -else - noinputmodules="tv-v4l1 $noinputmodules" - def_tv_v4l='#undef CONFIG_TV_V4L' -fi -echores "$_tv_v4l1" - - echocheck "Video 4 Linux 2 TV interface" if test "$_tv_v4l2" = auto ; then _tv_v4l2=no @@ -3756,8 +3729,6 @@ if test "$_tv_v4l2" = auto ; then fi if test "$_tv_v4l2" = yes ; then _audio_input=yes - _tv_v4l=yes - def_tv_v4l='#define CONFIG_TV_V4L 1' def_tv_v4l2='#define CONFIG_TV_V4L2 1' inputmodules="tv-v4l2 $inputmodules" else @@ -3804,19 +3775,6 @@ else fi echores "$_radio_v4l2" -echocheck "Video 4 Linux Radio interface" -if test "$_radio_v4l" = auto ; then - _radio_v4l=no - if test "$_radio" = yes && linux ; then - header_check linux/videodev.h && _radio_v4l=yes - fi -fi -if test "$_radio_v4l" = yes ; then - def_radio_v4l='#define CONFIG_RADIO_V4L 1' -else - def_radio_v4l='#undef CONFIG_RADIO_V4L' -fi -echores "$_radio_v4l" if freebsd || netbsd || openbsd || dragonfly && test "$_radio" = yes && test "$_radio_bsdbt848" = auto ; then @@ -3840,9 +3798,9 @@ else def_radio_bsdbt848='#undef CONFIG_RADIO_BSDBT848' fi -if test "$_radio_v4l" = no && test "$_radio_v4l2" = no && +if test "$_radio_v4l2" = no && test "$_radio_bsdbt848" = no && test "$_radio" = yes ; then - die "Radio driver requires BSD BT848, V4L or V4L2!" + die "Radio driver requires BSD BT848 or V4L2!" fi echocheck "Video 4 Linux 2 MPEG PVR interface" @@ -4183,8 +4141,6 @@ TGA = $_tga TV = $_tv TV_BSDBT848 = $_tv_bsdbt848 TV_DSHOW = $_tv_dshow -TV_V4L = $_tv_v4l -TV_V4L1 = $_tv_v4l1 TV_V4L2 = $_tv_v4l2 V4L2 = $_v4l2 VCD = $_vcd @@ -4417,13 +4373,10 @@ $def_pvr $def_radio $def_radio_bsdbt848 $def_radio_capture -$def_radio_v4l $def_radio_v4l2 $def_tv $def_tv_bsdbt848 $def_tv_dshow -$def_tv_v4l -$def_tv_v4l1 $def_tv_v4l2 diff --git a/stream/stream_radio.c b/stream/stream_radio.c index f7612f0085..245f889bbe 100644 --- a/stream/stream_radio.c +++ b/stream/stream_radio.c @@ -49,10 +49,6 @@ #include <linux/videodev2.h> #endif -#ifdef CONFIG_RADIO_V4L -#include <linux/videodev.h> -#endif - #endif // !IOCTL_BT848_H_NAME @@ -408,137 +404,6 @@ static const radio_driver_t radio_driver_v4l2={ get_frequency_v4l2 }; #endif /* CONFIG_RADIO_V4L2 */ -#ifdef CONFIG_RADIO_V4L -/***************************************************************** - * \brief get fraction value for using in set_frequency and get_frequency - * \return STREAM_OK if success, STREAM_ERROR otherwise - * - * V4L2_TUNER_CAP_LOW: - * unit=62.5Hz - * frac= 1MHz/unit=1000000/62.5 =16000 - * - * otherwise: - * unit=62500Hz - * frac= 1MHz/unit=1000000/62500 =16 - * - */ -static int init_frac_v4l(radio_priv_t* priv){ - struct video_tuner tuner; - memset(&tuner,0,sizeof(tuner)); - if (ioctl(priv->radio_fd, VIDIOCGTUNER, &tuner) <0){ - mp_tmsg(MSGT_RADIO,MSGL_WARN,"[radio] Warning: ioctl get tuner failed: %s. Setting frac to %d.\n",strerror(errno),priv->frac); - return STREAM_ERROR; - } - if(tuner.flags & VIDEO_TUNER_LOW){ - priv->frac=16000; - mp_tmsg(MSGT_RADIO,MSGL_DBG2,"[radio] tuner is low:yes frac=%d\n",priv->frac); - }else{ - priv->frac=16; - mp_tmsg(MSGT_RADIO,MSGL_DBG2,"[radio] tuner is low:no frac=%d\n",priv->frac); - } - - priv->rangelow=((float)tuner.rangelow)/priv->frac; - priv->rangehigh=((float)tuner.rangehigh)/priv->frac; - mp_tmsg(MSGT_RADIO,MSGL_V,"[radio] Allowed frequency range is %.2f-%.2f MHz.\n",priv->rangelow,priv->rangehigh); - - return STREAM_OK; -} - -/***************************************************************** - * \brief tune card to given frequency - * \param frequency frequency in MHz - * \return STREAM_OK if success, STREAM_ERROR otherwise - */ -static int set_frequency_v4l(radio_priv_t* priv,float frequency){ - __u32 freq; - freq=frequency*priv->frac; - if (ioctl(priv->radio_fd, VIDIOCSFREQ, &freq) < 0) { - mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n",freq,frequency,strerror(errno)); - return STREAM_ERROR; - } - return STREAM_OK; -} -/***************************************************************** - * \brief get current tuned frequency from card - * \param frequency where to store frequency in MHz - * \return STREAM_OK if success, STREAM_ERROR otherwise - */ -static int get_frequency_v4l(radio_priv_t* priv,float* frequency){ - __u32 freq; - if (ioctl(priv->radio_fd, VIDIOCGFREQ, &freq) < 0) { - mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl get frequency failed: %s\n",strerror(errno)); - return STREAM_ERROR; - } - *frequency=((float)freq)/priv->frac; - return STREAM_OK; -} - -/***************************************************************** - * \brief set volume on radio card - * \param volume volume level (0..100) - * \return STREAM_OK if success, STREAM_ERROR otherwise - */ -static void set_volume_v4l(radio_priv_t* priv,int volume){ - struct video_audio audio; - - /*arg must be between 0 and 100*/ - if (volume > 100) volume = 100; - if (volume < 0) volume = 0; - - memset(&audio,0,sizeof(audio)); - audio.flags = (volume==0?VIDEO_AUDIO_MUTE:0); - if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio)<0){ - mp_tmsg(MSGT_RADIO,MSGL_WARN,"[radio] ioctl set mute failed: %s\n",strerror(errno)); - } - - memset(&audio,0,sizeof(audio)); - audio.flags = VIDEO_AUDIO_VOLUME; - audio.mode = VIDEO_SOUND_STEREO; - audio.audio = 0; - audio.volume = volume* (65535 / 100); - - if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio) < 0){ - mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl set volume failed: %s\n",strerror(errno)); - } -} - -/***************************************************************** - * \brief get current volume from radio card - * \param volume where to store volume level (0..100) - * \return STREAM_OK if success, STREAM_ERROR otherwise - */ -static int get_volume_v4l(radio_priv_t* priv,int* volume){ - struct video_audio audio; - - memset(&audio,0,sizeof(audio)); - audio.audio=0; - if (ioctl(priv->radio_fd, VIDIOCGAUDIO, &audio) < 0){ - mp_tmsg(MSGT_RADIO,MSGL_ERR,"[radio] ioctl get volume failed: %s\n",strerror(errno)); - return STREAM_ERROR; - } - - if (audio.flags & VIDEO_AUDIO_VOLUME){ - *volume=100*audio.volume/65535; - /*arg must be between 0 and 100*/ - if (*volume > 100) *volume = 100; - if (*volume < 0) *volume = 0; - return STREAM_OK; - } - - return STREAM_ERROR; -} - -/* v4l driver info structure */ -static const radio_driver_t radio_driver_v4l={ - "v4l", - _("[radio] Using V4Lv1 radio interface.\n"), - init_frac_v4l, - set_volume_v4l, - get_volume_v4l, - set_frequency_v4l, - get_frequency_v4l -}; -#endif /* CONFIG_RADIO_V4L */ #ifdef CONFIG_RADIO_BSDBT848 /***************************************************************** @@ -1084,9 +949,6 @@ static const radio_driver_t* radio_drivers[]={ #ifdef CONFIG_RADIO_V4L2 &radio_driver_v4l2, #endif -#ifdef CONFIG_RADIO_V4L - &radio_driver_v4l, -#endif 0 }; diff --git a/stream/tv.c b/stream/tv.c index 07fb0270a6..3ce7264691 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -58,7 +58,6 @@ char *tv_channel_last_real; /* enumerating drivers (like in stream.c) */ extern const tvi_info_t tvi_info_dummy; extern const tvi_info_t tvi_info_dshow; -extern const tvi_info_t tvi_info_v4l; extern const tvi_info_t tvi_info_v4l2; extern const tvi_info_t tvi_info_bsdbt848; @@ -67,9 +66,6 @@ static const tvi_info_t* tvi_driver_list[]={ #ifdef CONFIG_TV_V4L2 &tvi_info_v4l2, #endif -#ifdef CONFIG_TV_V4L1 - &tvi_info_v4l, -#endif #ifdef CONFIG_TV_BSDBT848 &tvi_info_bsdbt848, #endif @@ -478,26 +474,6 @@ static int open_tv(tvi_handle_t *tvh) #endif tv_set_norm(tvh,tvh->tv_param->norm); -#ifdef CONFIG_TV_V4L1 - if ( tvh->tv_param->mjpeg ) - { - /* set width to expected value */ - if (tvh->tv_param->width == -1) - { - tvh->tv_param->width = 704/tvh->tv_param->decimation; - } - if (tvh->tv_param->height == -1) - { - if ( tvh->norm != TV_NORM_NTSC ) - tvh->tv_param->height = 576/tvh->tv_param->decimation; - else - tvh->tv_param->height = 480/tvh->tv_param->decimation; - } - mp_tmsg(MSGT_TV, MSGL_INFO, - " MJP: width %d height %d\n", tvh->tv_param->width, tvh->tv_param->height); - } -#endif - /* limits on w&h are norm-dependent -- JM */ if (tvh->tv_param->width != -1 && tvh->tv_param->height != -1) { // first tell the driver both width and height, some drivers do not support setting them independently. diff --git a/stream/tvi_v4l.c b/stream/tvi_v4l.c deleted file mode 100644 index 31f767850b..0000000000 --- a/stream/tvi_v4l.c +++ /dev/null @@ -1,1910 +0,0 @@ -/* - * Video 4 Linux input - * - * Copyright (C) 2001 Alex Beregszaszi - * - * Some ideas are based on xawtv/libng's grab-v4l.c written by - * Gerd Knorr <kraxel@bytesex.org> - * - * Multithreading, a/v sync and native ALSA support by - * Jindrich Makovicka <makovick@gmail.com> - * - * MJPEG hardware encoding support by - * Ivan Szanto <szivan@freemail.hu> - * - * CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE! - * - * This file is part of MPlayer. - * - * MPlayer 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. - * - * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/time.h> - -/* Necessary to prevent collisions between <linux/time.h> and <sys/time.h> when V4L2 is installed. */ -#define _LINUX_TIME_H - -#include <linux/videodev.h> -#include <unistd.h> -#include <sys/mman.h> -#include <stdlib.h> -#include <string.h> -#include <pthread.h> -#ifdef HAVE_SYS_SYSINFO_H -#include <sys/sysinfo.h> -#endif - -#include "mp_msg.h" -#include "libaf/af_format.h" -#include "libmpcodecs/img_format.h" -#include "libmpcodecs/dec_teletext.h" -#include "libvo/fastmemcpy.h" -#include "libvo/videodev_mjpeg.h" - -#include "tv.h" - -#include "audio_in.h" - -static tvi_handle_t *tvi_init_v4l(tv_param_t* tv_param); - -const tvi_info_t tvi_info_v4l = { - tvi_init_v4l, - "Video 4 Linux input", - "v4l", - "Alex Beregszaszi", - "under development" -}; - -#define PAL_WIDTH 768 -#define PAL_HEIGHT 576 -#define PAL_FPS 25 - -#define NTSC_WIDTH 640 -#define NTSC_HEIGHT 480 -#define NTSC_FPS (30000.0/1001.0) - -#define MAX_AUDIO_CHANNELS 10 - -#define VID_BUF_SIZE_IMMEDIATE 2 -#define VIDEO_AVG_BUFFER_SIZE 600 - -typedef struct priv { - /* general */ - char *video_device; - int video_fd; - struct video_capability capability; - struct video_channel *channels; - int act_channel; - struct video_tuner tuner; - - /* video */ - struct video_picture picture; - int format; /* output format */ - int width; - int height; - int bytesperline; - float fps; - - struct video_mbuf mbuf; - unsigned char *mmap; - struct video_mmap *buf; - int nbuf; - - /* audio */ - char *audio_device; - audio_in_t audio_in; - - int audio_id; - struct video_audio audio[MAX_AUDIO_CHANNELS]; - int audio_channels[MAX_AUDIO_CHANNELS]; - - /* buffering stuff */ - int immediate_mode; - - int audio_buffer_size; - int aud_skew_cnt; - unsigned char *audio_ringbuffer; - long long *audio_skew_buffer; - volatile int audio_head; - volatile int audio_tail; - volatile int audio_cnt; - volatile long long audio_skew; - volatile double audio_skew_factor; - volatile long long audio_skew_measure_time; - volatile int audio_drop; - - int first; - int video_buffer_size_max; - volatile int video_buffer_size_current; - unsigned char **video_ringbuffer; - long long *video_timebuffer; - long long *video_avg_buffer; - int video_avg_ptr; - int video_interval_sum; - volatile int video_head; - volatile int video_tail; - volatile int video_cnt; - - volatile int shutdown; - - pthread_t audio_grabber_thread; - pthread_t video_grabber_thread; - pthread_mutex_t audio_starter; - pthread_mutex_t skew_mutex; - pthread_mutex_t video_buffer_mutex; - - long long starttime; - double audio_secs_per_block; - long long audio_skew_total; - long audio_recv_blocks_total; - long audio_sent_blocks_total; - long mjpeg_bufsize; - char *vbi_dev; - int vbi_fd; - int vbi_bufsize; - int vbi_shutdown; - pthread_t vbi_grabber_thread; - void *priv_vbi; - - tv_param_t *tv_param; -} priv_t; - -#include "tvi_def.h" - -static const char *device_cap2name[] = { - "capture", "tuner", "teletext", "overlay", "chromakey", "clipping", - "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder", - "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL -}; - -static const char *device_palette2name[] = { - "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422", - "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p", - "yuv420p", "yuv410p" -}; -#define PALETTE(x) ((x < sizeof(device_palette2name)/sizeof(char*)) ? device_palette2name[x] : "UNKNOWN") - -static const struct { - char* name; - int normid; - int tuner_flags; - int tuner_mode; - int input_norm; - float fps; -} supported_norms[]={ - {"pal", TV_NORM_PAL, VIDEO_TUNER_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, PAL_FPS }, - {"ntsc", TV_NORM_NTSC, VIDEO_TUNER_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, NTSC_FPS}, - {"secam", TV_NORM_SECAM, VIDEO_TUNER_SECAM, VIDEO_MODE_SECAM,VIDEO_MODE_SECAM,PAL_FPS }, - {"palnc", TV_NORM_PALNC, VIDEO_TUNER_PAL, VIDEO_MODE_PAL, 3, PAL_FPS }, - {"palm", TV_NORM_PALM, VIDEO_TUNER_NTSC, VIDEO_MODE_NTSC, 4, NTSC_FPS}, - {"paln", TV_NORM_PALN, VIDEO_TUNER_PAL, VIDEO_MODE_PAL, 5, PAL_FPS }, - {"ntscjp",TV_NORM_NTSCJP, VIDEO_TUNER_NTSC, VIDEO_MODE_NTSC, 6, NTSC_FPS}, - {"auto", -1, -1, -1, VIDEO_MODE_AUTO, -1 }, - {NULL, -1, -1, -1, -1 } -}; - -static const char *norm2name(int mode) -{ - int i; - for(i=0;supported_norms[i].name; i++) - if(supported_norms[i].input_norm==mode) - return supported_norms[i].name; - return "unknown"; -}; - -static const char *audio_mode2name(int mode) -{ - switch (mode) { - case VIDEO_SOUND_MONO: - return "mono"; - case VIDEO_SOUND_STEREO: - return "stereo"; - case VIDEO_SOUND_LANG1: - return "language1"; - case VIDEO_SOUND_LANG2: - return "language2"; - default: - return "unknown"; - } -}; - -static void *audio_grabber(void *data); -static void *video_grabber(void *data); - -static int palette2depth(int palette) -{ - switch(palette) - { - /* component */ - case VIDEO_PALETTE_RGB555: - return 15; - case VIDEO_PALETTE_RGB565: - return 16; - case VIDEO_PALETTE_RGB24: - return 24; - case VIDEO_PALETTE_RGB32: - return 32; - /* planar */ - case VIDEO_PALETTE_YUV411P: - case VIDEO_PALETTE_YUV420P: - case VIDEO_PALETTE_YUV410P: - return 12; - /* packed */ - case VIDEO_PALETTE_YUV422P: - case VIDEO_PALETTE_YUV422: - case VIDEO_PALETTE_YUYV: - case VIDEO_PALETTE_UYVY: - case VIDEO_PALETTE_YUV420: - case VIDEO_PALETTE_YUV411: - return 16; - } - return -1; -} - -static int format2palette(int format) -{ - switch(format) - { - case IMGFMT_BGR15: - return VIDEO_PALETTE_RGB555; - case IMGFMT_BGR16: - return VIDEO_PALETTE_RGB565; - case IMGFMT_BGR24: - return VIDEO_PALETTE_RGB24; - case IMGFMT_BGR32: - return VIDEO_PALETTE_RGB32; - case IMGFMT_YV12: - case IMGFMT_I420: - return VIDEO_PALETTE_YUV420P; - case IMGFMT_YUY2: - return VIDEO_PALETTE_YUV422; - case IMGFMT_UYVY: - return VIDEO_PALETTE_UYVY; - } - return -1; -} - -// sets and sanitizes audio buffer/block sizes -static void setup_audio_buffer_sizes(priv_t *priv) -{ - int bytes_per_sample = priv->audio_in.bytes_per_sample; - - // make the audio buffer at least 5 seconds long - priv->audio_buffer_size = 1 + 5*priv->audio_in.samplerate - *priv->audio_in.channels - *bytes_per_sample/priv->audio_in.blocksize; - if (priv->audio_buffer_size < 256) priv->audio_buffer_size = 256; - - // make the skew buffer at least 1 second long - priv->aud_skew_cnt = 1 + 1*priv->audio_in.samplerate - *priv->audio_in.channels - *bytes_per_sample/priv->audio_in.blocksize; - if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16; - - mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n", - priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt); -} - -static tvi_handle_t *tvi_init_v4l(tv_param_t* tv_param) -{ - tvi_handle_t *h; - priv_t *priv; - - h = tv_new_handle(sizeof(priv_t), &functions); - if (!h) - return NULL; - - priv = h->priv; - - /* set video device name */ - if (!tv_param->device) - priv->video_device = strdup("/dev/video0"); - else - priv->video_device = strdup(tv_param->device); - - /* set video device name */ - if (!tv_param->adevice) - priv->audio_device = NULL; - else { - priv->audio_device = strdup(tv_param->adevice); - } - - /* allocation failed */ - if (!priv->video_device) { - tv_free_handle(h); - return NULL; - } - - priv->tv_param=tv_param; - return h; -} - -/* retrieves info about audio channels from the BTTV */ -static void init_v4l_audio(priv_t *priv) -{ - int i; - int reqmode; - - if (!priv->capability.audios) return; - - /* audio chanlist */ - - mp_msg(MSGT_TV, MSGL_V, " Audio devices: %d\n", priv->capability.audios); - - mp_msg(MSGT_TV, MSGL_V, "Video capture card reports the audio setup as follows:\n"); - for (i = 0; i < priv->capability.audios; i++) - { - if (i >= MAX_AUDIO_CHANNELS) - { - mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (increase in source!) (%d > %d)\n", - i, MAX_AUDIO_CHANNELS); - i = priv->capability.audios; - break; - } - - priv->audio[i].audio = i; - if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) - { - mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); - break; - } - - /* mute all channels */ - priv->audio[i].flags |= VIDEO_AUDIO_MUTE; - reqmode = -1; - if (priv->tv_param->amode >= 0) { - switch (priv->tv_param->amode) { - case 0: - reqmode = VIDEO_SOUND_MONO; - break; - case 1: - reqmode = VIDEO_SOUND_STEREO; - break; - case 2: - reqmode = VIDEO_SOUND_LANG1; - break; - case 3: - reqmode = VIDEO_SOUND_LANG2; - break; - default: - mp_msg(MSGT_TV, MSGL_ERR, "Unknown audio mode requested.\n"); - break; - } - if (reqmode >= 0) priv->audio[i].mode = reqmode; - } - ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]); - - // get the parameters back - if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) - { - mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); - break; - } - - switch(priv->audio[i].mode) - { - case VIDEO_SOUND_MONO: - case VIDEO_SOUND_LANG1: - case VIDEO_SOUND_LANG2: - priv->audio_channels[i] = 1; - break; - case VIDEO_SOUND_STEREO: - priv->audio_channels[i] = 2; - break; - default: - mp_msg(MSGT_TV, MSGL_ERR, "Card reports an unknown audio mode !\n"); - mp_msg(MSGT_TV, MSGL_ERR, "Trying two channel audio. Use forcechan to override.\n"); - priv->audio_channels[i] = 2; - break; - } - - if (reqmode >= 0 && priv->audio[i].mode != reqmode) { - mp_msg(MSGT_TV, MSGL_ERR, "Audio mode setup warning!\n"); - mp_msg(MSGT_TV, MSGL_ERR, "Requested mode was %s, but v4l still reports %s.\n", - audio_mode2name(reqmode), audio_mode2name(priv->audio[i].mode)); - mp_msg(MSGT_TV, MSGL_ERR, "You may need \"forcechan\" option to force stereo/mono audio recording.\n"); - } - - /* display stuff */ - mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio, - priv->audio[i].name); - if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE) { - mp_msg(MSGT_TV, MSGL_V, "muted=%s ", - (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no"); - } - mp_msg(MSGT_TV, MSGL_V, "vol=%d bass=%d treble=%d balance=%d mode=%s", - priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble, - priv->audio[i].balance, audio_mode2name(priv->audio[i].mode)); - mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[i]); - - if (priv->tv_param->forcechan >= 0) - priv->audio_channels[i] = priv->tv_param->forcechan; - - // we'll call VIDIOCSAUDIO again when starting capture - // let's set audio mode to requested mode again for the case - // when VIDIOCGAUDIO just cannot report the mode correctly - if (reqmode >= 0) priv->audio[i].mode = reqmode; - } -} - -#if !defined(__LINUX_VIDEODEV2_H) && !defined(VIDIOC_QUERYCAP) -struct v4l2_capability -{ - __u8 driver[16]; /* i.e. "bttv" */ - __u8 card[32]; /* i.e. "Hauppauge WinTV" */ - __u8 bus_info[32]; /* "PCI:" + pci_dev->slot_name */ - __u32 version; /* should use KERNEL_VERSION() */ - __u32 capabilities; /* Device capabilities */ - __u32 reserved[4]; -}; - -#define VIDIOC_QUERYCAP _IOR ('V', 0, struct v4l2_capability) -#endif - -static int init(priv_t *priv) -{ - int i; - - if (priv->tv_param->immediate == 1) - priv->tv_param->noaudio = 1; - - priv->video_ringbuffer = NULL; - priv->video_timebuffer = NULL; - priv->video_avg_buffer = NULL; - priv->audio_ringbuffer = NULL; - priv->audio_skew_buffer = NULL; - - priv->video_fd = open(priv->video_device, O_RDWR); - mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %p\n", priv->video_fd, - priv->video_device); - if (priv->video_fd == -1) - { - mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", - priv->video_device, strerror(errno)); - goto err; - } - - /* check for v4l2 */ - if (ioctl(priv->video_fd, VIDIOC_QUERYCAP, &priv->capability) == 0) { - mp_msg(MSGT_TV, MSGL_ERR, "=================================================================\n"); - mp_msg(MSGT_TV, MSGL_ERR, " WARNING: YOU ARE USING V4L DEMUXER WITH V4L2 DRIVERS!!!\n"); - mp_msg(MSGT_TV, MSGL_ERR, " As the V4L1 compatibility layer is broken, this may not work.\n"); - mp_msg(MSGT_TV, MSGL_ERR, " If you encounter any problems, use driver=v4l2 instead.\n"); - mp_msg(MSGT_TV, MSGL_ERR, " Bugreports on driver=v4l with v4l2 drivers will be ignored.\n"); - mp_msg(MSGT_TV, MSGL_ERR, "=================================================================\n"); - } - - /* get capabilities (priv->capability is needed!) */ - if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) - { - mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilities failed: %s\n", strerror(errno)); - goto err; - } - - fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC); - - mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name); - mp_msg(MSGT_TV, MSGL_INFO, " Capabilities: "); - for (i = 0; device_cap2name[i] != NULL; i++) - if (priv->capability.type & (1 << i)) - mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]); - mp_msg(MSGT_TV, MSGL_INFO, "\n"); - mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type); - mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n", - priv->capability.minwidth, priv->capability.minheight, - priv->capability.maxwidth, priv->capability.maxheight); - priv->width = priv->capability.minwidth; - priv->height = priv->capability.minheight; - - /* somewhere here could disable priv->tv_param->mjpeg, if it is not a capability */ - - /* initialize if necessary */ - if ( priv->tv_param->mjpeg ) - { - struct mjpeg_params bparm; - struct mjpeg_requestbuffers breq; /* buffer requests */ - - if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0) - { - mp_msg(MSGT_TV, MSGL_ERR, - " MJP: Error getting video parameters: %s\n", strerror(errno)); - goto err; - } - - mp_msg(MSGT_TV, MSGL_INFO, - " MJP: previous params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n", - bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height, - bparm.decimation, bparm.field_per_buff); - - mp_msg(MSGT_TV, MSGL_INFO, - " MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n", - bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm); - - bparm.input = priv->tv_param->input; /* tv */ - if (!strcasecmp(priv->tv_param->norm, "pal")) - bparm.norm = 0; /* PAL */ - else if (!strcasecmp(priv->tv_param->norm, "ntsc")) - bparm.norm = 1; /* NTSC */ - else if (!strcasecmp(priv->tv_param->norm, "secam")) - bparm.norm = 2; /* SECAM */ - bparm.quality = priv->tv_param->quality; - bparm.decimation = priv->tv_param->decimation; - - mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting params to decimation: %d, quality: %d\n", - bparm.decimation, bparm.quality); - - if (ioctl(priv->video_fd, MJPIOC_S_PARAMS, &bparm) < 0) - { - mp_msg(MSGT_TV, MSGL_ERR, - " MJP: Error setting video parameters: %s\n", strerror(errno)); - goto err; - } - - if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0) - { - mp_msg(MSGT_TV, MSGL_ERR, - " MJP: Error getting video parameters: %s\n", strerror(errno)); - goto err; - } - - mp_msg(MSGT_TV, MSGL_INFO, - " MJP: current params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n", - bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height, - bparm.decimation, bparm.field_per_buff); |