From patchwork Tue Oct 19 21:02:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 31163 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp710506ioa; Tue, 19 Oct 2021 14:02:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjiDwmiLKp1Mg0YSeOW0Y/rTMf8fVnsYqGNKPCQmGyjkVsfI2T7UBWXfImiA3eDzPb0p16 X-Received: by 2002:a17:907:1006:: with SMTP id ox6mr41175452ejb.146.1634677375091; Tue, 19 Oct 2021 14:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634677375; cv=none; d=google.com; s=arc-20160816; b=Mt3d+vOFxs/8gbcxB0jGGdb8/NtI2VgbkOCfewV9xMVhnp+KJyoKq+YjsSnetCbViq zGdT1OIWXno/xgfIZf5uXZ4DTm8SWn9JmimJLgDEJ67U6TbbLOgr8X6Y9MQ8eV5z6Xne NcACeRHh2tAt8u9aCzAZNm8Mb7Him/Gcnm/jM14acdfyHO7qn5x7yBBqqYse4EeSan2i p8Fi7Zuk9aH6XfrDhjTa+vqmJ7MtG3A5ng7KbM87myAfgTJ+WH5h7B9KDwkR59zq6FOH kItnzj4WL/PVzeJNTPKaCe9zeSecax7tQaSi7U8rg27ezECPLtXS0Mco70Ab6pyDWXzU 3jwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=Yt8rlFeh3tozt1FqtDSqVkN0WWRoScuEOmXid3ZOanw=; b=dffm8zU2RUjTgm48Dzh0L8Pr3vbYdhVy1XvEzIGi/+dKKORbPfE/ZrM6yix5X3943n ddD6FL4mSLnaZzTERps1xWEwXbZ6Ds9VsJy1XhdBrMUvx38P/VvVHJpxJLW7johefsSt 9JW7Y1gLorfIe+ZKyZ8VTiOZ+3OehrcTjywS1QcS5XR9DspS3Cfax6qJ0r0EAycd9PjA c32OVRaOk86S1XbyAuDrPtxLVArYcIWsdNQlM5nAptWXYmbhQWw3LIsXyKVkZEx3ZC5W OPj+Iwv0Ye2JBdbsVr+bC5xne91wO+edSw/yxf7qmpARldI/d51HN1NFIuG6qq0bi2Z1 nF1w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m15si421063edc.103.2021.10.19.14.02.54; Tue, 19 Oct 2021 14:02:55 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 061FA68A5FC; Wed, 20 Oct 2021 00:02:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F784680867 for ; Wed, 20 Oct 2021 00:02:46 +0300 (EEST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E216A21A68 for ; Tue, 19 Oct 2021 21:02:45 +0000 (UTC) Received: from mail.home.jeffm.io (unknown [10.163.40.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C1496A3B81 for ; Tue, 19 Oct 2021 21:02:45 +0000 (UTC) Received: from localhost (nuc.home.jeffm.io [192.168.110.64]) by mail.home.jeffm.io (Postfix) with ESMTPS id CBDB98955CBB for ; Tue, 19 Oct 2021 17:02:11 -0400 (EDT) Received: by localhost (Postfix, from userid 1000) id 8DFD57636B8; Tue, 19 Oct 2021 17:02:44 -0400 (EDT) From: Jeff Mahoney To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Oct 2021 17:02:44 -0400 Message-Id: <20211019210244.4130-1-jeffm@jeffm.io> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] libavformat/rtpdec_mpeg: handle bare ADTS packets with explicit decoder config 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3l/1RYFSwocB When SDP specifies a decoder config, there may not be any AU headers provided by the sender. This can result in rtp_parse_mp4_au failing and aac_parse_packet reporting "Error parsing AU headers." and no audio is recovered from the stream. This commit modifies aac_parse_header to check for an explicit decoder config set by the sdp parser (e.g. a:fmtp # config=hexvalue). If it has and there is an ADTS header present, it skips the header and copies the RTP payload directly as an AAC packet. This resolves an issue observed with some inexpensive IP cameras. Signed-off-by: Jeff Mahoney --- libavformat/rtpdec_mpeg4.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 34c7950bcc..13d0770dd6 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -32,6 +32,8 @@ #include "libavutil/attributes.h" #include "libavutil/avstring.h" #include "libavcodec/get_bits.h" +#include "libavcodec/adts_header.h" +#include "libavcodec/adts_parser.h" #define MAX_AAC_HBR_FRAME_SIZE 8191 @@ -176,7 +178,7 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, int flags) { int ret; - + AVCodecParameters *par = st->codecpar; if (!buf) { if (data->cur_au_index > data->nb_au_headers) { @@ -204,6 +206,39 @@ static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, return 1; } + /* Check for an explicit decoder config (e.g. SDP a:fmtp... config=) */ + if (par->extradata && len > 7) { + AACADTSHeaderInfo *header; + + /* + * Check for ADTS header + * If present skip the header and copy the entire payload as AAC data + */ + ret = avpriv_adts_header_parse(&header, buf, len); + if (!ret) { + buf += AV_AAC_ADTS_HEADER_SIZE; + len -= AV_AAC_ADTS_HEADER_SIZE; + + /* Skip 16-bit CRC if present */ + if (!header->crc_absent) { + buf += 2; + len -= 2; + } + av_free(header); + + ret = av_new_packet(pkt, len); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); + return ret; + } + + memcpy(pkt->data, buf, len); + pkt->stream_index = st->index; + + return 0; + } + } + if (rtp_parse_mp4_au(data, buf, len)) { av_log(ctx, AV_LOG_ERROR, "Error parsing AU headers\n"); return -1;