/drivers/media/video/ivtv/ivtv-controls.c

https://bitbucket.org/ndreys/linux-sunxi · C · 101 lines · 63 code · 13 blank · 25 comment · 14 complexity · 483c2eb1c21e7a7a0083b90fd8c4a721 MD5 · raw file

  1. /*
  2. ioctl control functions
  3. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  4. Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "ivtv-driver.h"
  18. #include "ivtv-ioctl.h"
  19. #include "ivtv-controls.h"
  20. static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
  21. {
  22. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  23. /* First try to allocate sliced VBI buffers if needed. */
  24. if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
  25. int i;
  26. for (i = 0; i < IVTV_VBI_FRAMES; i++) {
  27. /* Yuck, hardcoded. Needs to be a define */
  28. itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL);
  29. if (itv->vbi.sliced_mpeg_data[i] == NULL) {
  30. while (--i >= 0) {
  31. kfree(itv->vbi.sliced_mpeg_data[i]);
  32. itv->vbi.sliced_mpeg_data[i] = NULL;
  33. }
  34. return -ENOMEM;
  35. }
  36. }
  37. }
  38. itv->vbi.insert_mpeg = fmt;
  39. if (itv->vbi.insert_mpeg == 0) {
  40. return 0;
  41. }
  42. /* Need sliced data for mpeg insertion */
  43. if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) {
  44. if (itv->is_60hz)
  45. itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525;
  46. else
  47. itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
  48. ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz);
  49. }
  50. return 0;
  51. }
  52. static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
  53. {
  54. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  55. int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
  56. struct v4l2_mbus_framefmt fmt;
  57. /* fix videodecoder resolution */
  58. fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
  59. fmt.height = cxhdl->height;
  60. fmt.code = V4L2_MBUS_FMT_FIXED;
  61. v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
  62. return 0;
  63. }
  64. static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
  65. {
  66. static const u32 freqs[3] = { 44100, 48000, 32000 };
  67. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  68. /* The audio clock of the digitizer must match the codec sample
  69. rate otherwise you get some very strange effects. */
  70. if (idx < ARRAY_SIZE(freqs))
  71. ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
  72. return 0;
  73. }
  74. static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
  75. {
  76. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  77. itv->dualwatch_stereo_mode = val;
  78. return 0;
  79. }
  80. struct cx2341x_handler_ops ivtv_cxhdl_ops = {
  81. .s_audio_mode = ivtv_s_audio_mode,
  82. .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
  83. .s_video_encoding = ivtv_s_video_encoding,
  84. .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
  85. };