From f06badf4d44415e535da37f9c5fc4645369f20db Mon Sep 17 00:00:00 2001
From: Shivaprasad Hongal <shongal@codeaurora.org>
Date: Mon, 6 Jul 2015 17:21:45 -0700
Subject: [PATCH] msm_vidc: Fix for DRC in Adative Mode

Add mechanism to store Adaptive width and height
values in start and check while resolution_decreased_event
with new resolution (width/height). In new resolution,
if any width/height is greater than adaptive values,
Send PORT_RECONFIG_EVENT

BUG:20895249
Change-Id: I03ccc7d13a767240b962e7c6f4aa25566f3c5a7e
Signed-off-by: Manikanta Kanamarlapudi <kmanikan@codeaurora.org>
Signed-off-by: Shivaprasad Hongal <shongal@codeaurora.org>
---
 drivers/video/msm/vidc/1080p/ddl/vcd_ddl.h    |  2 ++
 .../video/msm/vidc/1080p/ddl/vcd_ddl_helper.c | 19 ++++++++++++++++++-
 .../msm/vidc/1080p/ddl/vcd_ddl_properties.c   |  8 +++++++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl.h b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl.h
index 58a932990d30..b13b92afd807 100644
--- a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl.h
+++ b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl.h
@@ -343,6 +343,8 @@ struct ddl_decoder_data {
 	struct ddl_mp2_datadumpenabletype mp2_datadump_enable;
 	u32 mp2_datadump_status;
 	u32 extn_user_data_enable;
+	u32 adaptive_width;
+	u32 adaptive_height;
 };
 union ddl_codec_data{
 	struct ddl_codec_data_hdr  hdr;
diff --git a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_helper.c b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_helper.c
index 20fdf4069a34..e9765f1bd6ac 100644
--- a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_helper.c
+++ b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_helper.c
@@ -1021,6 +1021,8 @@ u32 ddl_check_reconfig(struct ddl_client_context *ddl)
 	if (decoder->cont_mode) {
 		if ((decoder->actual_output_buf_req.sz <=
 			 decoder->client_output_buf_req.sz) &&
+			 decoder->frame_size.width <= decoder->adaptive_width &&
+			 decoder->frame_size.height <= decoder->adaptive_height &&
 			(decoder->actual_output_buf_req.actual_count <=
 			 decoder->client_output_buf_req.actual_count)) {
 			need_reconfig = false;
@@ -1060,8 +1062,23 @@ u32 ddl_check_reconfig(struct ddl_client_context *ddl)
 void ddl_handle_reconfig(u32 res_change, struct ddl_client_context *ddl)
 {
 	struct ddl_decoder_data *decoder = &ddl->codec_data.decoder;
+	struct vidc_1080p_dec_disp_info *dec_disp_info =
+		&(decoder->dec_disp_info);
+
+	u32 width = 0;
+	u32 height = 0;
+	u32 adaptive_width = 0;
+	u32 adaptive_height = 0;
+
+	width = DDL_ALIGN(dec_disp_info->img_size_x, DDL_TILE_ALIGN_WIDTH);
+	height = DDL_ALIGN(dec_disp_info->img_size_y, DDL_TILE_ALIGN_HEIGHT);
+
+	adaptive_width = DDL_ALIGN(decoder->adaptive_width, DDL_TILE_ALIGN_WIDTH);
+	adaptive_height = DDL_ALIGN(decoder->adaptive_height, DDL_TILE_ALIGN_HEIGHT);
+
 	if ((decoder->cont_mode) &&
-		(res_change == DDL_RESL_CHANGE_DECREASED)) {
+		(res_change == DDL_RESL_CHANGE_DECREASED) &&
+		width <= adaptive_width && height <= adaptive_height) {
 		DDL_MSG_LOW("%s Resolution decreased, continue decoding\n",
 				 __func__);
 		vidc_sm_get_min_yc_dpb_sizes(
diff --git a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_properties.c b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_properties.c
index 7705734bb6f0..32ecda3ed00e 100644
--- a/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_properties.c
+++ b/drivers/video/msm/vidc/1080p/ddl/vcd_ddl_properties.c
@@ -288,7 +288,11 @@ static u32 ddl_set_dec_property(struct ddl_client_context *ddl,
 				ddl_set_default_decoder_buffer_req(decoder,
 					true);
 			}
-			DDL_MSG_LOW("set  VCD_I_FRAME_SIZE width = %d"
+			if (decoder->cont_mode) {
+				decoder->adaptive_width = decoder->client_frame_size.width;
+				decoder->adaptive_height = decoder->client_frame_size.height;
+			}
+			DDL_MSG_LOW("set VCD_I_FRAME_SIZE width = %d"
 				" height = %d\n",
 				frame_size->width, frame_size->height);
 			vcd_status = VCD_S_SUCCESS;
@@ -1792,6 +1796,8 @@ void ddl_set_default_dec_property(struct ddl_client_context *ddl)
 	decoder->output_order = VCD_DEC_ORDER_DISPLAY;
 	decoder->field_needed_for_prev_ip = 0;
 	decoder->cont_mode = 0;
+	decoder->adaptive_width = 0;
+	decoder->adaptive_height = 0;
 	decoder->reconfig_detected = false;
 	decoder->dmx_disable = false;
 	ddl_set_default_metadata_flag(ddl);
-- 
GitLab