summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input/input_v4l.c129
1 files changed, 56 insertions, 73 deletions
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c
index 7bb5322b5..e010132ec 100644
--- a/src/input/input_v4l.c
+++ b/src/input/input_v4l.c
@@ -120,6 +120,10 @@ typedef struct {
int old_zoomx;
int old_zoomy;
int audio_only;
+
+ buf_element_t *frames_base;
+ void *audio_content_base;
+ void *video_content_base;
/* Audio */
buf_element_t *aud_frames;
@@ -711,23 +715,50 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source)
return 1;
}
-static void allocate_audio_frames(v4l_input_plugin_t *this)
+static void allocate_frames(v4l_input_plugin_t *this, unsigned dovideo)
{
+ const size_t framescount = dovideo ? 2*NUM_FRAMES : NUM_FRAMES;
+
+ /* Allocate a single memory area for both audio and video frames */
+ buf_element_t *frames = this->frames_base =
+ calloc(framescount, sizeof(buf_element_t));
+ extra_info_t *infos =
+ calloc(framescount, sizeof(extra_info_t));
+
int i;
-
+
+ uint8_t *audio_content = this->audio_content_base =
+ calloc(NUM_FRAMES, this->periodsize);
+
+ /* Set up audio frames */
for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
/* Audio frame */
- frame = calloc(1, sizeof(buf_element_t));
-
- frame->content = xine_xmalloc(this->periodsize);
- frame->type = BUF_AUDIO_LPCM_LE;
- frame->source = this;
- frame->free_buffer = store_aud_frame;
- frame->extra_info = calloc(1, sizeof(extra_info_t));
-
- store_aud_frame(frame);
+ frames[i].content = audio_content;
+ frames[i].type = BUF_AUDIO_LPCM_LE;
+ 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]);
+ }
+
+ if ( dovideo ) {
+ uint8_t *video_content = this->video_content_base =
+ calloc(NUM_FRAMES, this->frame_size);
+
+ /* Set up video frames */
+ for (i = NUM_FRAMES; i < 2*NUM_FRAMES; i++) {
+ /* Video frame */
+ frames[i].content = video_content;
+ frames[i].type = this->frame_format;
+ frames[i].source = this;
+ frames[i].free_buffer = store_vid_frame;
+ frames[i].extra_info = &infos[i];
+
+ video_content += this->frame_size;
+ store_vid_frame(&frames[i]);
+ }
}
}
@@ -778,7 +809,7 @@ static int open_radio_capture_device(v4l_input_plugin_t *this)
/* Pre-allocate some frames for audio so it doesn't have to be done during
* capture */
- allocate_audio_frames(this);
+ allocate_frames(this, 0);
this->audio_only = 1;
@@ -850,7 +881,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
/* Pre-allocate some frames for audio and video so it doesn't have to be
* done during capture */
- allocate_audio_frames(this);
+ allocate_frames(this, 1);
/* Unmute audio off video capture device */
unmute_audio(this);
@@ -954,20 +985,6 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
break;
}
- for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
- frame = calloc(1, sizeof (buf_element_t));
-
- frame->content = xine_xmalloc (this->frame_size);
- frame->type = this->frame_format;
- frame->source = this;
- frame->free_buffer = store_vid_frame;
- frame->extra_info = calloc(1, sizeof(extra_info_t));
-
- store_vid_frame(frame);
- }
-
/* 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);
@@ -1569,52 +1586,18 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) {
if (this->event_queue)
xine_event_dispose_queue (this->event_queue);
-
- lprintf("Freeing allocated audio frames");
- if (this->aud_frames) {
- buf_element_t *cur_frame = this->aud_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
-#ifdef LOG
- printf("\n");
-#endif
+ /* All the frames, both video and audio, are allocated in a single
+ memory area pointed by the frames_base pointer. The content of
+ the frames is divided in two areas, one pointed by
+ audio_content_base and the other by video_content_base. The
+ extra_info structures are all allocated in the first frame
+ data. */
+ free(this->audio_content_base);
+ free(this->video_content_base);
+ free(this->frames_base->extra_info);
+ free(this->frames_base);
-
- lprintf("Freeing allocated video frames");
- if (this->vid_frames) {
- buf_element_t *cur_frame = this->vid_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
-
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
#ifdef LOG
printf("\n");
#endif