Browse Source

Make H.264 and H.265 support dependent on V4L2 definitions

Since the H.264 and H.265 series are still work in progress, only
enable support for these codecs if the matching V4L2 pixel format
definitions are found.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Paul Kocialkowski 6 years ago
parent
commit
899480fe7c
3 changed files with 26 additions and 0 deletions
  1. 14 0
      presets.c
  2. 4 0
      v4l2-request-test.h
  3. 8 0
      v4l2.c

+ 14 - 0
presets.c

@@ -37,6 +37,7 @@ static struct frame ed_mpeg2_frames[] = {
 #include "data/ed-mpeg2/frames.h"
 };
 
+#ifdef V4L2_PIX_FMT_H264_SLICE
 static struct frame bbb_h264_all_i_32_frames[] = {
 #include "data/bbb-h264-all-i-32/frames.h"
 };
@@ -48,7 +49,9 @@ static struct frame bbb_h264_32_frames[] = {
 static struct frame bbb_h264_high_32_frames[] = {
 #include "data/bbb-h264-high-32/frames.h"
 };
+#endif
 
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 static struct frame caminandes_h265_frames[] = {
 #include "data/caminandes-h265/frames.h"
 };
@@ -56,6 +59,7 @@ static struct frame caminandes_h265_frames[] = {
 static struct frame caminandes_fall_h265_frames[] = {
 #include "data/caminandes-fall-h265/frames.h"
 };
+#endif
 
 static struct preset presets[] = {
 	{
@@ -94,6 +98,7 @@ static struct preset presets[] = {
 		.frames = ed_mpeg2_frames,
 		.frames_count = ARRAY_SIZE(ed_mpeg2_frames),
 	},
+#ifdef V4L2_PIX_FMT_H264_SLICE
 	{
 		.name = "bbb-h264-all-i-32",
 		.description = "big_buck_bunny_480p_H264_AAC_25fps_1800K.MP4",
@@ -130,6 +135,8 @@ static struct preset presets[] = {
 		.frames = bbb_h264_32_frames,
 		.frames_count = ARRAY_SIZE(bbb_h264_32_frames),
 	},
+#endif
+#ifdef V4L2_PIX_FMT_H264_SLICE
 	{
 		.name = "caminandes-h265",
 		.description = "Caminandes 2: Gran Dillema",
@@ -154,6 +161,7 @@ static struct preset presets[] = {
 		.frames = caminandes_fall_h265_frames,
 		.frames_count = ARRAY_SIZE(caminandes_fall_h265_frames),
 	},
+#endif
 };
 
 static unsigned int presets_count = ARRAY_SIZE(presets);
@@ -218,6 +226,7 @@ int frame_controls_fill(struct frame *frame, struct preset *preset,
 		break;
 	case CODEC_TYPE_H264:
 		break;
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 	case CODEC_TYPE_H265:
 		count = frame->frame.h265.slice_params.num_active_dpb_entries;
 
@@ -225,6 +234,7 @@ int frame_controls_fill(struct frame *frame, struct preset *preset,
 			frame->frame.h265.slice_params.dpb[i].buffer_index %=
 				buffers_count;
 		break;
+#endif
 	default:
 		return -1;
 	}
@@ -253,6 +263,7 @@ unsigned int frame_pct(struct preset *preset, unsigned int index)
 		default:
 			return PCT_I;
 		}
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 	case CODEC_TYPE_H265:
 		type = preset->frames[index].frame.h265.slice_params.slice_type;
 
@@ -266,6 +277,7 @@ unsigned int frame_pct(struct preset *preset, unsigned int index)
 		default:
 			return PCT_I;
 		}
+#endif
 	default:
 		return PCT_I;
 	}
@@ -274,8 +286,10 @@ unsigned int frame_pct(struct preset *preset, unsigned int index)
 unsigned int frame_poc(struct preset *preset, unsigned int index)
 {
 	switch (preset->type) {
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 	case CODEC_TYPE_H265:
 		return preset->frames[index].frame.h265.slice_params.slice_pic_order_cnt;
+#endif
 	default:
 		return 0;
 	}

+ 4 - 0
v4l2-request-test.h

@@ -79,6 +79,7 @@ union controls {
 		struct v4l2_ctrl_mpeg2_slice_params slice_params;
 		struct v4l2_ctrl_mpeg2_quantization quantization;
 	} mpeg2;
+#ifdef V4L2_PIX_FMT_H264_SLICE
 	struct {
 		struct v4l2_ctrl_h264_decode_param decode_param;
 		struct v4l2_ctrl_h264_pps pps;
@@ -87,11 +88,14 @@ union controls {
 		struct v4l2_ctrl_h264_slice_param slice_param;
 		struct v4l2_ctrl_h264_sps sps;
 	} h264;
+#endif
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 	struct {
 		struct v4l2_ctrl_hevc_sps sps;
 		struct v4l2_ctrl_hevc_pps pps;
 		struct v4l2_ctrl_hevc_slice_params slice_params;
 	} h265;
+#endif
 };
 
 struct frame {

+ 8 - 0
v4l2.c

@@ -489,6 +489,7 @@ static int set_format_controls(int video_fd, int request_fd,
 		  V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION,
 		  &frame->mpeg2.quantization,
 		  sizeof(frame->mpeg2.quantization) },
+#ifdef V4L2_PIX_FMT_H264_SLICE
 		{ CODEC_TYPE_H264, "decode parameters",
 		  V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS,
 		  &frame->h264.decode_param, sizeof(frame->h264.decode_param) },
@@ -505,6 +506,8 @@ static int set_format_controls(int video_fd, int request_fd,
 		{ CODEC_TYPE_H264, "scaling matrix",
 		  V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS,
 		  &frame->h264.slice_param, sizeof(frame->h264.slice_param) },
+#endif
+#ifdef V4L2_PIX_FMT_HEVC_SLICE
 		{ CODEC_TYPE_H265, "sequence parameter set",
 		  V4L2_CID_MPEG_VIDEO_HEVC_SPS, &frame->h265.sps,
 		  sizeof(frame->h265.sps) },
@@ -514,6 +517,7 @@ static int set_format_controls(int video_fd, int request_fd,
 		{ CODEC_TYPE_H265, "slice parameters",
 		  V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS,
 		  &frame->h265.slice_params, sizeof(frame->h265.slice_params) },
+#endif
 	};
 	unsigned int i;
 	int rc;
@@ -539,10 +543,14 @@ static int codec_source_format(enum codec_type type)
 	switch (type) {
 	case CODEC_TYPE_MPEG2:
 		return V4L2_PIX_FMT_MPEG2_SLICE;
+#ifdef V4L2_PIX_FMT_H264_SLICE
 	case CODEC_TYPE_H264:
 		return V4L2_PIX_FMT_H264_SLICE;
+#endif
+#ifdef V4L2_PIX_FMT_H265_SLICE
 	case CODEC_TYPE_H265:
 		return V4L2_PIX_FMT_HEVC_SLICE;
+#endif
 	default:
 		fprintf(stderr, "Invalid format type\n");
 		return -1;