Browse Source

dsp: codecs: Add synchronization between SSR and native encoder decoder

Add change to use global lock to make synchronization
between SSR and native encoder decoder.

Change-Id: I6c1f48c32d4c8290de8bf3dfa86e022abe2b34bc
Signed-off-by: Saurav Kumar <[email protected]>
Saurav Kumar 5 years ago
parent
commit
d8a0703a77

+ 4 - 1
dsp/codecs/audio_native.c

@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017, 2020, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include "audio_utils.h"
 
+spinlock_t enc_dec_lock;
+
 static int __init audio_native_init(void)
 {
 	aac_in_init();
@@ -31,6 +33,7 @@ static int __init audio_native_init(void)
 	g711alaw_in_init();
 	g711mlaw_in_init();
 	qcelp_in_init();
+	spin_lock_init(&enc_dec_lock);
 	return 0;
 }
 

+ 4 - 1
dsp/codecs/audio_utils.c

@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
-/* Copyright (c) 2010-2019, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010-2020, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -943,8 +943,11 @@ int audio_in_release(struct inode *inode, struct file *file)
 	audio_in_disable(audio);
 	q6asm_audio_client_free(audio->ac);
 	mutex_unlock(&audio->lock);
+	spin_lock(&enc_dec_lock);
 	kfree(audio->enc_cfg);
 	kfree(audio->codec_cfg);
 	kfree(audio);
+	file->private_data = NULL;
+	spin_unlock(&enc_dec_lock);
 	return 0;
 }

+ 3 - 1
dsp/codecs/audio_utils_aio.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /* Copyright (C) 2008 Google, Inc.
  * Copyright (C) 2008 HTC Corporation
- * Copyright (c) 2009-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2020, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -631,9 +631,11 @@ int audio_aio_release(struct inode *inode, struct file *file)
 #ifdef CONFIG_DEBUG_FS
 	debugfs_remove(audio->dentry);
 #endif
+	spin_lock(&enc_dec_lock);
 	kfree(audio->codec_cfg);
 	kfree(audio);
 	file->private_data = NULL;
+	spin_unlock(&enc_dec_lock);
 	mutex_unlock(&lock);
 	return 0;
 }

+ 2 - 2
dsp/codecs/q6audio_common.h

@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-/* Copyright (c) 2012-2014, 2017 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2014, 2017, 2020 The Linux Foundation. All rights reserved.
  */
 
 
@@ -9,7 +9,7 @@
 
 #include <dsp/apr_audio-v2.h>
 #include <dsp/q6asm-v2.h>
-
+extern spinlock_t enc_dec_lock;
 
 void q6_audio_cb(uint32_t opcode, uint32_t token,
 		uint32_t *payload, void *priv);

+ 8 - 1
dsp/codecs/q6audio_v2.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2012-2013, 2015-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2013, 2015-2017, 2020 The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -21,6 +21,11 @@ void q6asm_in_cb(uint32_t opcode, uint32_t token,
 	struct q6audio_in *audio = (struct q6audio_in *)priv;
 	unsigned long flags;
 
+	spin_lock(&enc_dec_lock);
+	if (audio == NULL) {
+		pr_err("%s: failed to get q6audio value\n", __func__);
+		goto error;
+	}
 	pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
 			audio->ac->session, opcode);
 
@@ -58,6 +63,8 @@ void q6asm_in_cb(uint32_t opcode, uint32_t token,
 		break;
 	}
 	spin_unlock_irqrestore(&audio->dsp_lock, flags);
+error:
+	spin_unlock(&enc_dec_lock);
 }
 
 void  audio_in_get_dsp_frames(void *priv,

+ 5 - 2
dsp/codecs/q6audio_v2_aio.c

@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
-/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -43,9 +43,10 @@ void audio_aio_cb(uint32_t opcode, uint32_t token,
 	struct q6audio_aio *audio = (struct q6audio_aio *)priv;
 	union msm_audio_event_payload e_payload;
 
+	spin_lock(&enc_dec_lock);
 	if (audio == NULL) {
 		pr_err("%s: failed to get q6audio value\n", __func__);
-		return;
+		goto error;
 	}
 	switch (opcode) {
 	case ASM_DATA_EVENT_WRITE_DONE_V2:
@@ -111,6 +112,8 @@ void audio_aio_cb(uint32_t opcode, uint32_t token,
 	default:
 		break;
 	}
+error:
+	spin_unlock(&enc_dec_lock);
 }
 
 int extract_meta_out_info(struct q6audio_aio *audio,