⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v4l.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * v4l.c : Video4Linux input module for vlc ***************************************************************************** * Copyright (C) 2002-2004 the VideoLAN team * $Id$ * * Author: Laurent Aimar <fenrir@via.ecp.fr> *         Paul Forgey <paulf at aphrodite dot com> *         Gildas Bazin <gbazin@videolan.org> *         Benjamin Pracht <bigben at videolan dot org> * * 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_input.h>#include <vlc_demux.h>#include <vlc_access.h>#include <vlc_vout.h>#include <vlc_codecs.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <unistd.h>#include <sys/mman.h>#include <errno.h>#include <fcntl.h>/* From GStreamer's v4l plugin: * Because of some really cool feature in video4linux1, also known as * 'not including sys/types.h and sys/time.h', we had to include it * ourselves. In all their intelligence, these people decided to fix * this in the next version (video4linux2) in such a cool way that it * breaks all compilations of old stuff... * The real problem is actually that linux/time.h doesn't use proper * macro checks before defining types like struct timeval. The proper * fix here is to either fuck the kernel header (which is what we do * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it * upstream, which I'll consider doing later on. If you get compiler * errors here, check your linux/time.h && sys/time.h header setup.*/#define _LINUX_TIME_H#include <linux/videodev.h>#include "videodev_mjpeg.h"#include <sys/soundcard.h>/***************************************************************************** * Module descriptior *****************************************************************************/static int  Open ( vlc_object_t * );static void Close( vlc_object_t * );#define CACHING_TEXT N_("Caching value in ms")#define CACHING_LONGTEXT N_( \    "Caching value for V4L captures. This " \    "value should be set in milliseconds." )#define VDEV_TEXT N_("Video device name")#define VDEV_LONGTEXT N_( \    "Name of the video device to use. " \    "If you don't specify anything, no video device will be used.")#define ADEV_TEXT N_("Audio device name")#define ADEV_LONGTEXT N_( \    "Name of the audio device to use. " \    "If you don't specify anything, no audio device will be used.")#define CHROMA_TEXT N_("Video input chroma format")#define CHROMA_LONGTEXT N_( \    "Force the Video4Linux video device to use a specific chroma format " \    "(eg. I420 (default), RV24, etc.)")#define FREQUENCY_TEXT N_( "Frequency" )#define FREQUENCY_LONGTEXT N_( \    "Frequency to capture (in kHz), if applicable." )#define CHANNEL_TEXT N_( "Channel" )#define CHANNEL_LONGTEXT N_( \    "Channel of the card to use (Usually, 0 = tuner, " \    "1 = composite, 2 = svideo)." )#define NORM_TEXT N_( "Norm" )#define NORM_LONGTEXT N_( \    "Norm of the stream (Automatic, SECAM, PAL, or NTSC)." )#define AUDIO_TEXT N_( "Audio Channel" )#define AUDIO_LONGTEXT N_( \    "Audio Channel to use, if there are several audio inputs." )#define WIDTH_TEXT N_( "Width" )#define WIDTH_LONGTEXT N_( "Width of the stream to capture " \    "(-1 for autodetect)." )#define HEIGHT_TEXT N_( "Height" )#define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \    "(-1 for autodetect)." )#define BRIGHTNESS_TEXT N_( "Brightness" )#define BRIGHTNESS_LONGTEXT N_( \    "Brightness of the video input." )#define HUE_TEXT N_( "Hue" )#define HUE_LONGTEXT N_( \    "Hue of the video input." )#define COLOUR_TEXT N_( "Color" )#define COLOUR_LONGTEXT N_( \    "Color of the video input." )#define CONTRAST_TEXT N_( "Contrast" )#define CONTRAST_LONGTEXT N_( \    "Contrast of the video input." )#define TUNER_TEXT N_( "Tuner" )#define TUNER_LONGTEXT N_( "Tuner to use, if there are several ones." )#define SAMPLERATE_TEXT N_( "Samplerate" )#define SAMPLERATE_LONGTEXT N_( \    "Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100)" )#define STEREO_TEXT N_( "Stereo" )#define STEREO_LONGTEXT N_( \    "Capture the audio stream in stereo." )#define MJPEG_TEXT N_( "MJPEG" )#define MJPEG_LONGTEXT N_(  \    "Set this option if the capture device outputs MJPEG" )#define DECIMATION_TEXT N_( "Decimation" )#define DECIMATION_LONGTEXT N_( \    "Decimation level for MJPEG streams" )#define QUALITY_TEXT N_( "Quality" )#define QUALITY_LONGTEXT N_( "Quality of the stream." )#define FPS_TEXT N_( "Framerate" )#define FPS_LONGTEXT N_( "Framerate to capture, if applicable " \    "(-1 for autodetect)." )static const int i_norm_list[] =    { VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };static const char *const psz_norm_list_text[] =    { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };vlc_module_begin();    set_shortname( N_("Video4Linux") );    set_description( N_("Video4Linux input") );    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_ACCESS );    add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,                 CACHING_TEXT, CACHING_LONGTEXT, true );    add_string( "v4l-vdev", "/dev/video", 0, VDEV_TEXT, VDEV_LONGTEXT,                false );    add_string( "v4l-adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT,                false );    add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,                true );    add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, true );    add_integer( "v4l-samplerate", 44100, NULL, SAMPLERATE_TEXT,                SAMPLERATE_LONGTEXT, true );    add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,                true );    add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, true );    add_integer( "v4l-norm", VIDEO_MODE_AUTO, NULL, NORM_TEXT, NORM_LONGTEXT,                false );        change_integer_list( i_norm_list, psz_norm_list_text, NULL );    add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,                false );    add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, true );    add_bool( "v4l-stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT,            true );    add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true );    add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,                true );    add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,                BRIGHTNESS_LONGTEXT, true );    add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,                true );    add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, true );    add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,                true );    add_bool( "v4l-mjpeg", false, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,            true );    add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,            DECIMATION_LONGTEXT, true );    add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,            true );    add_shortcut( "v4l" );    set_capability( "access_demux", 10 );    set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Access: local prototypes *****************************************************************************/static int Demux  ( demux_t * );static int Control( demux_t *, int, va_list );static void ParseMRL    ( demux_t * );static int  OpenVideoDev( demux_t *, char * );static int  OpenAudioDev( demux_t *, char * );static block_t *GrabAudio( demux_t * );static block_t *GrabVideo( demux_t * );#define MJPEG_BUFFER_SIZE (256*1024)struct quicktime_mjpeg_app1{    uint32_t    i_reserved;             /* set to 0 */    uint32_t    i_tag;                  /* 'mjpg' */    uint32_t    i_field_size;           /* offset following EOI */    uint32_t    i_padded_field_size;    /* offset following EOI+pad */    uint32_t    i_next_field;           /* offset to next field */    uint32_t    i_DQT_offset;    uint32_t    i_DHT_offset;    uint32_t    i_SOF_offset;    uint32_t    i_SOS_offset;    uint32_t    i_data_offset;          /* following SOS marker data */};static const struct{    int i_v4l;    int i_fourcc;} v4lchroma_to_fourcc[] ={    { VIDEO_PALETTE_GREY, VLC_FOURCC( 'G', 'R', 'E', 'Y' ) },    { VIDEO_PALETTE_HI240, VLC_FOURCC( 'I', '2', '4', '0' ) },    { VIDEO_PALETTE_RGB565, VLC_FOURCC( 'R', 'V', '1', '6' ) },    { VIDEO_PALETTE_RGB555, VLC_FOURCC( 'R', 'V', '1', '5' ) },    { VIDEO_PALETTE_RGB24, VLC_FOURCC( 'R', 'V', '2', '4' ) },    { VIDEO_PALETTE_RGB32, VLC_FOURCC( 'R', 'V', '3', '2' ) },    { VIDEO_PALETTE_YUV422, VLC_FOURCC( 'Y', 'U', 'Y', '2' ) },    { VIDEO_PALETTE_YUV422, VLC_FOURCC( 'Y', 'U', 'Y', 'V' ) },    { VIDEO_PALETTE_YUYV, VLC_FOURCC( 'Y', 'U', 'Y', '2' ) },    { VIDEO_PALETTE_YUYV, VLC_FOURCC( 'Y', 'U', 'Y', 'V' ) },    { VIDEO_PALETTE_UYVY, VLC_FOURCC( 'U', 'Y', 'V', 'Y' ) },    { VIDEO_PALETTE_YUV420, VLC_FOURCC( 'I', '4', '2', 'N' ) },    { VIDEO_PALETTE_YUV411, VLC_FOURCC( 'I', '4', '1', 'N' ) },    { VIDEO_PALETTE_RAW, VLC_FOURCC( 'G', 'R', 'A', 'W' ) },    { VIDEO_PALETTE_YUV422P, VLC_FOURCC( 'I', '4', '2', '2' ) },    { VIDEO_PALETTE_YUV420P, VLC_FOURCC( 'I', '4', '2', '0' ) },    { VIDEO_PALETTE_YUV411P, VLC_FOURCC( 'I', '4', '1', '1' ) },    { 0, 0 }};struct demux_sys_t{    /* Devices */    char *psz_device;         /* Main device from MRL, can be video or audio */    char *psz_vdev;    int  fd_video;    char *psz_adev;    int  fd_audio;    /* Video properties */    picture_t pic;    int i_fourcc;    int i_channel;    int i_audio;    int i_norm;    int i_tuner;    int i_frequency;    int i_width;    int i_height;    int i_brightness;    int i_hue;    int i_colour;    int i_contrast;    float f_fps;            /* <= 0.0 mean to grab at full rate */    mtime_t i_video_pts;    /* only used when f_fps > 0 */    bool b_mjpeg;    int i_decimation;    int i_quality;    struct video_capability vid_cap;    struct video_mbuf       vid_mbuf;    struct mjpeg_requestbuffers mjpeg_buffers;    uint8_t *p_video_mmap;    int     i_frame_pos;    struct video_mmap   vid_mmap;    struct video_picture vid_picture;    int          i_video_frame_size;    es_out_id_t  *p_es_video;    /* Audio properties */    vlc_fourcc_t i_acodec_raw;    int          i_sample_rate;    bool   b_stereo;    int          i_audio_max_frame_size;    block_t      *p_block_audio;    es_out_id_t  *p_es_audio;};/***************************************************************************** * Open: opens v4l device ***************************************************************************** * * url: <video device>:::: * *****************************************************************************/static int Open( vlc_object_t *p_this ){    demux_t     *p_demux = (demux_t*)p_this;    demux_sys_t *p_sys;    vlc_value_t val;    /* Only when selected */    if( *p_demux->psz_access == '\0' )        return VLC_EGENERIC;    /* Set up p_demux */    p_demux->pf_demux = Demux;    p_demux->pf_control = Control;    p_demux->info.i_update = 0;    p_demux->info.i_title = 0;    p_demux->info.i_seekpoint = 0;    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );    memset( p_sys, 0, sizeof( demux_sys_t ) );    var_Create( p_demux, "v4l-audio", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-audio", &val );    p_sys->i_audio          = val.i_int;    var_Create( p_demux, "v4l-channel", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-channel", &val );    p_sys->i_channel        = val.i_int;    var_Create( p_demux, "v4l-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-norm", &val );    p_sys->i_norm           = val.i_int;    var_Create( p_demux, "v4l-tuner", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-tuner", &val );    p_sys->i_tuner          = val.i_int;    var_Create( p_demux, "v4l-frequency",                                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-frequency", &val );    p_sys->i_frequency      = val.i_int;    var_Create( p_demux, "v4l-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-fps", &val );    p_sys->f_fps            = val.f_float;    var_Create( p_demux, "v4l-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-width", &val );    p_sys->i_width          = val.i_int;    var_Create( p_demux, "v4l-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-height", &val );    p_sys->i_height         = val.i_int;    p_sys->i_video_pts      = -1;    var_Create( p_demux, "v4l-brightness", VLC_VAR_INTEGER |                                                        VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-brightness", &val );    p_sys->i_brightness     = val.i_int;    var_Create( p_demux, "v4l-hue", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-hue", &val );    p_sys->i_hue            = -1;    var_Create( p_demux, "v4l-colour", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-colour", &val );    p_sys->i_colour         = val.i_int;    var_Create( p_demux, "v4l-contrast", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-contrast", &val );    p_sys->i_contrast       = val.i_int;    var_Create( p_demux, "v4l-mjpeg", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-mjpeg", &val );    p_sys->b_mjpeg     = val.b_bool;    var_Create( p_demux, "v4l-decimation", VLC_VAR_INTEGER |                                                            VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-decimation", &val );    p_sys->i_decimation = val.i_int;    var_Create( p_demux, "v4l-quality", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Get( p_demux, "v4l-quality", &val );    p_sys->i_quality = val.i_int;    var_Create( p_demux, "v4l-samplerate",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -