amvecm: hdr: add hdr10 plus support [1/2]
authorMingLiang Dong <mingliang.dong@amlogic.com>
Mon, 22 Oct 2018 08:20:05 +0000 (04:20 -0400)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 29 Oct 2018 02:15:46 +0000 (19:15 -0700)
PD#SWPL-869

Problem:
new feature, add hdr10 plus support

Solution:
1. add hdr10 plus metadat parser
2. add hdr10 plus code support
3. add hdr10 plus bypass mode

Verify:
verify on U200

Change-Id: I957954ce148021882e17f2913dd2552e64f1298c
Signed-off-by: MingLiang Dong <mingliang.dong@amlogic.com>
MAINTAINERS
drivers/amlogic/media/enhancement/amvecm/Makefile
drivers/amlogic/media/enhancement/amvecm/amcsc.c
drivers/amlogic/media/enhancement/amvecm/amvecm.c
drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.c [new file with mode: 0644]
drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.h [new file with mode: 0644]
drivers/amlogic/media/enhancement/amvecm/set_hdr2_v0.c
include/linux/amlogic/media/amvecm/amvecm.h
include/linux/amlogic/media/vfm/vframe.h

index 621438f..6c5077b 100644 (file)
@@ -13916,6 +13916,7 @@ F:      drivers/amlogic/media/enhancement/amvecm/dolby_vision/*
 F:     drivers/amlogic/media/enhancement/amvecm/arch/*
 F:     drivers/amlogic/media/enhancement/amvecm/dnlp_algorithm/*
 F:     include/linux/amlogic/media/amvecm/*
+F:     drivers/amlogic/media/enhancement/amvecm/hdr/*
 
 AMLOGIC GXL ADD SKT DTS
 M: Yun Cai <yun.cai@amlogic.com>
index 6044879..60740de 100644 (file)
@@ -4,4 +4,5 @@
 
 obj-$(CONFIG_AMLOGIC_MEDIA_ENHANCEMENT_VECM) += am_vecm.o
 am_vecm-objs := amve.o amcm.o amcsc.o amvecm.o keystone_correction.o bitdepth.o set_hdr2_v0.o dnlp_cal.o cm2_adj.o vlock.o
+am_vecm-objs += hdr/am_hdr10_plus.o
 
index b43eca6..fc4ae4b 100644 (file)
@@ -39,6 +39,7 @@
 #include "amcsc.h"
 #include "set_hdr2_v0.h"
 #include <linux/amlogic/media/amdolbyvision/dolby_vision.h>
+#include "hdr/am_hdr10_plus.h"
 
 #define pr_csc(fmt, args...)\
        do {\
@@ -323,6 +324,12 @@ static uint cur_hdr_process_mode = 2; /* 0: hdr->hdr, 1:hdr->sdr */
 module_param(hdr_process_mode, uint, 0444);
 MODULE_PARM_DESC(hdr_process_mode, "\n current hdr_process_mode\n");
 
+static uint hdr10_plus_process_mode; /* 0: bypass, 1:hdr10p->sdr */
+static uint cur_hdr10_plus_process_mode = 2; /* 0: bypass, 1:hdr10p->sdr */
+
+/* 0: tx don't support hdr10+, 1: tx support hdr10+*/
+static uint tx_hdr10_plus_support;
+
 /* 0: hlg->hlg, 1:hlg->hdr*/
 static uint hlg_process_mode = 1;
 /* 0: hdr->hdr, 1:hdr->sdr 2:hlg->hdr*/
@@ -3361,6 +3368,7 @@ static struct vframe_master_display_colour_s cur_master_display_colour = {
 #define SIG_HLG_SUPPORT        0x100
 #define SIG_OP_CHG     0x200
 #define SIG_SRC_OUTPUT_CHG     0x400/*for box*/
+#define SIG_HDR10_PLUS_MODE    0x800
 
 unsigned int pre_vd1_mtx_sel = VPP_MATRIX_NULL;
 module_param(pre_vd1_mtx_sel, uint, 0664);
@@ -3606,6 +3614,12 @@ int signal_type_changed(struct vframe_s *vf, struct vinfo_s *vinfo)
                cur_hlg_support = vinfo->hdr_info.hdr_support & 0x8;
        }
 
