From patchwork Thu Dec 12 08:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Bokowy X-Patchwork-Id: 13904847 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 798262063C2 for ; Thu, 12 Dec 2024 08:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733993073; cv=none; b=KArkzjb7+4xXT5AUJRh4asCSCn6JBYRplFJISccTrcB8ch19rdRQb8Tb7LonCB5wRm9wS79/nENGNPHjYA8apylncBTMQmBmkRm/c0nUa5VurXfkZgMnkasYfyhNrZP1waGZ45sizwkCgsKx2vaLAI57rMGdryXDzGndvG2/b8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733993073; c=relaxed/simple; bh=pu9hTPtCMtObxpP0cwNSw8LchlWDYWdY37q88nHLCHI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bF94lkhIpfOpNzLSDRlg/PsMAvbFwZprh0b68pxSK6W9pnOgyIF0w0Q9ngd67CMY3QwnMD7SpII9wXnma8mI61XLTfl6hfiAYzOTOb2t7eaLWLCTbwmx2PjOXhl8acykifSz8G6rkij59gVsgwmAc+YIkAznVChVa+kzVaVgBNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OvOwaPua; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OvOwaPua" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so569690a12.2 for ; Thu, 12 Dec 2024 00:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733993069; x=1734597869; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SZd0Gbu6XQwYCQcGohlZ2WR8NsphWYmvDVrFlMqvsUY=; b=OvOwaPuatLkgELAB5OSLupBGKIu0iuwKt57sqJD8pCJYRgutMt33CA3HCRzySyJ89t SV2/ELBEWl4sfvIqWdvBdmY/yoPpluUzHvW4w4TPW3e37foMkpVljGqgzzvi4MgiXEtO oP4R0jani1TGEx2LPENsnAeqz0mGeu9mI5EnLM+4yutY/npvucCXbeFrwk/ZwWpIfwzt 9qzvRnDW6vPv5fgsZXAZMR1Klh/0EclSioZ6ZUfM8JARjRLVLIGt5XNAvnChkw2E+byf Z8Zsh2Br36MFpiG0j5j4ha0ifL01elL7FRV4eB6n83QOX5sbYhUZGaF7SKiivTDoNcmH yHfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733993069; x=1734597869; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SZd0Gbu6XQwYCQcGohlZ2WR8NsphWYmvDVrFlMqvsUY=; b=iQ0X8fROtzAkeJ89RNd8D0+w2tQY+Gw0smA8v0xjpTXkmNQ0xB7TWiACxOud60jRr3 Lm7ONZE4T396tsm2ibvlEgfBailkcnJwitJWdDdUX0RO2q3hdLEiD1ewugQTewlCqclQ 5gGveoMYvJddd25OHhfzoKBp90Cx+6tzrewDG1gaMHf0ncSBXWyRv0Rj6PRbbddF71b4 NhbnBwkjXCi1lfiMylh3d2oJVUywNgUkeLiGS+EXUA62AqYsX4xSIoeNgDAVIfOtO978 ynGBJh2InWq0ETReh+vHV3GAvU5fRIloB1PHvf65hJoFdmxy6kAiwCxY+nEm6pfGyZt6 DOHQ== X-Gm-Message-State: AOJu0YwBpTQH1IkSow4TLuYdnjnaENOUtQWpj0hPgECSMOPYaylZDMus afOpj5DDWH2tJMrbPM4CY5ZFRqZwg9fqCtphCPIvRujf2/qBvH7knljbXQ== X-Gm-Gg: ASbGncsgeUUdim0V9fYzLtI1mfPpdl7/CoGRpKRugyCBxasXMVOTCeqnkSVHs6vgXOW GY8+5PiirelZ2SxfuKLgsiiWPbyVmJmmYpFafr2lGVfJGOvwLXa23MG7lfo1FvVpPC2GUWF/zWL 9KqoenFAXLTL04RaU1qlG9kT8nUC0dl3aabmnpMo2y8sPqmyMhFYlSUOgRBKpgxSMVIcC2yt2fL b7Yu1JCY2vH5dSCUQPn3U5Re/u58LKZJbAQCUy47+4l8LzYf0iQtT2bcObIPh16Rlm4PMBqdLYG eruky3727AqFkTAW0F8f9J2G5jCamM7vLydq98MudN0= X-Google-Smtp-Source: AGHT+IHtRMSM3zo+riWXa8ceQO8ws0eqTJpz2gA4PkdG99SzjPXht7cOhTYRpNBkK2n60ECDVsjv1w== X-Received: by 2002:a05:6402:1ecf:b0:5d0:e3fa:17e2 with SMTP id 4fb4d7f45d1cf-5d54763c067mr4423a12.11.1733993069164; Thu, 12 Dec 2024 00:44:29 -0800 (PST) Received: from raspberrypi.home (46.205.203.47.nat.ftth.dynamic.t-mobile.pl. [46.205.203.47]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d42a754cb0sm2948476a12.88.2024.12.12.00.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 00:44:28 -0800 (PST) From: Arkadiusz Bokowy To: linux-bluetooth@vger.kernel.org Cc: Arkadiusz Bokowy Subject: [PATCH 1/2] sbc: Pass const pointer if structure is not modified Date: Thu, 12 Dec 2024 09:44:18 +0100 Message-Id: <20241212084419.1326427-1-arkadiusz.bokowy@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- sbc/sbc.c | 8 ++++---- sbc/sbc.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sbc/sbc.c b/sbc/sbc.c index 886806d..428c8ee 100644 --- a/sbc/sbc.c +++ b/sbc/sbc.c @@ -1378,7 +1378,7 @@ SBC_EXPORT void sbc_finish(sbc_t *sbc) memset(sbc, 0, sizeof(sbc_t)); } -SBC_EXPORT size_t sbc_get_frame_length(sbc_t *sbc) +SBC_EXPORT size_t sbc_get_frame_length(const sbc_t *sbc) { int ret; uint8_t subbands, channels, blocks, joint, bitpool; @@ -1407,7 +1407,7 @@ SBC_EXPORT size_t sbc_get_frame_length(sbc_t *sbc) return ret; } -SBC_EXPORT unsigned sbc_get_frame_duration(sbc_t *sbc) +SBC_EXPORT unsigned sbc_get_frame_duration(const sbc_t *sbc) { uint8_t subbands, blocks; uint16_t frequency; @@ -1448,7 +1448,7 @@ SBC_EXPORT unsigned sbc_get_frame_duration(sbc_t *sbc) return (1000000 * blocks * subbands) / frequency; } -SBC_EXPORT size_t sbc_get_codesize(sbc_t *sbc) +SBC_EXPORT size_t sbc_get_codesize(const sbc_t *sbc) { uint16_t subbands, channels, blocks; struct sbc_priv *priv; @@ -1470,7 +1470,7 @@ SBC_EXPORT size_t sbc_get_codesize(sbc_t *sbc) return subbands * blocks * channels * 2; } -SBC_EXPORT const char *sbc_get_implementation_info(sbc_t *sbc) +SBC_EXPORT const char *sbc_get_implementation_info(const sbc_t *sbc) { struct sbc_priv *priv; diff --git a/sbc/sbc.h b/sbc/sbc.h index 9b8c6f2..b7323e8 100644 --- a/sbc/sbc.h +++ b/sbc/sbc.h @@ -86,15 +86,15 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len, void *output, size_t output_len, ssize_t *written); /* Returns the compressed block size in bytes */ -size_t sbc_get_frame_length(sbc_t *sbc); +size_t sbc_get_frame_length(const sbc_t *sbc); -/* Returns the time one input/output block takes to play in msec*/ -unsigned sbc_get_frame_duration(sbc_t *sbc); +/* Returns the time one input/output block takes to play in msec */ +unsigned sbc_get_frame_duration(const sbc_t *sbc); /* Returns the uncompressed block size in bytes */ -size_t sbc_get_codesize(sbc_t *sbc); +size_t sbc_get_codesize(const sbc_t *sbc); -const char *sbc_get_implementation_info(sbc_t *sbc); +const char *sbc_get_implementation_info(const sbc_t *sbc); void sbc_finish(sbc_t *sbc); #ifdef __cplusplus From patchwork Thu Dec 12 08:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Bokowy X-Patchwork-Id: 13904848 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 273A520E02D for ; Thu, 12 Dec 2024 08:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733993078; cv=none; b=IHVIpvoluz8cqY7PogGhYnsCGH5szn5GYWWUFXGYIrhGf5dWfmsqw6W7hhuoLlmrvvgtRwxocov4/faTNsfBoLSnH9v72D3m1kme4t3Id3TvnZF4Q6llD2MlVtQbdWVCXTa17OZ5E8APs+7Y2e9iMTSEhuHLfNXx2GM75E2gO18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733993078; c=relaxed/simple; bh=wll8mfUJPfBxpFYpKgOcB0K3t6bxxcxWKiVYQEF6/9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vCu3Ir1L1OVwDb7KOtAeVPaZNQxrSoxYGMTbB7QniiSMX584X67LkPnPUGtvviKoSP3nqP2f/Sv223td3Ht2GvxHjjKjvp2N9VIpk6LOFCMuPKC0U8OIzsFx1uXgejaXwM3XLHl9tr49INHxZktaWjUfwaZYaXqzy1UStKioxPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AoIWG+F5; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AoIWG+F5" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a9e8522445dso60414866b.1 for ; Thu, 12 Dec 2024 00:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733993075; x=1734597875; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gSc2uHjP/LSBPWbFukm535fyWEeje0qmDbvk4k0NIHQ=; b=AoIWG+F5qLd9o4ysCkXPKyRbRX9EHGEWNWf9h4/HrnIIZbpFMtsa8Lfbxdc1yJqIll Yxd3pXwNVzKkjGaQhRU8Lb4iRKQLXysTWk4Sg8ktk0Rmju2QTWXpIdFAFaB7S2IipK4X iNxyEb2i0t5/7irUNcLJbpDLCAUGTCODGW2yz9eMrQr2Px3fFkvmLTG3dEzHQCttpWAz kjKSSb6P+SZY8zMMGRf7DYwzuUt/Q23dyU7xdudfuAmDo/YwITd9OWfXZmrqv8GAd7C7 5d5CjaR+YT4IECJSnNsaFWv9dVwUIn8QfAevU21cMmZ6XXf1qELAObCWoI3Mwv4qqeMf H2Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733993075; x=1734597875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSc2uHjP/LSBPWbFukm535fyWEeje0qmDbvk4k0NIHQ=; b=BbSQAEyyY47f5LkbrMcJiFNoQVZ0pF7OJydqdn9bVm67lQ8u5maRzHmRNMXa7p8DAb zDx4NVtmHyIYgtzHh+dGBWyJpIG0w0K00fxhiR/iMafa45fSVcApSpZsZ6BUL8ixQQSh zgj/iX1yOSUGnC7DN00yxsWWf+llH7pGYsBAQ4hYVar0uJsY+BkxxQZiEaVtHnTGoCgh jpgXJjVkwDr244wF6dw8E9dU7I8cwDJBwJGUbsdmYdOGGKEaGMjkW/a7TK7gaORRGMd+ ptnZ9/Pk9GmlQ9EiRCdsQTiY4N13nhbF2liNos0u0Kx8P16HjDc0ULzT9ymrVfWNzJ4Y mLQw== X-Gm-Message-State: AOJu0YzKcN+hBHpuVrb6U8t4HzysJGIU0+tz40zqLCj/LQeREddip32q Z1ldmQcNgOq4tzCRQTFYEfyT6kPj0L/I79M0XM1gXRerACbGrEnac6WoVQ== X-Gm-Gg: ASbGncv8E5mW0fy3lA+reBsO363L4PzbxxZix9E9BW4T0SISdnpPsPgYc8SGlNZJRID E9qicXrJRprmJ4A0DVHE0yYR71cffmdSFdKrU7bAOytnT3+6DS1dXHS6ZZcvjTWSEMJpWG4CyB4 POqRpda/VxCLtqiIACaadSDkhDyq28oQr+Xh6UgEMcYBu9UqDN71LwQiWurF4Sdqwd3tQ/mGKKL nu8T8VmTrZ7LX7eZA489hvQR57FAHR1MM3qzh2tmhy8s0vGKBD4Jo2hd4eURJUf1WD7g1hLu8FT +1oSELyo13UiZc4GFwVj302XRNACGQAu+kittsD9Z8s= X-Google-Smtp-Source: AGHT+IHKIcj5/ArT/nhYljrt8qzcAgpHu85TivtEu1Tj/TzvelCPMJDn7mYpiqEoypTnzUlqevOmag== X-Received: by 2002:a17:906:31cc:b0:aa6:6ca2:b772 with SMTP id a640c23a62f3a-aa6b10d6602mr660144166b.10.1733993074993; Thu, 12 Dec 2024 00:44:34 -0800 (PST) Received: from raspberrypi.home (46.205.203.47.nat.ftth.dynamic.t-mobile.pl. [46.205.203.47]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d42a754cb0sm2948476a12.88.2024.12.12.00.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 00:44:34 -0800 (PST) From: Arkadiusz Bokowy To: linux-bluetooth@vger.kernel.org Cc: Arkadiusz Bokowy Subject: [PATCH 2/2] sbc: Add sbc_get_delay API to retrieve codec delay Date: Thu, 12 Dec 2024 09:44:19 +0100 Message-Id: <20241212084419.1326427-2-arkadiusz.bokowy@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241212084419.1326427-1-arkadiusz.bokowy@gmail.com> References: <20241212084419.1326427-1-arkadiusz.bokowy@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most audio codecs introduce intrinsic codec delay. SBC codec introduces encode/decode delay which is not constant but depends on the number of subbunds used. Providing API for that will simplify library usage in case when precise delay calculation is required. --- sbc/sbc.c | 20 ++++++++++++++++++++ sbc/sbc.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/sbc/sbc.c b/sbc/sbc.c index 428c8ee..869f367 100644 --- a/sbc/sbc.c +++ b/sbc/sbc.c @@ -1470,6 +1470,26 @@ SBC_EXPORT size_t sbc_get_codesize(const sbc_t *sbc) return subbands * blocks * channels * 2; } +SBC_EXPORT unsigned sbc_get_delay(const sbc_t *sbc) +{ + uint16_t subbands; + struct sbc_priv *priv; + + priv = sbc->priv; + if (!priv->init) { + subbands = sbc->subbands ? 8 : 4; + } else { + subbands = priv->frame.subbands; + } + + /* + * The delay is caused by the processing function which analyzes + * old samples to encode the current frame. The amount of that + * samples depends on the number of subbands. + */ + return subbands * 9 + 1; +} + SBC_EXPORT const char *sbc_get_implementation_info(const sbc_t *sbc) { struct sbc_priv *priv; diff --git a/sbc/sbc.h b/sbc/sbc.h index b7323e8..829b161 100644 --- a/sbc/sbc.h +++ b/sbc/sbc.h @@ -94,6 +94,9 @@ unsigned sbc_get_frame_duration(const sbc_t *sbc); /* Returns the uncompressed block size in bytes */ size_t sbc_get_codesize(const sbc_t *sbc); +/* Returns the delay introduced by the codec in frames */ +unsigned sbc_get_delay(const sbc_t *sbc); + const char *sbc_get_implementation_info(const sbc_t *sbc); void sbc_finish(sbc_t *sbc);