📄 pvr.c
字号:
/***************************************************************************** * pvr.c ***************************************************************************** * Copyright (C) 2001, 2002 the VideoLAN team * $Id$ * * Authors: Eric Petit <titer@videolan.org> * Paul Corke <paulc@datatote.co.uk> * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_access.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <linux/types.h>#include <sys/ioctl.h>#include <sys/poll.h>#ifdef HAVE_NEW_LINUX_VIDEODEV2_H# ifdef VIDEODEV2_H_FILE# include VIDEODEV2_H_FILE# else# include <linux/videodev2.h># endif#else#include "videodev2.h"#endif/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close( vlc_object_t * );#define CACHING_TEXT N_("Caching value in ms")#define CACHING_LONGTEXT N_( \ "Default caching value for PVR streams. This " \ "value should be set in milliseconds." )#define DEVICE_TEXT N_( "Device" )#define DEVICE_LONGTEXT N_( "PVR video device" )#define RADIO_DEVICE_TEXT N_( "Radio device" )#define RADIO_DEVICE_LONGTEXT N_( "PVR radio device" )#define NORM_TEXT N_( "Norm" )#define NORM_LONGTEXT N_( "Norm of the stream " \ "(Automatic, SECAM, PAL, or NTSC)." )#define WIDTH_TEXT N_( "Width" )#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \ "(-1 for autodetection)." )#define HEIGHT_TEXT N_( "Height" )#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \ "(-1 for autodetection)." )#define FREQUENCY_TEXT N_( "Frequency" )#define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable." )#define FRAMERATE_TEXT N_( "Framerate" )#define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable " \ "(-1 for autodetect)." )#define KEYINT_TEXT N_( "Key interval" )#define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for autodetect)." )#define BFRAMES_TEXT N_( "B Frames" )#define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used. " \ "Use this option to set the number of B-Frames.")#define BITRATE_TEXT N_( "Bitrate" )#define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)." )#define BITRATE_PEAK_TEXT N_( "Bitrate peak" )#define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode." )#define BITRATE_MODE_TEXT N_( "Bitrate mode" )#define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use (VBR or CBR)." )#define BITMASK_TEXT N_( "Audio bitmask" )#define BITMASK_LONGTEXT N_("Bitmask that will "\ "get used by the audio part of the card." )#define VOLUME_TEXT N_( "Volume" )#define VOLUME_LONGTEXT N_("Audio volume (0-65535)." )#define CHAN_TEXT N_( "Channel" )#define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \ "1 = composite, 2 = svideo)" )static const int i_norm_list[] = { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };static const char *const psz_norm_list_text[] = { N_("Automatic"), N_("SECAM"), N_("PAL"), N_("NTSC") };static const int i_bitrates[] = { 0, 1 };static const char *const psz_bitrates_list_text[] = { N_("vbr"), N_("cbr") };static const int pi_radio_range[2] = { 65000, 108000 };vlc_module_begin(); set_shortname( N_("PVR") ); set_description( N_("IVTV MPEG Encoding cards input") ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_ACCESS ); set_capability( "access", 0 ); add_shortcut( "pvr" ); add_integer( "pvr-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ); add_string( "pvr-device", "/dev/video0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT, false ); add_string( "pvr-radio-device", "/dev/radio0", NULL, RADIO_DEVICE_TEXT, RADIO_DEVICE_LONGTEXT, false ); add_integer( "pvr-norm", V4L2_STD_UNKNOWN , NULL, NORM_TEXT, NORM_LONGTEXT, false ); change_integer_list( i_norm_list, psz_norm_list_text, NULL ); add_integer( "pvr-width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true ); add_integer( "pvr-height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true ); add_integer( "pvr-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT, false ); add_integer( "pvr-framerate", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT, true ); add_integer( "pvr-keyint", -1, NULL, KEYINT_TEXT, KEYINT_LONGTEXT, true ); add_integer( "pvr-bframes", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT, true ); add_integer( "pvr-bitrate", -1, NULL, BITRATE_TEXT, BITRATE_LONGTEXT, false ); add_integer( "pvr-bitrate-peak", -1, NULL, BITRATE_PEAK_TEXT, BITRATE_PEAK_LONGTEXT, true ); add_integer( "pvr-bitrate-mode", -1, NULL, BITRATE_MODE_TEXT, BITRATE_MODE_LONGTEXT, true ); change_integer_list( i_bitrates, psz_bitrates_list_text, NULL ); add_integer( "pvr-audio-bitmask", -1, NULL, BITMASK_TEXT, BITMASK_LONGTEXT, true ); add_integer( "pvr-audio-volume", -1, NULL, VOLUME_TEXT, VOLUME_LONGTEXT, true ); add_integer( "pvr-channel", -1, NULL, CHAN_TEXT, CHAN_LONGTEXT, true ); set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Prototypes *****************************************************************************/static ssize_t Read ( access_t *, uint8_t *, size_t );static int Control( access_t *, int, va_list );/* ivtv specific ioctls */#define IVTV_IOC_G_CODEC 0xFFEE7703#define IVTV_IOC_S_CODEC 0xFFEE7704/* for use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */struct ivtv_ioctl_codec { uint32_t aspect; uint32_t audio_bitmask; uint32_t bframes; uint32_t bitrate_mode; uint32_t bitrate; uint32_t bitrate_peak; uint32_t dnr_mode; uint32_t dnr_spatial; uint32_t dnr_temporal; uint32_t dnr_type; uint32_t framerate; uint32_t framespergop; uint32_t gop_closure; uint32_t pulldown; uint32_t stream_type;};struct access_sys_t{ /* file descriptor */ int i_fd; int i_radio_fd; char *psz_videodev; char *psz_radiodev; /* options */ int i_standard; int i_width; int i_height; int i_frequency; int i_framerate; int i_keyint; int i_bframes; int i_bitrate; int i_bitrate_peak; int i_bitrate_mode; int i_audio_bitmask; int i_input; int i_volume; /* driver version */ bool b_v4l2_api;};/***************************************************************************** * ConfigureIVTV: set up codec parameters using the old ivtv api *****************************************************************************/static int ConfigureIVTV( access_t * p_access ){ access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; struct ivtv_ioctl_codec codec; int result; memset( &codec, 0, sizeof(struct ivtv_ioctl_codec) ); result = ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ); if( result < 0 ) { msg_Err( p_access, "Failed to read current capture card settings." ); return VLC_EGENERIC; } if( p_sys->i_framerate != -1 ) { switch( p_sys->i_framerate ) { case 30: codec.framerate = 0; break; case 25: codec.framerate = 1; break; default: msg_Warn( p_access, "Invalid framerate, reverting to 25." ); codec.framerate = 1; break; } } if( p_sys->i_bitrate != -1 ) { codec.bitrate = p_sys->i_bitrate; } if( p_sys->i_bitrate_peak != -1 ) { codec.bitrate_peak = p_sys->i_bitrate_peak; } if( p_sys->i_bitrate_mode != -1 ) { codec.bitrate_mode = p_sys->i_bitrate_mode; } if( p_sys->i_audio_bitmask != -1 ) { codec.audio_bitmask = p_sys->i_audio_bitmask; } if( p_sys->i_keyint != -1 ) { codec.framespergop = p_sys->i_keyint; } if( p_sys->i_bframes != -1 ) { codec.bframes = p_sys->i_bframes; } result = ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ); if( result < 0 ) { msg_Err( p_access, "Failed to write new capture card settings." ); return VLC_EGENERIC; } msg_Dbg( p_access, "Setting codec parameters to: framerate: " "%d, bitrate: %d/%d/%d", codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode ); return VLC_SUCCESS;}#ifdef HAVE_NEW_LINUX_VIDEODEV2_H#define MAX_V4L2_CTRLS (6)/***************************************************************************** * AddV4L2Ctrl: adds a control to the v4l2 controls list *****************************************************************************/static void AddV4L2Ctrl( access_t * p_access, struct v4l2_ext_controls * p_controls, uint32_t i_id, uint32_t i_value ){ if( p_controls->count >= MAX_V4L2_CTRLS ) { msg_Err( p_access, "Tried to set too many v4l2 controls at once." ); return; } p_controls->controls[p_controls->count].id = i_id; p_controls->controls[p_controls->count].value = i_value; p_controls->count++;}/***************************************************************************** * V4L2SampleRate: calculate v4l2 sample rate from pvr-audio-bitmask *****************************************************************************/static uint32_t V4L2SampleRate( uint32_t i_bitmask ){ switch( i_bitmask & 0x0003 ) { case 0x0001: return V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000; case 0x0002: return V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000; } return V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100;}/***************************************************************************** * V4L2AudioEncoding: calculate v4l2 audio encoding level from pvr-audio-bitmask *****************************************************************************/static uint32_t V4L2AudioEncoding( uint32_t i_bitmask ){ switch( i_bitmask & 0x000c ) { case 0x0004: return V4L2_MPEG_AUDIO_ENCODING_LAYER_1; case 0x0008: return V4L2_MPEG_AUDIO_ENCODING_LAYER_2; } return 0xffffffff;}/***************************************************************************** * V4L2AudioL1Bitrate: calculate v4l2 audio bitrate for layer-1 audio from pvr-audio-bitmask *****************************************************************************/static uint32_t V4L2AudioL1Bitrate( uint32_t i_bitmask ){ switch( i_bitmask & 0x00f0 ) { case 0x0010: return V4L2_MPEG_AUDIO_L1_BITRATE_32K; case 0x0020: return V4L2_MPEG_AUDIO_L1_BITRATE_64K; case 0x0030: return V4L2_MPEG_AUDIO_L1_BITRATE_96K; case 0x0040: return V4L2_MPEG_AUDIO_L1_BITRATE_128K; case 0x0050: return V4L2_MPEG_AUDIO_L1_BITRATE_160K; case 0x0060: return V4L2_MPEG_AUDIO_L1_BITRATE_192K; case 0x0070: return V4L2_MPEG_AUDIO_L1_BITRATE_224K; case 0x0080: return V4L2_MPEG_AUDIO_L1_BITRATE_256K; case 0x0090: return V4L2_MPEG_AUDIO_L1_BITRATE_288K; case 0x00a0: return V4L2_MPEG_AUDIO_L1_BITRATE_320K; case 0x00b0: return V4L2_MPEG_AUDIO_L1_BITRATE_352K; case 0x00c0: return V4L2_MPEG_AUDIO_L1_BITRATE_384K; case 0x00d0: return V4L2_MPEG_AUDIO_L1_BITRATE_416K; case 0x00e0: return V4L2_MPEG_AUDIO_L1_BITRATE_448K; } return V4L2_MPEG_AUDIO_L1_BITRATE_320K;}/***************************************************************************** * V4L2AudioL2Bitrate: calculate v4l2 audio bitrate for layer-1 audio from pvr-audio-bitmask *****************************************************************************/static uint32_t V4L2AudioL2Bitrate( uint32_t i_bitmask ){ switch( i_bitmask & 0x00f0 ) { case 0x0010: return V4L2_MPEG_AUDIO_L2_BITRATE_32K; case 0x0020: return V4L2_MPEG_AUDIO_L2_BITRATE_48K;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -