From patchwork Sun Aug 15 18:25:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nachiket Tarate X-Patchwork-Id: 29542 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1402380iov; Sun, 15 Aug 2021 11:26:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNGescnnniqPBL9FkErCXn1e+obd7S2jNrxnUGqDd5BLWSmq1CCR86WZmS2THEwNHqgoDx X-Received: by 2002:a17:906:76da:: with SMTP id q26mr12450570ejn.402.1629051981002; Sun, 15 Aug 2021 11:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629051980; cv=none; d=google.com; s=arc-20160816; b=wIedV1lAFth6fKz3mYntfTZ/l620JIzc5iNScKKCRxNfqZppYXNy+0u/OYLHvdYSdG XIO1Sj55BGTFFEogaeFp7d09KdbtpagP7eV0wOfgFS/iuqYEQcCQXGmjNGQKnwzdjS7T 4bSBWmQ/Wwu+6rILTbbqvRJIrCra2ST6pX4veFQodp8Nznm6oYgMAh0X40ujtB2lUHSF yHsX9Hd1Q9BvQdGPNa01m/lZ+vMafTbL1c/HwF6+mpcIpetZnIZjf9H7kOGkyZqVqNEf +BB4Qw/zCyUSu81IBSnZHiYK+YwZ+f7rsQ651gyG8SatJTRDvzWKpIZ4E9cS1Vym1O6q weAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=NhUNBPGsVsXWCzGW+5ViZzTXRV95GHMUgCOOhWzDkFM=; b=cbAALBRDjJ9Bn75nt8/ugiDH7aNvrJxPdpskM/XfvQr0UsEv5g7OQwytQJfxArEXKi o6jETyFI+PWru2Vcnr63BLCb18u/NpNaPf5dbNpryi4T0poZlFrAlyFGhEUXMPZ6yOVw 4ZM6+ThIkDTMfW7soGcVrrPSeoEtTb0B6GcIIQTf+KPfKjDL30SdxbQduu8keBcjRmxW KWm3Pm0gGvP4KvOyAp70EbEmfoJWqXryQhUDPjGPgIh6OI5ej1EVQgW2LCa9znpk8ZPm deBuzy/f7LHGQuqNQcqawwd/v+TkuycnNScxmLqF4Cz0OJ3NVtdDoWrV7JJOJtcMU072 Z+7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=MgsJrlLH; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j7si9638810ejm.492.2021.08.15.11.26.20; Sun, 15 Aug 2021 11:26:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=MgsJrlLH; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F30FC68A41C; Sun, 15 Aug 2021 21:26:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6AE80687EBB for ; Sun, 15 Aug 2021 21:26:10 +0300 (EEST) Received: by mail-pj1-f53.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so16092117pje.0 for ; Sun, 15 Aug 2021 11:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=rH//sR6h/d6ERccj10gXUgD260cVKVDxasaeeHrEGFE=; b=MgsJrlLHMgAfd+lN9oXrx76XFGFbR9XhZBWaZL3Hvd9UEXNHIx+9WGXDNpxdzIE9sQ c1GhtY3agIxItqfzrQRRF5SRWMIjHXNqQZ4JPzUiJK612HME2sBwDq6QTopyFWxumG8O sHR0PCcpJciutWUdSZjoq7MNj8o8MYuBHfBh3EQRpl5kxqPtlkvqmoe73aKwan6V4svm 1z0EEmqwde9AKAxgvP5xhIQtSUY6PTQgN7JyGafxdqbdv3jQcO8D/U6yH9e7qlr6/5GG gHd2o7zd0zBuNUG6FR1HXEBpgLygwYs3gy4uyMpfZtQyX+kyFzc6nJPNYJiagKZW3jQv wLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=rH//sR6h/d6ERccj10gXUgD260cVKVDxasaeeHrEGFE=; b=dFTxxWtCFSzEyvXkConZis8bXpGxuEJSKX0WFVrKu47G4PmiuKlfZHyIDGOIS5aQrE vyGcDvZElgStguI1BrKLoOYwPyiIpJgS+6ib5Sml7gujp4DYbUTSb8AaA2BySSKSnSIL 1rd2sjvjDj7YL71II4VJ85bh/7O3zWVnbvoMjD7fNflUBpzEW+OQwSiFwB43cSJMZiY6 lmLaabR78vCVJD+51ql5nWQKELbmtnq6JyIIbOC33A4LEcxaNnnwwVh5E+iVRkK5J8l0 UId/spQH3TwVqqQKCLcAwomeaSd/F1G1MU9ibEZRIoTmGgrcRfdkh3Gfi+xeQq5LsqQI 7JEQ== X-Gm-Message-State: AOAM533cVj56N2zenvQsdmaKKVXOJ6RboX8gNvSzPWI5Fa//KEpJt76+ 1fFQ592p/LMitXx+4gy2tUeejhKs/LhVaw== X-Received: by 2002:a17:903:234e:b0:12d:ad8d:56c6 with SMTP id c14-20020a170903234e00b0012dad8d56c6mr5180532plh.23.1629051968008; Sun, 15 Aug 2021 11:26:08 -0700 (PDT) Received: from localhost.localdomain ([2401:4900:4458:83cd:6c5d:85b2:b4ee:c5e3]) by smtp.gmail.com with ESMTPSA id t10sm7054681pji.30.2021.08.15.11.26.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 11:26:07 -0700 (PDT) From: Nachiket Tarate To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Aug 2021 23:55:51 +0530 Message-Id: <20210815182551.12684-1-nachiket.programmer@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/4] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: a0oGC8JxGlOD These will be used by HLS demuxer in case of sample decryption. Signed-off-by: Nachiket Tarate --- libavcodec/adts_header.c | 1 + libavcodec/adts_header.h | 14 ++++++++++++++ libavcodec/adts_parser.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/libavcodec/adts_header.c b/libavcodec/adts_header.c index 0889820f8a..e4454529c4 100644 --- a/libavcodec/adts_header.c +++ b/libavcodec/adts_header.c @@ -66,6 +66,7 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr) hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr]; hdr->samples = (rdb + 1) * 1024; hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples; + hdr->frame_length = size; return size; } diff --git a/libavcodec/adts_header.h b/libavcodec/adts_header.h index f615f6a9f9..9ecd67fb5b 100644 --- a/libavcodec/adts_header.h +++ b/libavcodec/adts_header.h @@ -34,6 +34,7 @@ typedef struct AACADTSHeaderInfo { uint8_t sampling_index; uint8_t chan_config; uint8_t num_aac_frames; + uint32_t frame_length; } AACADTSHeaderInfo; /** @@ -47,4 +48,17 @@ typedef struct AACADTSHeaderInfo { */ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr); +/** + * Parse the ADTS frame header contained in the buffer, which is + * the first 54 bits. + * @param[in] buf Pointer to buffer containing the first 54 bits of the frame. + * @param[in] size Size of buffer containing the first 54 bits of the frame. + * @param[out] phdr Pointer to pointer to struct AACADTSHeaderInfo for which + * memory is allocated and header info is written into it. + * @return Returns 0 on success, -1 if there is a sync word mismatch, + * -2 if the version element is invalid, -3 if the sample rate + * element is invalid, or -4 if the bit rate element is invalid. + */ +int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size); + #endif /* AVCODEC_ADTS_HEADER_H */ diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c index 5c9f8ff6f2..32489dadf4 100644 --- a/libavcodec/adts_parser.c +++ b/libavcodec/adts_parser.c @@ -42,3 +42,35 @@ int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames) return AVERROR(ENOSYS); #endif } + +int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size) +{ +#if CONFIG_ADTS_HEADER + int ret = 0; + GetBitContext gb; + + if (size < AV_AAC_ADTS_HEADER_SIZE) + return AVERROR_INVALIDDATA; + + if (!*phdr) + *phdr = av_mallocz(sizeof(AACADTSHeaderInfo)); + if (!*phdr) + return AVERROR(ENOMEM); + + ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE); + if (ret < 0) { + av_free(*phdr); + return ret; + } + + ret = ff_adts_header_parse(&gb, *phdr); + if (ret < 0) { + av_free(*phdr); + return ret; + } + + return 0; +#else + return AVERROR(ENOSYS); +#endif +}