📄 v4l2.c
字号:
/***************************************************************************** * v4l2.c : Video4Linux2 input module for vlc ***************************************************************************** * Copyright (C) 2002-2007 the VideoLAN team * $Id: a1e52526f58a94c4f1e0c26a798f2b3633a8e0a8 $ * * Authors: Benjamin Pracht <bigben at videolan dot org> * Richard Hosking <richard at hovis dot net> * Antoine Cellerier <dionoea at videolan d.t org> * Dennis Lou <dlou99 at yahoo dot com> * * 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. *****************************************************************************//* * Sections based on the reference V4L2 capture example at * http://v4l2spec.bytesex.org/spec/capture-example.html * * ALSA support based on parts of * http://www.equalarea.com/paul/alsa-audio.html * and hints taken from alsa-utils (aplay/arecord) * http://www.alsa-project.org *//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_access.h>#include <vlc_demux.h>#include <vlc_input.h>#include <vlc_vout.h>#include <ctype.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <linux/videodev2.h>#include <sys/soundcard.h>#ifdef HAVE_ALSA# define ALSA_PCM_NEW_HW_PARAMS_API# define ALSA_PCM_NEW_SW_PARAMS_API# include <alsa/asoundlib.h>#endif#include <poll.h>#ifdef HAVE_LIBV4L2# include <libv4l2.h>#else# define v4l2_fd_open(fd, flags) (fd)# define v4l2_close close# define v4l2_dup dup# define v4l2_ioctl ioctl# define v4l2_read read# define v4l2_mmap mmap# define v4l2_munmap munmap#endif/***************************************************************************** * Module descriptior *****************************************************************************/static int DemuxOpen ( vlc_object_t * );static void DemuxClose( vlc_object_t * );static int AccessOpen ( vlc_object_t * );static void AccessClose( vlc_object_t * );#define DEV_TEXT N_("Device name")#define DEV_LONGTEXT N_( \ "Name of the device to use. " \ "If you don't specify anything, /dev/video0 will be used.")#define STANDARD_TEXT N_( "Standard" )#define STANDARD_LONGTEXT N_( \ "Video standard (Default, SECAM, PAL, or NTSC)." )#define CHROMA_TEXT N_("Video input chroma format")#define CHROMA_LONGTEXT N_( \ "Force the Video4Linux2 video device to use a specific chroma format " \ "(eg. I420 or I422 for raw images, MJPG for M-JPEG compressed input) " \ "(Complete list: GREY, I240, RV16, RV15, RV24, RV32, YUY2, YUYV, UYVY, " \ "I41N, I422, I420, I411, I410, MJPG)")#define INPUT_TEXT N_( "Input" )#define INPUT_LONGTEXT N_( \ "Input of the card to use (see debug)." )#define AUDIO_INPUT_TEXT N_( "Audio input" )#define AUDIO_INPUT_LONGTEXT N_( \ "Audio input of the card to use (see debug)." )#define IOMETHOD_TEXT N_( "IO Method" )#define IOMETHOD_LONGTEXT N_( \ "IO Method (READ, MMAP, USERPTR)." )#define WIDTH_TEXT N_( "Width" )#define WIDTH_LONGTEXT N_( \ "Force width (-1 for autodetect)." )#define HEIGHT_TEXT N_( "Height" )#define HEIGHT_LONGTEXT N_( \ "Force height (-1 for autodetect)." )#define FPS_TEXT N_( "Framerate" )#define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \ "(-1 for autodetect)." )#define CTRL_RESET_TEXT N_( "Reset v4l2 controls" )#define CTRL_RESET_LONGTEXT N_( \ "Reset controls to defaults provided by the v4l2 driver." )#define BRIGHTNESS_TEXT N_( "Brightness" )#define BRIGHTNESS_LONGTEXT N_( \ "Brightness of the video input (if supported by the v4l2 driver)." )#define CONTRAST_TEXT N_( "Contrast" )#define CONTRAST_LONGTEXT N_( \ "Contrast of the video input (if supported by the v4l2 driver)." )#define SATURATION_TEXT N_( "Saturation" )#define SATURATION_LONGTEXT N_( \ "Saturation of the video input (if supported by the v4l2 driver)." )#define HUE_TEXT N_( "Hue" )#define HUE_LONGTEXT N_( \ "Hue of the video input (if supported by the v4l2 driver)." )#define BLACKLEVEL_TEXT N_( "Black level" )#define BLACKLEVEL_LONGTEXT N_( \ "Black level of the video input (if supported by the v4l2 driver)." )#define AUTOWHITEBALANCE_TEXT N_( "Auto white balance" )#define AUTOWHITEBALANCE_LONGTEXT N_( \ "Automatically set the white balance of the video input " \ "(if supported by the v4l2 driver)." )#define DOWHITEBALANCE_TEXT N_( "Do white balance" )#define DOWHITEBALANCE_LONGTEXT N_( \ "Trigger a white balancing action, useless if auto white balance is " \ "activated (if supported by the v4l2 driver)." )#define REDBALANCE_TEXT N_( "Red balance" )#define REDBALANCE_LONGTEXT N_( \ "Red balance of the video input (if supported by the v4l2 driver)." )#define BLUEBALANCE_TEXT N_( "Blue balance" )#define BLUEBALANCE_LONGTEXT N_( \ "Blue balance of the video input (if supported by the v4l2 driver)." )#define GAMMA_TEXT N_( "Gamma" )#define GAMMA_LONGTEXT N_( \ "Gamma of the video input (if supported by the v4l2 driver)." )#define EXPOSURE_TEXT N_( "Exposure" )#define EXPOSURE_LONGTEXT N_( \ "Exposure of the video input (if supported by the v4L2 driver)." )#define AUTOGAIN_TEXT N_( "Auto gain" )#define AUTOGAIN_LONGTEXT N_( \ "Automatically set the video input's gain (if supported by the " \ "v4l2 driver)." )#define GAIN_TEXT N_( "Gain" )#define GAIN_LONGTEXT N_( \ "Video input's gain (if supported by the v4l2 driver)." )#define HFLIP_TEXT N_( "Horizontal flip" )#define HFLIP_LONGTEXT N_( \ "Flip the video horizontally (if supported by the v4l2 driver)." )#define VFLIP_TEXT N_( "Vertical flip" )#define VFLIP_LONGTEXT N_( \ "Flip the video vertically (if supported by the v4l2 driver)." )#define HCENTER_TEXT N_( "Horizontal centering" )#define HCENTER_LONGTEXT N_( \ "Set the camera's horizontal centering (if supported by the v4l2 driver)." )#define VCENTER_TEXT N_( "Vertical centering" )#define VCENTER_LONGTEXT N_( \ "Set the camera's vertical centering (if supported by the v4l2 driver)." )#define ADEV_TEXT N_("Audio device name")#ifndef HAVE_ALSA#define ADEV_LONGTEXT N_( \ "Name of the audio device to use. " \ "If you don't specify anything, \"/dev/dsp\" will be used for OSS.")#else#define ADEV_LONGTEXT N_( \ "Name of the audio device to use. " \ "If you don't specify anything, \"/dev/dsp\" will be used for OSS, " \ "\"hw\" for Alsa.")#endif#define AUDIO_METHOD_TEXT N_( "Audio method" )#ifndef HAVE_ALSA#define AUDIO_METHOD_LONGTEXT N_( \ "Audio method to use: 0 to disable audio, 1 for OSS." )#else#define AUDIO_METHOD_LONGTEXT N_( \ "Audio method to use: 0 to disable audio, 1 for OSS, 2 for ALSA, " \ "3 for ALSA or OSS (ALSA is preferred)." )#endif#define AUDIO_VOLUME_TEXT N_( "Volume" )#define AUDIO_VOLUME_LONGTEXT N_( \ "Volume of the audio input (if supported by the v4l2 driver)." )#define AUDIO_BALANCE_TEXT N_( "Balance" )#define AUDIO_BALANCE_LONGTEXT N_( \ "Balance of the audio input (if supported by the v4l2 driver)." )#define AUDIO_MUTE_TEXT N_( "Mute" )#define AUDIO_MUTE_LONGTEXT N_( \ "Mute audio input (if supported by the v4l2 driver)." )#define AUDIO_BASS_TEXT N_( "Bass" )#define AUDIO_BASS_LONGTEXT N_( \ "Bass level of the audio input (if supported by the v4l2 driver)." )#define AUDIO_TREBLE_TEXT N_( "Treble" )#define AUDIO_TREBLE_LONGTEXT N_( \ "Treble level of the audio input (if supported by the v4l2 driver)." )#define AUDIO_LOUDNESS_TEXT N_( "Loudness" )#define AUDIO_LOUDNESS_LONGTEXT N_( \ "Loudness of the audio input (if supported by the v4l2 driver)." )#define STEREO_TEXT N_( "Stereo" )#define STEREO_LONGTEXT N_( \ "Capture the audio stream in stereo." )#define SAMPLERATE_TEXT N_( "Samplerate" )#define SAMPLERATE_LONGTEXT N_( \ "Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100, 48000)" )#define CACHING_TEXT N_("Caching value in ms")#define CACHING_LONGTEXT N_( \ "Caching value for V4L2 captures. This " \ "value should be set in milliseconds." )#define S_CTRLS_TEXT N_("v4l2 driver controls")#define S_CTRLS_LONGTEXT N_( \ "Set the v4l2 driver controls to the values specified using a comma " \ "separated list optionally encapsulated by curly braces " \ "(e.g.: {video_bitrate=6000000,audio_crc=0,stream_type=3} ). " \ "To list available controls, increase verbosity (-vvv) " \ "or use the v4l2-ctl application." )#define TUNER_TEXT N_("Tuner id")#define TUNER_LONGTEXT N_( \ "Tuner id (see debug output)." )#define FREQUENCY_TEXT N_("Frequency")#define FREQUENCY_LONGTEXT N_( \ "Tuner frequency in Hz or kHz (see debug output)" )#define TUNER_AUDIO_MODE_TEXT N_("Audio mode")#define TUNER_AUDIO_MODE_LONGTEXT N_( \ "Tuner audio mono/stereo and track selection." )typedef enum { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR,} io_method;static const int i_standards_list[] = { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };static const char *const psz_standards_list_text[] = { N_("Default"), N_("SECAM"), N_("PAL"), N_("NTSC") };static const int i_iomethod_list[] = { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR };static const char *const psz_iomethod_list_text[] = { N_("READ"), N_("MMAP"), N_("USERPTR") };static const int i_tuner_audio_modes_list[] = { V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO, V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2, V4L2_TUNER_MODE_SAP, V4L2_TUNER_MODE_LANG1_LANG2 };static const char *const psz_tuner_audio_modes_list_text[] = { N_( "Mono" ), N_( "Stereo" ), N_( "Primary language (Analog TV tuners only)" ), N_( "Secondary language (Analog TV tuners only)" ), N_( "Second audio program (Analog TV tuners only)" ), N_( "Primary language left, Secondary language right" ) };#define FIND_VIDEO 1#define FIND_AUDIO 2#define AUDIO_METHOD_OSS 1#define OSS_DEFAULT "/dev/dsp"#define AUDIO_METHOD_ALSA 2#define ALSA_DEFAULT "hw"#define CFG_PREFIX "v4l2-"vlc_module_begin(); set_shortname( N_("Video4Linux2") ); set_description( N_("Video4Linux2 input") ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_ACCESS ); set_section( N_( "Video input" ), NULL ); add_string( CFG_PREFIX "dev", "/dev/video0", 0, DEV_TEXT, DEV_LONGTEXT, false ); add_integer( CFG_PREFIX "standard", 0, NULL, STANDARD_TEXT, STANDARD_LONGTEXT, false ); change_integer_list( i_standards_list, psz_standards_list_text, NULL ); add_string( CFG_PREFIX "chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true ); add_integer( CFG_PREFIX "input", 0, NULL, INPUT_TEXT, INPUT_LONGTEXT, true ); add_integer( CFG_PREFIX "audio-input", 0, NULL, AUDIO_INPUT_TEXT, AUDIO_INPUT_LONGTEXT, true ); add_integer( CFG_PREFIX "io", IO_METHOD_MMAP, NULL, IOMETHOD_TEXT, IOMETHOD_LONGTEXT, true ); change_integer_list( i_iomethod_list, psz_iomethod_list_text, NULL ); add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true ); add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true ); add_float( CFG_PREFIX "fps", 0, NULL, FPS_TEXT, FPS_LONGTEXT, true ); set_section( N_( "Audio input" ), NULL ); add_string( CFG_PREFIX "adev", NULL, 0, ADEV_TEXT, ADEV_LONGTEXT, false ); add_integer( CFG_PREFIX "audio-method", AUDIO_METHOD_OSS|AUDIO_METHOD_ALSA, NULL, AUDIO_METHOD_TEXT, AUDIO_METHOD_LONGTEXT, true ); add_bool( CFG_PREFIX "stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT, true ); add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT, SAMPLERATE_LONGTEXT, true ); add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ); set_section( N_( "Tuner" ), NULL ); add_integer( CFG_PREFIX "tuner", 0, NULL, TUNER_TEXT, TUNER_LONGTEXT, true ); add_integer( CFG_PREFIX "tuner-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT, true ); add_integer( CFG_PREFIX "tuner-audio-mode", -1, NULL, TUNER_AUDIO_MODE_TEXT, TUNER_AUDIO_MODE_LONGTEXT, true ); change_integer_list( i_tuner_audio_modes_list, psz_tuner_audio_modes_list_text, 0 ); set_section( N_( "Controls" ), N_( "v4l2 driver controls, if supported by your v4l2 driver." ) ); add_bool( CFG_PREFIX "controls-reset", false, NULL, CTRL_RESET_TEXT, CTRL_RESET_LONGTEXT, true ); add_integer( CFG_PREFIX "brightness", -1, NULL, BRIGHTNESS_TEXT, BRIGHTNESS_LONGTEXT, true ); add_integer( CFG_PREFIX "contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT, true ); add_integer( CFG_PREFIX "saturation", -1, NULL, SATURATION_TEXT, SATURATION_LONGTEXT, true ); add_integer( CFG_PREFIX "hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, true ); add_integer( CFG_PREFIX "black-level", -1, NULL, BLACKLEVEL_TEXT, BLACKLEVEL_LONGTEXT, true ); add_integer( CFG_PREFIX "auto-white-balance", -1, NULL, AUTOWHITEBALANCE_TEXT, AUTOWHITEBALANCE_LONGTEXT, true ); add_integer( CFG_PREFIX "do-white-balance", -1, NULL, DOWHITEBALANCE_TEXT, DOWHITEBALANCE_LONGTEXT, true ); add_integer( CFG_PREFIX "red-balance", -1, NULL, REDBALANCE_TEXT, REDBALANCE_LONGTEXT, true ); add_integer( CFG_PREFIX "blue-balance", -1, NULL, BLUEBALANCE_TEXT, BLUEBALANCE_LONGTEXT, true ); add_integer( CFG_PREFIX "gamma", -1, NULL, GAMMA_TEXT, GAMMA_LONGTEXT, true ); add_integer( CFG_PREFIX "exposure", -1, NULL, EXPOSURE_TEXT, EXPOSURE_LONGTEXT, true ); add_integer( CFG_PREFIX "autogain", -1, NULL, AUTOGAIN_TEXT, AUTOGAIN_LONGTEXT, true ); add_integer( CFG_PREFIX "gain", -1, NULL, GAIN_TEXT, GAIN_LONGTEXT, true ); add_integer( CFG_PREFIX "hflip", -1, NULL, HFLIP_TEXT, HFLIP_LONGTEXT, true ); add_integer( CFG_PREFIX "vflip", -1, NULL, VFLIP_TEXT, VFLIP_LONGTEXT, true ); add_integer( CFG_PREFIX "hcenter", -1, NULL, HCENTER_TEXT, HCENTER_LONGTEXT, true ); add_integer( CFG_PREFIX "vcenter", -1, NULL, VCENTER_TEXT, VCENTER_LONGTEXT, true ); add_integer( CFG_PREFIX "audio-volume", -1, NULL, AUDIO_VOLUME_TEXT, AUDIO_VOLUME_LONGTEXT, true ); add_integer( CFG_PREFIX "audio-balance", -1, NULL, AUDIO_BALANCE_TEXT, AUDIO_BALANCE_LONGTEXT, true ); add_bool( CFG_PREFIX "audio-mute", false, NULL, AUDIO_MUTE_TEXT,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -