|
| 1 | +/* |
| 2 | + * Broadcom BM2835 V4L2 driver |
| 3 | + * |
| 4 | + * Copyright © 2013 Raspberry Pi (Trading) Ltd. |
| 5 | + * |
| 6 | + * This file is subject to the terms and conditions of the GNU General Public |
| 7 | + * License. See the file COPYING in the main directory of this archive |
| 8 | + * for more details. |
| 9 | + * |
| 10 | + * Authors: Vincent Sanders <[email protected]> |
| 11 | + * Dave Stevenson <[email protected]> |
| 12 | + * Simon Mellor <[email protected]> |
| 13 | + * Luke Diamand <[email protected]> |
| 14 | + * |
| 15 | + * core driver device |
| 16 | + */ |
| 17 | + |
| 18 | +#define V4L2_CTRL_COUNT 29 /* number of v4l controls */ |
| 19 | + |
| 20 | +enum { |
| 21 | + MMAL_COMPONENT_CAMERA = 0, |
| 22 | + MMAL_COMPONENT_PREVIEW, |
| 23 | + MMAL_COMPONENT_IMAGE_ENCODE, |
| 24 | + MMAL_COMPONENT_VIDEO_ENCODE, |
| 25 | + MMAL_COMPONENT_COUNT |
| 26 | +}; |
| 27 | + |
| 28 | +enum { |
| 29 | + MMAL_CAMERA_PORT_PREVIEW = 0, |
| 30 | + MMAL_CAMERA_PORT_VIDEO, |
| 31 | + MMAL_CAMERA_PORT_CAPTURE, |
| 32 | + MMAL_CAMERA_PORT_COUNT |
| 33 | +}; |
| 34 | + |
| 35 | +#define PREVIEW_LAYER 2 |
| 36 | + |
| 37 | +extern int bcm2835_v4l2_debug; |
| 38 | + |
| 39 | +struct bm2835_mmal_dev { |
| 40 | + /* v4l2 devices */ |
| 41 | + struct v4l2_device v4l2_dev; |
| 42 | + struct video_device vdev; |
| 43 | + struct mutex mutex; |
| 44 | + |
| 45 | + /* controls */ |
| 46 | + struct v4l2_ctrl_handler ctrl_handler; |
| 47 | + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT]; |
| 48 | + enum v4l2_scene_mode scene_mode; |
| 49 | + struct mmal_colourfx colourfx; |
| 50 | + int hflip; |
| 51 | + int vflip; |
| 52 | + int red_gain; |
| 53 | + int blue_gain; |
| 54 | + enum mmal_parameter_exposuremode exposure_mode_user; |
| 55 | + enum v4l2_exposure_auto_type exposure_mode_v4l2_user; |
| 56 | + /* active exposure mode may differ if selected via a scene mode */ |
| 57 | + enum mmal_parameter_exposuremode exposure_mode_active; |
| 58 | + enum mmal_parameter_exposuremeteringmode metering_mode; |
| 59 | + unsigned int manual_shutter_speed; |
| 60 | + bool exp_auto_priority; |
| 61 | + bool manual_iso_enabled; |
| 62 | + uint32_t iso; |
| 63 | + |
| 64 | + /* allocated mmal instance and components */ |
| 65 | + struct vchiq_mmal_instance *instance; |
| 66 | + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT]; |
| 67 | + int camera_use_count; |
| 68 | + |
| 69 | + struct v4l2_window overlay; |
| 70 | + |
| 71 | + struct { |
| 72 | + unsigned int width; /* width */ |
| 73 | + unsigned int height; /* height */ |
| 74 | + unsigned int stride; /* stride */ |
| 75 | + unsigned int buffersize; /* buffer size with padding */ |
| 76 | + struct mmal_fmt *fmt; |
| 77 | + struct v4l2_fract timeperframe; |
| 78 | + |
| 79 | + /* H264 encode bitrate */ |
| 80 | + int encode_bitrate; |
| 81 | + /* H264 bitrate mode. CBR/VBR */ |
| 82 | + int encode_bitrate_mode; |
| 83 | + /* H264 profile */ |
| 84 | + enum v4l2_mpeg_video_h264_profile enc_profile; |
| 85 | + /* H264 level */ |
| 86 | + enum v4l2_mpeg_video_h264_level enc_level; |
| 87 | + /* JPEG Q-factor */ |
| 88 | + int q_factor; |
| 89 | + |
| 90 | + struct vb2_queue vb_vidq; |
| 91 | + |
| 92 | + /* VC start timestamp for streaming */ |
| 93 | + s64 vc_start_timestamp; |
| 94 | + /* Kernel start timestamp for streaming */ |
| 95 | + struct timeval kernel_start_ts; |
| 96 | + |
| 97 | + struct vchiq_mmal_port *port; /* port being used for capture */ |
| 98 | + /* camera port being used for capture */ |
| 99 | + struct vchiq_mmal_port *camera_port; |
| 100 | + /* component being used for encode */ |
| 101 | + struct vchiq_mmal_component *encode_component; |
| 102 | + /* number of frames remaining which driver should capture */ |
| 103 | + unsigned int frame_count; |
| 104 | + /* last frame completion */ |
| 105 | + struct completion frame_cmplt; |
| 106 | + |
| 107 | + } capture; |
| 108 | + |
| 109 | + unsigned int camera_num; |
| 110 | + unsigned int max_width; |
| 111 | + unsigned int max_height; |
| 112 | + unsigned int rgb_bgr_swapped; |
| 113 | +}; |
| 114 | + |
| 115 | +int bm2835_mmal_init_controls( |
| 116 | + struct bm2835_mmal_dev *dev, |
| 117 | + struct v4l2_ctrl_handler *hdl); |
| 118 | + |
| 119 | +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev); |
| 120 | +int set_framerate_params(struct bm2835_mmal_dev *dev); |
| 121 | + |
| 122 | +/* Debug helpers */ |
| 123 | + |
| 124 | +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \ |
| 125 | +{ \ |
| 126 | + v4l2_dbg(level, debug, dev, \ |
| 127 | +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \ |
| 128 | + desc == NULL ? "" : desc, \ |
| 129 | + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \ |
| 130 | + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \ |
| 131 | + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \ |
| 132 | +} |
| 133 | +#define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \ |
| 134 | +{ \ |
| 135 | + v4l2_dbg(level, debug, dev, \ |
| 136 | +"%s: w %u h %u l %u t %u field %u chromakey %06X clip %p " \ |
| 137 | +"clipcount %u bitmap %p\n", \ |
| 138 | + desc == NULL ? "" : desc, \ |
| 139 | + (win_fmt)->w.width, (win_fmt)->w.height, \ |
| 140 | + (win_fmt)->w.left, (win_fmt)->w.top, \ |
| 141 | + (win_fmt)->field, \ |
| 142 | + (win_fmt)->chromakey, \ |
| 143 | + (win_fmt)->clips, (win_fmt)->clipcount, \ |
| 144 | + (win_fmt)->bitmap); \ |
| 145 | +} |
0 commit comments