From 550dc42835e20600f06fbbf0700893b40eeceda1 Mon Sep 17 00:00:00 2001 From: "shihong.zheng" Date: Tue, 8 Dec 2020 10:56:51 +0800 Subject: [PATCH] amstream: fix crashed after video port init failed. [1/1] PD#SWPL-38536 Problem: crash after video port init failed. Solution: fix bug when port init failed. Verify: ah212 Change-Id: Icc2d40a4899bf7d8a780a50178df782cec3a2da0 Signed-off-by: shihong.zheng --- drivers/amvdec_ports/aml_vcodec_adapt.c | 100 +------------------- drivers/frame_provider/decoder/utils/vdec.c | 7 -- drivers/stream_input/amports/amstream.c | 16 +++- 3 files changed, 15 insertions(+), 108 deletions(-) diff --git a/drivers/amvdec_ports/aml_vcodec_adapt.c b/drivers/amvdec_ports/aml_vcodec_adapt.c index 34e9c8f..95ee48a 100644 --- a/drivers/amvdec_ports/aml_vcodec_adapt.c +++ b/drivers/amvdec_ports/aml_vcodec_adapt.c @@ -237,56 +237,6 @@ static void user_buffer_init(void) pubuf->buf_rp = 0; } -static void audio_component_release(struct stream_port_s *port, - struct stream_buf_s *pbuf, int release_num) -{ - switch (release_num) { - default: - case 0: - case 4: - esparser_release(pbuf); - case 3: - adec_release(port->vformat); - case 2: - stbuf_release(pbuf); - case 1: - ; - } -} - -static int audio_component_init(struct stream_port_s *port, - struct stream_buf_s *pbuf) -{ - int r; - - if ((port->flag & PORT_FLAG_AFORMAT) == 0) { - v4l_dbg(0, V4L_DEBUG_CODEC_ERROR, "aformat not set\n"); - return 0; - } - - r = stbuf_init(pbuf, NULL); - if (r < 0) - return r; - - r = adec_init(port); - if (r < 0) { - audio_component_release(port, pbuf, 2); - return r; - } - - if (port->type & PORT_TYPE_ES) { - r = esparser_init(pbuf, NULL); - if (r < 0) { - audio_component_release(port, pbuf, 3); - return r; - } - } - - pbuf->flag |= BUF_FLAG_IN_USE; - - return 0; -} - static void video_component_release(struct stream_port_s *port, struct stream_buf_s *pbuf, int release_num) { @@ -301,7 +251,7 @@ struct stream_buf_s *pbuf, int release_num) case 0: case 4: { if ((port->type & PORT_TYPE_FRAME) == 0) - esparser_release(pbuf); + esparser_release(pbuf); } case 3: { @@ -316,7 +266,7 @@ struct stream_buf_s *pbuf, int release_num) case 2: { if ((port->type & PORT_TYPE_FRAME) == 0) - stbuf_release(pbuf); + stbuf_release(pbuf); } case 1: @@ -409,14 +359,7 @@ static int video_component_init(struct stream_port_s *port, static int vdec_ports_release(struct stream_port_s *port) { - struct aml_vdec_adapt *ada_ctx - = container_of(port, struct aml_vdec_adapt, port); - struct vdec_s *vdec = ada_ctx->vdec; - struct stream_buf_s *pvbuf = &bufs[BUF_TYPE_VIDEO]; - struct stream_buf_s *pabuf = &bufs[BUF_TYPE_AUDIO]; - //struct stream_buf_s *psbuf = &bufs[BUF_TYPE_SUBTITLE]; - struct vdec_s *slave = NULL; if (has_hevc_vdec()) { if (port->vformat == VFORMAT_HEVC @@ -435,23 +378,6 @@ static int vdec_ports_release(struct stream_port_s *port) if (port->type & PORT_TYPE_VIDEO) video_component_release(port, pvbuf, 0); - if (port->type & PORT_TYPE_AUDIO) - audio_component_release(port, pabuf, 0); - - if (port->type & PORT_TYPE_SUB) - //sub_port_release(port, psbuf); - - if (vdec) { - if (vdec->slave) - slave = vdec->slave; - - vdec_release(vdec); - - if (slave) - vdec_release(slave); - vdec = NULL; - } - port->pcr_inited = 0; port->flag = 0; @@ -512,8 +438,6 @@ static int vdec_ports_init(struct aml_vdec_adapt *ada_ctx) { int ret = -1; struct stream_buf_s *pvbuf = &bufs[BUF_TYPE_VIDEO]; - struct stream_buf_s *pabuf = &bufs[BUF_TYPE_AUDIO]; - //struct stream_buf_s *psbuf = &bufs[BUF_TYPE_SUBTITLE]; struct vdec_s *vdec = NULL; /* create the vdec instance.*/ @@ -527,21 +451,12 @@ static int vdec_ports_init(struct aml_vdec_adapt *ada_ctx) ret = enable_hardware(vdec->port); if (ret < 0) { v4l_dbg(ada_ctx->ctx, V4L_DEBUG_CODEC_ERROR, "enable hw fail.\n"); - goto error1; + return ret; } stbuf_fetch_init(); user_buffer_init(); - if ((vdec->port->type & PORT_TYPE_AUDIO) - && (vdec->port_flag & PORT_FLAG_AFORMAT)) { - ret = audio_component_init(vdec->port, pabuf); - if (ret < 0) { - v4l_dbg(ada_ctx->ctx, V4L_DEBUG_CODEC_ERROR, "audio_component_init failed\n"); - goto error1; - } - } - if ((vdec->port->type & PORT_TYPE_VIDEO) && (vdec->port_flag & PORT_FLAG_VFORMAT)) { vdec->port->is_4k = false; @@ -554,7 +469,7 @@ static int vdec_ports_init(struct aml_vdec_adapt *ada_ctx) ret = video_component_init(vdec->port, pvbuf); if (ret < 0) { v4l_dbg(ada_ctx->ctx, V4L_DEBUG_CODEC_ERROR, "video_component_init failed\n"); - goto error2; + return ret; } /* connect vdec at the end after all HW initialization */ @@ -562,13 +477,6 @@ static int vdec_ports_init(struct aml_vdec_adapt *ada_ctx) } return 0; - -//error3: - //video_component_release(port, pvbuf, 0); -error2: - audio_component_release(vdec->port, pabuf, 0); -error1: - return ret; } int video_decoder_init(struct aml_vdec_adapt *vdec) diff --git a/drivers/frame_provider/decoder/utils/vdec.c b/drivers/frame_provider/decoder/utils/vdec.c index f0193b8..1d6edc5 100644 --- a/drivers/frame_provider/decoder/utils/vdec.c +++ b/drivers/frame_provider/decoder/utils/vdec.c @@ -1363,8 +1363,6 @@ void vdec_stream_skip_data(struct vdec_s *vdec, int skip_size) rp = STBUF_READ(&vdec->vbuf, get_rp); wp = STBUF_READ(&vdec->vbuf, get_wp); - pr_err("aaaa wp %x, rp %x\n", wp, rp); - pr_err("1VLD_MEM_VIFIFO_RP %x\n", rp); if (wp > rp) level = wp - rp; @@ -1377,14 +1375,11 @@ void vdec_stream_skip_data(struct vdec_s *vdec, int skip_size) } if (wp >= rp) { - pr_err("case 1\n"); rp_set = rp + skip_size; } else if ((rp + skip_size) < (input->start + input->size)) { - pr_err("case 2\n"); rp_set = rp + skip_size; } else { - pr_err("case 3\n"); rp_set = rp + skip_size - input->size; input->stream_cookie++; } @@ -1416,8 +1411,6 @@ void vdec_stream_skip_data(struct vdec_s *vdec, int skip_size) while (READ_VREG(VLD_MEM_SWAP_CTL) & (1<<7)) ; WRITE_VREG(VLD_MEM_SWAP_CTL, 0); - pr_err("2VLD_MEM_VIFIFO_RP %x\n", READ_VREG(VLD_MEM_VIFIFO_RP)); - } EXPORT_SYMBOL(vdec_stream_skip_data); diff --git a/drivers/stream_input/amports/amstream.c b/drivers/stream_input/amports/amstream.c index d48a24a..854c3a8 100644 --- a/drivers/stream_input/amports/amstream.c +++ b/drivers/stream_input/amports/amstream.c @@ -1015,7 +1015,7 @@ static int amstream_port_init(struct port_priv_s *priv) 0, vdec); if (r < 0) { pr_err("tsdemux_init failed\n"); - goto error4; + goto error3; } tsync_pcr_start(); } @@ -1024,7 +1024,7 @@ static int amstream_port_init(struct port_priv_s *priv) r = sub_port_init(port, psbuf); if (r < 0) { pr_err("sub_port_init failed\n"); - goto error3; + goto error4; } } @@ -1058,11 +1058,17 @@ static int amstream_port_init(struct port_priv_s *priv) /*errors follow here */ error4: - sub_port_release(port, psbuf); + if ((port->type & PORT_TYPE_MPTS) && + !(port->flag & PORT_FLAG_VFORMAT)) + tsdemux_release(); error3: - video_port_release(priv, &priv->vdec->vbuf, 0); + if ((port->type & PORT_TYPE_VIDEO) && + (port->flag & PORT_FLAG_VFORMAT)) + video_port_release(priv, &priv->vdec->vbuf, 0); error2: - audio_port_release(port, pabuf, 0); + if ((port->type & PORT_TYPE_AUDIO) && + (port->flag & PORT_FLAG_AFORMAT)) + audio_port_release(port, pabuf, 0); error1: mutex_unlock(&amstream_mutex); return r; -- 2.20.1