vivid-vid-out.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /*
  2. * vivid-vid-out.c - video output support functions.
  3. *
  4. * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  14. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  15. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. #include <linux/errno.h>
  20. #include <linux/kernel.h>
  21. #include <linux/sched.h>
  22. #include <linux/videodev2.h>
  23. #include <linux/v4l2-dv-timings.h>
  24. #include <media/v4l2-common.h>
  25. #include <media/v4l2-event.h>
  26. #include <media/v4l2-dv-timings.h>
  27. #include "vivid-core.h"
  28. #include "vivid-vid-common.h"
  29. #include "vivid-kthread-out.h"
  30. #include "vivid-vid-out.h"
  31. static int vid_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  32. unsigned *nbuffers, unsigned *nplanes,
  33. unsigned sizes[], void *alloc_ctxs[])
  34. {
  35. struct vivid_dev *dev = vb2_get_drv_priv(vq);
  36. unsigned planes = dev->fmt_out->planes;
  37. unsigned h = dev->fmt_out_rect.height;
  38. unsigned size = dev->bytesperline_out[0] * h;
  39. if (dev->field_out == V4L2_FIELD_ALTERNATE) {
  40. /*
  41. * You cannot use write() with FIELD_ALTERNATE since the field
  42. * information (TOP/BOTTOM) cannot be passed to the kernel.
  43. */
  44. if (vb2_fileio_is_active(vq))
  45. return -EINVAL;
  46. }
  47. if (dev->queue_setup_error) {
  48. /*
  49. * Error injection: test what happens if queue_setup() returns
  50. * an error.
  51. */
  52. dev->queue_setup_error = false;
  53. return -EINVAL;
  54. }
  55. if (fmt) {
  56. const struct v4l2_pix_format_mplane *mp;
  57. struct v4l2_format mp_fmt;
  58. if (!V4L2_TYPE_IS_MULTIPLANAR(fmt->type)) {
  59. fmt_sp2mp(fmt, &mp_fmt);
  60. fmt = &mp_fmt;
  61. }
  62. mp = &fmt->fmt.pix_mp;
  63. /*
  64. * Check if the number of planes in the specified format match
  65. * the number of planes in the current format. You can't mix that.
  66. */
  67. if (mp->num_planes != planes)
  68. return -EINVAL;
  69. sizes[0] = mp->plane_fmt[0].sizeimage;
  70. if (planes == 2) {
  71. sizes[1] = mp->plane_fmt[1].sizeimage;
  72. if (sizes[0] < dev->bytesperline_out[0] * h ||
  73. sizes[1] < dev->bytesperline_out[1] * h)
  74. return -EINVAL;
  75. } else if (sizes[0] < size) {
  76. return -EINVAL;
  77. }
  78. } else {
  79. if (planes == 2) {
  80. sizes[0] = dev->bytesperline_out[0] * h;
  81. sizes[1] = dev->bytesperline_out[1] * h;
  82. } else {
  83. sizes[0] = size;
  84. }
  85. }
  86. if (vq->num_buffers + *nbuffers < 2)
  87. *nbuffers = 2 - vq->num_buffers;
  88. *nplanes = planes;
  89. /*
  90. * videobuf2-vmalloc allocator is context-less so no need to set
  91. * alloc_ctxs array.
  92. */
  93. if (planes == 2)
  94. dprintk(dev, 1, "%s, count=%d, sizes=%u, %u\n", __func__,
  95. *nbuffers, sizes[0], sizes[1]);
  96. else
  97. dprintk(dev, 1, "%s, count=%d, size=%u\n", __func__,
  98. *nbuffers, sizes[0]);
  99. return 0;
  100. }
  101. static int vid_out_buf_prepare(struct vb2_buffer *vb)
  102. {
  103. struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  104. unsigned long size;
  105. unsigned planes = dev->fmt_out->planes;
  106. unsigned p;
  107. dprintk(dev, 1, "%s\n", __func__);
  108. if (WARN_ON(NULL == dev->fmt_out))
  109. return -EINVAL;
  110. if (dev->buf_prepare_error) {
  111. /*
  112. * Error injection: test what happens if buf_prepare() returns
  113. * an error.
  114. */
  115. dev->buf_prepare_error = false;
  116. return -EINVAL;
  117. }
  118. if (dev->field_out != V4L2_FIELD_ALTERNATE)
  119. vb->v4l2_buf.field = dev->field_out;
  120. else if (vb->v4l2_buf.field != V4L2_FIELD_TOP &&
  121. vb->v4l2_buf.field != V4L2_FIELD_BOTTOM)
  122. return -EINVAL;
  123. for (p = 0; p < planes; p++) {
  124. size = dev->bytesperline_out[p] * dev->fmt_out_rect.height +
  125. vb->v4l2_planes[p].data_offset;
  126. if (vb2_get_plane_payload(vb, p) < size) {
  127. dprintk(dev, 1, "%s the payload is too small for plane %u (%lu < %lu)\n",
  128. __func__, p, vb2_get_plane_payload(vb, p), size);
  129. return -EINVAL;
  130. }
  131. }
  132. return 0;
  133. }
  134. static void vid_out_buf_queue(struct vb2_buffer *vb)
  135. {
  136. struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  137. struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
  138. dprintk(dev, 1, "%s\n", __func__);
  139. spin_lock(&dev->slock);
  140. list_add_tail(&buf->list, &dev->vid_out_active);
  141. spin_unlock(&dev->slock);
  142. }
  143. static int vid_out_start_streaming(struct vb2_queue *vq, unsigned count)
  144. {
  145. struct vivid_dev *dev = vb2_get_drv_priv(vq);
  146. int err;
  147. if (vb2_is_streaming(&dev->vb_vid_cap_q))
  148. dev->can_loop_video = vivid_vid_can_loop(dev);
  149. if (dev->kthread_vid_out)
  150. return 0;
  151. dev->vid_out_seq_count = 0;
  152. dprintk(dev, 1, "%s\n", __func__);
  153. if (dev->start_streaming_error) {
  154. dev->start_streaming_error = false;
  155. err = -EINVAL;
  156. } else {
  157. err = vivid_start_generating_vid_out(dev, &dev->vid_out_streaming);
  158. }
  159. if (err) {
  160. struct vivid_buffer *buf, *tmp;
  161. list_for_each_entry_safe(buf, tmp, &dev->vid_out_active, list) {
  162. list_del(&buf->list);
  163. vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
  164. }
  165. }
  166. return err;
  167. }
  168. /* abort streaming and wait for last buffer */
  169. static void vid_out_stop_streaming(struct vb2_queue *vq)
  170. {
  171. struct vivid_dev *dev = vb2_get_drv_priv(vq);
  172. dprintk(dev, 1, "%s\n", __func__);
  173. vivid_stop_generating_vid_out(dev, &dev->vid_out_streaming);
  174. dev->can_loop_video = false;
  175. }
  176. const struct vb2_ops vivid_vid_out_qops = {
  177. .queue_setup = vid_out_queue_setup,
  178. .buf_prepare = vid_out_buf_prepare,
  179. .buf_queue = vid_out_buf_queue,
  180. .start_streaming = vid_out_start_streaming,
  181. .stop_streaming = vid_out_stop_streaming,
  182. .wait_prepare = vivid_unlock,
  183. .wait_finish = vivid_lock,
  184. };
  185. /*
  186. * Called whenever the format has to be reset which can occur when
  187. * changing outputs, standard, timings, etc.
  188. */
  189. void vivid_update_format_out(struct vivid_dev *dev)
  190. {
  191. struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt;
  192. unsigned size;
  193. switch (dev->output_type[dev->output]) {
  194. case SVID:
  195. default:
  196. dev->field_out = dev->tv_field_out;
  197. dev->sink_rect.width = 720;
  198. if (dev->std_out & V4L2_STD_525_60) {
  199. dev->sink_rect.height = 480;
  200. dev->timeperframe_vid_out = (struct v4l2_fract) { 1001, 30000 };
  201. dev->service_set_out = V4L2_SLICED_CAPTION_525;
  202. } else {
  203. dev->sink_rect.height = 576;
  204. dev->timeperframe_vid_out = (struct v4l2_fract) { 1000, 25000 };
  205. dev->service_set_out = V4L2_SLICED_WSS_625 | V4L2_SLICED_TELETEXT_B;
  206. }
  207. dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M;
  208. break;
  209. case HDMI:
  210. dev->sink_rect.width = bt->width;
  211. dev->sink_rect.height = bt->height;
  212. size = V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt);
  213. dev->timeperframe_vid_out = (struct v4l2_fract) {
  214. size / 100, (u32)bt->pixelclock / 100
  215. };
  216. if (bt->interlaced)
  217. dev->field_out = V4L2_FIELD_ALTERNATE;
  218. else
  219. dev->field_out = V4L2_FIELD_NONE;
  220. if (!dev->dvi_d_out && (bt->standards & V4L2_DV_BT_STD_CEA861)) {
  221. if (bt->width == 720 && bt->height <= 576)
  222. dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M;
  223. else
  224. dev->colorspace_out = V4L2_COLORSPACE_REC709;
  225. } else {
  226. dev->colorspace_out = V4L2_COLORSPACE_SRGB;
  227. }
  228. break;
  229. }
  230. dev->compose_out = dev->sink_rect;
  231. dev->compose_bounds_out = dev->sink_rect;
  232. dev->crop_out = dev->compose_out;
  233. if (V4L2_FIELD_HAS_T_OR_B(dev->field_out))
  234. dev->crop_out.height /= 2;
  235. dev->fmt_out_rect = dev->crop_out;
  236. dev->bytesperline_out[0] = (dev->sink_rect.width * dev->fmt_out->depth) / 8;
  237. if (dev->fmt_out->planes == 2)
  238. dev->bytesperline_out[1] = (dev->sink_rect.width * dev->fmt_out->depth) / 8;
  239. }
  240. /* Map the field to something that is valid for the current output */
  241. static enum v4l2_field vivid_field_out(struct vivid_dev *dev, enum v4l2_field field)
  242. {
  243. if (vivid_is_svid_out(dev)) {
  244. switch (field) {
  245. case V4L2_FIELD_INTERLACED_TB:
  246. case V4L2_FIELD_INTERLACED_BT:
  247. case V4L2_FIELD_SEQ_TB:
  248. case V4L2_FIELD_SEQ_BT:
  249. case V4L2_FIELD_ALTERNATE:
  250. return field;
  251. case V4L2_FIELD_INTERLACED:
  252. default:
  253. return V4L2_FIELD_INTERLACED;
  254. }
  255. }
  256. if (vivid_is_hdmi_out(dev))
  257. return dev->dv_timings_out.bt.interlaced ? V4L2_FIELD_ALTERNATE :
  258. V4L2_FIELD_NONE;
  259. return V4L2_FIELD_NONE;
  260. }
  261. static enum tpg_pixel_aspect vivid_get_pixel_aspect(const struct vivid_dev *dev)
  262. {
  263. if (vivid_is_svid_out(dev))
  264. return (dev->std_out & V4L2_STD_525_60) ?
  265. TPG_PIXEL_ASPECT_NTSC : TPG_PIXEL_ASPECT_PAL;
  266. if (vivid_is_hdmi_out(dev) &&
  267. dev->sink_rect.width == 720 && dev->sink_rect.height <= 576)
  268. return dev->sink_rect.height == 480 ?
  269. TPG_PIXEL_ASPECT_NTSC : TPG_PIXEL_ASPECT_PAL;
  270. return TPG_PIXEL_ASPECT_SQUARE;
  271. }
  272. int vivid_g_fmt_vid_out(struct file *file, void *priv,
  273. struct v4l2_format *f)
  274. {
  275. struct vivid_dev *dev = video_drvdata(file);
  276. struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp;
  277. unsigned p;
  278. mp->width = dev->fmt_out_rect.width;
  279. mp->height = dev->fmt_out_rect.height;
  280. mp->field = dev->field_out;
  281. mp->pixelformat = dev->fmt_out->fourcc;
  282. mp->colorspace = dev->colorspace_out;
  283. mp->num_planes = dev->fmt_out->planes;
  284. for (p = 0; p < mp->num_planes; p++) {
  285. mp->plane_fmt[p].bytesperline = dev->bytesperline_out[p];
  286. mp->plane_fmt[p].sizeimage =
  287. mp->plane_fmt[p].bytesperline * mp->height;
  288. }
  289. return 0;
  290. }
  291. int vivid_try_fmt_vid_out(struct file *file, void *priv,
  292. struct v4l2_format *f)
  293. {
  294. struct vivid_dev *dev = video_drvdata(file);
  295. struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt;
  296. struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp;
  297. struct v4l2_plane_pix_format *pfmt = mp->plane_fmt;
  298. const struct vivid_fmt *fmt;
  299. unsigned bytesperline, max_bpl;
  300. unsigned factor = 1;
  301. unsigned w, h;
  302. unsigned p;
  303. fmt = vivid_get_format(dev, mp->pixelformat);
  304. if (!fmt) {
  305. dprintk(dev, 1, "Fourcc format (0x%08x) unknown.\n",
  306. mp->pixelformat);
  307. mp->pixelformat = V4L2_PIX_FMT_YUYV;
  308. fmt = vivid_get_format(dev, mp->pixelformat);
  309. }
  310. mp->field = vivid_field_out(dev, mp->field);
  311. if (vivid_is_svid_out(dev)) {
  312. w = 720;
  313. h = (dev->std_out & V4L2_STD_525_60) ? 480 : 576;
  314. } else {
  315. w = dev->sink_rect.width;
  316. h = dev->sink_rect.height;
  317. }
  318. if (V4L2_FIELD_HAS_T_OR_B(mp->field))
  319. factor = 2;
  320. if (!dev->has_scaler_out && !dev->has_crop_out && !dev->has_compose_out) {
  321. mp->width = w;
  322. mp->height = h / factor;
  323. } else {
  324. struct v4l2_rect r = { 0, 0, mp->width, mp->height * factor };
  325. rect_set_min_size(&r, &vivid_min_rect);
  326. rect_set_max_size(&r, &vivid_max_rect);
  327. if (dev->has_scaler_out && !dev->has_crop_out) {
  328. struct v4l2_rect max_r = { 0, 0, MAX_ZOOM * w, MAX_ZOOM * h };
  329. rect_set_max_size(&r, &max_r);
  330. } else if (!dev->has_scaler_out && dev->has_compose_out && !dev->has_crop_out) {
  331. rect_set_max_size(&r, &dev->sink_rect);
  332. } else if (!dev->has_scaler_out && !dev->has_compose_out) {
  333. rect_set_min_size(&r, &dev->sink_rect);
  334. }
  335. mp->width = r.width;
  336. mp->height = r.height / factor;
  337. }
  338. /* This driver supports custom bytesperline values */
  339. /* Calculate the minimum supported bytesperline value */
  340. bytesperline = (mp->width * fmt->depth) >> 3;
  341. /* Calculate the maximum supported bytesperline value */
  342. max_bpl = (MAX_ZOOM * MAX_WIDTH * fmt->depth) >> 3;
  343. mp->num_planes = fmt->planes;
  344. for (p = 0; p < mp->num_planes; p++) {
  345. if (pfmt[p].bytesperline > max_bpl)
  346. pfmt[p].bytesperline = max_bpl;
  347. if (pfmt[p].bytesperline < bytesperline)
  348. pfmt[p].bytesperline = bytesperline;
  349. pfmt[p].sizeimage = pfmt[p].bytesperline * mp->height;
  350. memset(pfmt[p].reserved, 0, sizeof(pfmt[p].reserved));
  351. }
  352. if (vivid_is_svid_out(dev))
  353. mp->colorspace = V4L2_COLORSPACE_SMPTE170M;
  354. else if (dev->dvi_d_out || !(bt->standards & V4L2_DV_BT_STD_CEA861))
  355. mp->colorspace = V4L2_COLORSPACE_SRGB;
  356. else if (bt->width == 720 && bt->height <= 576)
  357. mp->colorspace = V4L2_COLORSPACE_SMPTE170M;
  358. else if (mp->colorspace != V4L2_COLORSPACE_SMPTE170M &&
  359. mp->colorspace != V4L2_COLORSPACE_REC709 &&
  360. mp->colorspace != V4L2_COLORSPACE_SRGB)
  361. mp->colorspace = V4L2_COLORSPACE_REC709;
  362. memset(mp->reserved, 0, sizeof(mp->reserved));
  363. return 0;
  364. }
  365. int vivid_s_fmt_vid_out(struct file *file, void *priv,
  366. struct v4l2_format *f)
  367. {
  368. struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp;
  369. struct vivid_dev *dev = video_drvdata(file);
  370. struct v4l2_rect *crop = &dev->crop_out;
  371. struct v4l2_rect *compose = &dev->compose_out;
  372. struct vb2_queue *q = &dev->vb_vid_out_q;
  373. int ret = vivid_try_fmt_vid_out(file, priv, f);
  374. unsigned factor = 1;
  375. if (ret < 0)
  376. return ret;
  377. if (vb2_is_busy(q) &&
  378. (vivid_is_svid_out(dev) ||
  379. mp->width != dev->fmt_out_rect.width ||
  380. mp->height != dev->fmt_out_rect.height ||
  381. mp->pixelformat != dev->fmt_out->fourcc ||
  382. mp->field != dev->field_out)) {
  383. dprintk(dev, 1, "%s device busy\n", __func__);
  384. return -EBUSY;
  385. }
  386. /*
  387. * Allow for changing the colorspace on the fly. Useful for testing
  388. * purposes, and it is something that HDMI transmitters are able
  389. * to do.
  390. */
  391. if (vb2_is_busy(q))
  392. goto set_colorspace;
  393. dev->fmt_out = vivid_get_format(dev, mp->pixelformat);
  394. if (V4L2_FIELD_HAS_T_OR_B(mp->field))
  395. factor = 2;
  396. if (dev->has_scaler_out || dev->has_crop_out || dev->has_compose_out) {
  397. struct v4l2_rect r = { 0, 0, mp->width, mp->height };
  398. if (dev->has_scaler_out) {
  399. if (dev->has_crop_out)
  400. rect_map_inside(crop, &r);
  401. else
  402. *crop = r;
  403. if (dev->has_compose_out && !dev->has_crop_out) {
  404. struct v4l2_rect min_r = {
  405. 0, 0,
  406. r.width / MAX_ZOOM,
  407. factor * r.height / MAX_ZOOM
  408. };
  409. struct v4l2_rect max_r = {
  410. 0, 0,
  411. r.width * MAX_ZOOM,
  412. factor * r.height * MAX_ZOOM
  413. };
  414. rect_set_min_size(compose, &min_r);
  415. rect_set_max_size(compose, &max_r);
  416. rect_map_inside(compose, &dev->compose_bounds_out);
  417. } else if (dev->has_compose_out) {
  418. struct v4l2_rect min_r = {
  419. 0, 0,
  420. crop->width / MAX_ZOOM,
  421. factor * crop->height / MAX_ZOOM
  422. };
  423. struct v4l2_rect max_r = {
  424. 0, 0,
  425. crop->width * MAX_ZOOM,
  426. factor * crop->height * MAX_ZOOM
  427. };
  428. rect_set_min_size(compose, &min_r);
  429. rect_set_max_size(compose, &max_r);
  430. rect_map_inside(compose, &dev->compose_bounds_out);
  431. }
  432. } else if (dev->has_compose_out && !dev->has_crop_out) {
  433. rect_set_size_to(crop, &r);
  434. r.height *= factor;
  435. rect_set_size_to(compose, &r);
  436. rect_map_inside(compose, &dev->compose_bounds_out);
  437. } else if (!dev->has_compose_out) {
  438. rect_map_inside(crop, &r);
  439. r.height /= factor;
  440. rect_set_size_to(compose, &r);
  441. } else {
  442. r.height *= factor;
  443. rect_set_max_size(compose, &r);
  444. rect_map_inside(compose, &dev->compose_bounds_out);
  445. crop->top *= factor;
  446. crop->height *= factor;
  447. rect_set_size_to(crop, compose);
  448. rect_map_inside(crop, &r);
  449. crop->top /= factor;
  450. crop->height /= factor;
  451. }
  452. } else {
  453. struct v4l2_rect r = { 0, 0, mp->width, mp->height };
  454. rect_set_size_to(crop, &r);
  455. r.height /= factor;
  456. rect_set_size_to(compose, &r);
  457. }
  458. dev->fmt_out_rect.width = mp->width;
  459. dev->fmt_out_rect.height = mp->height;
  460. dev->bytesperline_out[0] = mp->plane_fmt[0].bytesperline;
  461. if (mp->num_planes > 1)
  462. dev->bytesperline_out[1] = mp->plane_fmt[1].bytesperline;
  463. dev->field_out = mp->field;
  464. if (vivid_is_svid_out(dev))
  465. dev->tv_field_out = mp->field;
  466. set_colorspace:
  467. dev->colorspace_out = mp->colorspace;
  468. if (dev->loop_video) {
  469. vivid_send_source_change(dev, SVID);
  470. vivid_send_source_change(dev, HDMI);
  471. }
  472. return 0;
  473. }
  474. int vidioc_g_fmt_vid_out_mplane(struct file *file, void *priv,
  475. struct v4l2_format *f)
  476. {
  477. struct vivid_dev *dev = video_drvdata(file);
  478. if (!dev->multiplanar)
  479. return -ENOTTY;
  480. return vivid_g_fmt_vid_out(file, priv, f);
  481. }
  482. int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
  483. struct v4l2_format *f)
  484. {
  485. struct vivid_dev *dev = video_drvdata(file);
  486. if (!dev->multiplanar)
  487. return -ENOTTY;
  488. return vivid_try_fmt_vid_out(file, priv, f);
  489. }
  490. int vidioc_s_fmt_vid_out_mplane(struct file *file, void *priv,
  491. struct v4l2_format *f)
  492. {
  493. struct vivid_dev *dev = video_drvdata(file);
  494. if (!dev->multiplanar)
  495. return -ENOTTY;
  496. return vivid_s_fmt_vid_out(file, priv, f);
  497. }
  498. int vidioc_g_fmt_vid_out(struct file *file, void *priv,
  499. struct v4l2_format *f)
  500. {
  501. struct vivid_dev *dev = video_drvdata(file);
  502. if (dev->multiplanar)
  503. return -ENOTTY;
  504. return fmt_sp2mp_func(file, priv, f, vivid_g_fmt_vid_out);
  505. }
  506. int vidioc_try_fmt_vid_out(struct file *file, void *priv,
  507. struct v4l2_format *f)
  508. {
  509. struct vivid_dev *dev = video_drvdata(file);
  510. if (dev->multiplanar)
  511. return -ENOTTY;
  512. return fmt_sp2mp_func(file, priv, f, vivid_try_fmt_vid_out);
  513. }
  514. int vidioc_s_fmt_vid_out(struct file *file, void *priv,
  515. struct v4l2_format *f)
  516. {
  517. struct vivid_dev *dev = video_drvdata(file);
  518. if (dev->multiplanar)
  519. return -ENOTTY;
  520. return fmt_sp2mp_func(file, priv, f, vivid_s_fmt_vid_out);
  521. }
  522. int vivid_vid_out_g_selection(struct file *file, void *priv,
  523. struct v4l2_selection *sel)
  524. {
  525. struct vivid_dev *dev = video_drvdata(file);
  526. if (!dev->has_crop_out && !dev->has_compose_out)
  527. return -ENOTTY;
  528. if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
  529. return -EINVAL;
  530. sel->r.left = sel->r.top = 0;
  531. switch (sel->target) {
  532. case V4L2_SEL_TGT_CROP:
  533. if (!dev->has_crop_out)
  534. return -EINVAL;
  535. sel->r = dev->crop_out;
  536. break;
  537. case V4L2_SEL_TGT_CROP_DEFAULT:
  538. if (!dev->has_crop_out)
  539. return -EINVAL;
  540. sel->r = dev->fmt_out_rect;
  541. break;
  542. case V4L2_SEL_TGT_CROP_BOUNDS:
  543. if (!dev->has_crop_out)
  544. return -EINVAL;
  545. sel->r = vivid_max_rect;
  546. break;
  547. case V4L2_SEL_TGT_COMPOSE:
  548. if (!dev->has_compose_out)
  549. return -EINVAL;
  550. sel->r = dev->compose_out;
  551. break;
  552. case V4L2_SEL_TGT_COMPOSE_DEFAULT:
  553. case V4L2_SEL_TGT_COMPOSE_BOUNDS:
  554. if (!dev->has_compose_out)
  555. return -EINVAL;
  556. sel->r = dev->sink_rect;
  557. break;
  558. default:
  559. return -EINVAL;
  560. }
  561. return 0;
  562. }
  563. int vivid_vid_out_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
  564. {
  565. struct vivid_dev *dev = video_drvdata(file);
  566. struct v4l2_rect *crop = &dev->crop_out;
  567. struct v4l2_rect *compose = &dev->compose_out;
  568. unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_out) ? 2 : 1;
  569. int ret;
  570. if (!dev->has_crop_out && !dev->has_compose_out)
  571. return -ENOTTY;
  572. if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
  573. return -EINVAL;
  574. switch (s->target) {
  575. case V4L2_SEL_TGT_CROP:
  576. if (!dev->has_crop_out)
  577. return -EINVAL;
  578. ret = vivid_vid_adjust_sel(s->flags, &s->r);
  579. if (ret)
  580. return ret;
  581. rect_set_min_size(&s->r, &vivid_min_rect);
  582. rect_set_max_size(&s->r, &dev->fmt_out_rect);
  583. if (dev->has_scaler_out) {
  584. struct v4l2_rect max_rect = {
  585. 0, 0,
  586. dev->sink_rect.width * MAX_ZOOM,
  587. (dev->sink_rect.height / factor) * MAX_ZOOM
  588. };
  589. rect_set_max_size(&s->r, &max_rect);
  590. if (dev->has_compose_out) {
  591. struct v4l2_rect min_rect = {
  592. 0, 0,
  593. s->r.width / MAX_ZOOM,
  594. (s->r.height * factor) / MAX_ZOOM
  595. };
  596. struct v4l2_rect max_rect = {
  597. 0, 0,
  598. s->r.width * MAX_ZOOM,
  599. (s->r.height * factor) * MAX_ZOOM
  600. };
  601. rect_set_min_size(compose, &min_rect);
  602. rect_set_max_size(compose, &max_rect);
  603. rect_map_inside(compose, &dev->compose_bounds_out);
  604. }
  605. } else if (dev->has_compose_out) {
  606. s->r.top *= factor;
  607. s->r.height *= factor;
  608. rect_set_max_size(&s->r, &dev->sink_rect);
  609. rect_set_size_to(compose, &s->r);
  610. rect_map_inside(compose, &dev->compose_bounds_out);
  611. s->r.top /= factor;
  612. s->r.height /= factor;
  613. } else {
  614. rect_set_size_to(&s->r, &dev->sink_rect);
  615. s->r.height /= factor;
  616. }
  617. rect_map_inside(&s->r, &dev->fmt_out_rect);
  618. *crop = s->r;
  619. break;
  620. case V4L2_SEL_TGT_COMPOSE:
  621. if (!dev->has_compose_out)
  622. return -EINVAL;
  623. ret = vivid_vid_adjust_sel(s->flags, &s->r);
  624. if (ret)
  625. return ret;
  626. rect_set_min_size(&s->r, &vivid_min_rect);
  627. rect_set_max_size(&s->r, &dev->sink_rect);
  628. rect_map_inside(&s->r, &dev->compose_bounds_out);
  629. s->r.top /= factor;
  630. s->r.height /= factor;
  631. if (dev->has_scaler_out) {
  632. struct v4l2_rect fmt = dev->fmt_out_rect;
  633. struct v4l2_rect max_rect = {
  634. 0, 0,
  635. s->r.width * MAX_ZOOM,
  636. s->r.height * MAX_ZOOM
  637. };
  638. struct v4l2_rect min_rect = {
  639. 0, 0,
  640. s->r.width / MAX_ZOOM,
  641. s->r.height / MAX_ZOOM
  642. };
  643. rect_set_min_size(&fmt, &min_rect);
  644. if (!dev->has_crop_out)
  645. rect_set_max_size(&fmt, &max_rect);
  646. if (!rect_same_size(&dev->fmt_out_rect, &fmt) &&
  647. vb2_is_busy(&dev->vb_vid_out_q))
  648. return -EBUSY;
  649. if (dev->has_crop_out) {
  650. rect_set_min_size(crop, &min_rect);
  651. rect_set_max_size(crop, &max_rect);
  652. }
  653. dev->fmt_out_rect = fmt;
  654. } else if (dev->has_crop_out) {
  655. struct v4l2_rect fmt = dev->fmt_out_rect;
  656. rect_set_min_size(&fmt, &s->r);
  657. if (!rect_same_size(&dev->fmt_out_rect, &fmt) &&
  658. vb2_is_busy(&dev->vb_vid_out_q))
  659. return -EBUSY;
  660. dev->fmt_out_rect = fmt;
  661. rect_set_size_to(crop, &s->r);
  662. rect_map_inside(crop, &dev->fmt_out_rect);
  663. } else {
  664. if (!rect_same_size(&s->r, &dev->fmt_out_rect) &&
  665. vb2_is_busy(&dev->vb_vid_out_q))
  666. return -EBUSY;
  667. rect_set_size_to(&dev->fmt_out_rect, &s->r);
  668. rect_set_size_to(crop, &s->r);
  669. crop->height /= factor;
  670. rect_map_inside(crop, &dev->fmt_out_rect);
  671. }
  672. s->r.top *= factor;
  673. s->r.height *= factor;
  674. if (dev->bitmap_out && (compose->width != s->r.width ||
  675. compose->height != s->r.height)) {
  676. kfree(dev->bitmap_out);
  677. dev->bitmap_out = NULL;
  678. }
  679. *compose = s->r;
  680. break;
  681. default:
  682. return -EINVAL;
  683. }
  684. return 0;
  685. }
  686. int vivid_vid_out_cropcap(struct file *file, void *priv,
  687. struct v4l2_cropcap *cap)
  688. {
  689. struct vivid_dev *dev = video_drvdata(file);
  690. if (cap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
  691. return -EINVAL;
  692. switch (vivid_get_pixel_aspect(dev)) {
  693. case TPG_PIXEL_ASPECT_NTSC:
  694. cap->pixelaspect.numerator = 11;
  695. cap->pixelaspect.denominator = 10;
  696. break;
  697. case TPG_PIXEL_ASPECT_PAL:
  698. cap->pixelaspect.numerator = 54;
  699. cap->pixelaspect.denominator = 59;
  700. break;
  701. case TPG_PIXEL_ASPECT_SQUARE:
  702. cap->pixelaspect.numerator = 1;
  703. cap->pixelaspect.denominator = 1;
  704. break;
  705. }
  706. return 0;
  707. }
  708. int vidioc_g_fmt_vid_out_overlay(struct file *file, void *priv,
  709. struct v4l2_format *f)
  710. {
  711. struct vivid_dev *dev = video_drvdata(file);
  712. const struct v4l2_rect *compose = &dev->compose_out;
  713. struct v4l2_window *win = &f->fmt.win;
  714. unsigned clipcount = win->clipcount;
  715. if (!dev->has_fb)
  716. return -EINVAL;
  717. win->w.top = dev->overlay_out_top;
  718. win->w.left = dev->overlay_out_left;
  719. win->w.width = compose->width;
  720. win->w.height = compose->height;
  721. win->clipcount = dev->clipcount_out;
  722. win->field = V4L2_FIELD_ANY;
  723. win->chromakey = dev->chromakey_out;
  724. win->global_alpha = dev->global_alpha_out;
  725. if (clipcount > dev->clipcount_out)
  726. clipcount = dev->clipcount_out;
  727. if (dev->bitmap_out == NULL)
  728. win->bitmap = NULL;
  729. else if (win->bitmap) {
  730. if (copy_to_user(win->bitmap, dev->bitmap_out,
  731. ((dev->compose_out.width + 7) / 8) * dev->compose_out.height))
  732. return -EFAULT;
  733. }
  734. if (clipcount && win->clips) {
  735. if (copy_to_user(win->clips, dev->clips_out,
  736. clipcount * sizeof(dev->clips_out[0])))
  737. return -EFAULT;
  738. }
  739. return 0;
  740. }
  741. int vidioc_try_fmt_vid_out_overlay(struct file *file, void *priv,
  742. struct v4l2_format *f)
  743. {
  744. struct vivid_dev *dev = video_drvdata(file);
  745. const struct v4l2_rect *compose = &dev->compose_out;
  746. struct v4l2_window *win = &f->fmt.win;
  747. int i, j;
  748. if (!dev->has_fb)
  749. return -EINVAL;
  750. win->w.left = clamp_t(int, win->w.left,
  751. -dev->display_width, dev->display_width);
  752. win->w.top = clamp_t(int, win->w.top,
  753. -dev->display_height, dev->display_height);
  754. win->w.width = compose->width;
  755. win->w.height = compose->height;
  756. /*
  757. * It makes no sense for an OSD to overlay only top or bottom fields,
  758. * so always set this to ANY.
  759. */
  760. win->field = V4L2_FIELD_ANY;
  761. if (win->clipcount && !win->clips)
  762. win->clipcount = 0;
  763. if (win->clipcount > MAX_CLIPS)
  764. win->clipcount = MAX_CLIPS;
  765. if (win->clipcount) {
  766. if (copy_from_user(dev->try_clips_out, win->clips,
  767. win->clipcount * sizeof(dev->clips_out[0])))
  768. return -EFAULT;
  769. for (i = 0; i < win->clipcount; i++) {
  770. struct v4l2_rect *r = &dev->try_clips_out[i].c;
  771. r->top = clamp_t(s32, r->top, 0, dev->display_height - 1);
  772. r->height = clamp_t(s32, r->height, 1, dev->display_height - r->top);
  773. r->left = clamp_t(u32, r->left, 0, dev->display_width - 1);
  774. r->width = clamp_t(u32, r->width, 1, dev->display_width - r->left);
  775. }
  776. /*
  777. * Yeah, so sue me, it's an O(n^2) algorithm. But n is a small
  778. * number and it's typically a one-time deal.
  779. */
  780. for (i = 0; i < win->clipcount - 1; i++) {
  781. struct v4l2_rect *r1 = &dev->try_clips_out[i].c;
  782. for (j = i + 1; j < win->clipcount; j++) {
  783. struct v4l2_rect *r2 = &dev->try_clips_out[j].c;
  784. if (rect_overlap(r1, r2))
  785. return -EINVAL;
  786. }
  787. }
  788. if (copy_to_user(win->clips, dev->try_clips_out,
  789. win->clipcount * sizeof(dev->clips_out[0])))
  790. return -EFAULT;
  791. }
  792. return 0;
  793. }
  794. int vidioc_s_fmt_vid_out_overlay(struct file *file, void *priv,
  795. struct v4l2_format *f)
  796. {
  797. struct vivid_dev *dev = video_drvdata(file);
  798. const struct v4l2_rect *compose = &dev->compose_out;
  799. struct v4l2_window *win = &f->fmt.win;
  800. int ret = vidioc_try_fmt_vid_out_overlay(file, priv, f);
  801. unsigned bitmap_size = ((compose->width + 7) / 8) * compose->height;
  802. unsigned clips_size = win->clipcount * sizeof(dev->clips_out[0]);
  803. void *new_bitmap = NULL;
  804. if (ret)
  805. return ret;
  806. if (win->bitmap) {
  807. new_bitmap = memdup_user(win->bitmap, bitmap_size);
  808. if (IS_ERR(new_bitmap))
  809. return PTR_ERR(new_bitmap);
  810. }
  811. dev->overlay_out_top = win->w.top;
  812. dev->overlay_out_left = win->w.left;
  813. kfree(dev->bitmap_out);
  814. dev->bitmap_out = new_bitmap;
  815. dev->clipcount_out = win->clipcount;
  816. if (dev->clipcount_out)
  817. memcpy(dev->clips_out, dev->try_clips_out, clips_size);
  818. dev->chromakey_out = win->chromakey;
  819. dev->global_alpha_out = win->global_alpha;
  820. return ret;
  821. }
  822. int vivid_vid_out_overlay(struct file *file, void *fh, unsigned i)
  823. {
  824. struct vivid_dev *dev = video_drvdata(file);
  825. if (i && !dev->fmt_out->can_do_overlay) {
  826. dprintk(dev, 1, "unsupported output format for output overlay\n");
  827. return -EINVAL;
  828. }
  829. dev->overlay_out_enabled = i;
  830. return 0;
  831. }
  832. int vivid_vid_out_g_fbuf(struct file *file, void *fh,
  833. struct v4l2_framebuffer *a)
  834. {
  835. struct vivid_dev *dev = video_drvdata(file);
  836. a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY |
  837. V4L2_FBUF_CAP_BITMAP_CLIPPING |
  838. V4L2_FBUF_CAP_LIST_CLIPPING |
  839. V4L2_FBUF_CAP_CHROMAKEY |
  840. V4L2_FBUF_CAP_SRC_CHROMAKEY |
  841. V4L2_FBUF_CAP_GLOBAL_ALPHA |
  842. V4L2_FBUF_CAP_LOCAL_ALPHA |
  843. V4L2_FBUF_CAP_LOCAL_INV_ALPHA;
  844. a->flags = V4L2_FBUF_FLAG_OVERLAY | dev->fbuf_out_flags;
  845. a->base = (void *)dev->video_pbase;
  846. a->fmt.width = dev->display_width;
  847. a->fmt.height = dev->display_height;
  848. if (dev->fb_defined.green.length == 5)
  849. a->fmt.pixelformat = V4L2_PIX_FMT_ARGB555;
  850. else
  851. a->fmt.pixelformat = V4L2_PIX_FMT_RGB565;
  852. a->fmt.bytesperline = dev->display_byte_stride;
  853. a->fmt.sizeimage = a->fmt.height * a->fmt.bytesperline;
  854. a->fmt.field = V4L2_FIELD_NONE;
  855. a->fmt.colorspace = V4L2_COLORSPACE_SRGB;
  856. a->fmt.priv = 0;
  857. return 0;
  858. }
  859. int vivid_vid_out_s_fbuf(struct file *file, void *fh,
  860. const struct v4l2_framebuffer *a)
  861. {
  862. struct vivid_dev *dev = video_drvdata(file);
  863. const unsigned chroma_flags = V4L2_FBUF_FLAG_CHROMAKEY |
  864. V4L2_FBUF_FLAG_SRC_CHROMAKEY;
  865. const unsigned alpha_flags = V4L2_FBUF_FLAG_GLOBAL_ALPHA |
  866. V4L2_FBUF_FLAG_LOCAL_ALPHA |
  867. V4L2_FBUF_FLAG_LOCAL_INV_ALPHA;
  868. if ((a->flags & chroma_flags) == chroma_flags)
  869. return -EINVAL;
  870. switch (a->flags & alpha_flags) {
  871. case 0:
  872. case V4L2_FBUF_FLAG_GLOBAL_ALPHA:
  873. case V4L2_FBUF_FLAG_LOCAL_ALPHA:
  874. case V4L2_FBUF_FLAG_LOCAL_INV_ALPHA:
  875. break;
  876. default:
  877. return -EINVAL;
  878. }
  879. dev->fbuf_out_flags &= ~(chroma_flags | alpha_flags);
  880. dev->fbuf_out_flags = a->flags & (chroma_flags | alpha_flags);
  881. return 0;
  882. }
  883. static const struct v4l2_audioout vivid_audio_outputs[] = {
  884. { 0, "Line-Out 1" },
  885. { 1, "Line-Out 2" },
  886. };
  887. int vidioc_enum_output(struct file *file, void *priv,
  888. struct v4l2_output *out)
  889. {
  890. struct vivid_dev *dev = video_drvdata(file);
  891. if (out->index >= dev->num_outputs)
  892. return -EINVAL;
  893. out->type = V4L2_OUTPUT_TYPE_ANALOG;
  894. switch (dev->output_type[out->index]) {
  895. case SVID:
  896. snprintf(out->name, sizeof(out->name), "S-Video %u",
  897. dev->output_name_counter[out->index]);
  898. out->std = V4L2_STD_ALL;
  899. if (dev->has_audio_outputs)
  900. out->audioset = (1 << ARRAY_SIZE(vivid_audio_outputs)) - 1;
  901. out->capabilities = V4L2_OUT_CAP_STD;
  902. break;
  903. case HDMI:
  904. snprintf(out->name, sizeof(out->name), "HDMI %u",
  905. dev->output_name_counter[out->index]);
  906. out->capabilities = V4L2_OUT_CAP_DV_TIMINGS;
  907. break;
  908. }
  909. return 0;
  910. }
  911. int vidioc_g_output(struct file *file, void *priv, unsigned *o)
  912. {
  913. struct vivid_dev *dev = video_drvdata(file);
  914. *o = dev->output;
  915. return 0;
  916. }
  917. int vidioc_s_output(struct file *file, void *priv, unsigned o)
  918. {
  919. struct vivid_dev *dev = video_drvdata(file);
  920. if (o >= dev->num_outputs)
  921. return -EINVAL;
  922. if (o == dev->output)
  923. return 0;
  924. if (vb2_is_busy(&dev->vb_vid_out_q) || vb2_is_busy(&dev->vb_vbi_out_q))
  925. return -EBUSY;
  926. dev->output = o;
  927. dev->tv_audio_output = 0;
  928. if (dev->output_type[o] == SVID)
  929. dev->vid_out_dev.tvnorms = V4L2_STD_ALL;
  930. else
  931. dev->vid_out_dev.tvnorms = 0;
  932. dev->vbi_out_dev.tvnorms = dev->vid_out_dev.tvnorms;
  933. vivid_update_format_out(dev);
  934. return 0;
  935. }
  936. int vidioc_enumaudout(struct file *file, void *fh, struct v4l2_audioout *vout)
  937. {
  938. if (vout->index >= ARRAY_SIZE(vivid_audio_outputs))
  939. return -EINVAL;
  940. *vout = vivid_audio_outputs[vout->index];
  941. return 0;
  942. }
  943. int vidioc_g_audout(struct file *file, void *fh, struct v4l2_audioout *vout)
  944. {
  945. struct vivid_dev *dev = video_drvdata(file);
  946. if (!vivid_is_svid_out(dev))
  947. return -EINVAL;
  948. *vout = vivid_audio_outputs[dev->tv_audio_output];
  949. return 0;
  950. }
  951. int vidioc_s_audout(struct file *file, void *fh, const struct v4l2_audioout *vout)
  952. {
  953. struct vivid_dev *dev = video_drvdata(file);
  954. if (!vivid_is_svid_out(dev))
  955. return -EINVAL;
  956. if (vout->index >= ARRAY_SIZE(vivid_audio_outputs))
  957. return -EINVAL;
  958. dev->tv_audio_output = vout->index;
  959. return 0;
  960. }
  961. int vivid_vid_out_s_std(struct file *file, void *priv, v4l2_std_id id)
  962. {
  963. struct vivid_dev *dev = video_drvdata(file);
  964. if (!vivid_is_svid_out(dev))
  965. return -ENODATA;
  966. if (dev->std_out == id)
  967. return 0;
  968. if (vb2_is_busy(&dev->vb_vid_out_q) || vb2_is_busy(&dev->vb_vbi_out_q))
  969. return -EBUSY;
  970. dev->std_out = id;
  971. vivid_update_format_out(dev);
  972. return 0;
  973. }
  974. int vivid_vid_out_s_dv_timings(struct file *file, void *_fh,
  975. struct v4l2_dv_timings *timings)
  976. {
  977. struct vivid_dev *dev = video_drvdata(file);
  978. if (!vivid_is_hdmi_out(dev))
  979. return -ENODATA;
  980. if (vb2_is_busy(&dev->vb_vid_out_q))
  981. return -EBUSY;
  982. if (!v4l2_find_dv_timings_cap(timings, &vivid_dv_timings_cap,
  983. 0, NULL, NULL))
  984. return -EINVAL;
  985. if (v4l2_match_dv_timings(timings, &dev->dv_timings_out, 0))
  986. return 0;
  987. dev->dv_timings_out = *timings;
  988. vivid_update_format_out(dev);
  989. return 0;
  990. }
  991. int vivid_vid_out_g_parm(struct file *file, void *priv,
  992. struct v4l2_streamparm *parm)
  993. {
  994. struct vivid_dev *dev = video_drvdata(file);
  995. if (parm->type != (dev->multiplanar ?
  996. V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE :
  997. V4L2_BUF_TYPE_VIDEO_OUTPUT))
  998. return -EINVAL;
  999. parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
  1000. parm->parm.output.timeperframe = dev->timeperframe_vid_out;
  1001. parm->parm.output.writebuffers = 1;
  1002. return 0;
  1003. }
  1004. int vidioc_subscribe_event(struct v4l2_fh *fh,
  1005. const struct v4l2_event_subscription *sub)
  1006. {
  1007. switch (sub->type) {
  1008. case V4L2_EVENT_CTRL:
  1009. return v4l2_ctrl_subscribe_event(fh, sub);
  1010. case V4L2_EVENT_SOURCE_CHANGE:
  1011. if (fh->vdev->vfl_dir == VFL_DIR_RX)
  1012. return v4l2_src_change_event_subscribe(fh, sub);
  1013. break;
  1014. default:
  1015. break;
  1016. }
  1017. return -EINVAL;
  1018. }