+       if (cur_hdr10_plus_process_mode != hdr10_plus_process_mode) {
+               pr_csc("HDR10 plus mode changed.\n");
+               change_flag |= SIG_HDR10_PLUS_MODE;
+               cur_hdr10_plus_process_mode = hdr10_plus_process_mode;
+       }
+
        if ((cur_eye_protect_mode != wb_val[0]) ||
                (cur_eye_protect_mode == 1)) {
                pr_csc(" eye protect mode changed.\n");
@@ -3638,7 +3652,7 @@ enum vpp_matrix_csc_e get_csc_type(void)
                else
                        csc_type = VPP_MATRIX_YUV601F_RGB;
        } else if ((signal_color_primaries == 9) ||
-                       (signal_transfer_characteristic == 16)) {
+                       (signal_transfer_characteristic >= 14)) {
                if (signal_transfer_characteristic == 16) {
                        /* smpte st-2084 */
                        if (signal_color_primaries != 9)
@@ -3659,6 +3673,9 @@ enum vpp_matrix_csc_e get_csc_type(void)
                        /* bt2020-12 */
                        pr_csc("\tWARNING: HLG!!!\n");
                        csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB;
+               } else if (signal_transfer_characteristic == 0x30) {
+                       pr_csc("\tWARNING: HDR10 PLUS!!!\n");
+                       csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC;
                } else {
                        /* unknown transfer characteristic */
                        pr_csc("\tWARNING: unknown HDR!!!\n");
@@ -5831,24 +5848,16 @@ static int vpp_eye_protection_process(
        return 0;
 }
 
-static int vpp_matrix_update(
-       struct vframe_s *vf, struct vinfo_s *vinfo, int flags)
+static void hdr_support_process(struct vinfo_s *vinfo)
 {
-       enum vpp_matrix_csc_e csc_type = VPP_MATRIX_NULL;
-       int signal_change_flag = 0;
-       struct vframe_master_display_colour_s *p = &cur_master_display_colour;
-       struct master_display_info_s send_info;
-       int need_adjust_contrast_saturation = 0;
-       int hdmi_scs_type_changed = 0;
-       struct vout_device_s *vdev = NULL;
-
-       if (vinfo == NULL)
-               return 0;
-       if (vinfo->vout_device)
-               vdev = vinfo->vout_device;
-       /* Tx hdr information */
-       memcpy(&receiver_hdr_info, &vinfo->hdr_info,
-                       sizeof(struct hdr_info));
+       /*check if hdmitx support hdr10+*/
+       if ((vinfo->hdr_info.hdr10plus_info.ieeeoui
+                       == HDR_PLUS_IEEE_OUI) &&
+               (vinfo->hdr_info.hdr10plus_info.application_version
+                       == 1))
+               tx_hdr10_plus_support = 1;
+       else
+               tx_hdr10_plus_support = 0;
 
        /* check hdr support info from Tx or Panel */
        if (hdr_mode == 2) { /* auto */
@@ -5873,9 +5882,15 @@ static int vpp_matrix_update(
                        hdr_process_mode = 1;
                        hlg_process_mode = 1;
                }
+
+               if (tx_hdr10_plus_support)
+                       hdr10_plus_process_mode = 0;
+               else
+                       hdr10_plus_process_mode = 1;
        } else if (hdr_mode == 1) {
                hdr_process_mode = 1;
                hlg_process_mode = 1;
+               hdr10_plus_process_mode = 1;
        } else {
                hdr_process_mode = 0;
                if (vinfo->hdr_info.hdr_support & HDR_SUPPORT) {
@@ -5886,6 +5901,8 @@ static int vpp_matrix_update(
                                hlg_process_mode = 1;
                } else
                        hlg_process_mode = 0;
+
+               hdr10_plus_process_mode = 0;
        }
 
        if (sdr_mode == 2) { /* auto */
@@ -5904,18 +5921,44 @@ static int vpp_matrix_update(
        } else
                sdr_process_mode = sdr_mode; /* force sdr->hdr */
 
-       if (vf && vinfo)
-               signal_change_flag = signal_type_changed(vf, vinfo);
+}
 
-       if (force_csc_type != 0xff)
-               csc_type = force_csc_type;
-       else
-               csc_type = get_csc_type();
+static void hdr10_plus_metadata_update(struct vframe_s *vf,
+       enum vpp_matrix_csc_e csc_type,
+       struct hdr10plus_para *hdmitx_hdr10plus_param)
+{
+       if (!vf)
+               return;
+       if (csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC)
+               return;
+
+       hdr10_plus_parser_metadata(vf);
+
+       if (tx_hdr10_plus_support)
+               hdr10_plus_hdmitx_vsif_parser(hdmitx_hdr10plus_param);
+}
+
+static void hdr_tx_pkt_cb(
+       struct vinfo_s *vinfo,
+       int signal_change_flag,
+       enum vpp_matrix_csc_e csc_type,
+       struct vframe_master_display_colour_s *p,
+       int *hdmi_scs_type_changed,
+       struct hdr10plus_para *hdmitx_hdr10plus_param)
+{
+       struct vout_device_s *vdev = NULL;
+       struct master_display_info_s send_info;
+
+       if (vinfo->vout_device)
+               vdev = vinfo->vout_device;
 
        if ((vinfo->viu_color_fmt != COLOR_FMT_RGB444) &&
                ((vinfo->hdr_info.hdr_support & 0xc) ||
                (signal_change_flag & SIG_HDR_SUPPORT) ||
-               (signal_change_flag & SIG_HLG_SUPPORT))) {
+               (signal_change_flag & SIG_HLG_SUPPORT) ||
+               /*hdr10 plus*/
+               (tx_hdr10_plus_support) ||
+               (signal_change_flag & SIG_HDR10_PLUS_MODE))) {
                if (sdr_process_mode &&
                        (csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB)) {
                        /* sdr source convert to hdr */
@@ -5937,11 +5980,11 @@ static int vpp_matrix_update(
                        }
                        if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) {
                                hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB;
-                               hdmi_scs_type_changed = 1;
+                               *hdmi_scs_type_changed = 1;
                        }
                } else if ((hdr_process_mode == 0) &&
                        (hlg_process_mode == 0) &&
-                       (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       (csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB)) {
                        /* source is hdr, send hdr info */
                        /* use the features to discribe source info */
                        send_info.features =
@@ -5962,11 +6005,11 @@ static int vpp_matrix_update(
                        }
                        if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) {
                                hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB;
-                               hdmi_scs_type_changed = 1;
+                               *hdmi_scs_type_changed = 1;
                        }
                } else if ((hdr_process_mode == 0) &&
                        (hlg_process_mode == 1) &&
-                       (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       (csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB)) {
                        /* source is hdr, send hdr info */
                        /* use the features to discribe source info */
                        if (get_hdr_type() & HLG_FLAG)
@@ -6000,11 +6043,11 @@ static int vpp_matrix_update(
                        }
                        if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) {
                                hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB;
-                               hdmi_scs_type_changed = 1;
+                               *hdmi_scs_type_changed = 1;
                        }
                } else if ((hdr_process_mode == 1) &&
                        (hlg_process_mode == 0) &&
-                       (csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       (csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB)) {
                        /* source is hdr, send hdr info */
                        /* use the features to discribe source info */
                        if (get_hdr_type() & HLG_FLAG)
@@ -6037,7 +6080,15 @@ static int vpp_matrix_update(
                        }
                        if (hdmi_csc_type != VPP_MATRIX_BT2020YUV_BT2020RGB) {
                                hdmi_csc_type = VPP_MATRIX_BT2020YUV_BT2020RGB;
-                               hdmi_scs_type_changed = 1;
+                               *hdmi_scs_type_changed = 1;
+                       }
+               } else if ((hdr10_plus_process_mode == 0) &&
+                       (csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC)) {
+                       /*source is hdr10 plus, send hdr10 plus info*/
+                       if (vdev) {
+                               if (vdev->fresh_tx_hdr10plus_pkt)
+                                       vdev->fresh_tx_hdr10plus_pkt(1,
+                                               hdmitx_hdr10plus_param);
                        }
                } else {
                        /* sdr source send normal info*/
@@ -6068,199 +6119,211 @@ static int vpp_matrix_update(
                                        | (1 << 8)      /* bt709 */
                                        | (1 << 0);     /* bt709 */
                        amvecm_cp_hdr_info(&send_info, p);
-                       if (vdev) {
-                               if (vdev->fresh_tx_hdr_pkt)
-                                       vdev->fresh_tx_hdr_pkt(&send_info);
+                       if (cur_csc_type <= VPP_MATRIX_BT2020YUV_BT2020RGB) {
+                               if (vdev) {
+                                       if (vdev->fresh_tx_hdr_pkt)
+                                               vdev->fresh_tx_hdr_pkt(
+                                                       &send_info);
+                               }
+                       } else if (cur_csc_type ==
+                               VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC)
+                               if (vdev) {
+                                       if (vdev->fresh_tx_hdr10plus_pkt)
+                                               vdev->fresh_tx_hdr10plus_pkt(0,
+                                                       hdmitx_hdr10plus_param);
                        }
+
                        if (hdmi_csc_type != VPP_MATRIX_YUV709_RGB) {
                                hdmi_csc_type = VPP_MATRIX_YUV709_RGB;
-                               hdmi_scs_type_changed = 1;
+                               *hdmi_scs_type_changed = 1;
                        }
                }
        }
+}
 
-       if (hdmi_scs_type_changed &&
-               (flags & CSC_FLAG_CHECK_OUTPUT) &&
-               csc_en & 0x10)
-               return 1;
-
-       if (((!signal_change_flag) && (force_csc_type == 0xff))
-               && ((flags & CSC_FLAG_TOGGLE_FRAME) == 0))
-               return 0;
-
-       vecm_latch_flag |= FLAG_MATRIX_UPDATE;
+static void video_process(
+       struct vframe_s *vf,
+       enum vpp_matrix_csc_e csc_type,
+       int signal_change_flag,
+       struct vinfo_s *vinfo,
+       struct vframe_master_display_colour_s *p)
+{
+       int need_adjust_contrast_saturation = 0;
 
-       if ((cur_csc_type != csc_type)
-       || (signal_change_flag
-       & (SIG_CS_CHG | SIG_PRI_INFO | SIG_KNEE_FACTOR | SIG_HDR_MODE |
-               SIG_HDR_SUPPORT | SIG_HLG_MODE | SIG_OP_CHG |
-               SIG_SRC_OUTPUT_CHG))) {
-               /* decided by edid or panel info or user setting */
-               if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
-                       (hdr_process_mode == 1) &&
-                       (hlg_process_mode == 1)) {
-                       /* hdr->sdr hlg->sdr */
-                       if ((signal_change_flag &
-                                       (SIG_CS_CHG |
-                                       SIG_PRI_INFO |
-                                       SIG_KNEE_FACTOR |
-                                       SIG_HDR_MODE |
-                                       SIG_HDR_SUPPORT |
-                                       SIG_HLG_MODE)
-                               ) ||
-                               (cur_csc_type <
-                                       VPP_MATRIX_BT2020YUV_BT2020RGB)) {
-                               if (get_hdr_type() & HLG_FLAG)
-                                       need_adjust_contrast_saturation =
-                                               hlg_process(csc_type, vinfo, p);
-                               else
-                                       need_adjust_contrast_saturation
-                                       = hdr_process(csc_type, vinfo, p);
-                               pr_csc("hdr_process_mode = 0x%x\n"
-                                       "hlg_process_mode = 0x%x.\n",
-                               hdr_process_mode, hlg_process_mode);
-                       }
-               } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
-                       (hdr_process_mode == 0) &&
-                       (hlg_process_mode == 1)) {
-                       /* hdr->hdr hlg->hlg*/
-                       if ((signal_change_flag &
-                                       (SIG_CS_CHG |
-                                       SIG_PRI_INFO |
-                                       SIG_KNEE_FACTOR |
-                                       SIG_HDR_MODE |
-                                       SIG_HDR_SUPPORT |
-                                       SIG_HLG_MODE)
-                               ) ||
-                               (cur_csc_type <
-                                       VPP_MATRIX_BT2020YUV_BT2020RGB)) {
-                               if (get_hdr_type() & HLG_FLAG)
-                                       hlg_hdr_process(csc_type, vinfo, p);
-                               else
-                                       bypass_hdr_process(csc_type, vinfo, p);
-                               pr_csc("hdr_process_mode = 0x%x\n"
-                                       "hlg_process_mode = 0x%x.\n",
-                                       hdr_process_mode, hlg_process_mode);
-                       }
-               } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
-                       (hdr_process_mode == 1) && (hlg_process_mode == 0)) {
-                       /* hdr->sdr hlg->hlg*/
-                       if ((signal_change_flag &
-                                       (SIG_CS_CHG |
-                                       SIG_PRI_INFO |
-                                       SIG_KNEE_FACTOR |
-                                       SIG_HDR_MODE |
-                                       SIG_HDR_SUPPORT |
-                                       SIG_HLG_MODE)
-                               ) ||
-                               (cur_csc_type <
-                                       VPP_MATRIX_BT2020YUV_BT2020RGB)) {
-                               if (get_hdr_type() & HLG_FLAG)
-                                       bypass_hdr_process(csc_type, vinfo, p);
-                               else
-                                       need_adjust_contrast_saturation =
-                                               hdr_process(csc_type, vinfo, p);
-                               pr_csc("hdr_process_mode = 0x%x\n"
-                                       "hlg_process_mode = 0x%x.\n",
-                                       hdr_process_mode, hlg_process_mode);
-                       }
-               } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
-                       (hdr_process_mode == 0) && (hlg_process_mode == 0)) {
-                       /* hdr->hdr hlg->hlg*/
-                       if ((signal_change_flag &
+       /* decided by edid or panel info or user setting */
+       if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+               (hdr_process_mode == 1) &&
+               (hlg_process_mode == 1)) {
+               /* hdr->sdr hlg->sdr */
+               if ((signal_change_flag &
                                (SIG_CS_CHG |
                                SIG_PRI_INFO |
                                SIG_KNEE_FACTOR |
                                SIG_HDR_MODE |
                                SIG_HDR_SUPPORT |
-                               SIG_HLG_MODE)) ||
-                               (cur_csc_type <
-                                       VPP_MATRIX_BT2020YUV_BT2020RGB)) {
-                               bypass_hdr_process(csc_type, vinfo, p);
-                               pr_csc("bypass_hdr_process: 0x%x, 0x%x.\n",
-                                       hdr_process_mode, hlg_process_mode);
-                       }
-               } else {
-                       if ((csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB) &&
-                               sdr_process_mode)
-                               /* for gxl and gxm SDR to HDR process */
-                                       sdr_hdr_process(csc_type, vinfo, p);
-                       else {
-                               /* for gxtvbb and gxl HDR bypass process */
-                               if (((vinfo->hdr_info.hdr_support &
-                                       HDR_SUPPORT) ||
-                                       (vinfo->hdr_info.hdr_support &
-                                       HLG_SUPPORT)) &&
-                                       (csc_type <
-                                       VPP_MATRIX_BT2020YUV_BT2020RGB)
-                                       && tx_op_color_primary)
-                                       set_bt2020csc_process(csc_type,
-                                       vinfo, p);
-                               else
-                                       bypass_hdr_process(csc_type,
-                                       vinfo, p);
-                               pr_csc("csc_type = 0x%x\n"
-                                       "sdr_process_mode = 0x%x.\n",
-                                       csc_type, sdr_process_mode);
-                       }
-               }
-
-               if (get_cpu_type() >= MESON_CPU_MAJOR_ID_G12A) {
-                       if (vinfo->viu_color_fmt != COLOR_FMT_RGB444)
-                               mtx_setting(POST2_MTX, MATRIX_NULL, MTX_OFF);
+                               SIG_HLG_MODE)
+                       ) ||
+                       (cur_csc_type <
+                               VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       if (get_hdr_type() & HLG_FLAG)
+                               need_adjust_contrast_saturation =
+                                       hlg_process(csc_type, vinfo, p);
                        else
-                               mtx_setting(POST2_MTX,
-                                       MATRIX_YUV709_RGB, MTX_ON);
-               }
-
-               if (cur_hdr_process_mode != hdr_process_mode) {
-                       cur_hdr_process_mode = hdr_process_mode;
-                       pr_csc("hdr_process_mode changed to %d",
-                               hdr_process_mode);
+                               need_adjust_contrast_saturation
+                               = hdr_process(csc_type, vinfo, p);
+                       pr_csc("hdr_process_mode = 0x%x\n"
+                               "hlg_process_mode = 0x%x.\n",
+                       hdr_process_mode, hlg_process_mode);
                }
-               if (cur_sdr_process_mode != sdr_process_mode) {
-                       cur_sdr_process_mode = sdr_process_mode;
-                       pr_csc("sdr_process_mode changed to %d",
-                               sdr_process_mode);
-               }
-               if (cur_hlg_process_mode != hlg_process_mode) {
-                       cur_hlg_process_mode = hlg_process_mode;
-                       pr_csc("hlg_process_mode changed to %d",
-                               hlg_process_mode);
+       } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+               (hdr_process_mode == 0) &&
+               (hlg_process_mode == 1)) {
+               /* hdr->hdr hlg->hlg*/
+               if ((signal_change_flag &
+                               (SIG_CS_CHG |
+                               SIG_PRI_INFO |
+                               SIG_KNEE_FACTOR |
+                               SIG_HDR_MODE |
+                               SIG_HDR_SUPPORT |
+                               SIG_HLG_MODE)
+                       ) ||
+                       (cur_csc_type <
+                               VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       if (get_hdr_type() & HLG_FLAG)
+                               hlg_hdr_process(csc_type, vinfo, p);
+                       else
+                               bypass_hdr_process(csc_type, vinfo, p);
+                       pr_csc("hdr_process_mode = 0x%x\n"
+                               "hlg_process_mode = 0x%x.\n",
+                               hdr_process_mode, hlg_process_mode);
                }
-               if (need_adjust_contrast_saturation & 1) {
-                       if (lut_289_en &&
-                               (get_cpu_type() <= MESON_CPU_MAJOR_ID_GXTVBB))
-                               vd1_contrast_offset = 0;
+       } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+               (hdr_process_mode == 1) && (hlg_process_mode == 0)) {
+               /* hdr->sdr hlg->hlg*/
+               if ((signal_change_flag &
+                               (SIG_CS_CHG |
+                               SIG_PRI_INFO |
+                               SIG_KNEE_FACTOR |
+                               SIG_HDR_MODE |
+                               SIG_HDR_SUPPORT |
+                               SIG_HLG_MODE)
+                       ) ||
+                       (cur_csc_type <
+                               VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       if (get_hdr_type() & HLG_FLAG)
+                               bypass_hdr_process(csc_type, vinfo, p);
                        else
-                               vd1_contrast_offset =
-                               calculate_contrast_adj(p->luminance[0] / 10000);
-                       vecm_latch_flag |= FLAG_VADJ1_CON;
-               } else {
-                       vd1_contrast_offset = 0;
-                       vecm_latch_flag |= FLAG_VADJ1_CON;
+                               need_adjust_contrast_saturation =
+                                       hdr_process(csc_type, vinfo, p);
+                       pr_csc("hdr_process_mode = 0x%x\n"
+                               "hlg_process_mode = 0x%x.\n",
+                               hdr_process_mode, hlg_process_mode);
                }
-               if (need_adjust_contrast_saturation & 2) {
-                       vecm_latch_flag |= FLAG_VADJ1_COLOR;
-               } else {
-                       if (((get_cpu_type() == MESON_CPU_MAJOR_ID_GXTVBB) ||
-                               (get_cpu_type() == MESON_CPU_MAJOR_ID_TXL)) &&
-                               (sdr_process_mode == 1))
-                               saturation_offset = sdr_saturation_offset;
+       } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+               (hdr_process_mode == 0) && (hlg_process_mode == 0)) {
+               /* hdr->hdr hlg->hlg*/
+               if ((signal_change_flag &
+                       (SIG_CS_CHG |
+                       SIG_PRI_INFO |
+                       SIG_KNEE_FACTOR |
+                       SIG_HDR_MODE |
+                       SIG_HDR_SUPPORT |
+                       SIG_HLG_MODE)) ||
+                       (cur_csc_type <
+                               VPP_MATRIX_BT2020YUV_BT2020RGB)) {
+                       bypass_hdr_process(csc_type, vinfo, p);
+                       pr_csc("bypass_hdr_process: 0x%x, 0x%x.\n",
+                               hdr_process_mode, hlg_process_mode);
+               }
+       } else if ((csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC) &&
+               (hdr10_plus_process_mode == 1)) {
+               if ((signal_change_flag & SIG_HDR10_PLUS_MODE) ||
+                       (cur_csc_type !=
+                       VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC))
+                       hdr10_plus_process(vf);
+               pr_csc("hdr10_plus_process.\n");
+       } else {
+               if ((csc_type < VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+                       sdr_process_mode)
+                       /* for gxl and gxm SDR to HDR process */
+                       sdr_hdr_process(csc_type, vinfo, p);
+               else {
+                       /* for gxtvbb and gxl HDR bypass process */
+                       if (((vinfo->hdr_info.hdr_support &
+                               HDR_SUPPORT) ||
+                               (vinfo->hdr_info.hdr_support &
+                               HLG_SUPPORT)) &&
+                               (csc_type <
+                               VPP_MATRIX_BT2020YUV_BT2020RGB)
+                               && tx_op_color_primary)
+                               set_bt2020csc_process(csc_type,
+                               vinfo, p);
                        else
-                               saturation_offset =     0;
-                       vecm_latch_flag |= FLAG_VADJ1_COLOR;
+                               bypass_hdr_process(csc_type,
+                               vinfo, p);
+                       pr_csc("csc_type = 0x%x\n"
+                               "sdr_process_mode = 0x%x.\n",
+                               csc_type, sdr_process_mode);
                }
-               if (cur_csc_type != csc_type) {
-                       pr_csc("CSC from 0x%x to 0x%x.\n",
-                               cur_csc_type, csc_type);
-                       pr_csc("contrast offset = %d.\n",
-                               vd1_contrast_offset);
-                       pr_csc("saturation offset = %d.\n",
-                               saturation_offset);
-                       cur_csc_type = csc_type;
-
-                       if ((cur_csc_type >= VPP_MATRIX_BT2020YUV_BT2020RGB) &&
+       }
+
+       if (get_cpu_type() >= MESON_CPU_MAJOR_ID_G12A) {
+               if (vinfo->viu_color_fmt != COLOR_FMT_RGB444)
+                       mtx_setting(POST2_MTX, MATRIX_NULL, MTX_OFF);
+               else
+                       mtx_setting(POST2_MTX,
+                               MATRIX_YUV709_RGB, MTX_ON);
+       }
+
+       if (cur_hdr_process_mode != hdr_process_mode) {
+               cur_hdr_process_mode = hdr_process_mode;
+               pr_csc("hdr_process_mode changed to %d",
+                       hdr_process_mode);
+       }
+       if (cur_sdr_process_mode != sdr_process_mode) {
+               cur_sdr_process_mode = sdr_process_mode;
+               pr_csc("sdr_process_mode changed to %d",
+                       sdr_process_mode);
+       }
+       if (cur_hlg_process_mode != hlg_process_mode) {
+               cur_hlg_process_mode = hlg_process_mode;
+               pr_csc("hlg_process_mode changed to %d",
+                       hlg_process_mode);
+       }
+       if (need_adjust_contrast_saturation & 1) {
+               if (lut_289_en &&
+                       (get_cpu_type() <= MESON_CPU_MAJOR_ID_GXTVBB))
+                       vd1_contrast_offset = 0;
+               else
+                       vd1_contrast_offset =
+                       calculate_contrast_adj(p->luminance[0] / 10000);
+               vecm_latch_flag |= FLAG_VADJ1_CON;
+       } else {
+               vd1_contrast_offset = 0;
+               vecm_latch_flag |= FLAG_VADJ1_CON;
+       }
+       if (need_adjust_contrast_saturation & 2) {
+               vecm_latch_flag |= FLAG_VADJ1_COLOR;
+       } else {
+               if (((get_cpu_type() == MESON_CPU_MAJOR_ID_GXTVBB) ||
+                       (get_cpu_type() == MESON_CPU_MAJOR_ID_TXL)) &&
+                       (sdr_process_mode == 1))
+                       saturation_offset = sdr_saturation_offset;
+               else
+                       saturation_offset = 0;
+               vecm_latch_flag |= FLAG_VADJ1_COLOR;
+       }
+       if (cur_csc_type != csc_type) {
+               pr_csc("CSC from 0x%x to 0x%x.\n",
+                       cur_csc_type, csc_type);
+               pr_csc("contrast offset = %d.\n",
+                       vd1_contrast_offset);
+               pr_csc("saturation offset = %d.\n",
+                       saturation_offset);
+               cur_csc_type = csc_type;
+
+               if (vf) {
+                       if ((cur_csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB) &&
                                (cur_csc_type != 0xffff) &&
                                (vf->source_type == VFRAME_SOURCE_TYPE_HDMI)) {
                                amvecm_wakeup_queue();
@@ -6268,12 +6331,64 @@ static int vpp_matrix_update(
                        }
                }
        }
+}
+
+static int vpp_matrix_update(
+       struct vframe_s *vf, struct vinfo_s *vinfo, int flags)
+{
+       enum vpp_matrix_csc_e csc_type = VPP_MATRIX_NULL;
+       int signal_change_flag = 0;
+       struct vframe_master_display_colour_s *p = &cur_master_display_colour;
+       int hdmi_scs_type_changed = 0;
+       struct hdr10plus_para hdmitx_hdr10plus_param;
+
+       if (vinfo == NULL)
+               return 0;
+
+       /* Tx hdr information */
+       memcpy(&receiver_hdr_info, &vinfo->hdr_info,
+                       sizeof(struct hdr_info));
+
+       hdr_support_process(vinfo);
+
+       if (vf && vinfo)
+               signal_change_flag = signal_type_changed(vf, vinfo);
+
+       if (force_csc_type != 0xff)
+               csc_type = force_csc_type;
+       else
+               csc_type = get_csc_type();
+
+       hdr10_plus_metadata_update(vf, csc_type,
+               &hdmitx_hdr10plus_param);
+
+       hdr_tx_pkt_cb(vinfo,
+               signal_change_flag,
+               csc_type,
+               p,
+               &hdmi_scs_type_changed,
+               &hdmitx_hdr10plus_param);
+
+       if (hdmi_scs_type_changed &&
+               (flags & CSC_FLAG_CHECK_OUTPUT) &&
+               csc_en & 0x10)
+               return 1;
+
+       if (((!signal_change_flag) && (force_csc_type == 0xff))
+               && ((flags & CSC_FLAG_TOGGLE_FRAME) == 0))
+               return 0;
+
+       if ((cur_csc_type != csc_type)
+       || (signal_change_flag
+       & (SIG_CS_CHG | SIG_PRI_INFO | SIG_KNEE_FACTOR | SIG_HDR_MODE |
+               SIG_HDR_SUPPORT | SIG_HLG_MODE | SIG_OP_CHG |
+               SIG_SRC_OUTPUT_CHG | SIG_HDR10_PLUS_MODE)))
+               video_process(vf, csc_type, signal_change_flag, vinfo, p);
 
        /* eye protection mode */
        if (signal_change_flag & SIG_WB_CHG)
                vpp_eye_protection_process(csc_type, vinfo);
 
-       vecm_latch_flag &= ~FLAG_MATRIX_UPDATE;
        return 0;
 }
 
@@ -6534,6 +6649,13 @@ hdr_dump:
        pr_err("knee_lut_on:0x%x,knee_interpolation_mode:0x%x,cur_knee_factor:0x%x\n",
                knee_lut_on, knee_interpolation_mode, cur_knee_factor);
 
+       pr_err("tx_hdr10_plus_support = 0x%x\n", tx_hdr10_plus_support);
+       pr_err("hdr10_plus_process_mode = 0x%x\n", hdr10_plus_process_mode);
+
+       //if (signal_transfer_characteristic == 0x30)
+       if (cur_csc_type == VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC)
+               hdr10_plus_debug();
+
        if ((receiver_hdr_info.hdr_support & 0xc) == 0)
                goto dbg_end;
        pr_err("----TV EDID info----\n");
index 11f966b..1a8ba0a 100644 (file)
@@ -59,6 +59,7 @@
 #include <linux/amlogic/media/amdolbyvision/dolby_vision.h>
 #include "dnlp_cal.h"
 #include "vlock.h"
+#include "hdr/am_hdr10_plus.h"
 
 #define pr_amvecm_dbg(fmt, args...)\
        do {\
@@ -3239,7 +3240,26 @@ static ssize_t amvecm_hdr_dbg_store(struct class *cla,
                        struct class_attribute *attr,
                        const char *buf, size_t count)
 {
-       return 0;
+       long val = 0;
+       char *buf_orig, *parm[5] = {NULL};
+
+       if (!buf)
+               return count;
+       buf_orig = kstrdup(buf, GFP_KERNEL);
+       parse_param_amvecm(buf_orig, (char **)&parm);
+
+       if (!strncmp(parm[0], "hdr_dbg", 10)) {
+               if (kstrtoul(parm[1], 16, &val) < 0) {
+                       kfree(buf_orig);
+                       return -EINVAL;
+               }
+               debug_hdr = val;
+               pr_info("debug_hdr=0x%x\n", debug_hdr);
+       } else
+               pr_info("error cmd\n");
+
+       kfree(buf_orig);
+       return count;
 }
 
 static ssize_t amvecm_hdr_reg_show(struct class *cla,
diff --git a/drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.c b/drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.c
new file mode 100644 (file)
index 0000000..ec9fbeb
--- /dev/null
@@ -0,0 +1,785 @@
+/*
+ * drivers/amlogic/media/enhancement/amvecm/amcsc.c
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+/* Standard Linux headers */
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/amlogic/media/vout/vout_notify.h>
+#include <linux/amlogic/media/vfm/vframe_provider.h>
+#include <linux/amlogic/media/vfm/vframe_receiver.h>
+
+#include "am_hdr10_plus.h"
+
+uint debug_hdr;
+#define pr_hdr(fmt, args...)\
+       do {\
+               if (debug_hdr)\
+                       pr_info(fmt, ## args);\
+       } while (0)
+
+#define HDR10_PLUS_VERSION  "hdr10_plus v1_20181024"
+
+struct hdr_plus_bits_s sei_md_bits = {
+       .len_itu_t_t35_country_code = 8,
+       .len_itu_t_t35_terminal_provider_code = 16,
+       .len_itu_t_t35_terminal_provider_oriented_code = 16,
+       .len_application_identifier = 8,
+       .len_application_version = 8,
+       .len_num_windows = 2,
+       .len_window_upper_left_corner_x = 16,
+       .len_window_upper_left_corner_y = 16,
+       .len_window_lower_right_corner_x = 16,
+       .len_window_lower_right_corner_y = 16,
+       .len_center_of_ellipse_x = 16,
+       .len_center_of_ellipse_y = 16,
+       .len_rotation_angle = 8,
+       .len_semimajor_axis_internal_ellipse = 16,
+       .len_semimajor_axis_external_ellipse = 16,
+       .len_semiminor_axis_external_ellipse = 16,
+       .len_overlap_process_option = 1,
+       .len_tgt_sys_disp_max_lumi = 27,
+       .len_tgt_sys_disp_act_pk_lumi_flag = 1,
+       .len_num_rows_tgt_sys_disp_act_pk_lumi = 5,
+       .len_num_cols_tgt_sys_disp_act_pk_lumi = 5,
+       .len_tgt_sys_disp_act_pk_lumi = 4,
+       .len_maxscl = 17,
+       .len_average_maxrgb = 17,
+       .len_num_distribution_maxrgb_percentiles = 4,
+       .len_distribution_maxrgb_percentages = 7,
+       .len_distribution_maxrgb_percentiles = 17,
+       .len_fraction_bright_pixels = 10,
+       .len_mast_disp_act_pk_lumi_flag = 1,
+       .len_num_rows_mast_disp_act_pk_lumi = 5,
+       .len_num_cols_mast_disp_act_pk_lumi = 5,
+       .len_mast_disp_act_pk_lumi = 4,
+       .len_tone_mapping_flag = 1,
+       .len_knee_point_x = 12,
+       .len_knee_point_y = 12,
+       .len_num_bezier_curve_anchors = 4,
+       .len_bezier_curve_anchors = 10,
+       .len_color_saturation_mapping_flag = 1,
+       .len_color_saturation_weight = 6
+};
+
+struct vframe_hdr_plus_sei_s hdr_plus_sei;
+#define NAL_UNIT_SEI 39
+#define NAL_UNIT_SEI_SUFFIX 40
+
+int GetBits(char buffer[], int totbitoffset, int *info, int bytecount,
+       int numbits)
+{
+       int inf;
+       int  bitoffset  = (totbitoffset & 0x07);/*bit from start of byte*/
+       long byteoffset = (totbitoffset >> 3);/*byte from start of buffer*/
+       int  bitcounter = numbits;
+       static char *curbyte;
+
+       if ((byteoffset) + ((numbits + bitoffset) >> 3) > bytecount)
+               return -1;
+
+       curbyte = &(buffer[byteoffset]);
+       bitoffset = 7 - bitoffset;
+       inf = 0;
+
+       while (numbits--) {
+               inf <<= 1;
+               inf |= ((*curbyte) >> (bitoffset--)) & 0x01;
+
+               if (bitoffset < 0) {
+                       curbyte++;
+                       bitoffset = 7;
+               }
+       /*curbyte   -= (bitoffset >> 3);*/
+       /*bitoffset &= 0x07;*/
+       /*curbyte   += (bitoffset == 7);*/
+       }
+
+       *info = inf;
+       return bitcounter;
+}
+
+void parser_hdr10_plus_medata(char *metadata, uint32_t size)
+{
+       int totbitoffset = 0;
+       int value = 0;
+       int i = 0;
+       int j = 0;
+       int num_win;
+       unsigned int num_col_tsdapl = 0, num_row_tsdapl = 0;
+       unsigned int tar_sys_disp_act_pk_lumi_flag = 0;
+       unsigned int num_d_m_p = 0;
+       unsigned int m_d_a_p_l_flag = 0;
+       unsigned int num_row_m_d_a_p_l = 0, num_col_m_d_a_p_l = 0;
+       unsigned int tone_mapping_flag = 0;
+       unsigned int num_bezier_curve_anchors = 0;
+       unsigned int color_saturation_mapping_flag = 0;
+
+       GetBits(metadata, totbitoffset,
+               &value, size, sei_md_bits.len_itu_t_t35_country_code);
+       hdr_plus_sei.itu_t_t35_country_code = (u16)value;
+       totbitoffset += sei_md_bits.len_itu_t_t35_country_code;
+
+       GetBits(metadata, totbitoffset,
+               &value, size, sei_md_bits.len_itu_t_t35_terminal_provider_code);
+       hdr_plus_sei.itu_t_t35_terminal_provider_code = (u16)value;
+       totbitoffset += sei_md_bits.len_itu_t_t35_terminal_provider_code;
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_itu_t_t35_terminal_provider_oriented_code);
+       hdr_plus_sei.itu_t_t35_terminal_provider_oriented_code =
+               (u16)value;
+       totbitoffset +=
+               sei_md_bits.len_itu_t_t35_terminal_provider_oriented_code;
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_application_identifier);
+       hdr_plus_sei.application_identifier = (u16)value;
+       totbitoffset += sei_md_bits.len_application_identifier;
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_application_version);
+       hdr_plus_sei.application_version = (u16)value;
+       totbitoffset += sei_md_bits.len_application_version;
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_num_windows);
+       hdr_plus_sei.num_windows = (u16)value;
+       totbitoffset += sei_md_bits.len_num_windows;
+
+       num_win = value;
+
+       if (value > 1) {
+               for (i = 1; i < num_win; i++) {
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_window_upper_left_corner_x);
+                       hdr_plus_sei.window_upper_left_corner_x[i] = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_window_upper_left_corner_x;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_window_upper_left_corner_y);
+                       hdr_plus_sei.window_upper_left_corner_y[i] = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_window_upper_left_corner_y;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_window_lower_right_corner_x);
+                       hdr_plus_sei.window_lower_right_corner_x[i]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_window_lower_right_corner_x;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_window_lower_right_corner_y);
+                       hdr_plus_sei.window_lower_right_corner_y[i]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_window_lower_right_corner_y;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_center_of_ellipse_x);
+                       hdr_plus_sei.center_of_ellipse_x[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_center_of_ellipse_x;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_center_of_ellipse_y);
+                       hdr_plus_sei.center_of_ellipse_y[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_center_of_ellipse_y;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_rotation_angle);
+                       hdr_plus_sei.rotation_angle[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_rotation_angle;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                       sei_md_bits.len_semimajor_axis_internal_ellipse);
+                       hdr_plus_sei.semimajor_axis_internal_ellipse[i]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_semimajor_axis_internal_ellipse;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                       sei_md_bits.len_semimajor_axis_external_ellipse);
+                       hdr_plus_sei.semimajor_axis_external_ellipse[i]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_semimajor_axis_external_ellipse;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                       sei_md_bits.len_semiminor_axis_external_ellipse);
+                       hdr_plus_sei.semiminor_axis_external_ellipse[i]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_semiminor_axis_external_ellipse;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_overlap_process_option);
+                       hdr_plus_sei.overlap_process_option[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_overlap_process_option;
+               }
+       }
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_tgt_sys_disp_max_lumi);
+               hdr_plus_sei.tgt_sys_disp_max_lumi = value;
+       totbitoffset +=
+               sei_md_bits.len_tgt_sys_disp_max_lumi;
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_tgt_sys_disp_act_pk_lumi_flag);
+       hdr_plus_sei.tgt_sys_disp_act_pk_lumi_flag
+               = (u16)value;
+       totbitoffset +=
+               sei_md_bits.len_tgt_sys_disp_act_pk_lumi_flag;
+
+       tar_sys_disp_act_pk_lumi_flag = value;
+
+       if (tar_sys_disp_act_pk_lumi_flag) {
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+               sei_md_bits.len_num_rows_tgt_sys_disp_act_pk_lumi);
+               hdr_plus_sei.num_rows_tgt_sys_disp_act_pk_lumi
+                       = (u16)value;
+               totbitoffset +=
+               sei_md_bits.len_num_rows_tgt_sys_disp_act_pk_lumi;
+
+               num_row_tsdapl = value;
+
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+               sei_md_bits.len_num_cols_tgt_sys_disp_act_pk_lumi);
+               hdr_plus_sei.num_cols_tgt_sys_disp_act_pk_lumi
+                       = (u16)value;
+               totbitoffset +=
+               sei_md_bits.len_num_cols_tgt_sys_disp_act_pk_lumi;
+
+               num_col_tsdapl = value;
+
+               for (i = 0; i < num_row_tsdapl; i++) {
+                       for (j = 0; j < num_col_tsdapl; j++) {
+                               GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_tgt_sys_disp_act_pk_lumi);
+                               hdr_plus_sei.tgt_sys_disp_act_pk_lumi[i][j]
+                                       = (u16)value;
+                               totbitoffset +=
+                               sei_md_bits.len_tgt_sys_disp_act_pk_lumi;
+                       }
+               }
+       }
+       for (i = 0; i < num_win; i++) {
+               for (j = 0; j < 3; j++) {
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_maxscl);
+                       hdr_plus_sei.maxscl[i][j] = value;
+                       totbitoffset += sei_md_bits.len_maxscl;
+               }
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_average_maxrgb);
+               hdr_plus_sei.average_maxrgb[i] = value;
+               totbitoffset += sei_md_bits.len_average_maxrgb;
+
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_num_distribution_maxrgb_percentiles);
+               hdr_plus_sei.num_distribution_maxrgb_percentiles[i]
+                       = (u16)value;
+               totbitoffset +=
+                       sei_md_bits.len_num_distribution_maxrgb_percentiles;
+
+               num_d_m_p = value;
+               for (j = 0; j < num_d_m_p; j++) {
+                       GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_distribution_maxrgb_percentages);
+                       hdr_plus_sei.distribution_maxrgb_percentages[i][j]
+                               = (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_distribution_maxrgb_percentages;
+
+                       GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_distribution_maxrgb_percentiles);
+                       hdr_plus_sei.distribution_maxrgb_percentiles[i][j]
+                               = value;
+                       totbitoffset +=
+                               sei_md_bits.len_distribution_maxrgb_percentiles;
+               }
+
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_fraction_bright_pixels);
+               hdr_plus_sei.fraction_bright_pixels[i] = (u16)value;
+               totbitoffset += sei_md_bits.len_fraction_bright_pixels;
+       }
+
+       GetBits(metadata, totbitoffset,
+               &value, size,
+               sei_md_bits.len_mast_disp_act_pk_lumi_flag);
+       hdr_plus_sei.mast_disp_act_pk_lumi_flag
+               = (u16)value;
+       totbitoffset +=
+               sei_md_bits.len_mast_disp_act_pk_lumi_flag;
+
+       m_d_a_p_l_flag = value;
+       if (m_d_a_p_l_flag) {
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+               sei_md_bits.len_num_rows_mast_disp_act_pk_lumi);
+               hdr_plus_sei.num_rows_mast_disp_act_pk_lumi
+                       = (u16)value;
+               totbitoffset +=
+                       sei_md_bits.len_num_rows_mast_disp_act_pk_lumi;
+
+               num_row_m_d_a_p_l = value;
+
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+               sei_md_bits.len_num_cols_mast_disp_act_pk_lumi);
+               hdr_plus_sei.num_cols_mast_disp_act_pk_lumi
+                       = (u16)value;
+               totbitoffset +=
+               sei_md_bits.len_num_cols_mast_disp_act_pk_lumi;
+
+               num_col_m_d_a_p_l = value;
+
+               for (i = 0; i < num_row_m_d_a_p_l; i++) {
+                       for (j = 0; j < num_col_m_d_a_p_l; j++) {
+                               GetBits(metadata, totbitoffset,
+                                       &value, size,
+                               sei_md_bits.len_mast_disp_act_pk_lumi);
+                               hdr_plus_sei.mast_disp_act_pk_lumi[i][j]
+                                       = (u16)value;
+                               totbitoffset +=
+                                       sei_md_bits.len_mast_disp_act_pk_lumi;
+                       }
+               }
+       }
+
+       for (i = 0; i < num_win; i++) {
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_tone_mapping_flag);
+               hdr_plus_sei.tone_mapping_flag[i] = (u16)value;
+               totbitoffset += sei_md_bits.len_tone_mapping_flag;
+
+               tone_mapping_flag = value;
+
+               if (tone_mapping_flag) {
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_knee_point_x);
+                       hdr_plus_sei.knee_point_x[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_knee_point_x;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_knee_point_y);
+                       hdr_plus_sei.knee_point_y[i] = (u16)value;
+                       totbitoffset += sei_md_bits.len_knee_point_y;
+
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_num_bezier_curve_anchors);
+                       hdr_plus_sei.num_bezier_curve_anchors[i] =
+                               (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_num_bezier_curve_anchors;
+
+                       num_bezier_curve_anchors = value;
+
+                       for (j = 0; j < num_bezier_curve_anchors; j++) {
+                               GetBits(metadata, totbitoffset,
+                                       &value, size,
+                                       sei_md_bits.len_bezier_curve_anchors);
+                               hdr_plus_sei.bezier_curve_anchors[i][j] =
+                                       (u16)value;
+                               totbitoffset +=
+                                       sei_md_bits.len_bezier_curve_anchors;
+                       }
+               }
+
+               GetBits(metadata, totbitoffset,
+                       &value, size,
+                       sei_md_bits.len_color_saturation_mapping_flag);
+               hdr_plus_sei.color_saturation_mapping_flag[i] =
+                       (u16)value;
+               totbitoffset +=
+                       sei_md_bits.len_color_saturation_mapping_flag;
+
+               color_saturation_mapping_flag = value;
+               if (color_saturation_mapping_flag) {
+                       GetBits(metadata, totbitoffset,
+                               &value, size,
+                               sei_md_bits.len_color_saturation_weight);
+                       hdr_plus_sei.color_saturation_weight[i] =
+                               (u16)value;
+                       totbitoffset +=
+                               sei_md_bits.len_color_saturation_weight;
+               }
+       }
+}
+
+static int parse_sei(char *sei_buf, uint32_t size)
+{
+       char *p = sei_buf;
+       char *p_sei;
+       uint16_t header;
+       uint8_t nal_unit_type;
+       uint8_t payload_type, payload_size;
+
+       if (size < 2)
+               return 0;
+       header = *p++;
+       header <<= 8;
+       header += *p++;
+       nal_unit_type = header >> 9;
+       if ((nal_unit_type != NAL_UNIT_SEI)
+       && (nal_unit_type != NAL_UNIT_SEI_SUFFIX))
+               return 0;
+       while (p+2 <= sei_buf+size) {
+               payload_type = *p++;
+               payload_size = *p++;
+               if (p + payload_size <= sei_buf + size) {
+                       switch (payload_type) {
+                       case SEI_Syntax:
+                               p_sei = p;
+                               parser_hdr10_plus_medata(p_sei, payload_size);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               p += payload_size;
+       }
+       return 0;
+}
+
+void hdr10_plus_parser_metadata(struct vframe_s *vf)
+{
+       struct provider_aux_req_s req;
+       char *p;
+       unsigned int size = 0;
+       unsigned int type = 0;
+
+       req.vf = vf;
+       req.bot_flag = 0;
+       req.aux_buf = NULL;
+       req.aux_size = 0;
+       req.dv_enhance_exist = 0;
+       req.low_latency = 0;
+
+       vf_notify_provider_by_name("vdec.h265.00",
+                       VFRAME_EVENT_RECEIVER_GET_AUX_DATA,
+                       (void *)&req);
+
+       if (req.aux_buf && req.aux_size) {
+               p = req.aux_buf;
+               while (p < req.aux_buf
+                       + req.aux_size - 8) {
+                       size = *p++;
+                       size = (size << 8) | *p++;
+                       size = (size << 8) | *p++;
+                       size = (size << 8) | *p++;
+                       type = *p++;
+                       type = (type << 8) | *p++;
+                       type = (type << 8) | *p++;
+                       type = (type << 8) | *p++;
+                       if (type == 0x02000000)
+                               parse_sei(p, size);
+
+                       p += size;
+               }
+
+       }
+}
+
+struct hdr10plus_para dbg_hdr10plus_pkt;
+
+void hdr10_plus_hdmitx_vsif_parser(
+       struct hdr10plus_para *hdmitx_hdr10plus_param)
+{
+       int vsif_tds_max_l;
+       int ave_maxrgb;
+       int distribution_values[9];
+       int i;
+       int kpx, kpy;
+       int bz_cur_anchors[9];
+
+       hdmitx_hdr10plus_param->application_version =
+               (u8)hdr_plus_sei.application_version;
+
+       if (hdr_plus_sei.tgt_sys_disp_max_lumi < 1024) {
+               vsif_tds_max_l =
+                       (hdr_plus_sei.tgt_sys_disp_max_lumi + (1 << 4)) >> 5;
+               if (vsif_tds_max_l > 31)
+                       vsif_tds_max_l = 31;
+       } else
+               vsif_tds_max_l = 31;
+       hdmitx_hdr10plus_param->targeted_max_lum = (u8)vsif_tds_max_l;
+
+       ave_maxrgb = hdr_plus_sei.average_maxrgb[0] / 10;
+       if (ave_maxrgb < (1 << 12)) {
+               ave_maxrgb = (ave_maxrgb + (1 << 3)) >> 4;
+               if (ave_maxrgb > 255)
+                       ave_maxrgb = 255;
+       } else
+               ave_maxrgb = 255;
+       hdmitx_hdr10plus_param->average_maxrgb = (u8)ave_maxrgb;
+
+       for (i = 0; i < 9; i++) {
+               if (i == 2) {
+                       distribution_values[i] =
+                       hdr_plus_sei.distribution_maxrgb_percentiles[0][i];
+                       hdmitx_hdr10plus_param->distribution_values[i] =
+                               (u8)distribution_values[i];
+                       continue;
+               }
+               distribution_values[i] =
+                       hdr_plus_sei.distribution_maxrgb_percentiles[0][i];
+               if (distribution_values[i] < (1 << 12)) {
+                       distribution_values[i] =
+                               (distribution_values[i] + (1 << 3)) >> 4;
+                       if (distribution_values[i] > 255)
+                               distribution_values[i] = 255;
+               } else
+                       distribution_values[i] = 255;
+               hdmitx_hdr10plus_param->distribution_values[i] =
+                       (u8)distribution_values[i];
+       }
+
+       if (hdr_plus_sei.tone_mapping_flag[0] == 0) {
+               hdmitx_hdr10plus_param->num_bezier_curve_anchors = 0;
+               hdmitx_hdr10plus_param->knee_point_x = 0;
+               hdmitx_hdr10plus_param->knee_point_y = 0;
+               for (i = 0; i < 9; i++)
+                       hdmitx_hdr10plus_param->bezier_curve_anchors[0] = 0;
+       } else {
+               hdmitx_hdr10plus_param->num_bezier_curve_anchors =
+                       (u8)hdr_plus_sei.num_bezier_curve_anchors[0];
+
+               kpx = hdr_plus_sei.knee_point_x[0];
+               kpx = (kpx + (1 << 1)) >> 2;
+               if (kpx > 1023)
+                       kpx = 1023;
+               hdmitx_hdr10plus_param->knee_point_x = kpx;
+
+               kpy = hdr_plus_sei.knee_point_y[0];
+               kpy = (kpy + (1 << 1)) >> 2;
+               if (kpy > 1023)
+                       kpy = 1023;
+               hdmitx_hdr10plus_param->knee_point_y = kpy;
+
+               for (i = 0; i < 9; i++) {
+                       bz_cur_anchors[i] =
+                               hdr_plus_sei.bezier_curve_anchors[0][i];
+
+                       bz_cur_anchors[i] = (bz_cur_anchors[i] + (1 << 1)) >> 2;
+                       if (bz_cur_anchors[i] > 255)
+                               bz_cur_anchors[i] = 255;
+                       hdmitx_hdr10plus_param->bezier_curve_anchors[i] =
+                               (u8)bz_cur_anchors[i];
+               }
+       }
+       /*only video, don't include graphic*/
+       hdmitx_hdr10plus_param->graphics_overlay_flag = 0;
+       /*metadata and video have no delay*/
+       hdmitx_hdr10plus_param->no_delay_flag = 1;
+
+       memcpy(&dbg_hdr10plus_pkt, hdmitx_hdr10plus_param,
+               sizeof(struct hdr10plus_para));
+}
+
+void hdr10_plus_process(struct vframe_s *vf)
+{
+       if (!vf)
+               return;
+}
+
+void hdr10_plus_debug(void)
+{
+       int i = 0;
+       int j = 0;
+
+       pr_hdr("itu_t_t35_country_code = 0x%x\n",
+               hdr_plus_sei.itu_t_t35_country_code);
+       pr_hdr("itu_t_t35_terminal_provider_code = 0x%x\n",
+               hdr_plus_sei.itu_t_t35_terminal_provider_code);
+       pr_hdr("itu_t_t35_terminal_provider_oriented_code = 0x%x\n",
+               hdr_plus_sei.itu_t_t35_terminal_provider_oriented_code);
+       pr_hdr("application_identifier = 0x%x\n",
+               hdr_plus_sei.application_identifier);
+       pr_hdr("application_version = 0x%x\n",
+               hdr_plus_sei.application_version);
+       pr_hdr("num_windows = 0x%x\n",
+               hdr_plus_sei.num_windows);
+       for (i = 1; i < hdr_plus_sei.num_windows; i++) {
+               pr_hdr("window_upper_left_corner_x[%d] = 0x%x\n",
+                       i, hdr_plus_sei.window_upper_left_corner_x[i]);
+               pr_hdr("window_upper_left_corner_y[%d] = 0x%x\n",
+                       i, hdr_plus_sei.window_upper_left_corner_y[i]);
+               pr_hdr("window_lower_right_corner_x[%d] = 0x%x\n",
+                       i, hdr_plus_sei.window_lower_right_corner_x[i]);
+               pr_hdr("window_lower_right_corner_y[%d] = 0x%x\n",
+                       i, hdr_plus_sei.window_lower_right_corner_y[i]);
+               pr_hdr("center_of_ellipse_x[%d] = 0x%x\n",
+                       i, hdr_plus_sei.center_of_ellipse_x[i]);
+               pr_hdr("center_of_ellipse_y[%d] = 0x%x\n",
+                       i, hdr_plus_sei.center_of_ellipse_y[i]);
+               pr_hdr("rotation_angle[%d] = 0x%x\n",
+                       i, hdr_plus_sei.rotation_angle[i]);
+               pr_hdr("semimajor_axis_internal_ellipse[%d] = 0x%x\n",
+                       i, hdr_plus_sei.semimajor_axis_internal_ellipse[i]);
+               pr_hdr("semimajor_axis_external_ellipse[%d] = 0x%x\n",
+                       i, hdr_plus_sei.semimajor_axis_external_ellipse[i]);
+               pr_hdr("semiminor_axis_external_ellipse[%d] = 0x%x\n",
+                       i, hdr_plus_sei.semiminor_axis_external_ellipse[i]);
+               pr_hdr("overlap_process_option[%d] = 0x%x\n",
+                       i, hdr_plus_sei.overlap_process_option[i]);
+       }
+       pr_hdr("targeted_system_display_maximum_luminance = 0x%x\n",
+               hdr_plus_sei.tgt_sys_disp_max_lumi);
+       pr_hdr("targeted_system_display_actual_peak_luminance_flag = 0x%x\n",
+               hdr_plus_sei.tgt_sys_disp_act_pk_lumi_flag);
+       if (hdr_plus_sei.tgt_sys_disp_act_pk_lumi_flag) {
+               for (i = 0;
+                       i < hdr_plus_sei.num_rows_tgt_sys_disp_act_pk_lumi;
+                       i++) {
+                       for (j = 0;
+                       j < hdr_plus_sei.num_cols_tgt_sys_disp_act_pk_lumi;
+                       j++) {
+                               pr_hdr("tgt_sys_disp_act_pk_lumi");
+                               pr_hdr("[%d][%d] = 0x%x\n",
+                               i, j,
+                               hdr_plus_sei.tgt_sys_disp_act_pk_lumi[i][j]);
+                       }
+               }
+       }
+
+       for (i = 0; i < hdr_plus_sei.num_windows; i++) {
+               for (j = 0; j < 3; j++)
+                       pr_hdr("maxscl[%d][%d] = 0x%x\n",
+                               i, j, hdr_plus_sei.maxscl[i][j]);
+
+               pr_hdr("average_maxrgb[%d] = 0x%x\n",
+                       i, hdr_plus_sei.average_maxrgb[i]);
+               pr_hdr("num_distribution_maxrgb_percentiles[%d] = 0x%x\n",
+                       i, hdr_plus_sei.num_distribution_maxrgb_percentiles[i]);
+               for (j = 0;
+               j < hdr_plus_sei.num_distribution_maxrgb_percentiles[i];
+               j++) {
+                       pr_hdr("distribution_maxrgb_pcntages[%d][%d] = 0x%x\n",
+                       i, j,
+                       hdr_plus_sei.distribution_maxrgb_percentages[i][j]);
+                       pr_hdr("distribution_maxrgb_pcntiles[%d][%d] = 0x%x\n",
+                       i, j,
+                       hdr_plus_sei.distribution_maxrgb_percentiles[i][j]);
+               }
+               pr_hdr("fraction_bright_pixels[%d] = 0x%x\n",
+                       i, hdr_plus_sei.fraction_bright_pixels[i]);
+       }
+
+       pr_hdr("mast_disp_act_pk_lumi_flag = 0x%x\n",
+               hdr_plus_sei.mast_disp_act_pk_lumi_flag);
+       if (hdr_plus_sei.mast_disp_act_pk_lumi_flag) {
+               pr_hdr("num_rows_mast_disp_act_pk_lumi = 0x%x\n",
+                       hdr_plus_sei.num_rows_mast_disp_act_pk_lumi);
+               pr_hdr("num_cols_mast_disp_act_pk_lumi = 0x%x\n",
+                       hdr_plus_sei.num_cols_mast_disp_act_pk_lumi);
+               for (i = 0;
+                       i < hdr_plus_sei.num_rows_mast_disp_act_pk_lumi;
+                       i++) {
+                       for (j = 0;
+                               j < hdr_plus_sei.num_cols_mast_disp_act_pk_lumi;
+                               j++)
+                               pr_hdr("mast_disp_act_pk_lumi[%d][%d] = 0x%x\n",
+                               i, j, hdr_plus_sei.mast_disp_act_pk_lumi[i][j]);
+               }
+       }
+
+       for (i = 0; i < hdr_plus_sei.num_windows; i++) {
+               pr_hdr("tone_mapping_flag[%d] = 0x%x\n",
+                       i, hdr_plus_sei.tone_mapping_flag[i]);
+               pr_hdr("knee_point_x[%d] = 0x%x\n",
+                       i, hdr_plus_sei.knee_point_x[i]);
+               pr_hdr("knee_point_y[%d] = 0x%x\n",
+                       i, hdr_plus_sei.knee_point_y[i]);
+               pr_hdr("num_bezier_curve_anchors[%d] = 0x%x\n",
+                       i, hdr_plus_sei.num_bezier_curve_anchors[i]);
+               for (j = 0; j < hdr_plus_sei.num_bezier_curve_anchors[i]; j++)
+                       pr_hdr("bezier_curve_anchors[%d][%d] = 0x%x\n",
+                               i, j, hdr_plus_sei.bezier_curve_anchors[i][j]);
+
+               pr_hdr("color_saturation_mapping_flag[%d] = 0x%x\n",
+                       i, hdr_plus_sei.color_saturation_mapping_flag[i]);
+               pr_hdr("color_saturation_weight[%d] = 0x%x\n",
+                       i, hdr_plus_sei.color_saturation_weight[i]);
+       }
+
+       pr_hdr("\ntx vsif packet data print begin\n");
+       pr_hdr("application_version = 0x%x\n",
+               dbg_hdr10plus_pkt.application_version);
+       pr_hdr("targeted_max_lum = 0x%x\n",
+               dbg_hdr10plus_pkt.targeted_max_lum);
+       pr_hdr("average_maxrgb = 0x%x\n",
+               dbg_hdr10plus_pkt.average_maxrgb);
+       for (i = 0; i < 9; i++)
+               pr_hdr("distribution_values[%d] = 0x%x\n",
+               i, dbg_hdr10plus_pkt.distribution_values[i]);
+       pr_hdr("num_bezier_curve_anchors = 0x%x\n",
+               dbg_hdr10plus_pkt.num_bezier_curve_anchors);
+       pr_hdr("knee_point_x = 0x%x\n",
+               dbg_hdr10plus_pkt.knee_point_x);
+       pr_hdr("knee_point_y = 0x%x\n",
+               dbg_hdr10plus_pkt.knee_point_y);
+
+       for (i = 0; i < 9; i++)
+               pr_hdr("bezier_curve_anchors[%d] = 0x%x\n",
+               i, dbg_hdr10plus_pkt.bezier_curve_anchors[i]);
+       pr_hdr("graphics_overlay_flag = 0x%x\n",
+               dbg_hdr10plus_pkt.graphics_overlay_flag);
+       pr_hdr("no_delay_flag = 0x%x\n",
+               dbg_hdr10plus_pkt.no_delay_flag);
+       pr_hdr("\ntx vsif packet data print end\n");
+
+       pr_hdr(HDR10_PLUS_VERSION);
+}
+
diff --git a/drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.h b/drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr10_plus.h
new file mode 100644 (file)
index 0000000..79c7356
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * drivers/amlogic/media/enhancement/amvecm/hdr/am_hdr.h
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#ifndef AM_HDR_H
+#define AM_HDR_H
+struct hdr_plus_bits_s {
+       u16 len_itu_t_t35_country_code;
+       u16 len_itu_t_t35_terminal_provider_code;
+       u16 len_itu_t_t35_terminal_provider_oriented_code;
+       u16 len_application_identifier;
+       u16 len_application_version;
+       /*num_windows max is 3*/
+       u16 len_num_windows;
+       /*windows xy*/
+       u16 len_window_upper_left_corner_x;
+       u16 len_window_upper_left_corner_y;
+       u16 len_window_lower_right_corner_x;
+       u16 len_window_lower_right_corner_y;
+       u16 len_center_of_ellipse_x;
+       u16 len_center_of_ellipse_y;
+       u16 len_rotation_angle;
+       u16 len_semimajor_axis_internal_ellipse;
+       u16 len_semimajor_axis_external_ellipse;
+       u16 len_semiminor_axis_external_ellipse;
+       u16 len_overlap_process_option;
+       /*target luminance*/
+       u16 len_tgt_sys_disp_max_lumi;
+       u16 len_tgt_sys_disp_act_pk_lumi_flag;
+       u16 len_num_rows_tgt_sys_disp_act_pk_lumi;
+       u16 len_num_cols_tgt_sys_disp_act_pk_lumi;
+       u16 len_tgt_sys_disp_act_pk_lumi;
+
+       /*num_windows max is 3, e.g maxscl[num_windows][i];*/
+       u16 len_maxscl;
+       u16 len_average_maxrgb;
+       u16 len_num_distribution_maxrgb_percentiles;
+       u16 len_distribution_maxrgb_percentages;
+       u16 len_distribution_maxrgb_percentiles;
+       u16 len_fraction_bright_pixels;
+
+       u16 len_mast_disp_act_pk_lumi_flag;
+       u16 len_num_rows_mast_disp_act_pk_lumi;
+       u16 len_num_cols_mast_disp_act_pk_lumi;
+       u16 len_mast_disp_act_pk_lumi;
+       /*num_windows max is 3, e.g knee_point_x[num_windows]*/
+       u16 len_tone_mapping_flag;
+       u16 len_knee_point_x;
+       u16 len_knee_point_y;
+       u16 len_num_bezier_curve_anchors;
+       u16 len_bezier_curve_anchors;
+       u16 len_color_saturation_mapping_flag;
+       u16 len_color_saturation_weight;
+};
+
+extern uint debug_hdr;
+#define HDR_PLUS_IEEE_OUI 0x90848B
+#define SEI_Syntax 0x4
+extern void hdr10_plus_hdmitx_vsif_parser(
+       struct hdr10plus_para *hdmitx_hdr10plus_param);
+extern void hdr10_plus_parser_metadata(struct vframe_s *vf);
+extern void hdr10_plus_process(struct vframe_s *vf);
+extern void hdr10_plus_debug(void);
+#endif /* AM_HDR_H */
+
index 3c21df4..7cdee0d 100644 (file)
@@ -1153,8 +1153,7 @@ void set_hdr_matrix(
                        } else
                                adpscl_shift[i] = adp_scal_shift;
 
-                       if (hdr_mtx_param->mtx_ogain)
-                               adpscl_ys_coef[i] =
+                       adpscl_ys_coef[i] =
                                        1 << adp_scal_shift;
                        adpscl_beta_s[i] = 0;
                        adpscl_beta[i] = 0;
index b5b1912..89bc899 100644 (file)
@@ -243,9 +243,16 @@ enum vpp_matrix_csc_e {
        VPP_MATRIX_BT2020YUV_BT2020RGB = 0x40,
        VPP_MATRIX_BT2020RGB_709RGB,
        VPP_MATRIX_BT2020RGB_CUSRGB,
+       VPP_MATRIX_BT2020YUV_BT2020RGB_DYNAMIC = 0x50,
        VPP_MATRIX_DEFAULT_CSCTYPE = 0xffff,
 };
 
+enum vpp_transfer_characteristic_e {
+       VPP_ST_NULL = 0,
+       VPP_ST709 = 0x1,
+       VPP_ST2084 = 0x2,
+       VPP_ST2094_40 = 0x4,
+};
 
 enum ve_source_input_e {
        SOURCE_INVALID = -1,
index 59cb9b6..c2936f3 100644 (file)
@@ -159,6 +159,55 @@ struct vframe_master_display_colour_s {
                content_light_level;
 }; /* master_display_colour_info_volume from SEI */
 
+struct vframe_hdr_plus_sei_s {
+       u16 present_flag;
+       u16 itu_t_t35_country_code;
+       u16 itu_t_t35_terminal_provider_code;
+       u16 itu_t_t35_terminal_provider_oriented_code;
+       u16 application_identifier;
+       u16 application_version;
+       /*num_windows max is 3*/
+       u16 num_windows;
+       /*windows xy*/
+       u16 window_upper_left_corner_x[3];
+       u16 window_upper_left_corner_y[3];
+       u16 window_lower_right_corner_x[3];
+       u16 window_lower_right_corner_y[3];
+       u16 center_of_ellipse_x[3];
+       u16 center_of_ellipse_y[3];
+       u16 rotation_angle[3];
+       u16 semimajor_axis_internal_ellipse[3];
+       u16 semimajor_axis_external_ellipse[3];
+       u16 semiminor_axis_external_ellipse[3];
+       u16 overlap_process_option[3];
+       /*target luminance*/
+       u32 tgt_sys_disp_max_lumi;
+       u16 tgt_sys_disp_act_pk_lumi_flag;
+       u16 num_rows_tgt_sys_disp_act_pk_lumi;
+       u16 num_cols_tgt_sys_disp_act_pk_lumi;
+       u16 tgt_sys_disp_act_pk_lumi[25][25];
+
+       /*num_windows max is 3, e.g maxscl[num_windows][i];*/
+       u32 maxscl[3][3];
+       u32 average_maxrgb[3];
+       u16 num_distribution_maxrgb_percentiles[3];
+       u16 distribution_maxrgb_percentages[3][15];
+       u32 distribution_maxrgb_percentiles[3][15];
+       u16 fraction_bright_pixels[3];
+
+       u16 mast_disp_act_pk_lumi_flag;
+       u16 num_rows_mast_disp_act_pk_lumi;
+       u16 num_cols_mast_disp_act_pk_lumi;
+       u16 mast_disp_act_pk_lumi[25][25];
+       /*num_windows max is 3, e.g knee_point_x[num_windows]*/
+       u16 tone_mapping_flag[3];
+       u16 knee_point_x[3];
+       u16 knee_point_y[3];
+       u16 num_bezier_curve_anchors[3];
+       u16 bezier_curve_anchors[3][15];
+       u16 color_saturation_mapping_flag[3];
+       u16 color_saturation_weight[3];
+};
 /* vframe properties */
 struct vframe_prop_s {
        struct vframe_hist_s hist;