Commit 35d2d76d authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] go7007: standardize MPEG handling support

The go7007 produces elementary streams, so we shouldn't use the STREAM_TYPE
control, since that is for multiplexed streams.
Instead use V4L2_PIX_FMT_MPEG1/2/4.
Initially set up all the values for MPEG-2 dvd-mode, and select the dvd_mode
field if those values match that setup precisely.
Clean up lots of obsolete code relating to the custom ioctls for the MPEG
support.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 50deb749
......@@ -433,12 +433,12 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
spin_lock(&go->spinlock);
switch (go->format) {
case GO7007_FORMAT_MPEG4:
case V4L2_PIX_FMT_MPEG4:
seq_start_code = 0xB0;
frame_start_code = 0xB6;
break;
case GO7007_FORMAT_MPEG1:
case GO7007_FORMAT_MPEG2:
case V4L2_PIX_FMT_MPEG1:
case V4L2_PIX_FMT_MPEG2:
seq_start_code = 0xB3;
frame_start_code = 0x00;
break;
......@@ -518,9 +518,9 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
}
/* If this is the start of a new MPEG frame,
* get a new buffer */
if ((go->format == GO7007_FORMAT_MPEG1 ||
go->format == GO7007_FORMAT_MPEG2 ||
go->format == GO7007_FORMAT_MPEG4) &&
if ((go->format == V4L2_PIX_FMT_MPEG1 ||
go->format == V4L2_PIX_FMT_MPEG2 ||
go->format == V4L2_PIX_FMT_MPEG4) &&
(buf[i] == seq_start_code ||
buf[i] == 0xB8 || /* GOP code */
buf[i] == frame_start_code)) {
......@@ -577,7 +577,7 @@ void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
/* go->state remains STATE_FF */
break;
case 0xD8:
if (go->format == GO7007_FORMAT_MJPEG)
if (go->format == V4L2_PIX_FMT_MJPEG)
frame_boundary(go);
/* fall through */
default:
......@@ -654,8 +654,8 @@ struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
go->encoder_h_halve = 0;
go->encoder_v_halve = 0;
go->encoder_subsample = 0;
go->format = V4L2_PIX_FMT_MJPEG;
go->streaming = 0;
go->format = GO7007_FORMAT_MJPEG;
go->bitrate = 1500000;
go->fps_scale = 1;
go->pali = 0;
......
......@@ -455,9 +455,9 @@ static int mpeg1_frame_header(struct go7007 *go, unsigned char *buf,
CODE_ADD(c, frame == PFRAME ? 0x2 : 0x3, 13);
CODE_ADD(c, 0xffff, 16);
CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 0x7 : 0x4, 4);
CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 0x7 : 0x4, 4);
if (frame != PFRAME)
CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 0x7 : 0x4, 4);
CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 0x7 : 0x4, 4);
else
CODE_ADD(c, 0, 4); /* Is this supposed to be here?? */
CODE_ADD(c, 0, 3); /* What is this?? */
......@@ -466,7 +466,7 @@ static int mpeg1_frame_header(struct go7007 *go, unsigned char *buf,
if (j != 8)
CODE_ADD(c, 0, j);
if (go->format == GO7007_FORMAT_MPEG2) {
if (go->format == V4L2_PIX_FMT_MPEG2) {
CODE_ADD(c, 0x1, 24);
CODE_ADD(c, 0xb5, 8);
CODE_ADD(c, 0x844, 12);
......@@ -537,7 +537,7 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
int i, aspect_ratio, picture_rate;
CODE_GEN(c, buf + 6);
if (go->format == GO7007_FORMAT_MPEG1) {
if (go->format == V4L2_PIX_FMT_MPEG1) {
switch (go->aspect_ratio) {
case GO7007_RATIO_4_3:
aspect_ratio = go->standard == GO7007_STD_NTSC ? 3 : 2;
......@@ -587,9 +587,9 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
CODE_ADD(c, go->height, 12);
CODE_ADD(c, aspect_ratio, 4);
CODE_ADD(c, picture_rate, 4);
CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 20000 : 0x3ffff, 18);
CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 20000 : 0x3ffff, 18);
CODE_ADD(c, 1, 1);
CODE_ADD(c, go->format == GO7007_FORMAT_MPEG2 ? 112 : 20, 10);
CODE_ADD(c, go->format == V4L2_PIX_FMT_MPEG2 ? 112 : 20, 10);
CODE_ADD(c, 0, 3);
/* Byte-align with zeros */
......@@ -597,7 +597,7 @@ static int mpeg1_sequence_header(struct go7007 *go, unsigned char *buf, int ext)
if (i != 8)
CODE_ADD(c, 0, i);
if (go->format == GO7007_FORMAT_MPEG2) {
if (go->format == V4L2_PIX_FMT_MPEG2) {
CODE_ADD(c, 0x1, 24);
CODE_ADD(c, 0xb5, 8);
CODE_ADD(c, 0x148, 12);
......@@ -930,10 +930,10 @@ static int brctrl_to_package(struct go7007 *go,
__le16 *code, int space, int *framelen)
{
int converge_speed = 0;
int lambda = (go->format == GO7007_FORMAT_MJPEG || go->dvd_mode) ?
int lambda = (go->format == V4L2_PIX_FMT_MJPEG || go->dvd_mode) ?
100 : 0;
int peak_rate = 6 * go->bitrate / 5;
int vbv_buffer = go->format == GO7007_FORMAT_MJPEG ?
int vbv_buffer = go->format == V4L2_PIX_FMT_MJPEG ?
go->bitrate :
(go->dvd_mode ? 900000 : peak_rate);
int fps = go->sensor_framerate / go->fps_scale;
......@@ -1096,10 +1096,10 @@ static int config_package(struct go7007 *go, __le16 *code, int space)
0xc003, 0x28b4,
0xc004, 0x3c5a,
0xdc05, 0x2a77,
0xc6c3, go->format == GO7007_FORMAT_MPEG4 ? 0 :
(go->format == GO7007_FORMAT_H263 ? 0 : 1),
0xc680, go->format == GO7007_FORMAT_MPEG4 ? 0xf1 :
(go->format == GO7007_FORMAT_H263 ? 0x61 :
0xc6c3, go->format == V4L2_PIX_FMT_MPEG4 ? 0 :
(go->format == V4L2_PIX_FMT_H263 ? 0 : 1),
0xc680, go->format == V4L2_PIX_FMT_MPEG4 ? 0xf1 :
(go->format == V4L2_PIX_FMT_H263 ? 0x61 :
0xd3),
0xc780, 0x0140,
0xe009, 0x0001,
......@@ -1123,15 +1123,15 @@ static int config_package(struct go7007 *go, __le16 *code, int space)
(!go->interlace_coding) ?
0x0008 : 0x0009,
0xc404, go->interlace_coding ? 0x44 :
(go->format == GO7007_FORMAT_MPEG4 ? 0x11 :
(go->format == GO7007_FORMAT_MPEG1 ? 0x02 :
(go->format == GO7007_FORMAT_MPEG2 ? 0x04 :
(go->format == GO7007_FORMAT_H263 ? 0x08 :
(go->format == V4L2_PIX_FMT_MPEG4 ? 0x11 :
(go->format == V4L2_PIX_FMT_MPEG1 ? 0x02 :
(go->format == V4L2_PIX_FMT_MPEG2 ? 0x04 :
(go->format == V4L2_PIX_FMT_H263 ? 0x08 :
0x20)))),
0xbf0a, (go->format == GO7007_FORMAT_MPEG4 ? 8 :
(go->format == GO7007_FORMAT_MPEG1 ? 1 :
(go->format == GO7007_FORMAT_MPEG2 ? 2 :
(go->format == GO7007_FORMAT_H263 ? 4 : 16)))) |
0xbf0a, (go->format == V4L2_PIX_FMT_MPEG4 ? 8 :
(go->format == V4L2_PIX_FMT_MPEG1 ? 1 :
(go->format == V4L2_PIX_FMT_MPEG2 ? 2 :
(go->format == V4L2_PIX_FMT_H263 ? 4 : 16)))) |
((go->repeat_seqhead ? 1 : 0) << 6) |
((go->dvd_mode ? 1 : 0) << 9) |
((go->gop_header_enable ? 1 : 0) << 10),
......@@ -1348,19 +1348,19 @@ static int final_package(struct go7007 *go, __le16 *code, int space)
0x41,
go->ipb ? 0xd4c : 0x36b,
(rows << 8) | (go->width >> 4),
go->format == GO7007_FORMAT_MPEG4 ? 0x0404 : 0,
go->format == V4L2_PIX_FMT_MPEG4 ? 0x0404 : 0,
(1 << 15) | ((go->interlace_coding ? 1 : 0) << 13) |
((go->closed_gop ? 1 : 0) << 12) |
((go->format == GO7007_FORMAT_MPEG4 ? 1 : 0) << 11) |
((go->format == V4L2_PIX_FMT_MPEG4 ? 1 : 0) << 11) |
/* (1 << 9) | */
((go->ipb ? 3 : 0) << 7) |
((go->modet_enable ? 1 : 0) << 2) |
((go->dvd_mode ? 1 : 0) << 1) | 1,
(go->format == GO7007_FORMAT_MPEG1 ? 0x89a0 :
(go->format == GO7007_FORMAT_MPEG2 ? 0x89a0 :
(go->format == GO7007_FORMAT_MJPEG ? 0x89a0 :
(go->format == GO7007_FORMAT_MPEG4 ? 0x8920 :
(go->format == GO7007_FORMAT_H263 ? 0x8920 : 0))))),
(go->format == V4L2_PIX_FMT_MPEG1 ? 0x89a0 :
(go->format == V4L2_PIX_FMT_MPEG2 ? 0x89a0 :
(go->format == V4L2_PIX_FMT_MJPEG ? 0x89a0 :
(go->format == V4L2_PIX_FMT_MPEG4 ? 0x8920 :
(go->format == V4L2_PIX_FMT_H263 ? 0x8920 : 0))))),
go->ipb ? 0x1f15 : 0x1f0b,
go->ipb ? 0x0015 : 0x000b,
go->ipb ? 0xa800 : 0x5800,
......@@ -1503,13 +1503,13 @@ static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
switch (type) {
case SPECIAL_FRM_HEAD:
switch (go->format) {
case GO7007_FORMAT_MJPEG:
case V4L2_PIX_FMT_MJPEG:
return gen_mjpeghdr_to_package(go, code, space);
case GO7007_FORMAT_MPEG1:
case GO7007_FORMAT_MPEG2:
case V4L2_PIX_FMT_MPEG1:
case V4L2_PIX_FMT_MPEG2:
return gen_mpeg1hdr_to_package(go, code, space,
framelen);
case GO7007_FORMAT_MPEG4:
case V4L2_PIX_FMT_MPEG4:
return gen_mpeg4hdr_to_package(go, code, space,
framelen);
}
......@@ -1519,11 +1519,11 @@ static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
return config_package(go, code, space);
case SPECIAL_SEQHEAD:
switch (go->format) {
case GO7007_FORMAT_MPEG1:
case GO7007_FORMAT_MPEG2:
case V4L2_PIX_FMT_MPEG1:
case V4L2_PIX_FMT_MPEG2:
return seqhead_to_package(go, code, space,
mpeg1_sequence_header);
case GO7007_FORMAT_MPEG4:
case V4L2_PIX_FMT_MPEG4:
return seqhead_to_package(go, code, space,
mpeg4_sequence_header);
default:
......@@ -1553,16 +1553,16 @@ int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen)
int ret;
switch (go->format) {
case GO7007_FORMAT_MJPEG:
case V4L2_PIX_FMT_MJPEG:
mode_flag = FLAG_MODE_MJPEG;
break;
case GO7007_FORMAT_MPEG1:
case V4L2_PIX_FMT_MPEG1:
mode_flag = FLAG_MODE_MPEG1;
break;
case GO7007_FORMAT_MPEG2:
case V4L2_PIX_FMT_MPEG2:
mode_flag = FLAG_MODE_MPEG2;
break;
case GO7007_FORMAT_MPEG4:
case V4L2_PIX_FMT_MPEG4:
mode_flag = FLAG_MODE_MPEG4;
break;
default:
......
......@@ -151,12 +151,6 @@ struct go7007_file {
struct go7007_buffer *bufs;
};
#define GO7007_FORMAT_MJPEG 0
#define GO7007_FORMAT_MPEG4 1
#define GO7007_FORMAT_MPEG1 2
#define GO7007_FORMAT_MPEG2 3
#define GO7007_FORMAT_H263 4
#define GO7007_RATIO_1_1 0
#define GO7007_RATIO_4_3 1
#define GO7007_RATIO_16_9 2
......@@ -186,6 +180,11 @@ struct go7007 {
unsigned boot_fw_len;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler hdl;
struct v4l2_ctrl *mpeg_video_encoding;
struct v4l2_ctrl *mpeg_video_gop_size;
struct v4l2_ctrl *mpeg_video_gop_closure;
struct v4l2_ctrl *mpeg_video_bitrate;
struct v4l2_ctrl *mpeg_video_aspect_ratio;
enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
spinlock_t spinlock;
struct mutex hw_lock;
......@@ -211,7 +210,7 @@ struct go7007 {
unsigned int encoder_subsample:1;
/* Encoder config */
int format;
u32 format;
int bitrate;
int fps_scale;
int pali;
......
This diff is collapsed.
......@@ -17,72 +17,6 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* DEPRECATED -- use V4L2_PIX_FMT_MPEG and then call GO7007IOC_S_MPEG_PARAMS
* to select between MPEG1, MPEG2, and MPEG4 */
#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG4 */
/* These will be replaced with a better interface
* soon, so don't get too attached to them */
#define GO7007IOC_S_BITRATE _IOW('V', BASE_VIDIOC_PRIVATE + 0, int)
#define GO7007IOC_G_BITRATE _IOR('V', BASE_VIDIOC_PRIVATE + 1, int)
enum go7007_aspect_ratio {
GO7007_ASPECT_RATIO_1_1 = 0,
GO7007_ASPECT_RATIO_4_3_NTSC = 1,
GO7007_ASPECT_RATIO_4_3_PAL = 2,
GO7007_ASPECT_RATIO_16_9_NTSC = 3,
GO7007_ASPECT_RATIO_16_9_PAL = 4,
};
/* Used to set generic compression parameters */
struct go7007_comp_params {
__u32 gop_size;
__u32 max_b_frames;
enum go7007_aspect_ratio aspect_ratio;
__u32 flags;
__u32 reserved[8];
};
#define GO7007_COMP_CLOSED_GOP 0x00000001
#define GO7007_COMP_OMIT_SEQ_HEADER 0x00000002
enum go7007_mpeg_video_standard {
GO7007_MPEG_VIDEO_MPEG1 = 0,
GO7007_MPEG_VIDEO_MPEG2 = 1,
GO7007_MPEG_VIDEO_MPEG4 = 2,
};
/* Used to set parameters for V4L2_PIX_FMT_MPEG format */
struct go7007_mpeg_params {
enum go7007_mpeg_video_standard mpeg_video_standard;
__u32 flags;
__u32 pali;
__u32 reserved[8];
};
#define GO7007_MPEG_FORCE_DVD_MODE 0x00000001
#define GO7007_MPEG_OMIT_GOP_HEADER 0x00000002
#define GO7007_MPEG_REPEAT_SEQHEADER 0x00000004
#define GO7007_MPEG_PROFILE(format, pali) (((format)<<24)|(pali))
#define GO7007_MPEG2_PROFILE_MAIN_MAIN GO7007_MPEG_PROFILE(2, 0x48)
#define GO7007_MPEG4_PROFILE_S_L0 GO7007_MPEG_PROFILE(4, 0x08)
#define GO7007_MPEG4_PROFILE_S_L1 GO7007_MPEG_PROFILE(4, 0x01)
#define GO7007_MPEG4_PROFILE_S_L2 GO7007_MPEG_PROFILE(4, 0x02)
#define GO7007_MPEG4_PROFILE_S_L3 GO7007_MPEG_PROFILE(4, 0x03)
#define GO7007_MPEG4_PROFILE_ARTS_L1 GO7007_MPEG_PROFILE(4, 0x91)
#define GO7007_MPEG4_PROFILE_ARTS_L2 GO7007_MPEG_PROFILE(4, 0x92)
#define GO7007_MPEG4_PROFILE_ARTS_L3 GO7007_MPEG_PROFILE(4, 0x93)
#define GO7007_MPEG4_PROFILE_ARTS_L4 GO7007_MPEG_PROFILE(4, 0x94)
#define GO7007_MPEG4_PROFILE_AS_L0 GO7007_MPEG_PROFILE(4, 0xf0)
#define GO7007_MPEG4_PROFILE_AS_L1 GO7007_MPEG_PROFILE(4, 0xf1)
#define GO7007_MPEG4_PROFILE_AS_L2 GO7007_MPEG_PROFILE(4, 0xf2)
#define GO7007_MPEG4_PROFILE_AS_L3 GO7007_MPEG_PROFILE(4, 0xf3)
#define GO7007_MPEG4_PROFILE_AS_L4 GO7007_MPEG_PROFILE(4, 0xf4)
#define GO7007_MPEG4_PROFILE_AS_L5 GO7007_MPEG_PROFILE(4, 0xf5)
struct go7007_md_params {
__u16 region;
__u16 trigger;
......@@ -98,14 +32,6 @@ struct go7007_md_region {
__u32 reserved[8];
};
#define GO7007IOC_S_MPEG_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 2, \
struct go7007_mpeg_params)
#define GO7007IOC_G_MPEG_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 3, \
struct go7007_mpeg_params)
#define GO7007IOC_S_COMP_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 4, \
struct go7007_comp_params)
#define GO7007IOC_G_COMP_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 5, \
struct go7007_comp_params)
#define GO7007IOC_S_MD_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 6, \
struct go7007_md_params)
#define GO7007IOC_G_MD_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 7, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment