vdec: CB2 v4l stream mode timestamp exception. [1/1]

PD#SWPL-192333

Problem:
1.The error frame called checkout to get pts.
2.Timestamp unit is ns in v4l2,result in pts and duration do not match.

Solution:
1.The error frame called peek to get pts.
2.Fixed checkin's pts.

Verify:
S905X4

Change-Id: Ie4a3d4938d9dfd254461a1e129bfe0a679032b50
Signed-off-by: yuna.liu <yuna.liu@amlogic.com>
diff --git a/drivers/amvdec_ports/aml_vcodec_ts.c b/drivers/amvdec_ports/aml_vcodec_ts.c
index 5fbe8b1..40b8ce5 100644
--- a/drivers/amvdec_ports/aml_vcodec_ts.c
+++ b/drivers/amvdec_ports/aml_vcodec_ts.c
@@ -40,6 +40,8 @@
 	}
 
 	*pts = mCheckOutPtsOffset;
+	pts->pts = pts->pts * 1000;
+	pts->pts_64 = pts->pts_64 * 1000;
 
 	pr_debug("%s duration: %lld offset: 0x%llx pts: 0x%x pts64: %llu\n",
 		__func__, (offset >> 32) & 0xffffffff,
@@ -76,8 +78,8 @@
 	checkin_pts_size mCheckinPtsSize;
 
 	mCheckinPtsSize.size =pkt_size;
-	mCheckinPtsSize.pts = (u32)div64_u64(pts_val * 9, 100);
-	mCheckinPtsSize.pts_64 = pts_val;
+	mCheckinPtsSize.pts = (u32)div64_u64(pts_val * 9, 100000);
+	mCheckinPtsSize.pts_64 = div64_u64(pts_val, 1000);
 	ptsserver_checkin_pts_size(ptsserver_id,&mCheckinPtsSize,false);
 
 	pr_debug("%s pkt_size:%d chekin pts: %d, pts64: %llu\n",
diff --git a/drivers/frame_provider/decoder_v4l/h264_multi/vmh264.c b/drivers/frame_provider/decoder_v4l/h264_multi/vmh264.c
index ae59b3f..e9980ce 100644
--- a/drivers/frame_provider/decoder_v4l/h264_multi/vmh264.c
+++ b/drivers/frame_provider/decoder_v4l/h264_multi/vmh264.c
@@ -7438,17 +7438,19 @@
 	u32 offset_lo, offset_hi;
 	u32 offset;
 	struct checkoutptsoffset pts_st = {0};
+	u64 dur_offset = hw->frame_dur;
 
 	offset_lo  = p_H264_Dpb->dpb_param.l.data[OFFSET_DELIMITER_LO];
 	offset_hi  = p_H264_Dpb->dpb_param.l.data[OFFSET_DELIMITER_HI];
 
 	offset = offset_lo | offset_hi << 16;
+	dur_offset = ((dur_offset << 32) & 0xffffffff00000000) | offset;;
 
-	if (!ctx->pts_serves_ops->checkout(ctx->ptsserver_id, offset, &pts_st)) {
+	if (!ctx->pts_serves_ops->cal_offset(ctx->ptsserver_id, dur_offset, &pts_st)) {
 		ctx->current_timestamp = pts_st.pts_64;
 		dpb_print(DECODE_ID(hw), PRINT_FLAG_UCODE_EVT,
-		"pts cal_offset current pts:0x%x pts_64:%llx\n",
-		pts_st.pts, pts_st.pts_64);
+		"%s: pts cal_offset current pts:0x%x pts_64:%llx timestamp %llu\n",
+		__func__, pts_st.pts, pts_st.pts_64, ctx->current_timestamp);
 	} else {
 		dpb_print(DECODE_ID(hw), 0, "pts cal_offset fail\n");
 		ctx->current_timestamp = 0;
@@ -8217,7 +8219,7 @@
 
 					offset = offset_lo | offset_hi << 16;
 
-					if (!ctx->pts_serves_ops->checkout(ctx->ptsserver_id, offset, &pts_st)) {
+					if (!ctx->pts_serves_ops->cal_offset(ctx->ptsserver_id, offset, &pts_st)) {
 						ctx->current_timestamp = pts_st.pts_64;
 						dpb_print(DECODE_ID(hw), PRINT_FLAG_UCODE_EVT, "pts cal_offset current pts:0x%x pts_64:%llx\n", pts_st.pts, pts_st.pts_64);
 					} else {
diff --git a/drivers/frame_provider/decoder_v4l/h265/vh265.c b/drivers/frame_provider/decoder_v4l/h265/vh265.c
index a08f9e7..4d2e6c9 100644
--- a/drivers/frame_provider/decoder_v4l/h265/vh265.c
+++ b/drivers/frame_provider/decoder_v4l/h265/vh265.c
@@ -9646,13 +9646,14 @@
 	u32 offset = READ_VREG(HEVC_SHIFT_BYTE_COUNT);
 	u64 dur_offset = hevc->frame_dur;
 
-	dur_offset = (dur_offset << 32 ) | offset;
+	dur_offset = ((dur_offset << 32) & 0xffffffff00000000) | offset;
+
 	if (!ctx || !ctx->pts_serves_ops ||
-		!ctx->pts_serves_ops->checkout(ctx->ptsserver_id, dur_offset, &pts_st)) {
+		!ctx->pts_serves_ops->cal_offset(ctx->ptsserver_id, dur_offset, &pts_st)) {
 		ctx->current_timestamp = pts_st.pts_64;
 		hevc_print(hevc, PRINT_FLAG_VDEC_STATUS,
-		"%s pts cal_offset current pts:0x%x pts_64:%llx  dur_offset:0x%llx \n",
-		__func__, pts_st.pts, pts_st.pts_64, dur_offset);
+		"%s pts cal_offset current pts:0x%x pts_64:%llx timestamp %llu\n",
+		__func__, pts_st.pts, pts_st.pts_64, ctx->current_timestamp);
 	} else {
 		hevc_print(hevc, H265_DEBUG_PIC_STRUCT, 0, "pts cal_offset fail  dur_offset:0x%llx\n",dur_offset);
 		ctx->current_timestamp = 0;
@@ -10035,11 +10036,6 @@
 				(DUR2PTS(hevc->frame_dur) * 100 / 9);
 		}
 		hevc->last_pts_us64 = vf->pts_us64;
-		if ((get_dbg_flag(hevc) & H265_DEBUG_OUT_PTS) != 0) {
-			hevc_print(hevc, 0,
-				"H265 dec out pts: vf->pts=%d, vf->pts_us64 = %lld, ts: %llu\n",
-				vf->pts, vf->pts_us64, vf->timestamp);
-		}
 
 		/*
 		 *vf->index:
@@ -10219,6 +10215,10 @@
 				vf->timestamp = 0;
 			}
 		}
+
+		hevc_print(hevc, H265_DEBUG_OUT_PTS, "%s: vf->pts %d, vf->pts_us64 %lld, ts: %llu\n",
+				__func__, vf->pts, vf->pts_us64, vf->timestamp);
+
 		vf->src_fmt.play_id = vdec->inst_cnt;
 
 		vf->width = vf->width /
@@ -10526,11 +10526,11 @@
 		vdec_fill_vdec_frame(vdec, &hevc->vframe_qos, &tmp4x, vf, pic->hw_decode_time);
 		vdec->vdec_fps_detec(vdec->id);
 		hevc_print(hevc, H265_DEBUG_BUFMGR,
-			"%s(type %d index 0x%x poc %d/%d) pts(%d,%d) dur %d\n",
+			"%s(type %d index 0x%x poc %d/%d) pts(%d,%d,%llu) dur %d\n",
 			__func__, vf->type, vf->index,
 			get_pic_poc(hevc, vf->index & 0xff),
 			get_pic_poc(hevc, (vf->index >> 8) & 0xff),
-			vf->pts, vf->pts_us64,
+			vf->pts, vf->pts_us64, vf->timestamp,
 			vf->duration);
 		if ((pic->pic_struct == 10 || pic->pic_struct == 12) && hevc->interlace_flag) {
 			index = (vf->index >> 8) & 0xff;
diff --git a/drivers/frame_provider/decoder_v4l/mpeg12/vmpeg12_multi.c b/drivers/frame_provider/decoder_v4l/mpeg12/vmpeg12_multi.c
index b14dcb6..6b596ee 100644
--- a/drivers/frame_provider/decoder_v4l/mpeg12/vmpeg12_multi.c
+++ b/drivers/frame_provider/decoder_v4l/mpeg12/vmpeg12_multi.c
@@ -1734,12 +1734,12 @@
 	struct checkoutptsoffset pts_st = { 0 };
 	u64 dur_offset = hw->frame_dur;
 
-	dur_offset = (dur_offset << 32 ) | offset;
-	if (!ctx->pts_serves_ops->checkout(ctx->ptsserver_id, dur_offset, &pts_st)) {
+	dur_offset = ((dur_offset << 32) & 0xffffffff00000000) | offset;
+	if (!ctx->pts_serves_ops->cal_offset(ctx->ptsserver_id, dur_offset, &pts_st)) {
 		ctx->current_timestamp = pts_st.pts_64;
 		debug_print(DECODE_ID(hw), PRINT_FLAG_DEC_DETAIL,
-		"%s pts cal_offset current pts:0x%x pts_64:%llx  dur_offset:0x%llx \n",
-		__func__, pts_st.pts, pts_st.pts_64, dur_offset);
+		"%s pts cal_offset current pts:0x%x pts_64:%llx timestamp %llu\n",
+		__func__, pts_st.pts, pts_st.pts_64, ctx->current_timestamp);
 	} else {
 		debug_print(DECODE_ID(hw), 0, "pts cal_offset fail  dur_offset:0x%llx\n",dur_offset);
 		ctx->current_timestamp = 0;
@@ -2102,7 +2102,7 @@
 			ATRACE_COUNTER(hw->new_q_name, kfifo_len(&hw->newframe_q));
 		} else {
 			debug_print(DECODE_ID(hw), PRINT_FLAG_TIMEINFO,
-				"%s, vf: %lx, num[%d]: %d(%c), dur: %d, type: %x, pts: %d(%lld), ts(%lld)\n",
+				"%s, vf: %lx, num[%d]: %d(%c), dur: %d, type: %x, pts: %d(%lld), ts(%llu)\n",
 				__func__, (ulong)vf, i, hw->disp_num, GET_SLICE_TYPE(info),
 				vf->duration, vf->type, vf->pts, vf->pts_us64, vf->timestamp);
 			atomic_add(1, &hw->disp_num);
@@ -3157,12 +3157,12 @@
 			struct checkoutptsoffset pts_st = { 0 };
 			u64 dur_offset = hw->frame_dur;
 			dur_offset = (dur_offset << 32 ) | offset;
-			if (!ctx->pts_serves_ops->checkout(ctx->ptsserver_id, dur_offset, &pts_st)) {
+			if (!ctx->pts_serves_ops->cal_offset(ctx->ptsserver_id, dur_offset, &pts_st)) {
 				hw->first_field_timestamp = pts_st.pts_64;
 				hw->first_field_timestamp_valid = true;
 
 				debug_print(DECODE_ID(hw), PRINT_FLAG_TIMEINFO,
-					"stream first filed checkout pts is%lx\n", pts_st.pts);
+					"stream first filed cal_offset pts is%lx\n", pts_st.pts);
 			}
 		}