amports: audio: Add mutex lock protect for audio port reset [1/1]
authorZhizhong Zhang <zhizhong.zhang@amlogic.com>
Fri, 25 Oct 2019 05:22:58 +0000 (13:22 +0800)
committerZhi Zhou <zhi.zhou@amlogic.com>
Mon, 28 Oct 2019 11:21:46 +0000 (04:21 -0700)
PD#OTT-6893

Problem:
System restart after launch/exit LiveTv multiple

Solution:
Add mutex lock protect for audio port reset

Verify:
patch build of U212

Change-Id: Id175422a3c829e23b59927aea6c60e8818b9dd37
Signed-off-by: Zhizhong Zhang <zhizhong.zhang@amlogic.com>
drivers/stream_input/amports/amstream.c

index 8c9ef119cfad898a8e64dffc7c1689bc4688709b..51fd4b700cfc13cf498f22e4365c2061c21b51c4 100644 (file)
@@ -555,6 +555,9 @@ static void port_set_inited(struct port_priv_s *priv)
                struct vdec_s *vdec = priv->vdec;
 
                vdec->port_flag |= PORT_FLAG_INITED;
+               port->flag |= PORT_FLAG_INITED;
+               pr_info("vdec->port_flag=0x%x, port_flag=0x%x\n",
+                       vdec->port_flag, port->flag);
        } else
                port->flag |= PORT_FLAG_INITED;
 }
@@ -716,23 +719,35 @@ static int audio_port_reset(struct stream_port_s *port,
                                struct stream_buf_s *pbuf)
 {
        int r;
-
+       mutex_lock(&amstream_mutex);
        if ((port->flag & PORT_FLAG_AFORMAT) == 0) {
                pr_err("aformat not set\n");
+               mutex_unlock(&amstream_mutex);
+               return 0;
+       }
+
+       pr_info("audio port reset, flag:0x%x\n", port->flag);
+       if ((port->flag & PORT_FLAG_INITED) == 0) {
+               pr_info("audio port not inited,return\n");
+               mutex_unlock(&amstream_mutex);
                return 0;
        }
 
+       pr_info("audio_port_reset begin\n");
        pts_stop(PTS_TYPE_AUDIO);
 
        stbuf_release(pbuf, false);
 
        r = stbuf_init(pbuf, NULL, false);
-       if (r < 0)
+       if (r < 0) {
+               mutex_unlock(&amstream_mutex);
                return r;
+       }
 
        r = adec_init(port);
        if (r < 0) {
                audio_port_release(port, pbuf, 2);
+               mutex_unlock(&amstream_mutex);
                return r;
        }
 
@@ -755,6 +770,8 @@ static int audio_port_reset(struct stream_port_s *port,
 
        r = pts_start(PTS_TYPE_AUDIO);
 
+       pr_info("audio_port_reset done\n");
+       mutex_unlock(&amstream_mutex);
        return r;
 }