From d8a0703a77497b9a649f84f6eac02755ab43dbde Mon Sep 17 00:00:00 2001 From: Saurav Kumar Date: Fri, 21 Feb 2020 18:29:26 +0530 Subject: [PATCH] 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 --- dsp/codecs/audio_native.c | 5 ++++- dsp/codecs/audio_utils.c | 5 ++++- dsp/codecs/audio_utils_aio.c | 4 +++- dsp/codecs/q6audio_common.h | 4 ++-- dsp/codecs/q6audio_v2.c | 9 ++++++++- dsp/codecs/q6audio_v2_aio.c | 7 +++++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dsp/codecs/audio_native.c b/dsp/codecs/audio_native.c index 93370295d4..6e2491459b 100644 --- a/dsp/codecs/audio_native.c +++ b/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 #include #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; } diff --git a/dsp/codecs/audio_utils.c b/dsp/codecs/audio_utils.c index 26e9b0b360..ac934132ac 100644 --- a/dsp/codecs/audio_utils.c +++ b/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 @@ -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; } diff --git a/dsp/codecs/audio_utils_aio.c b/dsp/codecs/audio_utils_aio.c index 62b9455dbd..93095e3007 100644 --- a/dsp/codecs/audio_utils_aio.c +++ b/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; } diff --git a/dsp/codecs/q6audio_common.h b/dsp/codecs/q6audio_common.h index c37813edd0..67003feaee 100644 --- a/dsp/codecs/q6audio_common.h +++ b/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 #include - +extern spinlock_t enc_dec_lock; void q6_audio_cb(uint32_t opcode, uint32_t token, uint32_t *payload, void *priv); diff --git a/dsp/codecs/q6audio_v2.c b/dsp/codecs/q6audio_v2.c index c98ef1c4bc..6a402f538b 100644 --- a/dsp/codecs/q6audio_v2.c +++ b/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 @@ -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, diff --git a/dsp/codecs/q6audio_v2_aio.c b/dsp/codecs/q6audio_v2_aio.c index a6f7836d81..ecd14dadfe 100644 --- a/dsp/codecs/q6audio_v2_aio.c +++ b/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 @@ -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,