Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: allegro: write vui parameters for HEVC

The vui parameters are optional. However, the vui data allows to specify
the color space of the encoded video. Write the vui parameters to make
sure that decoders are able to pick up the correct color space.

Also implement the necessary lookup functions to convert the values from
the V4L2 controls to the values specified in the hevc standard.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Michael Tretter and committed by
Mauro Carvalho Chehab
b35d3fea 42fd2806

+130 -6
+47
drivers/media/platform/allegro-dvt/allegro-core.c
··· 1762 1762 struct allegro_dev *dev = channel->dev; 1763 1763 struct nal_hevc_sps *sps; 1764 1764 struct nal_hevc_profile_tier_level *ptl; 1765 + struct nal_hevc_vui_parameters *vui; 1766 + struct nal_hevc_hrd_parameters *hrd; 1765 1767 ssize_t size; 1768 + unsigned int cpb_size; 1766 1769 unsigned int num_ref_frames = channel->num_ref_idx_l0; 1767 1770 s32 profile = v4l2_ctrl_g_ctrl(channel->mpeg_video_hevc_profile); 1768 1771 s32 level = v4l2_ctrl_g_ctrl(channel->mpeg_video_hevc_level); ··· 1817 1814 1818 1815 sps->sps_temporal_mvp_enabled_flag = channel->temporal_mvp_enable; 1819 1816 sps->strong_intra_smoothing_enabled_flag = channel->max_cu_size > 4; 1817 + 1818 + sps->vui_parameters_present_flag = 1; 1819 + vui = &sps->vui; 1820 + 1821 + vui->video_signal_type_present_flag = 1; 1822 + vui->video_format = 5; /* unspecified */ 1823 + vui->video_full_range_flag = nal_hevc_full_range(channel->quantization); 1824 + vui->colour_description_present_flag = 1; 1825 + vui->colour_primaries = nal_hevc_color_primaries(channel->colorspace); 1826 + vui->transfer_characteristics = nal_hevc_transfer_characteristics(channel->colorspace, 1827 + channel->xfer_func); 1828 + vui->matrix_coeffs = nal_hevc_matrix_coeffs(channel->colorspace, channel->ycbcr_enc); 1829 + 1830 + vui->chroma_loc_info_present_flag = 1; 1831 + vui->chroma_sample_loc_type_top_field = 0; 1832 + vui->chroma_sample_loc_type_bottom_field = 0; 1833 + 1834 + vui->vui_timing_info_present_flag = 1; 1835 + vui->vui_num_units_in_tick = channel->framerate.denominator; 1836 + vui->vui_time_scale = channel->framerate.numerator; 1837 + 1838 + vui->bitstream_restriction_flag = 1; 1839 + vui->motion_vectors_over_pic_boundaries_flag = 1; 1840 + vui->restricted_ref_pic_lists_flag = 1; 1841 + vui->log2_max_mv_length_horizontal = 15; 1842 + vui->log2_max_mv_length_vertical = 15; 1843 + 1844 + vui->vui_hrd_parameters_present_flag = 1; 1845 + hrd = &vui->nal_hrd_parameters; 1846 + hrd->vcl_hrd_parameters_present_flag = 1; 1847 + 1848 + hrd->initial_cpb_removal_delay_length_minus1 = 31; 1849 + hrd->au_cpb_removal_delay_length_minus1 = 30; 1850 + hrd->dpb_output_delay_length_minus1 = 30; 1851 + 1852 + hrd->bit_rate_scale = ffs(channel->bitrate_peak) - 6; 1853 + hrd->vcl_hrd[0].bit_rate_value_minus1[0] = 1854 + (channel->bitrate_peak >> (6 + hrd->bit_rate_scale)) - 1; 1855 + 1856 + cpb_size = v4l2_ctrl_g_ctrl(channel->mpeg_video_cpb_size) * 1000; 1857 + hrd->cpb_size_scale = ffs(cpb_size) - 4; 1858 + hrd->vcl_hrd[0].cpb_size_value_minus1[0] = (cpb_size >> (4 + hrd->cpb_size_scale)) - 1; 1859 + 1860 + hrd->vcl_hrd[0].cbr_flag[0] = !v4l2_ctrl_g_ctrl(channel->mpeg_video_frame_rc_enable); 1820 1861 1821 1862 size = nal_hevc_write_sps(&dev->plat_dev->dev, dest, n, sps); 1822 1863
+83 -6
drivers/media/platform/allegro-dvt/nal-hevc.h
··· 414 414 } 415 415 } 416 416 417 - int nal_range_from_v4l2(enum v4l2_quantization quantization); 418 - int nal_color_primaries_from_v4l2(enum v4l2_colorspace colorspace); 419 - int nal_transfer_characteristics_from_v4l2(enum v4l2_colorspace colorspace, 420 - enum v4l2_xfer_func xfer_func); 421 - int nal_matrix_coeffs_from_v4l2(enum v4l2_colorspace colorspace, 422 - enum v4l2_ycbcr_encoding ycbcr_encoding); 417 + static inline int nal_hevc_full_range(enum v4l2_quantization quantization) 418 + { 419 + switch (quantization) { 420 + case V4L2_QUANTIZATION_FULL_RANGE: 421 + return 1; 422 + case V4L2_QUANTIZATION_LIM_RANGE: 423 + return 0; 424 + default: 425 + break; 426 + } 427 + 428 + return 0; 429 + } 430 + 431 + static inline int nal_hevc_color_primaries(enum v4l2_colorspace colorspace) 432 + { 433 + switch (colorspace) { 434 + case V4L2_COLORSPACE_SMPTE170M: 435 + return 6; 436 + case V4L2_COLORSPACE_SMPTE240M: 437 + return 7; 438 + case V4L2_COLORSPACE_REC709: 439 + return 1; 440 + case V4L2_COLORSPACE_470_SYSTEM_M: 441 + return 4; 442 + case V4L2_COLORSPACE_JPEG: 443 + case V4L2_COLORSPACE_SRGB: 444 + case V4L2_COLORSPACE_470_SYSTEM_BG: 445 + return 5; 446 + case V4L2_COLORSPACE_BT2020: 447 + return 9; 448 + case V4L2_COLORSPACE_DEFAULT: 449 + case V4L2_COLORSPACE_OPRGB: 450 + case V4L2_COLORSPACE_RAW: 451 + case V4L2_COLORSPACE_DCI_P3: 452 + default: 453 + return 2; 454 + } 455 + } 456 + 457 + static inline int nal_hevc_transfer_characteristics(enum v4l2_colorspace colorspace, 458 + enum v4l2_xfer_func xfer_func) 459 + { 460 + if (xfer_func == V4L2_XFER_FUNC_DEFAULT) 461 + xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(colorspace); 462 + 463 + switch (xfer_func) { 464 + case V4L2_XFER_FUNC_709: 465 + return 6; 466 + case V4L2_XFER_FUNC_SMPTE2084: 467 + return 16; 468 + case V4L2_XFER_FUNC_SRGB: 469 + case V4L2_XFER_FUNC_OPRGB: 470 + case V4L2_XFER_FUNC_NONE: 471 + case V4L2_XFER_FUNC_DCI_P3: 472 + case V4L2_XFER_FUNC_SMPTE240M: 473 + default: 474 + return 2; 475 + } 476 + } 477 + 478 + static inline int nal_hevc_matrix_coeffs(enum v4l2_colorspace colorspace, 479 + enum v4l2_ycbcr_encoding ycbcr_encoding) 480 + { 481 + if (ycbcr_encoding == V4L2_YCBCR_ENC_DEFAULT) 482 + ycbcr_encoding = V4L2_MAP_YCBCR_ENC_DEFAULT(colorspace); 483 + 484 + switch (ycbcr_encoding) { 485 + case V4L2_YCBCR_ENC_601: 486 + case V4L2_YCBCR_ENC_XV601: 487 + return 5; 488 + case V4L2_YCBCR_ENC_709: 489 + case V4L2_YCBCR_ENC_XV709: 490 + return 1; 491 + case V4L2_YCBCR_ENC_BT2020: 492 + return 9; 493 + case V4L2_YCBCR_ENC_BT2020_CONST_LUM: 494 + return 10; 495 + case V4L2_YCBCR_ENC_SMPTE240M: 496 + default: 497 + return 2; 498 + } 499 + } 423 500 424 501 ssize_t nal_hevc_write_vps(const struct device *dev, 425 502 void *dest, size_t n, struct nal_hevc_vps *vps);