summaryrefslogtreecommitdiff
path: root/drivers/media/video/usbvision/usbvision-core.c
diff options
context:
space:
mode:
authorThierry MERLE <thierry.merle@free.fr>2007-02-07 10:13:11 -0300
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-02-21 13:35:19 -0200
commit6f78e186fe5d29dbff5e34f950adb573c4808de4 (patch)
tree23297d74fceeaa3b9668fda9a429c17c57107213 /drivers/media/video/usbvision/usbvision-core.c
parentc65eeaab1f04d1113b5c4fb21f7f61ded795d2bb (diff)
V4L/DVB (5205): Usbvision: dynamic allocation for frames
- fix decoder route output - dynamic frame buffer allocation Signed-off-by: Thierry MERLE <thierry.merle@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/usbvision/usbvision-core.c')
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 42f495c9f5ff..d4fcd5736ba9 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -1852,28 +1852,33 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
/*
* usbvision_frames_alloc
- * allocate the maximum frames this driver can manage
+ * allocate the required frames
*/
-int usbvision_frames_alloc(struct usb_usbvision *usbvision)
+int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames)
{
int i;
- /* Allocate memory for the frame buffers */
- usbvision->max_frame_size = MAX_FRAME_SIZE;
- usbvision->fbuf_size = USBVISION_NUMFRAMES * usbvision->max_frame_size;
- usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
+ /*needs to be page aligned cause the buffers can be mapped individually! */
+ usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
+ usbvision->curheight *
+ usbvision->palette.bytes_per_pixel);
- if(usbvision->fbuf == NULL) {
- err("%s: unable to allocate %d bytes for fbuf ",
- __FUNCTION__, usbvision->fbuf_size);
- return -ENOMEM;
+ /* Try to do my best to allocate the frames the user want in the remaining memory */
+ usbvision->num_frames = number_of_frames;
+ while (usbvision->num_frames > 0) {
+ usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
+ if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) {
+ break;
+ }
+ usbvision->num_frames--;
}
+
spin_lock_init(&usbvision->queue_lock);
init_waitqueue_head(&usbvision->wait_frame);
init_waitqueue_head(&usbvision->wait_stream);
/* Allocate all buffers */
- for (i = 0; i < USBVISION_NUMFRAMES; i++) {
+ for (i = 0; i < usbvision->num_frames; i++) {
usbvision->frame[i].index = i;
usbvision->frame[i].grabstate = FrameState_Unused;
usbvision->frame[i].data = usbvision->fbuf +
@@ -1887,7 +1892,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision)
usbvision->frame[i].height = usbvision->curheight;
usbvision->frame[i].bytes_read = 0;
}
- return 0;
+ PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size);
+ return usbvision->num_frames;
}
/*
@@ -1897,9 +1903,13 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision)
void usbvision_frames_free(struct usb_usbvision *usbvision)
{
/* Have to free all that memory */
+ PDEBUG(DBG_FUNC, "free %d frames",usbvision->num_frames);
+
if (usbvision->fbuf != NULL) {
usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
usbvision->fbuf = NULL;
+
+ usbvision->num_frames = 0;
}
}
/*
@@ -2490,6 +2500,7 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
usbvision->ctl_input = channel;
route.input = SAA7115_COMPOSITE1;
+ route.output = 0;
call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route);
call_i2c_clients(usbvision, VIDIOC_S_INPUT, &usbvision->ctl_input);