diff options
Diffstat (limited to 'src/input/input_v4l.c')
-rw-r--r-- | src/input/input_v4l.c | 680 |
1 files changed, 340 insertions, 340 deletions
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c index 3a020bd69..e3af41f85 100644 --- a/src/input/input_v4l.c +++ b/src/input/input_v4l.c @@ -1,19 +1,19 @@ /* * Copyright (C) 2003-2008 the xine project * Copyright (C) 2003 J.Asselman <j.asselman@itsec-ps.nl> - * + * * This file is part of xine, a free video player. - * + * * xine 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. - * + * * xine 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, USA @@ -65,7 +65,7 @@ #define LOG_MODULE "input_v4l" #define LOG_VERBOSE /* -#define LOG +#define LOG */ #include "xine_internal.h" @@ -109,7 +109,7 @@ typedef struct { typedef struct { input_plugin_t input_plugin; - + xine_stream_t *stream; char *mrl; @@ -123,7 +123,7 @@ typedef struct { buf_element_t *frames_base; void *audio_content_base; void *video_content_base; - + /* Audio */ buf_element_t *aud_frames; pthread_mutex_t aud_frames_lock; @@ -132,32 +132,32 @@ typedef struct { #ifdef HAVE_ALSA /* Handle for the PCM device */ snd_pcm_t *pcm_handle; - + /* Record stream (via line 1) */ snd_pcm_stream_t pcm_stream; - + /* Information and configuration for the PCM stream */ snd_pcm_hw_params_t *pcm_hwparams; /* Name of the PCM device, plughw:0,0?=>soundcard,device*/ - char *pcm_name; - + char *pcm_name; + /* Use alsa to capture the sound (for a/v sync) */ char audio_capture; - + int exact_rate; /* Actual sample rate sndpcm_hw_params_set_rate_near */ int dir; /* exact rate == rate --> dir = 0 exact rate < rate --> dir = -1 exact rate > rate --> dir = 1 */ - + unsigned char *pcm_data; - + int64_t pts_aud_start; #endif int audio_header_sent; - + int rate; /* Sample rate */ int periods; /* Number of periods */ int periodsize; /* Periodsize in bytes */ @@ -186,9 +186,9 @@ typedef struct { struct video_audio audio; struct video_audio audio_saved; struct video_mbuf gb_buffers; - + int video_header_sent; - + int frame_format; const resolution_t *resolution; int frame_size; @@ -225,13 +225,13 @@ typedef struct { struct pvrscr_s { scr_plugin_t scr; - + struct timeval cur_time; int64_t cur_pts; int xine_speed; double speed_factor; double speed_tuning; - + pthread_mutex_t lock; }; @@ -246,47 +246,47 @@ static void pvrscr_set_pivot(pvrscr_t *this) struct timeval tv; int64_t pts; double pts_calc; - + xine_monotonic_clock(&tv, NULL); pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor; pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6; pts = this->cur_pts + pts_calc; - + /* This next part introduces a one off inaccuracy * to the scr due to rounding tv to pts. */ this->cur_time.tv_sec = tv.tv_sec; this->cur_time.tv_usec = tv.tv_usec; this->cur_pts = pts; - + return; } static int pvrscr_set_fine_speed (scr_plugin_t *scr, int speed) { pvrscr_t *this = (pvrscr_t*) scr; - + pthread_mutex_lock (&this->lock); - + pvrscr_set_pivot( this ); this->xine_speed = speed; this->speed_factor = (double) speed * 90000.0 / XINE_FINE_SPEED_NORMAL * this->speed_tuning; - + pthread_mutex_unlock (&this->lock); - + return speed; } static void pvrscr_speed_tuning (pvrscr_t *this, double factor) { pthread_mutex_lock (&this->lock); - + pvrscr_set_pivot( this ); this->speed_tuning = factor; this->speed_factor = (double) this->xine_speed * 90000.0 / XINE_FINE_SPEED_NORMAL * this->speed_tuning; - + pthread_mutex_unlock (&this->lock); } @@ -294,28 +294,28 @@ static void pvrscr_adjust (scr_plugin_t *scr, int64_t vpts) { pvrscr_t *this = (pvrscr_t*) scr; struct timeval tv; - + pthread_mutex_lock (&this->lock); - + xine_monotonic_clock(&tv, NULL); this->cur_time.tv_sec = tv.tv_sec; this->cur_time.tv_usec = tv.tv_usec; this->cur_pts = vpts; - + pthread_mutex_unlock (&this->lock); } static void pvrscr_start (scr_plugin_t *scr, int64_t start_vpts) { pvrscr_t *this = (pvrscr_t*) scr; - + pthread_mutex_lock (&this->lock); - + xine_monotonic_clock(&this->cur_time, NULL); this->cur_pts = start_vpts; pthread_mutex_unlock (&this->lock); - + pvrscr_set_fine_speed (&this->scr, XINE_FINE_SPEED_NORMAL); } @@ -325,17 +325,17 @@ static int64_t pvrscr_get_current (scr_plugin_t *scr) struct timeval tv; int64_t pts; double pts_calc; - + pthread_mutex_lock (&this->lock); - + xine_monotonic_clock(&tv, NULL); - + pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor; pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6; pts = this->cur_pts + pts_calc; - + pthread_mutex_unlock (&this->lock); - + /*printf("returning pts %lld\n", pts);*/ return pts; } @@ -343,7 +343,7 @@ static int64_t pvrscr_get_current (scr_plugin_t *scr) static void pvrscr_exit (scr_plugin_t *scr) { pvrscr_t *this = (pvrscr_t*) scr; - + pthread_mutex_destroy (&this->lock); free(this); } @@ -351,9 +351,9 @@ static void pvrscr_exit (scr_plugin_t *scr) static pvrscr_t *XINE_MALLOC pvrscr_init (void) { pvrscr_t *this; - + this = calloc(1, sizeof(pvrscr_t)); - + this->scr.interface_version = 3; this->scr.get_priority = pvrscr_get_priority; this->scr.set_fine_speed = pvrscr_set_fine_speed; @@ -361,7 +361,7 @@ static pvrscr_t *XINE_MALLOC pvrscr_init (void) this->scr.start = pvrscr_start; this->scr.get_current = pvrscr_get_current; this->scr.exit = pvrscr_exit; - + pthread_mutex_init (&this->lock, NULL); pvrscr_speed_tuning(this, 1.0 ); @@ -369,7 +369,7 @@ static pvrscr_t *XINE_MALLOC pvrscr_init (void) #ifdef SCRLOG printf("input_v4l: scr init complete\n"); #endif - + return this; } @@ -380,7 +380,7 @@ static void report_progress (xine_stream_t *stream, int p) { xine_event_t event; xine_progress_data_t prg; - + if (p == SCR_PAUSED) { prg.description = _("Buffer underrun..."); p = 0; @@ -390,13 +390,13 @@ static void report_progress (xine_stream_t *stream, int p) p = 100; } else prg.description = _("Adjusting..."); - + prg.percent = (p>100)?100:p; - + event.type = XINE_EVENT_PROGRESS; event.data = &prg; event.data_length = sizeof (xine_progress_data_t); - + xine_event_send (stream, &event); } @@ -412,25 +412,25 @@ static void v4l_event_handler(v4l_input_plugin_t *this); inline static buf_element_t *alloc_aud_frame (v4l_input_plugin_t *this) { buf_element_t *frame; - + lprintf("alloc_aud_frame. trying to get lock...\n"); pthread_mutex_lock (&this->aud_frames_lock) ; - + lprintf("got the lock\n"); - + while (!this->aud_frames) { lprintf("no audio frame available...\n"); pthread_cond_wait (&this->aud_frame_freed, &this->aud_frames_lock); } - + frame = this->aud_frames; this->aud_frames = this->aud_frames->next; - + pthread_mutex_unlock (&this->aud_frames_lock); - + lprintf("alloc_aud_frame done\n"); - + return frame; } @@ -444,10 +444,10 @@ static void store_aud_frame (buf_element_t *frame) lprintf("store_aud_frame\n"); pthread_mutex_lock (&this->aud_frames_lock) ; - + frame->next = this->aud_frames; this->aud_frames = frame; - + pthread_cond_signal (&this->aud_frame_freed); pthread_mutex_unlock (&this->aud_frames_lock); } @@ -464,19 +464,19 @@ inline static buf_element_t *alloc_vid_frame (v4l_input_plugin_t *this) pthread_mutex_lock (&this->vid_frames_lock) ; lprintf("got the lock\n"); - + while (!this->vid_frames) { lprintf("no video frame available...\n"); pthread_cond_wait (&this->vid_frame_freed, &this->vid_frames_lock); } - + frame = this->vid_frames; this->vid_frames = this->vid_frames->next; - + pthread_mutex_unlock (&this->vid_frames_lock); - + lprintf("alloc_vid_frame done\n"); - + return frame; } @@ -487,50 +487,50 @@ static void store_vid_frame (buf_element_t *frame) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) frame->source; - + lprintf("store_vid_frame\n"); - + pthread_mutex_lock (&this->vid_frames_lock) ; frame->next = this->vid_frames; this->vid_frames = frame; - + pthread_cond_signal (&this->vid_frame_freed); pthread_mutex_unlock (&this->vid_frames_lock); } -static int extract_mrl(v4l_input_plugin_t *this, char *mrl) +static int extract_mrl(v4l_input_plugin_t *this, char *mrl) { char *tuner_name = NULL; int frequency = 0; char *locator = NULL; char *begin = NULL; - + if (mrl == NULL) { lprintf("Someone passed an empty mrl\n"); return 0; } - + for (locator = mrl; *locator != '\0' && *locator != '/' ; locator++); - + /* Get tuner name */ if (*locator == '/') { begin = ++locator; - + for (; *locator != '\0' && *locator != '/' ; locator++); - + tuner_name = (char *) strndup(begin, locator - begin); - - /* Get frequency, if available */ + + /* Get frequency, if available */ sscanf(locator, "/%d", &frequency); - + /* cannot use xprintf to log in this routine */ lprintf("input_v4l: Tuner name: %s frequency %d\n", tuner_name, frequency ); } - + this->frequency = frequency; this->tuner_name = tuner_name; - + return 1; } @@ -538,12 +538,12 @@ static int set_frequency(v4l_input_plugin_t *this, unsigned long frequency) { int ret = 0; int fd; - + if (this->video_fd > 0) fd = this->video_fd; else fd = this->radio_fd; - + if (frequency != 0) { /* FIXME: Don't assume tuner 0 ? */ this->tuner = 0; @@ -556,18 +556,18 @@ static int set_frequency(v4l_input_plugin_t *this, unsigned long frequency) } else { this->calc_frequency = (frequency * 16) / 1000; } - + ret = ioctl(fd, VIDIOCSFREQ, &this->calc_frequency); lprintf("IOCTL set frequency (%ld) returned: %d\n", frequency, ret); } else { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: No frequency given. Expected syntax: v4l:/tuner/frequency\n" "input_v4l: Using currently tuned settings\n"); } - + this->frequency = frequency; - + if (ret < 0) return ret; else @@ -577,11 +577,11 @@ static int set_frequency(v4l_input_plugin_t *this, unsigned long frequency) static int set_input_source(v4l_input_plugin_t *this, char *input_source) { int ret = 0; - + if ((ret = search_by_channel(this, input_source)) != 1) { ret = search_by_tuner(this, input_source); } - + return ret; } @@ -590,23 +590,23 @@ static int search_by_tuner(v4l_input_plugin_t *this, char *input_source) int ret = 0; int fd = 0; int cur_tuner = 0; - + if (this->video_fd > 0) fd = this->video_fd; else fd = this->radio_fd; - + this->video_tuner.tuner = cur_tuner; ioctl(fd, VIDIOCGCAP, &this->video_cap); - + lprintf("This device has %d channel(s)\n", this->video_cap.channels); - + for (ret = ioctl(fd, VIDIOCGTUNER, &this->video_tuner); ret == 0 && this->video_cap.channels > cur_tuner && strstr(this->video_tuner.name, input_source) == NULL; cur_tuner++) { - + this->video_tuner.tuner = cur_tuner; - + lprintf("(%d) V4L device currently set to: \n", ret); lprintf("Tuner: %d\n", this->video_tuner.tuner); lprintf("Name: %s\n", this->video_tuner.name); @@ -616,7 +616,7 @@ static int search_by_tuner(v4l_input_plugin_t *this, char *input_source) lprintf("Range: %ld - %ld\n", this->video_tuner.rangelow * 1000 / 16, this->video_tuner.rangehigh * 1000 / 16); } } - + lprintf("(%d) V4L device final: \n", ret); lprintf("Tuner: %d\n", this->video_tuner.tuner); lprintf("Name: %s\n", this->video_tuner.name); @@ -625,10 +625,10 @@ static int search_by_tuner(v4l_input_plugin_t *this, char *input_source) } else { lprintf("Range: %ld - %ld\n", this->video_tuner.rangelow * 1000 / 16, this->video_tuner.rangehigh * 1000 / 16); } - + if (strstr(this->video_tuner.name, input_source) == NULL) return -1; - + return 1; } @@ -639,20 +639,20 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source) cfg_entry_t *tv_standard_entry; lprintf("input_source: %s\n", input_source); - + this->input = 0; - + if (this->video_fd > 0) fd = this->video_fd; else fd = this->radio_fd; - + /* Tune into channel */ if (strlen(input_source) > 0) { for( this->video_channel.channel = 0; ioctl(fd, VIDIOCGCHAN, &this->video_channel) == 0; this->video_channel.channel++ ) { - + lprintf("V4L device currently set to:\n"); lprintf("Channel: %d\n", this->video_channel.channel); lprintf("Name: %s\n", this->video_channel.name); @@ -666,33 +666,33 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source) break; } } - + if (strstr(this->video_channel.name, input_source) == NULL) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _("Tuner name not found\n")); return -1; } - + tv_standard_entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, "media.video4linux.tv_standard"); this->tuner_name = input_source; if (tv_standard_entry->num_value != 0) { this->video_channel.norm = tv_standard_values[ tv_standard_entry->num_value ]; xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "input_v4l: TV Standard configured as STD %s (%d)\n", + "input_v4l: TV Standard configured as STD %s (%d)\n", tv_standard_names[ tv_standard_entry->num_value ], this->video_channel.norm ); ret = ioctl(fd, VIDIOCSCHAN, &this->video_channel); } else ret = ioctl(fd, VIDIOCSCHAN, &this->input); - + lprintf("(%d) Set channel to %d\n", ret, this->input); } else { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Not setting video source. No source given\n"); } ret = ioctl(fd, VIDIOCGTUNER, &this->video_tuner); lprintf("(%d) Flags %d\n", ret, this->video_tuner.flags); - + lprintf("VIDEO_TUNER_PAL %s set\n", this->video_tuner.flags & VIDEO_TUNER_PAL ? "" : "not"); lprintf("VIDEO_TUNER_NTSC %s set\n", this->video_tuner.flags & VIDEO_TUNER_NTSC ? "" : "not"); lprintf("VIDEO_TUNER_SECAM %s set\n", this->video_tuner.flags & VIDEO_TUNER_SECAM ? "" : "not"); @@ -701,7 +701,7 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source) lprintf("VIDEO_TUNER_STEREO_ON %s set\n", this->video_tuner.flags & VIDEO_TUNER_STEREO_ON ? "" : "not"); lprintf("VIDEO_TUNER_RDS_ON %s set\n", this->video_tuner.flags & VIDEO_TUNER_RDS_ON ? "" : "not"); lprintf("VIDEO_TUNER_MBS_ON %s set\n", this->video_tuner.flags & VIDEO_TUNER_MBS_ON ? "" : "not"); - + switch (this->video_tuner.mode) { case VIDEO_MODE_PAL: lprintf("The tuner is in PAL mode\n"); @@ -717,7 +717,7 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source) break; } - return 1; + return 1; } static void allocate_frames(v4l_input_plugin_t *this, unsigned dovideo) @@ -743,7 +743,7 @@ static void allocate_frames(v4l_input_plugin_t *this, unsigned dovideo) frames[i].source = this; frames[i].free_buffer = store_aud_frame; frames[i].extra_info = &infos[i]; - + audio_content += this->periodsize; store_aud_frame(&frames[i]); } @@ -772,12 +772,12 @@ static void unmute_audio(v4l_input_plugin_t *this) int fd; lprintf("unmute_audio\n"); - + if (this->video_fd > 0) fd = this->video_fd; else fd = this->radio_fd; - + ioctl(fd, VIDIOCGAUDIO, &this->audio); memcpy(&this->audio_saved, &this->audio, sizeof(this->audio)); @@ -786,43 +786,43 @@ static void unmute_audio(v4l_input_plugin_t *this) ioctl(fd, VIDIOCSAUDIO, &this->audio); } - + static int open_radio_capture_device(v4l_input_plugin_t *this) { int tuner_found = 0; cfg_entry_t *entry; - + lprintf("open_radio_capture_device\n"); - + entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, "media.video4linux.radio_device"); - + if((this->radio_fd = open(entry->str_value, O_RDWR)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "input_v4l: error opening v4l device (%s): %s\n", + "input_v4l: error opening v4l device (%s): %s\n", entry->str_value, strerror(errno)); return 0; } - + lprintf("Device opened, radio %d\n", this->radio_fd); - + if (set_input_source(this, this->tuner_name) > 0) tuner_found = 1; - + _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1); _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0); - + /* Pre-allocate some frames for audio so it doesn't have to be done during * capture */ allocate_frames(this, 0); - + this->audio_only = 1; - + /* Unmute audio off video capture device */ unmute_audio(this); - - set_frequency(this, this->frequency); - + + set_frequency(this, this->frequency); + if (tuner_found) return 1; else @@ -843,22 +843,22 @@ static int open_video_capture_device(v4l_input_plugin_t *this) int ret; unsigned int j; cfg_entry_t *entry; - + lprintf("open_video_capture_device\n"); - - entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, + + entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, "media.video4linux.video_device"); /* Try to open the video device */ if((this->video_fd = open(entry->str_value, O_RDWR)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "input_v4l: error opening v4l device (%s): %s\n", + "input_v4l: error opening v4l device (%s): %s\n", entry->str_value, strerror(errno)); return 0; } - + lprintf("Device opened, tv %d\n", this->video_fd); - + /* figure out the resolution */ for (j = 0; j < NUM_RESOLUTIONS; j++) { @@ -870,7 +870,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this) break; } } - + if (found == 0 || resolutions[j].width < this->video_cap.minwidth || resolutions[j].height < this->video_cap.minheight) { @@ -878,15 +878,15 @@ static int open_video_capture_device(v4l_input_plugin_t *this) lprintf("Grab device does not support any preset resolutions"); return 0; } - + this->resolution = &resolutions[j]; - + _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1); _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 1); - + /* Unmute audio off video capture device */ unmute_audio(this); - + if (strlen(this->tuner_name) > 0) { /* Tune into source and given frequency */ if (set_input_source(this, this->tuner_name) <= 0) @@ -894,20 +894,20 @@ static int open_video_capture_device(v4l_input_plugin_t *this) else tuner_found = 1; } - - set_frequency(this, this->frequency); - + + set_frequency(this, this->frequency); + /* Test for mmap video access */ ret = ioctl(this->video_fd,VIDIOCGMBUF, &this->gb_buffers); - + if (ret < 0) { /* Device driver does not support mmap */ /* try to use read based access */ struct video_picture pict; int val; - + ioctl(this->video_fd, VIDIOCGPICT, &pict); - + /* try to choose a suitable video format */ pict.palette = VIDEO_PALETTE_YUV420P; ret = ioctl(this->video_fd, VIDIOCSPICT, &pict); @@ -925,13 +925,13 @@ static int open_video_capture_device(v4l_input_plugin_t *this) } else lprintf("Grab: format YUV 4:2:0\n"); - + this->frame_format = pict.palette; val = 1; ioctl(this->video_fd, VIDIOCCAPTURE, &val); - + this->use_mmap = 0; - + } else { /* Good, device driver support mmap. Mmap the memory */ lprintf("using mmap, size %d\n", this->gb_buffers.size); @@ -945,23 +945,23 @@ static int open_video_capture_device(v4l_input_plugin_t *this) return 0; } this->gb_frame = 0; - + /* start to grab the first frame */ this->gb_buf.frame = (this->gb_frame + 1) % this->gb_buffers.frames; this->gb_buf.height = resolutions[j].height; this->gb_buf.width = resolutions[j].width; this->gb_buf.format = VIDEO_PALETTE_YUV420P; - + ret = ioctl(this->video_fd, VIDIOCMCAPTURE, &this->gb_buf); if (ret < 0 && errno != EAGAIN) { /* try YUV422 */ this->gb_buf.format = VIDEO_PALETTE_YUV422; - + ret = ioctl(this->video_fd, VIDIOCMCAPTURE, &this->gb_buf); } else lprintf("(%d) YUV420 should work\n", ret); - + if (ret < 0) { if (errno != EAGAIN) { lprintf("grab device does not support suitable format\n"); @@ -974,7 +974,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this) this->frame_format = this->gb_buf.format; this->use_mmap = 1; } - + switch(this->frame_format) { case VIDEO_PALETTE_YUV420P: this->frame_format = BUF_VIDEO_I420; @@ -985,19 +985,19 @@ static int open_video_capture_device(v4l_input_plugin_t *this) this->frame_size = resolutions[j].width * resolutions[j].height * 2; break; } - - /* Strip the vbi / sync signal from the image by zooming in */ + + /* Strip the vbi / sync signal from the image by zooming in */ this->old_zoomx = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_X); this->old_zoomy = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_Y); - + xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, 103); xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_Y, 103); - /* Pre-allocate some frames for audio and video so it doesn't have to be + /* Pre-allocate some frames for audio and video so it doesn't have to be * done during capture */ allocate_frames(this, 1); - /* If we made it here, everything went ok */ + /* If we made it here, everything went ok */ this->audio_only = 0; if (tuner_found) return 1; @@ -1021,98 +1021,98 @@ static int open_audio_capture_device(v4l_input_plugin_t *this) /* Allocate the snd_pcm_hw_params_t structure on the stack. */ snd_pcm_hw_params_alloca(&this->pcm_hwparams); - + /* If we are not capturing video, open the sound device in blocking mode, * otherwise xine gets too many NULL bufs and doesn't seem to handle them * correctly. If we are capturing video, open the sound device in non- * blocking mode, otherwise we will loose video frames while waiting */ if(!this->audio_only) mode = SND_PCM_NONBLOCK; - + /* Open the PCM device. */ if(snd_pcm_open(&this->pcm_handle, this->pcm_name, this->pcm_stream, mode) < 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error opening PCM device: %s\n", this->pcm_name); this->audio_capture = 0; } - + /* Get parameters */ if (this->audio_capture && (snd_pcm_hw_params_any(this->pcm_handle, this->pcm_hwparams) < 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Broken configuration for PCM device: No configurations available\n"); this->audio_capture = 0; } - + /* Set access type */ if (this->audio_capture && (snd_pcm_hw_params_set_access(this->pcm_handle, this->pcm_hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting SND_PCM_ACCESS_RW_INTERLEAVED\n"); this->audio_capture = 0; } - + /* Set sample format */ if (this->audio_capture && - (snd_pcm_hw_params_set_format(this->pcm_handle, + (snd_pcm_hw_params_set_format(this->pcm_handle, this->pcm_hwparams, SND_PCM_FORMAT_S16_LE) < 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting SND_PCM_FORMAT_S16_LE\n"); this->audio_capture = 0; } - + /* Set sample rate */ this->exact_rate = this->rate; if (this->audio_capture && - (snd_pcm_hw_params_set_rate_near(this->pcm_handle, this->pcm_hwparams, + (snd_pcm_hw_params_set_rate_near(this->pcm_handle, this->pcm_hwparams, &this->exact_rate, &this->dir) < 0)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting samplerate\n"); this->audio_capture = 0; } if (this->audio_capture && this->dir != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Samplerate %d Hz is not supported by your hardware\n", this->rate); - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Using %d instead\n", this->exact_rate); } - + /* Set number of channels */ if (this->audio_capture && (snd_pcm_hw_params_set_channels(this->pcm_handle, this->pcm_hwparams, 2) < 0)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting PCM channels\n"); this->audio_capture = 0; } - + if (this->audio_capture && (snd_pcm_hw_params_set_periods(this->pcm_handle, this->pcm_hwparams, this->periods, 0) < 0)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting PCM periods\n"); this->audio_capture = 0; } - + /* Set buffersize */ if (this->audio_capture && - (snd_pcm_hw_params_set_buffer_size_near(this->pcm_handle, + (snd_pcm_hw_params_set_buffer_size_near(this->pcm_handle, this->pcm_hwparams, &buf_size) < 0)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error setting PCM buffer size to %d\n", (int)buf_size ); this->audio_capture = 0; } - + /* Apply HW parameter settings */ if (this->audio_capture && (snd_pcm_hw_params(this->pcm_handle, this->pcm_hwparams) < 0)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error Setting PCM HW params\n"); this->audio_capture = 0; } - + if (this->audio_capture) { lprintf("Allocating memory for PCM capture :%d\n", this->periodsize); this->pcm_data = (unsigned char*) malloc(this->periodsize); } else - this->pcm_data = NULL; - + this->pcm_data = NULL; + lprintf("Audio device succesfully configured\n"); #endif return 0; @@ -1128,30 +1128,30 @@ static int v4l_adjust_realtime_speed(v4l_input_plugin_t *this, fifo_buffer_t *fi { int num_used, num_free; int scr_tuning = this->scr_tuning; - + if (fifo == NULL) return 0; - + num_used = fifo->size(fifo); num_free = NUM_FRAMES - num_used; - + if (!this->audio_only && num_used == 0 && scr_tuning != SCR_PAUSED) { /* Buffer is empty, and we did not pause playback */ report_progress(this->stream, SCR_PAUSED); - - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_v4l: Buffer empty, pausing playback (used: %d, num_free: %d)\n", num_used, num_free); - + _x_set_speed(this->stream, XINE_SPEED_PAUSE); this->stream->xine->clock->set_option (this->stream->xine->clock, CLOCK_SCR_ADJUSTABLE, 0); - + this->scr_tuning = SCR_PAUSED; /* pvrscr_speed_tuning(this->scr, 0.0); */ - + } else if (num_free <= 1 && scr_tuning != SCR_SKIP) { this->scr_tuning = SCR_SKIP; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_v4l: Buffer full, skipping (used: %d, free: %d)\n", num_used, num_free); return 0; } else if (scr_tuning == SCR_PAUSED) { @@ -1159,11 +1159,11 @@ static int v4l_adjust_realtime_speed(v4l_input_plugin_t *this, fifo_buffer_t *fi /* Playback was paused, but we have normal buffer usage again */ xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_v4l: Resuming from paused (used: %d, free: %d)\n", num_used, num_free); - + this->scr_tuning = 0; - + pvrscr_speed_tuning(this->scr, 1.0); - + _x_set_speed(this->stream, XINE_SPEED_NORMAL); this->stream->xine->clock->set_option (this->stream->xine->clock, CLOCK_SCR_ADJUSTABLE, 1); } @@ -1188,12 +1188,12 @@ static int v4l_adjust_realtime_speed(v4l_input_plugin_t *this, fifo_buffer_t *fi (scr_tuning < 0 && num_used > num_free)) /* Buffer usage is ok again. Set playback speed to normal */ scr_tuning = 0; - - /* Check if speed adjustment should be changed */ + + /* Check if speed adjustment should be changed */ if (scr_tuning != this->scr_tuning) { this->scr_tuning = scr_tuning; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "input_v4l: scr tuning = %d (used: %d, free: %d)\n", + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "input_v4l: scr tuning = %d (used: %d, free: %d)\n", scr_tuning, num_used, num_free); pvrscr_speed_tuning(this->scr, 1.0 + (0.01 * scr_tuning)); } @@ -1203,13 +1203,13 @@ static int v4l_adjust_realtime_speed(v4l_input_plugin_t *this, fifo_buffer_t *fi * speed */ this->scr_tuning = 0; - + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_v4l: scr tuning resetting (used: %d, free: %d\n", num_used, num_free); - + pvrscr_speed_tuning(this->scr, 1.0); } - + return 1; } @@ -1246,15 +1246,15 @@ static buf_element_t *v4l_plugin_read_block (input_plugin_t *this_gen, fifo_buff uint8_t *ptr; static char video = 0; int speed = _x_get_speed(this->stream); - - v4l_event_handler(this); - + + v4l_event_handler(this); + #ifdef HAVE_ALSA if (!this->audio_header_sent) { lprintf("sending audio header\n"); - + buf = alloc_aud_frame (this); - + buf->size = 0; buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; @@ -1262,60 +1262,60 @@ static buf_element_t *v4l_plugin_read_block (input_plugin_t *this_gen, fifo_buff buf->decoder_info[1] = this->exact_rate; buf->decoder_info[2] = this->bits; buf->decoder_info[3] = 2; - + this->audio_header_sent = 1; - + return buf; } -#endif - +#endif + if (!this->audio_only && !this->video_header_sent) { xine_bmiheader bih; - + lprintf("sending video header"); - + bih.biSize = sizeof(xine_bmiheader); bih.biWidth = this->resolution->width; bih.biHeight = this->resolution->height; - + buf = alloc_vid_frame (this); - + buf->size = sizeof(xine_bmiheader); buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; memcpy(buf->content, &bih, sizeof(xine_bmiheader)); - + this->video_header_sent = 1; - - return buf; + + return buf; } - + if (!this->audio_only) { if (!v4l_adjust_realtime_speed(this, fifo, speed)) { return NULL; } } - - if (!this->audio_only) + + if (!this->audio_only) video = !video; else video = 0; - + lprintf("%lld bytes...\n", todo); - - if (this->start_time == 0) + + if (this->start_time == 0) /* Create a start pts value */ this->start_time = get_time(); /* this->stream->xine->clock->get_current_time(this->stream->xine->clock); */ - + if (video) { /* Capture video */ buf = alloc_vid_frame (this); buf->decoder_flags = BUF_FLAG_FRAME_START|BUF_FLAG_FRAME_END; - + this->gb_buf.frame = this->gb_frame; - + lprintf("VIDIOCMCAPTURE\n"); - + while (ioctl(this->video_fd, VIDIOCMCAPTURE, &this->gb_buf) < 0) { lprintf("Upper while loop\n"); if (errno == EAGAIN) { @@ -1327,92 +1327,92 @@ static buf_element_t *v4l_plugin_read_block (input_plugin_t *this_gen, fifo_buff return NULL; } } - + this->gb_frame = (this->gb_frame + 1) % this->gb_buffers.frames; - + while (ioctl(this->video_fd, VIDIOCSYNC, &this->gb_frame) < 0 && (errno == EAGAIN || errno == EINTR)) { lprintf("Waiting for videosync\n"); } - + /* printf ("grabbing frame #%d\n", frame_num); */ - + ptr = this->video_buf + this->gb_buffers.offsets[this->gb_frame]; buf->pts = get_time(); /* this->stream->xine->clock->get_current_time(this->stream->xine->clock); */ - xine_fast_memcpy (buf->content, ptr, this->frame_size); + xine_fast_memcpy (buf->content, ptr, this->frame_size); } #ifdef HAVE_ALSA else if (this->audio_capture) { /* Record audio */ int pcmreturn; - - if ((pcmreturn = snd_pcm_readi(this->pcm_handle, this->pcm_data, (this->periodsize)>> 2)) < 0) { + + if ((pcmreturn = snd_pcm_readi(this->pcm_handle, this->pcm_data, (this->periodsize)>> 2)) < 0) { switch (pcmreturn) { case -EAGAIN: /* No data available at the moment */ break; case -EBADFD: /* PCM device in wrong state */ - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: PCM is not in the right state\n"); break; case -EPIPE: /* Buffer overrun */ - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: PCM buffer Overrun (lost some samples)\n"); /* On buffer overrun we need to re prepare the capturing pcm device */ snd_pcm_prepare(this->pcm_handle); break; case -ESTRPIPE: /* Suspend event */ - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: PCM suspend event occured\n"); break; default: /* Unknown */ - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Unknown PCM error code: %d\n", pcmreturn); snd_pcm_prepare(this->pcm_handle); } } else { /* Succesfully read audio data */ - + if (this->pts_aud_start) { buf = alloc_aud_frame (this); buf->decoder_flags = 0; } - + /* We want the pts on the start of the sample. As the soundcard starts * sampling a new sample as soon as the read function returned with a - * success we will save the current pts and assign the current pts to + * success we will save the current pts and assign the current pts to * that sample when we read it */ - + /* Assign start pts to sample */ if (buf) buf->pts = this->pts_aud_start; - + /* Save start pts */ this->pts_aud_start = get_time(); /* this->stream->xine->clock->get_current_time(this->stream->xine->clock); */ - + if (!buf) /* Skip first sample as we don't have a good pts for this one */ return NULL; - + lprintf("Audio: Data read: %d [%d, %d]. Pos: %d\n", pcmreturn, (int) (*this->pcm_data), (int) (*(this->pcm_data + this->periodsize - 3)), (int) this->curpos); - - + + /* Tell decoder the number of bytes we have read */ - buf->size = pcmreturn<<2; - + buf->size = pcmreturn<<2; + this->curpos++; - + xine_fast_memcpy(buf->content, this->pcm_data, buf->size); } } #endif - + lprintf("read block done\n"); - + return buf; } @@ -1422,7 +1422,7 @@ static buf_element_t *v4l_plugin_read_block (input_plugin_t *this_gen, fifo_buff */ static off_t v4l_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + lprintf("seek %lld bytes, origin %d\n", offset, origin); return this->curpos; } @@ -1433,10 +1433,10 @@ static off_t v4l_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin */ static off_t v4l_plugin_get_length (input_plugin_t *this_gen) { /* - v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; + v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; off_t length; */ - + return -1; } @@ -1446,8 +1446,8 @@ static off_t v4l_plugin_get_length (input_plugin_t *this_gen) { */ static uint32_t v4l_plugin_get_capabilities (input_plugin_t *this_gen) { - v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; + if (this->audio_only) return 0x10; else @@ -1469,26 +1469,26 @@ static uint32_t v4l_plugin_get_blocksize (input_plugin_t *this_gen) */ static off_t v4l_plugin_get_current_pos (input_plugin_t *this_gen){ v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + /* printf ("current pos is %lld\n", this->curpos); */ - + return this->curpos; } /** * Event handler. - * + * * Processes events from a frontend. This way frequencies can be changed * without closing the v4l plugin. */ static void v4l_event_handler (v4l_input_plugin_t *this) { xine_event_t *event; - + while ((event = xine_event_get (this->event_queue))) { xine_set_v4l2_data_t *v4l2_data = event->data; - + switch (event->type) { case XINE_EVENT_SET_V4L2: if( v4l2_data->input != this->input || @@ -1498,25 +1498,25 @@ static void v4l_event_handler (v4l_input_plugin_t *this) { this->input = v4l2_data->input; this->channel = v4l2_data->channel; this->frequency = v4l2_data->frequency; - + lprintf("Switching to input:%d chan:%d freq:%.2f\n", v4l2_data->input, v4l2_data->channel, (float)v4l2_data->frequency); set_frequency(this, this->frequency); - _x_demux_flush_engine(this->stream); + _x_demux_flush_engine(this->stream); } break; /* default: - + lprintf("Got an event, type 0x%08x\n", event->type); */ } - + xine_event_free (event); } -} +} /** * Dispose plugin. @@ -1526,69 +1526,69 @@ static void v4l_event_handler (v4l_input_plugin_t *this) { */ static void v4l_plugin_dispose (input_plugin_t *this_gen) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + if(this->mrl) free(this->mrl); - + if (this->scr) { this->stream->xine->clock->unregister_scr(this->stream->xine->clock, &this->scr->scr); this->scr->scr.exit(&this->scr->scr); } - + /* Close and free video device */ if (this->tuner_name) free(this->tuner_name); - + /* Close video device only if device was openend */ if (this->video_fd > 0) { - + /* Restore v4l audio volume */ - lprintf("Restoring v4l audio volume %d\n", + lprintf("Restoring v4l audio volume %d\n", ioctl(this->video_fd, VIDIOCSAUDIO, &this->audio_saved)); ioctl(this->video_fd, VIDIOCSAUDIO, &this->audio_saved); - + /* Unmap memory */ - if (this->video_buf != NULL && + if (this->video_buf != NULL && munmap(this->video_buf, this->gb_buffers.size) != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Could not unmap video memory: %s\n", strerror(errno)); } else lprintf("Succesfully unmapped video memory (size %d)\n", this->gb_buffers.size); - + lprintf("Closing video filehandler %d\n", this->video_fd); - + /* Now close the video device */ if (close(this->video_fd) != 0) - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: Error while closing video file handler: %s\n", strerror(errno)); else lprintf("Video device succesfully closed\n"); - - /* Restore zoom setting */ + + /* Restore zoom setting */ xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_X, this->old_zoomx); xine_set_param(this->stream, XINE_PARAM_VO_ZOOM_Y, this->old_zoomy); } - + if (this->radio_fd > 0) { close(this->radio_fd); } - + #ifdef HAVE_ALSA /* Close audio device */ if (this->pcm_handle) { snd_pcm_drop(this->pcm_handle); snd_pcm_close(this->pcm_handle); } - + if (this->pcm_data) { free(this->pcm_data); } - + if (this->pcm_name) { free(this->pcm_name); } #endif - + if (this->event_queue) xine_event_dispose_queue (this->event_queue); @@ -1607,9 +1607,9 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) { #ifdef LOG printf("\n"); #endif - + free (this); - + lprintf("plugin Bye bye! \n"); } @@ -1620,11 +1620,11 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) { */ static const char* v4l_plugin_get_mrl (input_plugin_t *this_gen) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + return this->mrl; } -static int v4l_plugin_get_optional_data (input_plugin_t *this_gen, +static int v4l_plugin_get_optional_data (input_plugin_t *this_gen, void *data, int data_type) { /* v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; */ @@ -1634,19 +1634,19 @@ static int v4l_plugin_get_optional_data (input_plugin_t *this_gen, static int v4l_plugin_radio_open (input_plugin_t *this_gen) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; - + if(open_radio_capture_device(this) != 1) return 0; - + open_audio_capture_device(this); - + #ifdef HAVE_ALSA this->start_time = 0; this->pts_aud_start = 0; this->curpos = 0; this->event_queue = xine_event_new_queue (this->stream); -#endif - +#endif + return 1; } @@ -1655,30 +1655,30 @@ static int v4l_plugin_video_open (input_plugin_t *this_gen) { v4l_input_plugin_t *this = (v4l_input_plugin_t *) this_gen; int64_t time; - + if(!open_video_capture_device(this)) return 0; - + open_audio_capture_device(this); - + #ifdef HAVE_ALSA this->pts_aud_start = 0; #endif this->start_time = 0; this->curpos = 0; - + /* Register our own scr provider */ time = this->stream->xine->clock->get_current_time(this->stream->xine->clock); this->scr = pvrscr_init(); this->scr->scr.start(&this->scr->scr, time); this->stream->xine->clock->register_scr(this->stream->xine->clock, &this->scr->scr); this->scr_tuning = 0; - + /* enable resample method */ this->stream->xine->config->update_num(this->stream->xine->config, "audio.synchronization.av_sync_method", 1); - + this->event_queue = xine_event_new_queue (this->stream); - + return 1; } @@ -1697,19 +1697,19 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, cfg_entry_t *entry; #endif char *mrl = strdup(data); - + /* Example mrl: v4l:/Television/62500 */ if(!mrl || strncasecmp(mrl, "v4l:/", 5)) { free(mrl); return NULL; } - + this = calloc(1, sizeof (v4l_input_plugin_t)); - + extract_mrl(this, mrl); - - this->stream = stream; - this->mrl = mrl; + + this->stream = stream; + this->mrl = mrl; this->video_buf = NULL; this->video_fd = -1; this->radio_fd = -1; @@ -1718,7 +1718,7 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, #ifdef HAVE_ALSA this->pcm_data = NULL; this->pcm_hwparams = NULL; - + /* Audio */ this->pcm_stream = SND_PCM_STREAM_CAPTURE; entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, @@ -1730,13 +1730,13 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, this->periods = 2; this->periodsize = 2 * 8192; this->bits = 16; - + pthread_mutex_init (&this->aud_frames_lock, NULL); pthread_cond_init (&this->aud_frame_freed, NULL); - + pthread_mutex_init (&this->vid_frames_lock, NULL); pthread_cond_init (&this->vid_frame_freed, NULL); - + this->input_plugin.get_capabilities = v4l_plugin_get_capabilities; this->input_plugin.read = v4l_plugin_read; this->input_plugin.read_block = v4l_plugin_read_block; @@ -1748,7 +1748,7 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, this->input_plugin.dispose = v4l_plugin_dispose; this->input_plugin.get_optional_data = v4l_plugin_get_optional_data; this->input_plugin.input_class = cls_gen; - + return &this->input_plugin; } @@ -1758,57 +1758,57 @@ static input_plugin_t *v4l_class_get_video_instance (input_class_t *cls_gen, v4l_input_plugin_t *this = NULL; int is_ok = 1; cfg_entry_t *entry; - + this = (v4l_input_plugin_t *) v4l_class_get_instance (cls_gen, stream, data); - + if (this) this->input_plugin.open = v4l_plugin_video_open; else return NULL; - - entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, + + entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, "media.video4linux.video_device"); - + /* Try to open the video device */ if((this->video_fd = open(entry->str_value, O_RDWR)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "input_v4l: error opening v4l device (%s): %s\n", + "input_v4l: error opening v4l device (%s): %s\n", entry->str_value, strerror(errno)); is_ok = 0; } else lprintf("Device opened, tv %d\n", this->video_fd); - + /* Get capabilities */ if (is_ok && ioctl(this->video_fd, VIDIOCGCAP, &this->video_cap) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: v4l card doesn't support some features needed by xine\n"); is_ok = 0;; } - + if (is_ok && !(this->video_cap.type & VID_TYPE_CAPTURE)) { /* Capture is not supported by the device. This is a must though! */ xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: v4l card doesn't support frame grabbing\n"); is_ok = 0; } - + if (is_ok && set_input_source(this, this->tuner_name) <= 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: unable to locate the tuner name (%s) on your v4l card\n", this->tuner_name); is_ok = 0; } - + if (this->video_fd > 0) { close(this->video_fd); this->video_fd = -1; } - + if (!is_ok) { v4l_plugin_dispose((input_plugin_t *) this); return NULL; } - + return &this->input_plugin; } @@ -1819,45 +1819,45 @@ static input_plugin_t *v4l_class_get_radio_instance (input_class_t *cls_gen, v4l_input_plugin_t *this = NULL; int is_ok = 1; cfg_entry_t *entry; - + if (strstr(data, "Radio") == NULL) return NULL; - + this = (v4l_input_plugin_t *) v4l_class_get_instance (cls_gen, stream, data); - + if (this) this->input_plugin.open = v4l_plugin_radio_open; else return NULL; - - entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, + + entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, "media.video4linux.radio_device"); - + if((this->radio_fd = open(entry->str_value, O_RDWR)) < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "input_v4l: error opening v4l device (%s): %s\n", + "input_v4l: error opening v4l device (%s): %s\n", entry->str_value, strerror(errno)); is_ok = 0; } else lprintf("Device opened, radio %d\n", this->radio_fd); - + if (is_ok && set_input_source(this, this->tuner_name) <= 0) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, "input_v4l: unable to locate the tuner name (%s) on your v4l card\n", this->tuner_name); is_ok = 0; } - + if (this->radio_fd > 0) { close(this->radio_fd); this->radio_fd = -1; } - + if (!is_ok) { v4l_plugin_dispose((input_plugin_t *) this); return NULL; } - + return &this->input_plugin; } @@ -1880,7 +1880,7 @@ static const char *v4l_class_get_identifier (input_class_t *this_gen) { static void v4l_class_dispose (input_class_t *this_gen) { v4l_input_class_t *this = (v4l_input_class_t *) this_gen; - + free (this); } @@ -1888,11 +1888,11 @@ static void *init_video_class (xine_t *xine, void *data) { v4l_input_class_t *this; config_values_t *config = xine->config; - + this = calloc(1, sizeof (v4l_input_class_t)); - + this->xine = xine; - + this->input_class.get_instance = v4l_class_get_video_instance; this->input_class.get_identifier = v4l_class_get_identifier; this->input_class.get_description = v4l_class_get_video_description; @@ -1900,7 +1900,7 @@ static void *init_video_class (xine_t *xine, void *data) this->input_class.get_autoplay_list = NULL; this->input_class.dispose = v4l_class_dispose; this->input_class.eject_media = NULL; - + config->register_filename (config, "media.video4linux.video_device", VIDEO_DEV, XINE_CONFIG_STRING_IS_DEVICE_NAME, _("v4l video device"), @@ -1926,11 +1926,11 @@ static void *init_radio_class (xine_t *xine, void *data) { v4l_input_class_t *this; config_values_t *config = xine->config; - + this = calloc(1, sizeof (v4l_input_class_t)); - + this->xine = xine; - + this->input_class.get_instance = v4l_class_get_radio_instance; this->input_class.get_identifier = v4l_class_get_identifier; this->input_class.get_description = v4l_class_get_radio_description; @@ -1938,13 +1938,13 @@ static void *init_radio_class (xine_t *xine, void *data) this->input_class.get_autoplay_list = NULL; this->input_class.dispose = v4l_class_dispose; this->input_class.eject_media = NULL; - + config->register_filename (config, "media.video4linux.radio_device", RADIO_DEV, XINE_CONFIG_STRING_IS_DEVICE_NAME, _("v4l radio device"), _("The path to your Video4Linux radio device."), 10, NULL, NULL); - + return this; } @@ -1953,12 +1953,12 @@ static void *init_radio_class (xine_t *xine, void *data) */ const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ + /* type, API, "name", version, special_info, init_function */ { PLUGIN_INPUT | PLUGIN_MUST_PRELOAD, 17, "v4l_radio", XINE_VERSION_CODE, NULL, init_radio_class }, { PLUGIN_INPUT | PLUGIN_MUST_PRELOAD, 17, "v4l_tv", XINE_VERSION_CODE, NULL, init_video_class }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; /* - * vim:sw=3:sts=3: + * vim:sw=3:sts=3: */ |