0028-V4L2-Fixes-from-6by9.patch 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398
  1. From c8fb291144efa1ab7f0628119894a1e72f08bce4 Mon Sep 17 00:00:00 2001
  2. From: Dave Stevenson <dsteve@broadcom.com>
  3. Date: Mon, 9 Dec 2013 10:58:01 +0000
  4. Subject: [PATCH 028/114] V4L2: Fixes from 6by9
  5. V4L2: Fix EV values. Add manual shutter speed control
  6. V4L2 EV values should be in units of 1/1000. Corrected.
  7. Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
  8. give manual shutter control. Requires manual exposure mode
  9. to be selected first.
  10. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  11. V4L2: Correct JPEG Q-factor range
  12. Should be 1-100, not 0-100
  13. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  14. V4L2: Fix issue of driver jamming if STREAMON failed.
  15. Fix issue where the driver was left in a partially enabled
  16. state if STREAMON failed, and would then reject many IOCTLs
  17. as it thought it was streaming.
  18. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  19. V4L2: Fix ISO controls.
  20. Driver was passing the index to the GPU, and not the desired
  21. ISO value.
  22. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  23. V4L2: Add flicker avoidance controls
  24. Add support for V4L2_CID_POWER_LINE_FREQUENCY to set flicker
  25. avoidance frequencies.
  26. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  27. V4L2: Add support for frame rate control.
  28. Add support for frame rate (or time per frame as V4L2
  29. inverts it) control via s_parm.
  30. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  31. V4L2: Improve G_FBUF handling so we pass conformance
  32. Return some sane numbers for get framebuffer so that
  33. we pass conformance.
  34. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  35. V4L2: Fix information advertised through g_vidfmt
  36. Width and height were being stored based on incorrect
  37. values.
  38. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  39. V4L2: Add support for inline H264 headers
  40. Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
  41. to control H264 inline headers.
  42. Requires firmware fix to work correctly, otherwise format
  43. has to be set to H264 before this parameter is set.
  44. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  45. V4L2: Fix JPEG timestamp issue
  46. JPEG images were coming through from the GPU with timestamp
  47. of 0. Detect this and give current system time instead
  48. of some invalid value.
  49. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  50. V4L2: Fix issue when switching down JPEG resolution.
  51. JPEG buffer size calculation is based on input resolution.
  52. Input resolution was being configured after output port
  53. format. Caused failures if switching from one JPEG resolution
  54. to a smaller one.
  55. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  56. V4L2: Enable MJPEG encoding
  57. Requires GPU firmware update to support MJPEG encoder.
  58. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  59. V4L2: Correct flag settings for compressed formats
  60. Set flags field correctly on enum_fmt_vid_cap for compressed
  61. image formats.
  62. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  63. V4L2: H264 profile & level ctrls, FPS control and auto exp pri
  64. Several control handling updates.
  65. H264 profile and level controls.
  66. Timeperframe/FPS reworked to add V4L2_CID_EXPOSURE_AUTO_PRIORITY to
  67. select whether AE is allowed to override the framerate specified.
  68. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  69. V4L2: Correct BGR24 to RGB24 in format table
  70. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  71. V4L2: Add additional pixel formats. Correct colourspace
  72. Adds the other flavours of YUYV, and NV12.
  73. Corrects the overlay advertised colourspace.
  74. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  75. V4L2: Drop logging msg from info to debug
  76. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  77. V4L2: Initial pass at scene modes.
  78. Only supports exposure mode and metering modes.
  79. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  80. V4L2: Add manual white balance control.
  81. Adds support for V4L2_CID_RED_BALANCE and
  82. V4L2_CID_BLUE_BALANCE. Only has an effect if
  83. V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE has
  84. V4L2_WHITE_BALANCE_MANUAL selected.
  85. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  86. config: Enable V4L / MMAL driver
  87. V4L2: Increase the MMAL timeout to 3sec
  88. MJPEG codec flush is now taking longer and results
  89. in a kernel panic if the driver has stopped waiting for
  90. the result when it finally completes.
  91. Increase the timeout value from 1 to 3secs.
  92. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  93. V4L2: Add support for setting H264_I_PERIOD
  94. Adds support for the parameter V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
  95. to set the frequency with which I frames are produced.
  96. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  97. V4L2: Enable GPU function for removing padding from images.
  98. GPU can now support arbitrary strides, although may require
  99. additional processing to achieve it. Enable this feature
  100. so that the images delivered are the size requested.
  101. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  102. V4L2: Add support for V4L2_PIX_FMT_BGR32
  103. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  104. V4L2: Set the colourspace to avoid odd YUV-RGB conversions
  105. Removes the amiguity from the conversion routines and stops
  106. them dropping back to the SD vs HD choice of coeffs.
  107. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  108. V4L2: Make video/still threshold a run-time param
  109. Move the define for at what resolution the driver
  110. switches from a video mode capture to a stills mode
  111. capture to module parameters.
  112. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  113. V4L2: Fix incorrect pool sizing
  114. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  115. V4L2: Add option to disable enum_framesizes.
  116. Gstreamer's handling of a driver that advertises
  117. V4L2_FRMSIZE_TYPE_STEPWISE to define the supported
  118. resolutions is broken. See bug
  119. https://bugzilla.gnome.org/show_bug.cgi?id=726521
  120. Optional parameter of gst_v4l2src_is_broken added.
  121. If non-zero, the driver claims not to support that
  122. ioctl, and gstreamer should be happy again (it
  123. guesses a set of defaults for itself).
  124. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  125. V4L2: Add support for more image formats
  126. Adds YVU420 (YV12), YVU420SP (NV21), and BGR888.
  127. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  128. V4L2: Extend range for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
  129. Request to extend the range from the fairly arbitrary
  130. 1000 frames (33 seconds at 30fps). Extend out to the
  131. max range supported (int32 value).
  132. Also allow 0, which is handled by the codec as only
  133. send an I-frame on the first frame and never again.
  134. There may be an exception if it detects a significant
  135. scene change, but there's no easy way around that.
  136. Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
  137. bcm2835-camera: stop_streaming now has a void return
  138. ---
  139. arch/arm/configs/bcmrpi_defconfig | 3 +
  140. drivers/media/platform/bcm2835/bcm2835-camera.c | 578 ++++++++++++++----
  141. drivers/media/platform/bcm2835/bcm2835-camera.h | 23 +-
  142. drivers/media/platform/bcm2835/controls.c | 723 +++++++++++++++++++++--
  143. drivers/media/platform/bcm2835/mmal-common.h | 1 +
  144. drivers/media/platform/bcm2835/mmal-encodings.h | 34 ++
  145. drivers/media/platform/bcm2835/mmal-parameters.h | 121 +++-
  146. drivers/media/platform/bcm2835/mmal-vchiq.c | 4 +-
  147. 8 files changed, 1300 insertions(+), 187 deletions(-)
  148. --- a/arch/arm/configs/bcmrpi_defconfig
  149. +++ b/arch/arm/configs/bcmrpi_defconfig
  150. @@ -708,6 +708,9 @@ CONFIG_DVB_AS102=m
  151. CONFIG_VIDEO_EM28XX=m
  152. CONFIG_VIDEO_EM28XX_ALSA=m
  153. CONFIG_VIDEO_EM28XX_DVB=m
  154. +CONFIG_V4L_PLATFORM_DRIVERS=y
  155. +CONFIG_VIDEO_BCM2835=y
  156. +CONFIG_VIDEO_BCM2835_MMAL=m
  157. CONFIG_RADIO_SI470X=y
  158. CONFIG_USB_SI470X=m
  159. CONFIG_I2C_SI470X=m
  160. --- a/drivers/media/platform/bcm2835/bcm2835-camera.c
  161. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
  162. @@ -36,7 +36,8 @@
  163. #define BM2835_MMAL_VERSION "0.0.2"
  164. #define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  165. -
  166. +#define MIN_WIDTH 16
  167. +#define MIN_HEIGHT 16
  168. #define MAX_WIDTH 2592
  169. #define MAX_HEIGHT 1944
  170. #define MIN_BUFFER_SIZE (80*1024)
  171. @@ -53,13 +54,43 @@ int bcm2835_v4l2_debug;
  172. module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  173. MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  174. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  175. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  176. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  177. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  178. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  179. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  180. +
  181. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  182. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  183. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  184. + * It's happier if we just don't say anything at all, when it then
  185. + * sets up a load of defaults that it thinks might work.
  186. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  187. + * our function table list (actually switch to an alternate set, but same
  188. + * result).
  189. + */
  190. +int gst_v4l2src_is_broken = 0;
  191. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  192. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  193. +
  194. static struct bm2835_mmal_dev *gdev; /* global device data */
  195. +#define FPS_MIN 1
  196. +#define FPS_MAX 90
  197. +
  198. +/* timeperframe: min/max and default */
  199. +static const struct v4l2_fract
  200. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  201. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  202. + tpf_default = {.numerator = 1000, .denominator = 30000};
  203. +
  204. /* video formats */
  205. static struct mmal_fmt formats[] = {
  206. {
  207. .name = "4:2:0, packed YUV",
  208. .fourcc = V4L2_PIX_FMT_YUV420,
  209. + .flags = 0,
  210. .mmal = MMAL_ENCODING_I420,
  211. .depth = 12,
  212. .mmal_component = MMAL_COMPONENT_CAMERA,
  213. @@ -67,13 +98,15 @@ static struct mmal_fmt formats[] = {
  214. {
  215. .name = "4:2:2, packed, YUYV",
  216. .fourcc = V4L2_PIX_FMT_YUYV,
  217. + .flags = 0,
  218. .mmal = MMAL_ENCODING_YUYV,
  219. .depth = 16,
  220. .mmal_component = MMAL_COMPONENT_CAMERA,
  221. },
  222. {
  223. - .name = "RGB24 (BE)",
  224. - .fourcc = V4L2_PIX_FMT_BGR24,
  225. + .name = "RGB24 (LE)",
  226. + .fourcc = V4L2_PIX_FMT_RGB24,
  227. + .flags = 0,
  228. .mmal = MMAL_ENCODING_BGR24,
  229. .depth = 24,
  230. .mmal_component = MMAL_COMPONENT_CAMERA,
  231. @@ -81,6 +114,7 @@ static struct mmal_fmt formats[] = {
  232. {
  233. .name = "JPEG",
  234. .fourcc = V4L2_PIX_FMT_JPEG,
  235. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  236. .mmal = MMAL_ENCODING_JPEG,
  237. .depth = 8,
  238. .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  239. @@ -88,10 +122,83 @@ static struct mmal_fmt formats[] = {
  240. {
  241. .name = "H264",
  242. .fourcc = V4L2_PIX_FMT_H264,
  243. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  244. .mmal = MMAL_ENCODING_H264,
  245. .depth = 8,
  246. .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  247. - }
  248. + },
  249. + {
  250. + .name = "MJPEG",
  251. + .fourcc = V4L2_PIX_FMT_MJPEG,
  252. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  253. + .mmal = MMAL_ENCODING_MJPEG,
  254. + .depth = 8,
  255. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  256. + },
  257. + {
  258. + .name = "4:2:2, packed, YVYU",
  259. + .fourcc = V4L2_PIX_FMT_YVYU,
  260. + .flags = 0,
  261. + .mmal = MMAL_ENCODING_YVYU,
  262. + .depth = 16,
  263. + .mmal_component = MMAL_COMPONENT_CAMERA,
  264. + },
  265. + {
  266. + .name = "4:2:2, packed, VYUY",
  267. + .fourcc = V4L2_PIX_FMT_VYUY,
  268. + .flags = 0,
  269. + .mmal = MMAL_ENCODING_VYUY,
  270. + .depth = 16,
  271. + .mmal_component = MMAL_COMPONENT_CAMERA,
  272. + },
  273. + {
  274. + .name = "4:2:2, packed, UYVY",
  275. + .fourcc = V4L2_PIX_FMT_UYVY,
  276. + .flags = 0,
  277. + .mmal = MMAL_ENCODING_UYVY,
  278. + .depth = 16,
  279. + .mmal_component = MMAL_COMPONENT_CAMERA,
  280. + },
  281. + {
  282. + .name = "4:2:0, packed, NV12",
  283. + .fourcc = V4L2_PIX_FMT_NV12,
  284. + .flags = 0,
  285. + .mmal = MMAL_ENCODING_NV12,
  286. + .depth = 12,
  287. + .mmal_component = MMAL_COMPONENT_CAMERA,
  288. + },
  289. + {
  290. + .name = "RGB24 (BE)",
  291. + .fourcc = V4L2_PIX_FMT_BGR24,
  292. + .flags = 0,
  293. + .mmal = MMAL_ENCODING_RGB24,
  294. + .depth = 24,
  295. + .mmal_component = MMAL_COMPONENT_CAMERA,
  296. + },
  297. + {
  298. + .name = "4:2:0, packed YVU",
  299. + .fourcc = V4L2_PIX_FMT_YVU420,
  300. + .flags = 0,
  301. + .mmal = MMAL_ENCODING_YV12,
  302. + .depth = 12,
  303. + .mmal_component = MMAL_COMPONENT_CAMERA,
  304. + },
  305. + {
  306. + .name = "4:2:0, packed, NV21",
  307. + .fourcc = V4L2_PIX_FMT_NV21,
  308. + .flags = 0,
  309. + .mmal = MMAL_ENCODING_NV21,
  310. + .depth = 12,
  311. + .mmal_component = MMAL_COMPONENT_CAMERA,
  312. + },
  313. + {
  314. + .name = "RGB32 (BE)",
  315. + .fourcc = V4L2_PIX_FMT_BGR32,
  316. + .flags = 0,
  317. + .mmal = MMAL_ENCODING_BGRA,
  318. + .depth = 32,
  319. + .mmal_component = MMAL_COMPONENT_CAMERA,
  320. + },
  321. };
  322. static struct mmal_fmt *get_format(struct v4l2_format *f)
  323. @@ -229,7 +336,8 @@ static void buffer_cb(struct vchiq_mmal_
  324. }
  325. } else {
  326. if (dev->capture.frame_count) {
  327. - if (dev->capture.vc_start_timestamp != -1) {
  328. + if (dev->capture.vc_start_timestamp != -1 &&
  329. + pts != 0) {
  330. s64 runtime_us = pts -
  331. dev->capture.vc_start_timestamp;
  332. u32 div = 0;
  333. @@ -250,7 +358,7 @@ static void buffer_cb(struct vchiq_mmal_
  334. USEC_PER_SEC;
  335. }
  336. v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  337. - "Convert start time %d.%06d and %llu"
  338. + "Convert start time %d.%06d and %llu "
  339. "with offset %llu to %d.%06d\n",
  340. (int)dev->capture.kernel_start_ts.
  341. tv_sec,
  342. @@ -425,7 +533,15 @@ static int start_streaming(struct vb2_qu
  343. vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  344. if (ret) {
  345. v4l2_err(&dev->v4l2_dev,
  346. - "Failed to enable capture port - error %d\n", ret);
  347. + "Failed to enable capture port - error %d. "
  348. + "Disabling camera port again\n", ret);
  349. +
  350. + vchiq_mmal_port_disable(dev->instance,
  351. + dev->capture.camera_port);
  352. + if (disable_camera(dev) < 0) {
  353. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  354. + return -EINVAL;
  355. + }
  356. return -1;
  357. }
  358. @@ -439,7 +555,7 @@ static int start_streaming(struct vb2_qu
  359. }
  360. /* abort streaming and wait for last buffer */
  361. -static int stop_streaming(struct vb2_queue *vq)
  362. +static void stop_streaming(struct vb2_queue *vq)
  363. {
  364. int ret;
  365. struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  366. @@ -451,8 +567,11 @@ static int stop_streaming(struct vb2_que
  367. dev->capture.frame_count = 0;
  368. /* ensure a format has actually been set */
  369. - if (dev->capture.port == NULL)
  370. - return -EINVAL;
  371. + if (dev->capture.port == NULL) {
  372. + v4l2_err(&dev->v4l2_dev,
  373. + "no capture port - stream not started?\n");
  374. + return;
  375. + }
  376. v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  377. @@ -483,12 +602,8 @@ static int stop_streaming(struct vb2_que
  378. ret);
  379. }
  380. - if (disable_camera(dev) < 0) {
  381. - v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  382. - return -EINVAL;
  383. - }
  384. -
  385. - return ret;
  386. + if (disable_camera(dev) < 0)
  387. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
  388. }
  389. static void bm2835_mmal_lock(struct vb2_queue *vq)
  390. @@ -530,6 +645,7 @@ static int vidioc_enum_fmt_vid_overlay(s
  391. strlcpy(f->description, fmt->name, sizeof(f->description));
  392. f->pixelformat = fmt->fourcc;
  393. + f->flags = fmt->flags;
  394. return 0;
  395. }
  396. @@ -647,10 +763,18 @@ static int vidioc_g_fbuf(struct file *fi
  397. {
  398. /* The video overlay must stay within the framebuffer and can't be
  399. positioned independently. */
  400. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  401. + struct vchiq_mmal_port *preview_port =
  402. + &dev->component[MMAL_COMPONENT_CAMERA]->
  403. + output[MMAL_CAMERA_PORT_PREVIEW];
  404. a->flags = V4L2_FBUF_FLAG_OVERLAY;
  405. -
  406. - /* todo: v4l2_framebuffer still needs more info filling in
  407. - * in order to pass the v4l2-compliance test. */
  408. + a->fmt.width = preview_port->es.video.width;
  409. + a->fmt.height = preview_port->es.video.height;
  410. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  411. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  412. + a->fmt.sizeimage = (preview_port->es.video.width *
  413. + preview_port->es.video.height * 3)>>1;
  414. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  415. return 0;
  416. }
  417. @@ -717,6 +841,8 @@ static int vidioc_enum_fmt_vid_cap(struc
  418. strlcpy(f->description, fmt->name, sizeof(f->description));
  419. f->pixelformat = fmt->fourcc;
  420. + f->flags = fmt->flags;
  421. +
  422. return 0;
  423. }
  424. @@ -729,20 +855,13 @@ static int vidioc_g_fmt_vid_cap(struct f
  425. f->fmt.pix.height = dev->capture.height;
  426. f->fmt.pix.field = V4L2_FIELD_NONE;
  427. f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  428. - f->fmt.pix.bytesperline =
  429. - (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  430. - f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  431. - if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  432. - && f->fmt.pix.sizeimage < (100 << 10)) {
  433. - /* Need a minimum size for JPEG to account for EXIF. */
  434. - f->fmt.pix.sizeimage = (100 << 10);
  435. - }
  436. + f->fmt.pix.bytesperline = dev->capture.stride;
  437. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  438. - if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  439. - dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  440. - f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  441. - else
  442. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  443. f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  444. + else
  445. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  446. f->fmt.pix.priv = 0;
  447. v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  448. @@ -766,21 +885,35 @@ static int vidioc_try_fmt_vid_cap(struct
  449. }
  450. f->fmt.pix.field = V4L2_FIELD_NONE;
  451. - /* image must be a multiple of 32 pixels wide and 16 lines high */
  452. - v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  453. - &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  454. - f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  455. - f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  456. - if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  457. +
  458. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  459. + "Clipping/aligning %dx%d format %08X\n",
  460. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  461. +
  462. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  463. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  464. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  465. +
  466. + /* Image buffer has to be padded to allow for alignment, even though
  467. + * we then remove that padding before delivering the buffer.
  468. + */
  469. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  470. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  471. +
  472. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  473. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  474. f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  475. - if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  476. - mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  477. - f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  478. - else
  479. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  480. f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  481. + else
  482. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  483. f->fmt.pix.priv = 0;
  484. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  485. + "Now %dx%d format %08X\n",
  486. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  487. +
  488. v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  489. __func__);
  490. return 0;
  491. @@ -818,8 +951,8 @@ static int mmal_setup_components(struct
  492. switch (mfmt->mmal_component) {
  493. case MMAL_COMPONENT_CAMERA:
  494. /* Make a further decision on port based on resolution */
  495. - if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  496. - && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  497. + if (f->fmt.pix.width <= max_video_width
  498. + && f->fmt.pix.height <= max_video_height)
  499. camera_port = port =
  500. &dev->component[MMAL_COMPONENT_CAMERA]->
  501. output[MMAL_CAMERA_PORT_VIDEO];
  502. @@ -861,8 +994,9 @@ static int mmal_setup_components(struct
  503. camera_port->es.video.crop.y = 0;
  504. camera_port->es.video.crop.width = f->fmt.pix.width;
  505. camera_port->es.video.crop.height = f->fmt.pix.height;
  506. - camera_port->es.video.frame_rate.num = 30;
  507. + camera_port->es.video.frame_rate.num = 0;
  508. camera_port->es.video.frame_rate.den = 1;
  509. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  510. ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  511. @@ -896,8 +1030,10 @@ static int mmal_setup_components(struct
  512. preview_port->es.video.crop.y = 0;
  513. preview_port->es.video.crop.width = f->fmt.pix.width;
  514. preview_port->es.video.crop.height = f->fmt.pix.height;
  515. - preview_port->es.video.frame_rate.num = 30;
  516. - preview_port->es.video.frame_rate.den = 1;
  517. + preview_port->es.video.frame_rate.num =
  518. + dev->capture.timeperframe.denominator;
  519. + preview_port->es.video.frame_rate.den =
  520. + dev->capture.timeperframe.numerator;
  521. ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  522. if (overlay_enabled) {
  523. ret = vchiq_mmal_port_connect_tunnel(
  524. @@ -913,7 +1049,9 @@ static int mmal_setup_components(struct
  525. if (ret) {
  526. v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  527. - "%s failed to set format\n", __func__);
  528. + "%s failed to set format %dx%d %08X\n", __func__,
  529. + f->fmt.pix.width, f->fmt.pix.height,
  530. + f->fmt.pix.pixelformat);
  531. /* ensure capture is not going to be tried */
  532. dev->capture.port = NULL;
  533. } else {
  534. @@ -927,69 +1065,91 @@ static int mmal_setup_components(struct
  535. camera_port->current_buffer.num =
  536. camera_port->recommended_buffer.num;
  537. - port->format.encoding = mfmt->mmal;
  538. - port->format.encoding_variant = 0;
  539. - /* Set any encoding specific parameters */
  540. - switch (mfmt->mmal_component) {
  541. - case MMAL_COMPONENT_VIDEO_ENCODE:
  542. - port->format.bitrate =
  543. - dev->capture.encode_bitrate;
  544. - break;
  545. - case MMAL_COMPONENT_IMAGE_ENCODE:
  546. - /* Could set EXIF parameters here */
  547. - break;
  548. - default:
  549. - break;
  550. - }
  551. - ret = vchiq_mmal_port_set_format(dev->instance, port);
  552. -
  553. + ret =
  554. + vchiq_mmal_port_connect_tunnel(
  555. + dev->instance,
  556. + camera_port,
  557. + &encode_component->input[0]);
  558. if (ret) {
  559. - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  560. - "%s failed to set format\n", __func__);
  561. + v4l2_dbg(1, bcm2835_v4l2_debug,
  562. + &dev->v4l2_dev,
  563. + "%s failed to create connection\n",
  564. + __func__);
  565. + /* ensure capture is not going to be tried */
  566. + dev->capture.port = NULL;
  567. } else {
  568. + port->es.video.width = f->fmt.pix.width;
  569. + port->es.video.height = f->fmt.pix.height;
  570. + port->es.video.crop.x = 0;
  571. + port->es.video.crop.y = 0;
  572. + port->es.video.crop.width = f->fmt.pix.width;
  573. + port->es.video.crop.height = f->fmt.pix.height;
  574. + port->es.video.frame_rate.num =
  575. + dev->capture.timeperframe.denominator;
  576. + port->es.video.frame_rate.den =
  577. + dev->capture.timeperframe.numerator;
  578. +
  579. + port->format.encoding = mfmt->mmal;
  580. + port->format.encoding_variant = 0;
  581. + /* Set any encoding specific parameters */
  582. + switch (mfmt->mmal_component) {
  583. + case MMAL_COMPONENT_VIDEO_ENCODE:
  584. + port->format.bitrate =
  585. + dev->capture.encode_bitrate;
  586. + break;
  587. + case MMAL_COMPONENT_IMAGE_ENCODE:
  588. + /* Could set EXIF parameters here */
  589. + break;
  590. + default:
  591. + break;
  592. + }
  593. + ret = vchiq_mmal_port_set_format(dev->instance,
  594. + port);
  595. + if (ret)
  596. + v4l2_dbg(1, bcm2835_v4l2_debug,
  597. + &dev->v4l2_dev,
  598. + "%s failed to set format %dx%d fmt %08X\n",
  599. + __func__,
  600. + f->fmt.pix.width,
  601. + f->fmt.pix.height,
  602. + f->fmt.pix.pixelformat
  603. + );
  604. + }
  605. +
  606. + if (!ret) {
  607. ret = vchiq_mmal_component_enable(
  608. dev->instance,
  609. encode_component);
  610. if (ret) {
  611. v4l2_dbg(1, bcm2835_v4l2_debug,
  612. - &dev->v4l2_dev,
  613. - "%s Failed to enable encode components\n",
  614. - __func__);
  615. - } else {
  616. - /* configure buffering */
  617. - port->current_buffer.num = 1;
  618. - port->current_buffer.size =
  619. - f->fmt.pix.sizeimage;
  620. - if (port->format.encoding ==
  621. - MMAL_ENCODING_JPEG) {
  622. - v4l2_dbg(1, bcm2835_v4l2_debug,
  623. - &dev->v4l2_dev,
  624. - "JPEG - fiddle buffer size\n");
  625. - port->current_buffer.size =
  626. - (f->fmt.pix.sizeimage <
  627. - (100 << 10))
  628. - ? (100 << 10) : f->fmt.pix.
  629. - sizeimage;
  630. - }
  631. + &dev->v4l2_dev,
  632. + "%s Failed to enable encode components\n",
  633. + __func__);
  634. + }
  635. + }
  636. + if (!ret) {
  637. + /* configure buffering */
  638. + port->current_buffer.num = 1;
  639. + port->current_buffer.size =
  640. + f->fmt.pix.sizeimage;
  641. + if (port->format.encoding ==
  642. + MMAL_ENCODING_JPEG) {
  643. v4l2_dbg(1, bcm2835_v4l2_debug,
  644. - &dev->v4l2_dev,
  645. - "vid_cap - current_buffer.size being set to %d\n",
  646. - f->fmt.pix.sizeimage);
  647. - port->current_buffer.alignment = 0;
  648. - ret =
  649. - vchiq_mmal_port_connect_tunnel(
  650. - dev->instance,
  651. - camera_port,
  652. - &encode_component->input[0]);
  653. - if (ret) {
  654. - v4l2_dbg(1, bcm2835_v4l2_debug,
  655. - &dev->v4l2_dev,
  656. - "%s failed to create connection\n",
  657. - __func__);
  658. - /* ensure capture is not going to be tried */
  659. - dev->capture.port = NULL;
  660. - }
  661. + &dev->v4l2_dev,
  662. + "JPG - buf size now %d was %d\n",
  663. + f->fmt.pix.sizeimage,
  664. + port->current_buffer.size);
  665. + port->current_buffer.size =
  666. + (f->fmt.pix.sizeimage <
  667. + (100 << 10))
  668. + ? (100 << 10) : f->fmt.pix.
  669. + sizeimage;
  670. }
  671. + v4l2_dbg(1, bcm2835_v4l2_debug,
  672. + &dev->v4l2_dev,
  673. + "vid_cap - cur_buf.size set to %d\n",
  674. + f->fmt.pix.sizeimage);
  675. + port->current_buffer.alignment = 0;
  676. }
  677. } else {
  678. /* configure buffering */
  679. @@ -1001,13 +1161,20 @@ static int mmal_setup_components(struct
  680. if (!ret) {
  681. dev->capture.fmt = mfmt;
  682. dev->capture.stride = f->fmt.pix.bytesperline;
  683. - dev->capture.width = port->es.video.crop.width;
  684. - dev->capture.height = port->es.video.crop.height;
  685. + dev->capture.width = camera_port->es.video.crop.width;
  686. + dev->capture.height = camera_port->es.video.crop.height;
  687. + dev->capture.buffersize = port->current_buffer.size;
  688. /* select port for capture */
  689. dev->capture.port = port;
  690. dev->capture.camera_port = camera_port;
  691. dev->capture.encode_component = encode_component;
  692. + v4l2_dbg(1, bcm2835_v4l2_debug,
  693. + &dev->v4l2_dev,
  694. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  695. + port->format.encoding,
  696. + dev->capture.width, dev->capture.height,
  697. + dev->capture.stride, dev->capture.buffersize);
  698. }
  699. }
  700. @@ -1048,14 +1215,115 @@ static int vidioc_s_fmt_vid_cap(struct f
  701. }
  702. ret = mmal_setup_components(dev, f);
  703. - if (ret != 0)
  704. + if (ret != 0) {
  705. v4l2_err(&dev->v4l2_dev,
  706. "%s: failed to setup mmal components: %d\n",
  707. __func__, ret);
  708. + ret = -EINVAL;
  709. + }
  710. return ret;
  711. }
  712. +int vidioc_enum_framesizes(struct file *file, void *fh,
  713. + struct v4l2_frmsizeenum *fsize)
  714. +{
  715. + static const struct v4l2_frmsize_stepwise sizes = {
  716. + MIN_WIDTH, MAX_WIDTH, 2,
  717. + MIN_HEIGHT, MAX_HEIGHT, 2
  718. + };
  719. + int i;
  720. +
  721. + if (fsize->index)
  722. + return -EINVAL;
  723. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  724. + if (formats[i].fourcc == fsize->pixel_format)
  725. + break;
  726. + if (i == ARRAY_SIZE(formats))
  727. + return -EINVAL;
  728. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  729. + fsize->stepwise = sizes;
  730. + return 0;
  731. +}
  732. +
  733. +/* timeperframe is arbitrary and continous */
  734. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  735. + struct v4l2_frmivalenum *fival)
  736. +{
  737. + int i;
  738. +
  739. + if (fival->index)
  740. + return -EINVAL;
  741. +
  742. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  743. + if (formats[i].fourcc == fival->pixel_format)
  744. + break;
  745. + if (i == ARRAY_SIZE(formats))
  746. + return -EINVAL;
  747. +
  748. + /* regarding width & height - we support any within range */
  749. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  750. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  751. + return -EINVAL;
  752. +
  753. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  754. +
  755. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  756. + fival->stepwise.min = tpf_min;
  757. + fival->stepwise.max = tpf_max;
  758. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  759. +
  760. + return 0;
  761. +}
  762. +
  763. +static int vidioc_g_parm(struct file *file, void *priv,
  764. + struct v4l2_streamparm *parm)
  765. +{
  766. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  767. +
  768. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  769. + return -EINVAL;
  770. +
  771. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  772. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  773. + parm->parm.capture.readbuffers = 1;
  774. + return 0;
  775. +}
  776. +
  777. +#define FRACT_CMP(a, OP, b) \
  778. + ((u64)(a).numerator * (b).denominator OP \
  779. + (u64)(b).numerator * (a).denominator)
  780. +
  781. +static int vidioc_s_parm(struct file *file, void *priv,
  782. + struct v4l2_streamparm *parm)
  783. +{
  784. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  785. + struct v4l2_fract tpf;
  786. + struct mmal_parameter_rational fps_param;
  787. +
  788. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  789. + return -EINVAL;
  790. +
  791. + tpf = parm->parm.capture.timeperframe;
  792. +
  793. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  794. + tpf = tpf.denominator ? tpf : tpf_default;
  795. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  796. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  797. +
  798. + dev->capture.timeperframe = tpf;
  799. + parm->parm.capture.timeperframe = tpf;
  800. + parm->parm.capture.readbuffers = 1;
  801. +
  802. + fps_param.num = 0; /* Select variable fps, and then use
  803. + * FPS_RANGE to select the actual limits.
  804. + */
  805. + fps_param.den = 1;
  806. + set_framerate_params(dev);
  807. +
  808. + return 0;
  809. +}
  810. +
  811. static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  812. /* overlay */
  813. .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  814. @@ -1084,6 +1352,51 @@ static const struct v4l2_ioctl_ops camer
  815. .vidioc_querybuf = vb2_ioctl_querybuf,
  816. .vidioc_qbuf = vb2_ioctl_qbuf,
  817. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  818. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  819. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  820. + .vidioc_g_parm = vidioc_g_parm,
  821. + .vidioc_s_parm = vidioc_s_parm,
  822. + .vidioc_streamon = vb2_ioctl_streamon,
  823. + .vidioc_streamoff = vb2_ioctl_streamoff,
  824. +
  825. + .vidioc_log_status = v4l2_ctrl_log_status,
  826. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  827. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  828. +};
  829. +
  830. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  831. + /* overlay */
  832. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  833. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  834. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  835. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  836. + .vidioc_overlay = vidioc_overlay,
  837. + .vidioc_g_fbuf = vidioc_g_fbuf,
  838. +
  839. + /* inputs */
  840. + .vidioc_enum_input = vidioc_enum_input,
  841. + .vidioc_g_input = vidioc_g_input,
  842. + .vidioc_s_input = vidioc_s_input,
  843. +
  844. + /* capture */
  845. + .vidioc_querycap = vidioc_querycap,
  846. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  847. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  848. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  849. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  850. +
  851. + /* buffer management */
  852. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  853. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  854. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  855. + .vidioc_querybuf = vb2_ioctl_querybuf,
  856. + .vidioc_qbuf = vb2_ioctl_qbuf,
  857. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  858. + /* Remove this function ptr to fix gstreamer bug
  859. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  860. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  861. + .vidioc_g_parm = vidioc_g_parm,
  862. + .vidioc_s_parm = vidioc_s_parm,
  863. .vidioc_streamon = vb2_ioctl_streamon,
  864. .vidioc_streamoff = vb2_ioctl_streamoff,
  865. @@ -1122,8 +1435,10 @@ static int set_camera_parameters(struct
  866. .max_stills_h = MAX_HEIGHT,
  867. .stills_yuv422 = 1,
  868. .one_shot_stills = 1,
  869. - .max_preview_video_w = 1920,
  870. - .max_preview_video_h = 1088,
  871. + .max_preview_video_w = (max_video_width > 1920) ?
  872. + max_video_width : 1920,
  873. + .max_preview_video_h = (max_video_height > 1088) ?
  874. + max_video_height : 1088,
  875. .num_preview_video_frames = 3,
  876. .stills_capture_circular_buffer_height = 0,
  877. .fast_preview_resume = 0,
  878. @@ -1141,6 +1456,7 @@ static int __init mmal_init(struct bm283
  879. {
  880. int ret;
  881. struct mmal_es_format *format;
  882. + u32 bool_true = 1;
  883. ret = vchiq_mmal_init(&dev->instance);
  884. if (ret < 0)
  885. @@ -1176,8 +1492,8 @@ static int __init mmal_init(struct bm283
  886. format->es->video.crop.y = 0;
  887. format->es->video.crop.width = 1024;
  888. format->es->video.crop.height = 768;
  889. - format->es->video.frame_rate.num = PREVIEW_FRAME_RATE_NUM;
  890. - format->es->video.frame_rate.den = PREVIEW_FRAME_RATE_DEN;
  891. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  892. + format->es->video.frame_rate.den = 1;
  893. format =
  894. &dev->component[MMAL_COMPONENT_CAMERA]->
  895. @@ -1192,8 +1508,14 @@ static int __init mmal_init(struct bm283
  896. format->es->video.crop.y = 0;
  897. format->es->video.crop.width = 1024;
  898. format->es->video.crop.height = 768;
  899. - format->es->video.frame_rate.num = PREVIEW_FRAME_RATE_NUM;
  900. - format->es->video.frame_rate.den = PREVIEW_FRAME_RATE_DEN;
  901. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  902. + format->es->video.frame_rate.den = 1;
  903. +
  904. + vchiq_mmal_port_parameter_set(dev->instance,
  905. + &dev->component[MMAL_COMPONENT_CAMERA]->
  906. + output[MMAL_CAMERA_PORT_VIDEO],
  907. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  908. + &bool_true, sizeof(bool_true));
  909. format =
  910. &dev->component[MMAL_COMPONENT_CAMERA]->
  911. @@ -1207,13 +1529,22 @@ static int __init mmal_init(struct bm283
  912. format->es->video.crop.y = 0;
  913. format->es->video.crop.width = 2592;
  914. format->es->video.crop.height = 1944;
  915. - format->es->video.frame_rate.num = 30;
  916. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  917. format->es->video.frame_rate.den = 1;
  918. dev->capture.width = format->es->video.width;
  919. dev->capture.height = format->es->video.height;
  920. dev->capture.fmt = &formats[0];
  921. dev->capture.encode_component = NULL;
  922. + dev->capture.timeperframe = tpf_default;
  923. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  924. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  925. +
  926. + vchiq_mmal_port_parameter_set(dev->instance,
  927. + &dev->component[MMAL_COMPONENT_CAMERA]->
  928. + output[MMAL_CAMERA_PORT_CAPTURE],
  929. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  930. + &bool_true, sizeof(bool_true));
  931. /* get the preview component ready */
  932. ret = vchiq_mmal_component_init(
  933. @@ -1260,6 +1591,14 @@ static int __init mmal_init(struct bm283
  934. }
  935. {
  936. + struct vchiq_mmal_port *encoder_port =
  937. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  938. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  939. + ret = vchiq_mmal_port_set_format(dev->instance,
  940. + encoder_port);
  941. + }
  942. +
  943. + {
  944. unsigned int enable = 1;
  945. vchiq_mmal_port_parameter_set(
  946. dev->instance,
  947. @@ -1312,6 +1651,11 @@ static int __init bm2835_mmal_init_devic
  948. int ret;
  949. *vfd = vdev_template;
  950. + if (gst_v4l2src_is_broken) {
  951. + v4l2_info(&dev->v4l2_dev,
  952. + "Work-around for gstreamer issue is active.\n");
  953. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  954. + }
  955. vfd->v4l2_dev = &dev->v4l2_dev;
  956. @@ -1326,8 +1670,9 @@ static int __init bm2835_mmal_init_devic
  957. if (ret < 0)
  958. return ret;
  959. - v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  960. - video_device_node_name(vfd));
  961. + v4l2_info(vfd->v4l2_dev,
  962. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  963. + video_device_node_name(vfd), max_video_width, max_video_height);
  964. return 0;
  965. }
  966. @@ -1335,9 +1680,9 @@ static int __init bm2835_mmal_init_devic
  967. static struct v4l2_format default_v4l2_format = {
  968. .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  969. .fmt.pix.width = 1024,
  970. - .fmt.pix.bytesperline = 1024 * 3 / 2,
  971. + .fmt.pix.bytesperline = 1024,
  972. .fmt.pix.height = 768,
  973. - .fmt.pix.sizeimage = 1<<18,
  974. + .fmt.pix.sizeimage = 1024*768,
  975. };
  976. static int __init bm2835_mmal_init(void)
  977. @@ -1400,6 +1745,9 @@ static int __init bm2835_mmal_init(void)
  978. if (ret < 0)
  979. goto unreg_dev;
  980. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  981. + * format, but currently the APIs don't join up.
  982. + */
  983. ret = mmal_setup_components(dev, &default_v4l2_format);
  984. if (ret < 0) {
  985. v4l2_err(&dev->v4l2_dev,
  986. --- a/drivers/media/platform/bcm2835/bcm2835-camera.h
  987. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
  988. @@ -15,7 +15,7 @@
  989. * core driver device
  990. */
  991. -#define V4L2_CTRL_COUNT 18 /* number of v4l controls */
  992. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  993. enum {
  994. MMAL_COMPONENT_CAMERA = 0,
  995. @@ -32,9 +32,6 @@ enum {
  996. MMAL_CAMERA_PORT_COUNT
  997. };
  998. -#define PREVIEW_FRAME_RATE_NUM 30
  999. -#define PREVIEW_FRAME_RATE_DEN 1
  1000. -
  1001. #define PREVIEW_LAYER 2
  1002. extern int bcm2835_v4l2_debug;
  1003. @@ -48,9 +45,19 @@ struct bm2835_mmal_dev {
  1004. /* controls */
  1005. struct v4l2_ctrl_handler ctrl_handler;
  1006. struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  1007. + enum v4l2_scene_mode scene_mode;
  1008. struct mmal_colourfx colourfx;
  1009. int hflip;
  1010. int vflip;
  1011. + int red_gain;
  1012. + int blue_gain;
  1013. + enum mmal_parameter_exposuremode exposure_mode_user;
  1014. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  1015. + /* active exposure mode may differ if selected via a scene mode */
  1016. + enum mmal_parameter_exposuremode exposure_mode_active;
  1017. + enum mmal_parameter_exposuremeteringmode metering_mode;
  1018. + unsigned int manual_shutter_speed;
  1019. + bool exp_auto_priority;
  1020. /* allocated mmal instance and components */
  1021. struct vchiq_mmal_instance *instance;
  1022. @@ -63,12 +70,18 @@ struct bm2835_mmal_dev {
  1023. unsigned int width; /* width */
  1024. unsigned int height; /* height */
  1025. unsigned int stride; /* stride */
  1026. + unsigned int buffersize; /* buffer size with padding */
  1027. struct mmal_fmt *fmt;
  1028. + struct v4l2_fract timeperframe;
  1029. /* H264 encode bitrate */
  1030. int encode_bitrate;
  1031. /* H264 bitrate mode. CBR/VBR */
  1032. int encode_bitrate_mode;
  1033. + /* H264 profile */
  1034. + enum v4l2_mpeg_video_h264_profile enc_profile;
  1035. + /* H264 level */
  1036. + enum v4l2_mpeg_video_h264_level enc_level;
  1037. /* JPEG Q-factor */
  1038. int q_factor;
  1039. @@ -98,7 +111,7 @@ int bm2835_mmal_init_controls(
  1040. struct v4l2_ctrl_handler *hdl);
  1041. int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  1042. -
  1043. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  1044. /* Debug helpers */
  1045. --- a/drivers/media/platform/bcm2835/controls.c
  1046. +++ b/drivers/media/platform/bcm2835/controls.c
  1047. @@ -30,11 +30,23 @@
  1048. #include "mmal-parameters.h"
  1049. #include "bcm2835-camera.h"
  1050. -/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -24 to +24.
  1051. - * These are in 1/6th increments so the effective range is -4.0EV to +4.0EV.
  1052. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  1053. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  1054. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  1055. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  1056. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  1057. + * -4 to +4
  1058. */
  1059. static const s64 ev_bias_qmenu[] = {
  1060. - -24, -21, -18, -15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15, 18, 21, 24
  1061. + -4000, -3667, -3333,
  1062. + -3000, -2667, -2333,
  1063. + -2000, -1667, -1333,
  1064. + -1000, -667, -333,
  1065. + 0, 333, 667,
  1066. + 1000, 1333, 1667,
  1067. + 2000, 2333, 2667,
  1068. + 3000, 3333, 3667,
  1069. + 4000
  1070. };
  1071. /* Supported ISO values
  1072. @@ -44,13 +56,19 @@ static const s64 iso_qmenu[] = {
  1073. 0, 100, 200, 400, 800,
  1074. };
  1075. +static const s64 mains_freq_qmenu[] = {
  1076. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  1077. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  1078. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  1079. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  1080. +};
  1081. +
  1082. /* Supported video encode modes */
  1083. static const s64 bitrate_mode_qmenu[] = {
  1084. (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  1085. (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  1086. };
  1087. -
  1088. enum bm2835_mmal_ctrl_type {
  1089. MMAL_CONTROL_TYPE_STD,
  1090. MMAL_CONTROL_TYPE_STD_MENU,
  1091. @@ -77,6 +95,7 @@ struct bm2835_mmal_v4l2_ctrl {
  1092. const s64 *imenu; /* integer menu array */
  1093. u32 mmal_id; /* mmal parameter id */
  1094. bm2835_mmal_v4l2_ctrl_cb *setter;
  1095. + bool ignore_errors;
  1096. };
  1097. struct v4l2_to_mmal_effects_setting {
  1098. @@ -126,6 +145,25 @@ static const struct v4l2_to_mmal_effects
  1099. 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  1100. };
  1101. +struct v4l2_mmal_scene_config {
  1102. + enum v4l2_scene_mode v4l2_scene;
  1103. + enum mmal_parameter_exposuremode exposure_mode;
  1104. + enum mmal_parameter_exposuremeteringmode metering_mode;
  1105. +};
  1106. +
  1107. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  1108. + /* V4L2_SCENE_MODE_NONE automatically added */
  1109. + {
  1110. + V4L2_SCENE_MODE_NIGHT,
  1111. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  1112. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  1113. + },
  1114. + {
  1115. + V4L2_SCENE_MODE_SPORTS,
  1116. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  1117. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  1118. + },
  1119. +};
  1120. /* control handlers*/
  1121. @@ -133,10 +171,7 @@ static int ctrl_set_rational(struct bm28
  1122. struct v4l2_ctrl *ctrl,
  1123. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1124. {
  1125. - struct {
  1126. - s32 num; /**< Numerator */
  1127. - s32 den; /**< Denominator */
  1128. - } rational_value;
  1129. + struct mmal_parameter_rational rational_value;
  1130. struct vchiq_mmal_port *control;
  1131. control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1132. @@ -166,6 +201,41 @@ static int ctrl_set_value(struct bm2835_
  1133. &u32_value, sizeof(u32_value));
  1134. }
  1135. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  1136. + struct v4l2_ctrl *ctrl,
  1137. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1138. +{
  1139. + u32 u32_value;
  1140. + struct vchiq_mmal_port *control;
  1141. +
  1142. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  1143. + return 1;
  1144. +
  1145. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1146. +
  1147. + u32_value = mmal_ctrl->imenu[ctrl->val];
  1148. +
  1149. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  1150. + mmal_ctrl->mmal_id,
  1151. + &u32_value, sizeof(u32_value));
  1152. +}
  1153. +
  1154. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  1155. + struct v4l2_ctrl *ctrl,
  1156. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1157. +{
  1158. + s32 s32_value;
  1159. + struct vchiq_mmal_port *control;
  1160. +
  1161. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1162. +
  1163. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  1164. +
  1165. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  1166. + mmal_ctrl->mmal_id,
  1167. + &s32_value, sizeof(s32_value));
  1168. +}
  1169. +
  1170. static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  1171. struct v4l2_ctrl *ctrl,
  1172. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1173. @@ -245,37 +315,97 @@ static int ctrl_set_exposure(struct bm28
  1174. struct v4l2_ctrl *ctrl,
  1175. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1176. {
  1177. - u32 u32_value;
  1178. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  1179. + u32 shutter_speed = 0;
  1180. struct vchiq_mmal_port *control;
  1181. + int ret = 0;
  1182. control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1183. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  1184. + /* V4L2 is in 100usec increments.
  1185. + * MMAL is 1usec.
  1186. + */
  1187. + dev->manual_shutter_speed = ctrl->val * 100;
  1188. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  1189. + switch (ctrl->val) {
  1190. + case V4L2_EXPOSURE_AUTO:
  1191. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  1192. + break;
  1193. +
  1194. + case V4L2_EXPOSURE_MANUAL:
  1195. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  1196. + break;
  1197. + }
  1198. + dev->exposure_mode_user = exp_mode;
  1199. + dev->exposure_mode_v4l2_user = ctrl->val;
  1200. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  1201. + dev->exp_auto_priority = ctrl->val;
  1202. + }
  1203. +
  1204. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  1205. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  1206. + shutter_speed = dev->manual_shutter_speed;
  1207. +
  1208. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  1209. + control,
  1210. + MMAL_PARAMETER_SHUTTER_SPEED,
  1211. + &shutter_speed,
  1212. + sizeof(shutter_speed));
  1213. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1214. + control,
  1215. + MMAL_PARAMETER_EXPOSURE_MODE,
  1216. + &exp_mode,
  1217. + sizeof(u32));
  1218. + dev->exposure_mode_active = exp_mode;
  1219. + }
  1220. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  1221. + * always apply irrespective of scene mode.
  1222. + */
  1223. + ret += set_framerate_params(dev);
  1224. +
  1225. + return ret;
  1226. +}
  1227. +
  1228. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  1229. + struct v4l2_ctrl *ctrl,
  1230. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1231. +{
  1232. switch (ctrl->val) {
  1233. - case V4L2_EXPOSURE_AUTO:
  1234. - u32_value = MMAL_PARAM_EXPOSUREMODE_AUTO;
  1235. + case V4L2_EXPOSURE_METERING_AVERAGE:
  1236. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  1237. break;
  1238. - case V4L2_EXPOSURE_MANUAL:
  1239. - u32_value = MMAL_PARAM_EXPOSUREMODE_OFF;
  1240. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  1241. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  1242. break;
  1243. - case V4L2_EXPOSURE_SHUTTER_PRIORITY:
  1244. - u32_value = MMAL_PARAM_EXPOSUREMODE_SPORTS;
  1245. + case V4L2_EXPOSURE_METERING_SPOT:
  1246. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  1247. break;
  1248. - case V4L2_EXPOSURE_APERTURE_PRIORITY:
  1249. - u32_value = MMAL_PARAM_EXPOSUREMODE_NIGHT;
  1250. + /* todo matrix weighting not added to Linux API till 3.9
  1251. + case V4L2_EXPOSURE_METERING_MATRIX:
  1252. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  1253. break;
  1254. + */
  1255. }
  1256. - /* todo: what about the other ten modes there are MMAL parameters for */
  1257. - return vchiq_mmal_port_parameter_set(dev->instance, control,
  1258. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  1259. + struct vchiq_mmal_port *control;
  1260. + u32 u32_value = dev->metering_mode;
  1261. +
  1262. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1263. +
  1264. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  1265. mmal_ctrl->mmal_id,
  1266. &u32_value, sizeof(u32_value));
  1267. + } else
  1268. + return 0;
  1269. }
  1270. -static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  1271. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  1272. struct v4l2_ctrl *ctrl,
  1273. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1274. {
  1275. @@ -285,24 +415,18 @@ static int ctrl_set_metering_mode(struct
  1276. control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1277. switch (ctrl->val) {
  1278. - case V4L2_EXPOSURE_METERING_AVERAGE:
  1279. - u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  1280. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  1281. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  1282. break;
  1283. -
  1284. - case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  1285. - u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  1286. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  1287. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  1288. break;
  1289. -
  1290. - case V4L2_EXPOSURE_METERING_SPOT:
  1291. - u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  1292. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  1293. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  1294. break;
  1295. -
  1296. - /* todo matrix weighting not added to Linux API till 3.9
  1297. - case V4L2_EXPOSURE_METERING_MATRIX:
  1298. - u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  1299. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  1300. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  1301. break;
  1302. - */
  1303. -
  1304. }
  1305. return vchiq_mmal_port_parameter_set(dev->instance, control,
  1306. @@ -367,6 +491,29 @@ static int ctrl_set_awb_mode(struct bm28
  1307. &u32_value, sizeof(u32_value));
  1308. }
  1309. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  1310. + struct v4l2_ctrl *ctrl,
  1311. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1312. +{
  1313. + struct vchiq_mmal_port *control;
  1314. + struct mmal_parameter_awbgains gains;
  1315. +
  1316. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1317. +
  1318. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  1319. + dev->red_gain = ctrl->val;
  1320. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  1321. + dev->blue_gain = ctrl->val;
  1322. +
  1323. + gains.r_gain.num = dev->red_gain;
  1324. + gains.b_gain.num = dev->blue_gain;
  1325. + gains.r_gain.den = gains.b_gain.den = 1000;
  1326. +
  1327. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  1328. + mmal_ctrl->mmal_id,
  1329. + &gains, sizeof(gains));
  1330. +}
  1331. +
  1332. static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  1333. struct v4l2_ctrl *ctrl,
  1334. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1335. @@ -443,8 +590,8 @@ static int ctrl_set_colfx(struct bm2835_
  1336. &dev->colourfx, sizeof(dev->colourfx));
  1337. v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1338. - "After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  1339. - mmal_ctrl, ctrl->id, ctrl->val, ret,
  1340. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  1341. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  1342. (ret == 0 ? 0 : -EINVAL));
  1343. return (ret == 0 ? 0 : EINVAL);
  1344. }
  1345. @@ -494,7 +641,7 @@ static int ctrl_set_bitrate_mode(struct
  1346. return 0;
  1347. }
  1348. -static int ctrl_set_q_factor(struct bm2835_mmal_dev *dev,
  1349. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  1350. struct v4l2_ctrl *ctrl,
  1351. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1352. {
  1353. @@ -510,12 +657,247 @@ static int ctrl_set_q_factor(struct bm28
  1354. &u32_value, sizeof(u32_value));
  1355. }
  1356. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  1357. + struct v4l2_ctrl *ctrl,
  1358. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1359. +{
  1360. + u32 u32_value;
  1361. + struct vchiq_mmal_port *vid_enc_ctl;
  1362. +
  1363. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  1364. +
  1365. + u32_value = ctrl->val;
  1366. +
  1367. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  1368. + mmal_ctrl->mmal_id,
  1369. + &u32_value, sizeof(u32_value));
  1370. +}
  1371. +
  1372. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  1373. + struct v4l2_ctrl *ctrl,
  1374. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1375. +{
  1376. + struct mmal_parameter_video_profile param;
  1377. + int ret = 0;
  1378. +
  1379. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  1380. + switch (ctrl->val) {
  1381. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  1382. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  1383. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  1384. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  1385. + dev->capture.enc_profile = ctrl->val;
  1386. + break;
  1387. + default:
  1388. + ret = -EINVAL;
  1389. + break;
  1390. + }
  1391. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  1392. + switch (ctrl->val) {
  1393. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  1394. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  1395. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  1396. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  1397. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  1398. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  1399. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  1400. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  1401. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  1402. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  1403. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  1404. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  1405. + dev->capture.enc_level = ctrl->val;
  1406. + break;
  1407. + default:
  1408. + ret = -EINVAL;
  1409. + break;
  1410. + }
  1411. + }
  1412. +
  1413. + if (!ret) {
  1414. + switch (dev->capture.enc_profile) {
  1415. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  1416. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  1417. + break;
  1418. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  1419. + param.profile =
  1420. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  1421. + break;
  1422. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  1423. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  1424. + break;
  1425. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  1426. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  1427. + break;
  1428. + default:
  1429. + /* Should never get here */
  1430. + break;
  1431. + }
  1432. +
  1433. + switch (dev->capture.enc_level) {
  1434. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  1435. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  1436. + break;
  1437. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  1438. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  1439. + break;
  1440. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  1441. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  1442. + break;
  1443. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  1444. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  1445. + break;
  1446. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  1447. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  1448. + break;
  1449. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  1450. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  1451. + break;
  1452. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  1453. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  1454. + break;
  1455. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  1456. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  1457. + break;
  1458. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  1459. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  1460. + break;
  1461. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  1462. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  1463. + break;
  1464. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  1465. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  1466. + break;
  1467. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  1468. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  1469. + break;
  1470. + default:
  1471. + /* Should never get here */
  1472. + break;
  1473. + }
  1474. +
  1475. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  1476. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  1477. + mmal_ctrl->mmal_id,
  1478. + &param, sizeof(param));
  1479. + }
  1480. + return ret;
  1481. +}
  1482. +
  1483. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  1484. + struct v4l2_ctrl *ctrl,
  1485. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  1486. +{
  1487. + int ret = 0;
  1488. + int shutter_speed;
  1489. + struct vchiq_mmal_port *control;
  1490. +
  1491. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1492. + "scene mode selected %d, was %d\n", ctrl->val,
  1493. + dev->scene_mode);
  1494. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  1495. +
  1496. + if (ctrl->val == dev->scene_mode)
  1497. + return 0;
  1498. +
  1499. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  1500. + /* Restore all user selections */
  1501. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  1502. +
  1503. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  1504. + shutter_speed = dev->manual_shutter_speed;
  1505. + else
  1506. + shutter_speed = 0;
  1507. +
  1508. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1509. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  1510. + __func__, shutter_speed, dev->exposure_mode_user,
  1511. + dev->metering_mode);
  1512. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  1513. + control,
  1514. + MMAL_PARAMETER_SHUTTER_SPEED,
  1515. + &shutter_speed,
  1516. + sizeof(shutter_speed));
  1517. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1518. + control,
  1519. + MMAL_PARAMETER_EXPOSURE_MODE,
  1520. + &dev->exposure_mode_user,
  1521. + sizeof(u32));
  1522. + dev->exposure_mode_active = dev->exposure_mode_user;
  1523. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1524. + control,
  1525. + MMAL_PARAMETER_EXP_METERING_MODE,
  1526. + &dev->metering_mode,
  1527. + sizeof(u32));
  1528. + ret += set_framerate_params(dev);
  1529. + } else {
  1530. + /* Set up scene mode */
  1531. + int i;
  1532. + const struct v4l2_mmal_scene_config *scene = NULL;
  1533. + int shutter_speed;
  1534. + enum mmal_parameter_exposuremode exposure_mode;
  1535. + enum mmal_parameter_exposuremeteringmode metering_mode;
  1536. +
  1537. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  1538. + if (scene_configs[i].v4l2_scene ==
  1539. + ctrl->val) {
  1540. + scene = &scene_configs[i];
  1541. + break;
  1542. + }
  1543. + }
  1544. + if (i >= ARRAY_SIZE(scene_configs))
  1545. + return -EINVAL;
  1546. +
  1547. + /* Set all the values */
  1548. + dev->scene_mode = ctrl->val;
  1549. +
  1550. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  1551. + shutter_speed = dev->manual_shutter_speed;
  1552. + else
  1553. + shutter_speed = 0;
  1554. + exposure_mode = scene->exposure_mode;
  1555. + metering_mode = scene->metering_mode;
  1556. +
  1557. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1558. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  1559. + __func__, shutter_speed, exposure_mode, metering_mode);
  1560. +
  1561. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  1562. + MMAL_PARAMETER_SHUTTER_SPEED,
  1563. + &shutter_speed,
  1564. + sizeof(shutter_speed));
  1565. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1566. + control,
  1567. + MMAL_PARAMETER_EXPOSURE_MODE,
  1568. + &exposure_mode,
  1569. + sizeof(u32));
  1570. + dev->exposure_mode_active = exposure_mode;
  1571. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  1572. + MMAL_PARAMETER_EXPOSURE_MODE,
  1573. + &exposure_mode,
  1574. + sizeof(u32));
  1575. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  1576. + MMAL_PARAMETER_EXP_METERING_MODE,
  1577. + &metering_mode,
  1578. + sizeof(u32));
  1579. + ret += set_framerate_params(dev);
  1580. + }
  1581. + if (ret) {
  1582. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1583. + "%s: Setting scene to %d, ret=%d\n",
  1584. + __func__, ctrl->val, ret);
  1585. + ret = -EINVAL;
  1586. + }
  1587. + return 0;
  1588. +}
  1589. +
  1590. static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  1591. {
  1592. struct bm2835_mmal_dev *dev =
  1593. container_of(ctrl->handler, struct bm2835_mmal_dev,
  1594. ctrl_handler);
  1595. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  1596. + int ret;
  1597. if ((mmal_ctrl == NULL) ||
  1598. (mmal_ctrl->id != ctrl->id) ||
  1599. @@ -524,7 +906,13 @@ static int bm2835_mmal_s_ctrl(struct v4l
  1600. return -EINVAL;
  1601. }
  1602. - return mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  1603. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  1604. + if (ret)
  1605. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  1606. + ctrl->id, mmal_ctrl->mmal_id, ret);
  1607. + if (mmal_ctrl->ignore_errors)
  1608. + ret = 0;
  1609. + return ret;
  1610. }
  1611. static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  1612. @@ -537,40 +925,54 @@ static const struct bm2835_mmal_v4l2_ctr
  1613. {
  1614. V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  1615. -100, 100, 0, 1, NULL,
  1616. - MMAL_PARAMETER_SATURATION, &ctrl_set_rational
  1617. + MMAL_PARAMETER_SATURATION,
  1618. + &ctrl_set_rational,
  1619. + false
  1620. },
  1621. {
  1622. V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  1623. -100, 100, 0, 1, NULL,
  1624. - MMAL_PARAMETER_SHARPNESS, &ctrl_set_rational
  1625. + MMAL_PARAMETER_SHARPNESS,
  1626. + &ctrl_set_rational,
  1627. + false
  1628. },
  1629. {
  1630. V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  1631. -100, 100, 0, 1, NULL,
  1632. - MMAL_PARAMETER_CONTRAST, &ctrl_set_rational
  1633. + MMAL_PARAMETER_CONTRAST,
  1634. + &ctrl_set_rational,
  1635. + false
  1636. },
  1637. {
  1638. V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  1639. 0, 100, 50, 1, NULL,
  1640. - MMAL_PARAMETER_BRIGHTNESS, &ctrl_set_rational
  1641. + MMAL_PARAMETER_BRIGHTNESS,
  1642. + &ctrl_set_rational,
  1643. + false
  1644. },
  1645. {
  1646. V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  1647. 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  1648. - MMAL_PARAMETER_ISO, &ctrl_set_value
  1649. + MMAL_PARAMETER_ISO,
  1650. + &ctrl_set_value_menu,
  1651. + false
  1652. },
  1653. {
  1654. V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  1655. 0, 1, 0, 1, NULL,
  1656. - MMAL_PARAMETER_VIDEO_STABILISATION, &ctrl_set_value
  1657. + MMAL_PARAMETER_VIDEO_STABILISATION,
  1658. + &ctrl_set_value,
  1659. + false
  1660. },
  1661. /* {
  1662. 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  1663. - },
  1664. -*/ {
  1665. + }, */
  1666. + {
  1667. V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  1668. ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  1669. - MMAL_PARAMETER_EXPOSURE_MODE, &ctrl_set_exposure
  1670. + MMAL_PARAMETER_EXPOSURE_MODE,
  1671. + &ctrl_set_exposure,
  1672. + false
  1673. },
  1674. /* todo this needs mixing in with set exposure
  1675. {
  1676. @@ -578,83 +980,258 @@ static const struct bm2835_mmal_v4l2_ctr
  1677. },
  1678. */
  1679. {
  1680. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  1681. + /* Units of 100usecs */
  1682. + 1, 1*1000*10, 100*10, 1, NULL,
  1683. + MMAL_PARAMETER_SHUTTER_SPEED,
  1684. + &ctrl_set_exposure,
  1685. + false
  1686. + },
  1687. + {
  1688. V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  1689. 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  1690. (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  1691. - MMAL_PARAMETER_EXPOSURE_COMP, &ctrl_set_value
  1692. + MMAL_PARAMETER_EXPOSURE_COMP,
  1693. + &ctrl_set_value_ev,
  1694. + false
  1695. + },
  1696. + {
  1697. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  1698. + 0, 1,
  1699. + 0, 1, NULL,
  1700. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  1701. + &ctrl_set_exposure,
  1702. + false
  1703. },
  1704. {
  1705. V4L2_CID_EXPOSURE_METERING,
  1706. MMAL_CONTROL_TYPE_STD_MENU,
  1707. ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  1708. - MMAL_PARAMETER_EXP_METERING_MODE, &ctrl_set_metering_mode
  1709. + MMAL_PARAMETER_EXP_METERING_MODE,
  1710. + &ctrl_set_metering_mode,
  1711. + false
  1712. },
  1713. {
  1714. V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  1715. MMAL_CONTROL_TYPE_STD_MENU,
  1716. - ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  1717. - MMAL_PARAMETER_AWB_MODE, &ctrl_set_awb_mode
  1718. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  1719. + MMAL_PARAMETER_AWB_MODE,
  1720. + &ctrl_set_awb_mode,
  1721. + false
  1722. + },
  1723. + {
  1724. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  1725. + 1, 7999, 1000, 1, NULL,
  1726. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  1727. + &ctrl_set_awb_gains,
  1728. + false
  1729. + },
  1730. + {
  1731. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  1732. + 1, 7999, 1000, 1, NULL,
  1733. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  1734. + &ctrl_set_awb_gains,
  1735. + false
  1736. },
  1737. {
  1738. V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  1739. 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  1740. - MMAL_PARAMETER_IMAGE_EFFECT, &ctrl_set_image_effect
  1741. + MMAL_PARAMETER_IMAGE_EFFECT,
  1742. + &ctrl_set_image_effect,
  1743. + false
  1744. },
  1745. {
  1746. V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  1747. 0, 0xffff, 0x8080, 1, NULL,
  1748. - MMAL_PARAMETER_COLOUR_EFFECT, &ctrl_set_colfx
  1749. + MMAL_PARAMETER_COLOUR_EFFECT,
  1750. + &ctrl_set_colfx,
  1751. + false
  1752. },
  1753. {
  1754. V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  1755. 0, 360, 0, 90, NULL,
  1756. - MMAL_PARAMETER_ROTATION, &ctrl_set_rotate
  1757. + MMAL_PARAMETER_ROTATION,
  1758. + &ctrl_set_rotate,
  1759. + false
  1760. },
  1761. {
  1762. V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  1763. 0, 1, 0, 1, NULL,
  1764. - MMAL_PARAMETER_MIRROR, &ctrl_set_flip
  1765. + MMAL_PARAMETER_MIRROR,
  1766. + &ctrl_set_flip,
  1767. + false
  1768. },
  1769. {
  1770. V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  1771. 0, 1, 0, 1, NULL,
  1772. - MMAL_PARAMETER_MIRROR, &ctrl_set_flip
  1773. + MMAL_PARAMETER_MIRROR,
  1774. + &ctrl_set_flip,
  1775. + false
  1776. },
  1777. {
  1778. V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  1779. 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  1780. 0, 0, bitrate_mode_qmenu,
  1781. - MMAL_PARAMETER_RATECONTROL, &ctrl_set_bitrate_mode
  1782. + MMAL_PARAMETER_RATECONTROL,
  1783. + &ctrl_set_bitrate_mode,
  1784. + false
  1785. },
  1786. {
  1787. V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  1788. 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  1789. - MMAL_PARAMETER_VIDEO_BIT_RATE, &ctrl_set_bitrate
  1790. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  1791. + &ctrl_set_bitrate,
  1792. + false
  1793. },
  1794. {
  1795. V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  1796. - 0, 100,
  1797. + 1, 100,
  1798. 30, 1, NULL,
  1799. - MMAL_PARAMETER_JPEG_Q_FACTOR, &ctrl_set_q_factor
  1800. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  1801. + &ctrl_set_image_encode_output,
  1802. + false
  1803. + },
  1804. + {
  1805. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  1806. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  1807. + 1, 1, NULL,
  1808. + MMAL_PARAMETER_FLICKER_AVOID,
  1809. + &ctrl_set_flicker_avoidance,
  1810. + false
  1811. + },
  1812. + {
  1813. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  1814. + 0, 1,
  1815. + 0, 1, NULL,
  1816. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  1817. + &ctrl_set_video_encode_param_output,
  1818. + true /* Errors ignored as requires latest firmware to work */
  1819. + },
  1820. + {
  1821. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  1822. + MMAL_CONTROL_TYPE_STD_MENU,
  1823. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  1824. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  1825. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  1826. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  1827. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  1828. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  1829. + MMAL_PARAMETER_PROFILE,
  1830. + &ctrl_set_video_encode_profile_level,
  1831. + false
  1832. + },
  1833. + {
  1834. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  1835. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  1836. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  1837. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  1838. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  1839. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  1840. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  1841. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  1842. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  1843. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  1844. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  1845. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  1846. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  1847. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  1848. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  1849. + MMAL_PARAMETER_PROFILE,
  1850. + &ctrl_set_video_encode_profile_level,
  1851. + false
  1852. + },
  1853. + {
  1854. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  1855. + -1, /* Min is computed at runtime */
  1856. + V4L2_SCENE_MODE_TEXT,
  1857. + V4L2_SCENE_MODE_NONE, 1, NULL,
  1858. + MMAL_PARAMETER_PROFILE,
  1859. + &ctrl_set_scene_mode,
  1860. + false
  1861. + },
  1862. + {
  1863. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  1864. + 0, 0x7FFFFFFF, 60, 1, NULL,
  1865. + MMAL_PARAMETER_INTRAPERIOD,
  1866. + &ctrl_set_video_encode_param_output,
  1867. + false
  1868. },
  1869. };
  1870. int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  1871. {
  1872. int c;
  1873. - int ret;
  1874. + int ret = 0;
  1875. for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  1876. if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  1877. ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  1878. &v4l2_ctrls[c]);
  1879. - if (ret)
  1880. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  1881. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1882. + "Failed when setting default values for ctrl %d\n",
  1883. + c);
  1884. break;
  1885. + }
  1886. }
  1887. }
  1888. return ret;
  1889. }
  1890. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  1891. +{
  1892. + struct mmal_parameter_fps_range fps_range;
  1893. + int ret;
  1894. +
  1895. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  1896. + (dev->exp_auto_priority)) {
  1897. + /* Variable FPS. Define min FPS as 1fps.
  1898. + * Max as max defined FPS.
  1899. + */
  1900. + fps_range.fps_low.num = 1;
  1901. + fps_range.fps_low.den = 1;
  1902. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  1903. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  1904. + } else {
  1905. + /* Fixed FPS - set min and max to be the same */
  1906. + fps_range.fps_low.num = fps_range.fps_high.num =
  1907. + dev->capture.timeperframe.denominator;
  1908. + fps_range.fps_low.den = fps_range.fps_high.den =
  1909. + dev->capture.timeperframe.numerator;
  1910. + }
  1911. +
  1912. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1913. + "Set fps range to %d/%d to %d/%d\n",
  1914. + fps_range.fps_low.num,
  1915. + fps_range.fps_low.den,
  1916. + fps_range.fps_high.num,
  1917. + fps_range.fps_high.den
  1918. + );
  1919. +
  1920. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  1921. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1922. + output[MMAL_CAMERA_PORT_PREVIEW],
  1923. + MMAL_PARAMETER_FPS_RANGE,
  1924. + &fps_range, sizeof(fps_range));
  1925. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1926. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1927. + output[MMAL_CAMERA_PORT_VIDEO],
  1928. + MMAL_PARAMETER_FPS_RANGE,
  1929. + &fps_range, sizeof(fps_range));
  1930. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  1931. + &dev->component[MMAL_COMPONENT_CAMERA]->
  1932. + output[MMAL_CAMERA_PORT_CAPTURE],
  1933. + MMAL_PARAMETER_FPS_RANGE,
  1934. + &fps_range, sizeof(fps_range));
  1935. + if (ret)
  1936. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  1937. + "Failed to set fps ret %d\n",
  1938. + ret);
  1939. +
  1940. + return ret;
  1941. +
  1942. +}
  1943. +
  1944. int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  1945. struct v4l2_ctrl_handler *hdl)
  1946. {
  1947. @@ -674,10 +1251,30 @@ int bm2835_mmal_init_controls(struct bm2
  1948. break;
  1949. case MMAL_CONTROL_TYPE_STD_MENU:
  1950. + {
  1951. + int mask = ctrl->min;
  1952. +
  1953. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  1954. + /* Special handling to work out the mask
  1955. + * value based on the scene_configs array
  1956. + * at runtime. Reduces the chance of
  1957. + * mismatches.
  1958. + */
  1959. + int i;
  1960. + mask = 1<<V4L2_SCENE_MODE_NONE;
  1961. + for (i = 0;
  1962. + i < ARRAY_SIZE(scene_configs);
  1963. + i++) {
  1964. + mask |= 1<<scene_configs[i].v4l2_scene;
  1965. + }
  1966. + mask = ~mask;
  1967. + }
  1968. +
  1969. dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  1970. &bm2835_mmal_ctrl_ops, ctrl->id,
  1971. - ctrl->max, ctrl->min, ctrl->def);
  1972. + ctrl->max, mask, ctrl->def);
  1973. break;
  1974. + }
  1975. case MMAL_CONTROL_TYPE_INT_MENU:
  1976. dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  1977. --- a/drivers/media/platform/bcm2835/mmal-common.h
  1978. +++ b/drivers/media/platform/bcm2835/mmal-common.h
  1979. @@ -26,6 +26,7 @@
  1980. struct mmal_fmt {
  1981. char *name;
  1982. u32 fourcc; /* v4l2 format id */
  1983. + int flags; /* v4l2 flags field */
  1984. u32 mmal;
  1985. int depth;
  1986. u32 mmal_component; /* MMAL component index to be used to encode */
  1987. --- a/drivers/media/platform/bcm2835/mmal-encodings.h
  1988. +++ b/drivers/media/platform/bcm2835/mmal-encodings.h
  1989. @@ -12,6 +12,8 @@
  1990. * Simon Mellor <simellor@broadcom.com>
  1991. * Luke Diamand <luked@broadcom.com>
  1992. */
  1993. +#ifndef MMAL_ENCODINGS_H
  1994. +#define MMAL_ENCODINGS_H
  1995. #define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  1996. #define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  1997. @@ -27,6 +29,7 @@
  1998. #define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  1999. #define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  2000. #define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  2001. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  2002. #define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  2003. #define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  2004. @@ -91,3 +94,34 @@
  2005. #define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  2006. /** Implicitly delineated NAL units without emulation prevention */
  2007. #define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  2008. +
  2009. +
  2010. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  2011. + * This defines a list of common color spaces. This list isn't exhaustive and
  2012. + * is only provided as a convenience to avoid clients having to use FourCC
  2013. + * codes directly. However components are allowed to define and use their own
  2014. + * FourCC codes.
  2015. + */
  2016. +/* @{ */
  2017. +
  2018. +/** Unknown color space */
  2019. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  2020. +/** ITU-R BT.601-5 [SDTV] */
  2021. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  2022. +/** ITU-R BT.709-3 [HDTV] */
  2023. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  2024. +/** JPEG JFIF */
  2025. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  2026. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  2027. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  2028. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  2029. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  2030. +/** ITU-R BT.470-2 System M */
  2031. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  2032. +/** ITU-R BT.470-2 System BG */
  2033. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  2034. +/** JPEG JFIF, but with 16..255 luma */
  2035. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  2036. +/* @} MmalColorSpace List */
  2037. +
  2038. +#endif /* MMAL_ENCODINGS_H */
  2039. --- a/drivers/media/platform/bcm2835/mmal-parameters.h
  2040. +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
  2041. @@ -57,7 +57,8 @@ enum mmal_parameter_common_type {
  2042. MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  2043. MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  2044. MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  2045. - MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  2046. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  2047. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  2048. };
  2049. /* camera parameters */
  2050. @@ -161,6 +162,13 @@ enum mmal_parameter_camera_type {
  2051. MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2052. MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2053. MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2054. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  2055. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  2056. +};
  2057. +
  2058. +struct mmal_parameter_rational {
  2059. + s32 num; /**< Numerator */
  2060. + s32 den; /**< Denominator */
  2061. };
  2062. enum mmal_parameter_camera_config_timestamp_mode {
  2063. @@ -176,6 +184,14 @@ enum mmal_parameter_camera_config_timest
  2064. */
  2065. };
  2066. +struct mmal_parameter_fps_range {
  2067. + /**< Low end of the permitted framerate range */
  2068. + struct mmal_parameter_rational fps_low;
  2069. + /**< High end of the permitted framerate range */
  2070. + struct mmal_parameter_rational fps_high;
  2071. +};
  2072. +
  2073. +
  2074. /* camera configuration parameter */
  2075. struct mmal_parameter_camera_config {
  2076. /* Parameters for setting up the image pools */
  2077. @@ -270,6 +286,19 @@ enum mmal_parameter_imagefx {
  2078. MMAL_PARAM_IMAGEFX_CARTOON,
  2079. };
  2080. +enum MMAL_PARAM_FLICKERAVOID_T {
  2081. + MMAL_PARAM_FLICKERAVOID_OFF,
  2082. + MMAL_PARAM_FLICKERAVOID_AUTO,
  2083. + MMAL_PARAM_FLICKERAVOID_50HZ,
  2084. + MMAL_PARAM_FLICKERAVOID_60HZ,
  2085. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  2086. +};
  2087. +
  2088. +struct mmal_parameter_awbgains {
  2089. + struct mmal_parameter_rational r_gain; /**< Red gain */
  2090. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  2091. +};
  2092. +
  2093. /** Manner of video rate control */
  2094. enum mmal_parameter_rate_control_mode {
  2095. MMAL_VIDEO_RATECONTROL_DEFAULT,
  2096. @@ -279,6 +308,85 @@ enum mmal_parameter_rate_control_mode {
  2097. MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  2098. };
  2099. +enum mmal_video_profile {
  2100. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  2101. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  2102. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  2103. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  2104. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  2105. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  2106. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  2107. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  2108. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  2109. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  2110. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  2111. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  2112. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  2113. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  2114. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  2115. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  2116. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  2117. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  2118. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  2119. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  2120. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  2121. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  2122. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  2123. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  2124. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  2125. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  2126. + MMAL_VIDEO_PROFILE_H264_MAIN,
  2127. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  2128. + MMAL_VIDEO_PROFILE_H264_HIGH,
  2129. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  2130. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  2131. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  2132. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  2133. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  2134. +};
  2135. +
  2136. +enum mmal_video_level {
  2137. + MMAL_VIDEO_LEVEL_H263_10,
  2138. + MMAL_VIDEO_LEVEL_H263_20,
  2139. + MMAL_VIDEO_LEVEL_H263_30,
  2140. + MMAL_VIDEO_LEVEL_H263_40,
  2141. + MMAL_VIDEO_LEVEL_H263_45,
  2142. + MMAL_VIDEO_LEVEL_H263_50,
  2143. + MMAL_VIDEO_LEVEL_H263_60,
  2144. + MMAL_VIDEO_LEVEL_H263_70,
  2145. + MMAL_VIDEO_LEVEL_MP4V_0,
  2146. + MMAL_VIDEO_LEVEL_MP4V_0b,
  2147. + MMAL_VIDEO_LEVEL_MP4V_1,
  2148. + MMAL_VIDEO_LEVEL_MP4V_2,
  2149. + MMAL_VIDEO_LEVEL_MP4V_3,
  2150. + MMAL_VIDEO_LEVEL_MP4V_4,
  2151. + MMAL_VIDEO_LEVEL_MP4V_4a,
  2152. + MMAL_VIDEO_LEVEL_MP4V_5,
  2153. + MMAL_VIDEO_LEVEL_MP4V_6,
  2154. + MMAL_VIDEO_LEVEL_H264_1,
  2155. + MMAL_VIDEO_LEVEL_H264_1b,
  2156. + MMAL_VIDEO_LEVEL_H264_11,
  2157. + MMAL_VIDEO_LEVEL_H264_12,
  2158. + MMAL_VIDEO_LEVEL_H264_13,
  2159. + MMAL_VIDEO_LEVEL_H264_2,
  2160. + MMAL_VIDEO_LEVEL_H264_21,
  2161. + MMAL_VIDEO_LEVEL_H264_22,
  2162. + MMAL_VIDEO_LEVEL_H264_3,
  2163. + MMAL_VIDEO_LEVEL_H264_31,
  2164. + MMAL_VIDEO_LEVEL_H264_32,
  2165. + MMAL_VIDEO_LEVEL_H264_4,
  2166. + MMAL_VIDEO_LEVEL_H264_41,
  2167. + MMAL_VIDEO_LEVEL_H264_42,
  2168. + MMAL_VIDEO_LEVEL_H264_5,
  2169. + MMAL_VIDEO_LEVEL_H264_51,
  2170. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  2171. +};
  2172. +
  2173. +struct mmal_parameter_video_profile {
  2174. + enum mmal_video_profile profile;
  2175. + enum mmal_video_level level;
  2176. +};
  2177. +
  2178. /* video parameters */
  2179. enum mmal_parameter_video_type {
  2180. @@ -407,7 +515,16 @@ enum mmal_parameter_video_type {
  2181. MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  2182. /** @ref MMAL_PARAMETER_BYTES_T */
  2183. - MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3
  2184. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  2185. +
  2186. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2187. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  2188. +
  2189. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2190. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  2191. +
  2192. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  2193. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  2194. };
  2195. /** Valid mirror modes */
  2196. --- a/drivers/media/platform/bcm2835/mmal-vchiq.c
  2197. +++ b/drivers/media/platform/bcm2835/mmal-vchiq.c
  2198. @@ -742,7 +742,7 @@ static int send_synchronous_mmal_msg(str
  2199. return ret;
  2200. }
  2201. - ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  2202. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  2203. if (ret <= 0) {
  2204. pr_err("error %d waiting for sync completion\n", ret);
  2205. if (ret == 0)
  2206. @@ -1326,7 +1326,7 @@ static int port_parameter_get(struct vch
  2207. memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  2208. rmsg->u.port_parameter_get_reply.size);
  2209. - pr_info("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  2210. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  2211. ret, port->component->handle, port->handle, parameter_id);
  2212. release_msg: