Commit 5bbe18d7 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

[media] pwc: Get rid of compression module parameter

Instead of making this a module parameter, automatically fallback to
higher compression settings if there is not enough bandwidth.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 795e6eb3
...@@ -168,7 +168,8 @@ int send_control_msg(struct pwc_device *pdev, ...@@ -168,7 +168,8 @@ int send_control_msg(struct pwc_device *pdev,
request, value, pdev->vcinterface, buf, buflen); request, value, pdev->vcinterface, buf, buflen);
} }
static int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames) static int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames,
int *compression)
{ {
unsigned char buf[3]; unsigned char buf[3];
int ret, fps; int ret, fps;
...@@ -234,32 +235,35 @@ static int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames) ...@@ -234,32 +235,35 @@ static int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames)
} }
else else
pdev->vbandlength = 0; pdev->vbandlength = 0;
/* Let pwc-if.c:isoc_init know we don't support higher compression */
*compression = 3;
return 0; return 0;
} }
static int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, static int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames,
int compression) int *compression)
{ {
unsigned char buf[13]; unsigned char buf[13];
const struct Timon_table_entry *pChoose; const struct Timon_table_entry *pChoose;
int ret, fps; int ret, fps;
if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) if (size >= PSZ_MAX || frames < 5 || frames > 30 ||
*compression < 0 || *compression > 3)
return -EINVAL; return -EINVAL;
if (size == PSZ_VGA && frames > 15) if (size == PSZ_VGA && frames > 15)
return -EINVAL; return -EINVAL;
fps = (frames / 5) - 1; fps = (frames / 5) - 1;
/* Find a supported framerate with progressively higher compression ratios /* Find a supported framerate with progressively higher compression */
if the preferred ratio is not available.
*/
pChoose = NULL; pChoose = NULL;
while (compression <= 3) { while (*compression <= 3) {
pChoose = &Timon_table[size][fps][compression]; pChoose = &Timon_table[size][fps][*compression];
if (pChoose->alternate != 0) if (pChoose->alternate != 0)
break; break;
compression++; (*compression)++;
} }
if (pChoose == NULL || pChoose->alternate == 0) if (pChoose == NULL || pChoose->alternate == 0)
return -ENOENT; /* Not supported. */ return -ENOENT; /* Not supported. */
...@@ -293,27 +297,25 @@ static int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, ...@@ -293,27 +297,25 @@ static int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames,
static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames,
int compression) int *compression)
{ {
const struct Kiara_table_entry *pChoose = NULL; const struct Kiara_table_entry *pChoose = NULL;
int fps, ret; int fps, ret;
unsigned char buf[12]; unsigned char buf[12];
if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) if (size >= PSZ_MAX || frames < 5 || frames > 30 ||
*compression < 0 || *compression > 3)
return -EINVAL; return -EINVAL;
if (size == PSZ_VGA && frames > 15) if (size == PSZ_VGA && frames > 15)
return -EINVAL; return -EINVAL;
fps = (frames / 5) - 1; fps = (frames / 5) - 1;
/* Find a supported framerate with progressively higher compression /* Find a supported framerate with progressively higher compression */
ratios if the preferred ratio is not available. while (*compression <= 3) {
Skip this step when using RAW modes. pChoose = &Kiara_table[size][fps][*compression];
*/
while (compression <= 3) {
pChoose = &Kiara_table[size][fps][compression];
if (pChoose->alternate != 0) if (pChoose->alternate != 0)
break; break;
compression++; (*compression)++;
} }
if (pChoose == NULL || pChoose->alternate == 0) if (pChoose == NULL || pChoose->alternate == 0)
return -ENOENT; /* Not supported. */ return -ENOENT; /* Not supported. */
...@@ -352,7 +354,7 @@ static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, ...@@ -352,7 +354,7 @@ static int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames,
} }
int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
int frames, int compression) int frames, int *compression)
{ {
int ret, size; int ret, size;
...@@ -361,7 +363,7 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, ...@@ -361,7 +363,7 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
PWC_TRACE("decode_size = %d.\n", size); PWC_TRACE("decode_size = %d.\n", size);
if (DEVICE_USE_CODEC1(pdev->type)) { if (DEVICE_USE_CODEC1(pdev->type)) {
ret = set_video_mode_Nala(pdev, size, frames); ret = set_video_mode_Nala(pdev, size, frames, compression);
} else if (DEVICE_USE_CODEC3(pdev->type)) { } else if (DEVICE_USE_CODEC3(pdev->type)) {
ret = set_video_mode_Kiara(pdev, size, frames, compression); ret = set_video_mode_Kiara(pdev, size, frames, compression);
...@@ -373,7 +375,6 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, ...@@ -373,7 +375,6 @@ int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
PWC_ERROR("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret); PWC_ERROR("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret);
return ret; return ret;
} }
pdev->vcompression = compression;
pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size; pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size;
PWC_DEBUG_SIZE("Set resolution to %dx%d\n", pdev->width, pdev->height); PWC_DEBUG_SIZE("Set resolution to %dx%d\n", pdev->width, pdev->height);
return 0; return 0;
......
...@@ -134,7 +134,6 @@ static int default_fps = 10; ...@@ -134,7 +134,6 @@ static int default_fps = 10;
#endif #endif
static int power_save = -1; static int power_save = -1;
static int led_on = 100, led_off; /* defaults to LED that is on while in use */ static int led_on = 100, led_off; /* defaults to LED that is on while in use */
static int pwc_preferred_compression = 1; /* 0..3 = uncompressed..high */
static struct { static struct {
int type; int type;
char serial_number[30]; char serial_number[30];
...@@ -372,6 +371,7 @@ static int pwc_isoc_init(struct pwc_device *pdev) ...@@ -372,6 +371,7 @@ static int pwc_isoc_init(struct pwc_device *pdev)
int i, j, ret; int i, j, ret;
struct usb_interface *intf; struct usb_interface *intf;
struct usb_host_interface *idesc = NULL; struct usb_host_interface *idesc = NULL;
int compression = 0; /* 0..3 = uncompressed..high */
if (pdev->iso_init) if (pdev->iso_init)
return 0; return 0;
...@@ -383,6 +383,12 @@ static int pwc_isoc_init(struct pwc_device *pdev) ...@@ -383,6 +383,12 @@ static int pwc_isoc_init(struct pwc_device *pdev)
pdev->visoc_errors = 0; pdev->visoc_errors = 0;
udev = pdev->udev; udev = pdev->udev;
retry:
/* We first try with low compression and then retry with a higher
compression setting if there is not enough bandwidth. */
ret = pwc_set_video_mode(pdev, pdev->width, pdev->height,
pdev->vframes, &compression);
/* Get the current alternate interface, adjust packet size */ /* Get the current alternate interface, adjust packet size */
intf = usb_ifnum_to_if(udev, 0); intf = usb_ifnum_to_if(udev, 0);
if (intf) if (intf)
...@@ -405,9 +411,12 @@ static int pwc_isoc_init(struct pwc_device *pdev) ...@@ -405,9 +411,12 @@ static int pwc_isoc_init(struct pwc_device *pdev)
} }
/* Set alternate interface */ /* Set alternate interface */
ret = 0;
PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate); PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate);
ret = usb_set_interface(pdev->udev, 0, pdev->valternate); ret = usb_set_interface(pdev->udev, 0, pdev->valternate);
if (ret == -ENOSPC && compression < 3) {
compression++;
goto retry;
}
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -451,6 +460,12 @@ static int pwc_isoc_init(struct pwc_device *pdev) ...@@ -451,6 +460,12 @@ static int pwc_isoc_init(struct pwc_device *pdev)
/* link */ /* link */
for (i = 0; i < MAX_ISO_BUFS; i++) { for (i = 0; i < MAX_ISO_BUFS; i++) {
ret = usb_submit_urb(pdev->urbs[i], GFP_KERNEL); ret = usb_submit_urb(pdev->urbs[i], GFP_KERNEL);
if (ret == -ENOSPC && compression < 3) {
compression++;
pdev->iso_init = 1;
pwc_isoc_cleanup(pdev);
goto retry;
}
if (ret) { if (ret) {
PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret); PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
pdev->iso_init = 1; pdev->iso_init = 1;
...@@ -743,14 +758,16 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count) ...@@ -743,14 +758,16 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
/* Turn on camera and set LEDS on */ /* Turn on camera and set LEDS on */
pwc_camera_power(pdev, 1); pwc_camera_power(pdev, 1);
if (pdev->power_save) {
/* Restore video mode */
pwc_set_video_mode(pdev, pdev->width, pdev->height,
pdev->vframes, pdev->vcompression);
}
pwc_set_leds(pdev, led_on, led_off); pwc_set_leds(pdev, led_on, led_off);
r = pwc_isoc_init(pdev); r = pwc_isoc_init(pdev);
if (r) {
/* If we failed turn camera and LEDS back off */
pwc_set_leds(pdev, 0, 0);
pwc_camera_power(pdev, 0);
/* And cleanup any queued bufs!! */
pwc_cleanup_queued_bufs(pdev);
}
leave: leave:
mutex_unlock(&pdev->udevlock); mutex_unlock(&pdev->udevlock);
return r; return r;
...@@ -798,6 +815,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id ...@@ -798,6 +815,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
int vendor_id, product_id, type_id; int vendor_id, product_id, type_id;
int hint, rc; int hint, rc;
int features = 0; int features = 0;
int compression = 0;
int video_nr = -1; /* default: use next available device */ int video_nr = -1; /* default: use next available device */
int my_power_save = power_save; int my_power_save = power_save;
char serial_number[30], *name; char serial_number[30], *name;
...@@ -1068,7 +1086,6 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id ...@@ -1068,7 +1086,6 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
INIT_LIST_HEAD(&pdev->queued_bufs); INIT_LIST_HEAD(&pdev->queued_bufs);
pdev->udev = udev; pdev->udev = udev;
pdev->vcompression = pwc_preferred_compression;
pdev->power_save = my_power_save; pdev->power_save = my_power_save;
/* Init videobuf2 queue structure */ /* Init videobuf2 queue structure */
...@@ -1121,8 +1138,8 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id ...@@ -1121,8 +1138,8 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
pwc_set_leds(pdev, 0, 0); pwc_set_leds(pdev, 0, 0);
/* Setup intial videomode */ /* Setup intial videomode */
rc = pwc_set_video_mode(pdev, MAX_WIDTH, MAX_HEIGHT, rc = pwc_set_video_mode(pdev, MAX_WIDTH, MAX_HEIGHT, pdev->vframes,
pdev->vframes, pdev->vcompression); &compression);
if (rc) if (rc)
goto err_free_mem; goto err_free_mem;
...@@ -1227,7 +1244,6 @@ static void usb_pwc_disconnect(struct usb_interface *intf) ...@@ -1227,7 +1244,6 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
*/ */
static int fps; static int fps;
static int compression = -1;
static int leds[2] = { -1, -1 }; static int leds[2] = { -1, -1 };
static unsigned int leds_nargs; static unsigned int leds_nargs;
static char *dev_hint[MAX_DEV_HINTS]; static char *dev_hint[MAX_DEV_HINTS];
...@@ -1238,7 +1254,6 @@ module_param(fps, int, 0444); ...@@ -1238,7 +1254,6 @@ module_param(fps, int, 0444);
module_param_named(trace, pwc_trace, int, 0644); module_param_named(trace, pwc_trace, int, 0644);
#endif #endif
module_param(power_save, int, 0644); module_param(power_save, int, 0644);
module_param(compression, int, 0444);
module_param_array(leds, int, &leds_nargs, 0444); module_param_array(leds, int, &leds_nargs, 0444);
module_param_array(dev_hint, charp, &dev_hint_nargs, 0444); module_param_array(dev_hint, charp, &dev_hint_nargs, 0444);
...@@ -1247,7 +1262,6 @@ MODULE_PARM_DESC(fps, "Initial frames per second. Varies with model, useful rang ...@@ -1247,7 +1262,6 @@ MODULE_PARM_DESC(fps, "Initial frames per second. Varies with model, useful rang
MODULE_PARM_DESC(trace, "For debugging purposes"); MODULE_PARM_DESC(trace, "For debugging purposes");
#endif #endif
MODULE_PARM_DESC(power_save, "Turn power saving for new cameras on or off"); MODULE_PARM_DESC(power_save, "Turn power saving for new cameras on or off");
MODULE_PARM_DESC(compression, "Preferred compression quality. Range 0 (uncompressed) to 3 (high compression)");
MODULE_PARM_DESC(leds, "LED on,off time in milliseconds"); MODULE_PARM_DESC(leds, "LED on,off time in milliseconds");
MODULE_PARM_DESC(dev_hint, "Device node hints"); MODULE_PARM_DESC(dev_hint, "Device node hints");
...@@ -1281,14 +1295,6 @@ static int __init usb_pwc_init(void) ...@@ -1281,14 +1295,6 @@ static int __init usb_pwc_init(void)
PWC_DEBUG_MODULE("Default framerate set to %d.\n", default_fps); PWC_DEBUG_MODULE("Default framerate set to %d.\n", default_fps);
} }
if (compression >= 0) {
if (compression > 3) {
PWC_ERROR("Invalid compression setting; use a number between 0 (uncompressed) and 3 (high).\n");
return -EINVAL;
}
pwc_preferred_compression = compression;
PWC_DEBUG_MODULE("Preferred compression set to %d.\n", pwc_preferred_compression);
}
if (leds[0] >= 0) if (leds[0] >= 0)
led_on = leds[0]; led_on = leds[0];
if (leds[1] >= 0) if (leds[1] >= 0)
......
...@@ -469,7 +469,7 @@ static int pwc_vidioc_try_fmt(struct pwc_device *pdev, struct v4l2_format *f) ...@@ -469,7 +469,7 @@ static int pwc_vidioc_try_fmt(struct pwc_device *pdev, struct v4l2_format *f)
static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
{ {
struct pwc_device *pdev = video_drvdata(file); struct pwc_device *pdev = video_drvdata(file);
int ret, pixelformat; int ret, pixelformat, compression = 0;
if (pwc_test_n_set_capt_file(pdev, file)) if (pwc_test_n_set_capt_file(pdev, file))
return -EBUSY; return -EBUSY;
...@@ -497,19 +497,15 @@ static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) ...@@ -497,19 +497,15 @@ static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
} }
PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d " PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d "
"compression=%d format=%c%c%c%c\n", "format=%c%c%c%c\n",
f->fmt.pix.width, f->fmt.pix.height, pdev->vframes, f->fmt.pix.width, f->fmt.pix.height, pdev->vframes,
pdev->vcompression,
(pixelformat)&255, (pixelformat)&255,
(pixelformat>>8)&255, (pixelformat>>8)&255,
(pixelformat>>16)&255, (pixelformat>>16)&255,
(pixelformat>>24)&255); (pixelformat>>24)&255);
ret = pwc_set_video_mode(pdev, ret = pwc_set_video_mode(pdev, f->fmt.pix.width, f->fmt.pix.height,
f->fmt.pix.width, pdev->vframes, &compression);
f->fmt.pix.height,
pdev->vframes,
pdev->vcompression);
PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret); PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret);
......
...@@ -243,7 +243,6 @@ struct pwc_device ...@@ -243,7 +243,6 @@ struct pwc_device
int vmax_packet_size; /* USB maxpacket size */ int vmax_packet_size; /* USB maxpacket size */
int vlast_packet_size; /* for frame synchronisation */ int vlast_packet_size; /* for frame synchronisation */
int visoc_errors; /* number of contiguous ISOC errors */ int visoc_errors; /* number of contiguous ISOC errors */
int vcompression; /* desired compression factor */
int vbandlength; /* compressed band length; 0 is uncompressed */ int vbandlength; /* compressed band length; 0 is uncompressed */
char vsync; /* used by isoc handler */ char vsync; /* used by isoc handler */
char vmirror; /* for ToUCaM series */ char vmirror; /* for ToUCaM series */
...@@ -365,7 +364,7 @@ void pwc_construct(struct pwc_device *pdev); ...@@ -365,7 +364,7 @@ void pwc_construct(struct pwc_device *pdev);
/** Functions in pwc-ctrl.c */ /** Functions in pwc-ctrl.c */
/* Request a certain video mode. Returns < 0 if not possible */ /* Request a certain video mode. Returns < 0 if not possible */
extern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, extern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
int frames, int compression); int frames, int *compression);
extern unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size); extern unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size);
extern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value); extern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value);
extern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor); extern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment