From patchwork Fri Oct 1 22:53:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 30881 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp2154221iob; Fri, 1 Oct 2021 15:53:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz1dFjhA0Hz98YRYlv2lhGH9DbHxJsEGesL5ziZaa3DoPBXC4URvhkoNfC6jcfTrNHZxx4 X-Received: by 2002:a50:bf02:: with SMTP id f2mr194535edk.226.1633128826208; Fri, 01 Oct 2021 15:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633128826; cv=none; d=google.com; s=arc-20160816; b=RvmBZj3h9ZT4xSa+KRB2RtD7fpD89/O4tS3/m9r7TAGcw5P6Fhe9cFF/v3JPAkpp2f YYG1r7O8LUk/A5fT0b6dOrocWoPNTwC/lkavzpjdRGo/0VgNzXkao5m6zd6twKD6p4wF BhSPFXn809qEeQ5+zIttR5U9e6AI8jjeNQ8VQn1WmQGocqZs65RUlxqozXmyFrEhHg2F t/vjkXUThmFyBe2tlk+wIqhAshKfdj49C2UNBiEcCCokKTdd9pgpNmLTJg0jylxbiEpb O/Pu3+EPANht1Zj5OOvHB88oUAKGx3INofhNp61Xo/8IN+Eg57KLMaJPUh6pqQ6oNbg2 ou6g== 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=l7SlSkUMe2oD8QCGDnoR4N9IhMkHeKqG0v4VyE0iZc8=; b=oxEvgrQeyWIe0Xorum8c+K4gx1iwUE9uRdUy8no3FlvkutR665vufFYSlvLShMqtZc UII+955KjRTQ9g9Z4s6wc2uJtmXdwbieyXZjZpGZuNGsmkZSR5/OrYZ+ytwvDsV5DDlF 7eMujUC3ybJjOvk9TNKCRc8ifdCk3jCxnmLKDsTjndO0V9OtsbIJge8djqymCOyIWf+O 8k/wmqkPVGlB+WTz7849xA/9tE3EHUN8xZ7HczDiL4T8UVlMjgRe/6Xnf/tvqpqtem+C JQb51KBXIquO3NFkn+Dikp+t3Hu8HU+SgKTj+N5jgkHA5AQrM1IyO9HIp8eLykR/y+fI EuWQ== 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 k7si8742170ejk.77.2021.10.01.15.53.37; Fri, 01 Oct 2021 15:53:46 -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 C8DD068A744; Sat, 2 Oct 2021 01:53:33 +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 DD5B468A6D2 for ; Sat, 2 Oct 2021 01:53:27 +0300 (EEST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 3EF2F22618 for ; Fri, 1 Oct 2021 22:53:27 +0000 (UTC) Received: from mail.home.jeffm.io (jeffm.udp.ovpn1.nue.suse.de [10.163.30.74]) (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 2169FA3B81 for ; Fri, 1 Oct 2021 22:53:27 +0000 (UTC) Received: from localhost (nuc.home.jeffm.io [IPv6:2001:559:57b:110::64]) by mail.home.jeffm.io (Postfix) with ESMTPS id DE5A08BDF01E for ; Fri, 1 Oct 2021 18:53:03 -0400 (EDT) Received: by localhost (Postfix, from userid 1000) id 7CE6D73968C; Fri, 1 Oct 2021 18:53:23 -0400 (EDT) From: Jeff Mahoney To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Oct 2021 18:53:23 -0400 Message-Id: <20211001225323.32700-1-jeffm@jeffm.io> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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: wscDyuRJ6N2H 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 | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 34c7950bcc..dd0ced790e 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -176,7 +176,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 +204,38 @@ 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) { + /* + * Start of ADTS header - syncword + * If present skip the header and copy the entire payload as AAC data + */ + if (buf[0] == 0xff && (buf[1] & 0xf0) == 0xf0) { + /* + * The ADTS header is 7 or 9 bytes depending on whether + * the protection absent bit is set. If it is unset, a 16-bit CRC + * is appended to the header. + */ + size_t header_size = 7 + ((buf[1] & 0x01) ? 0 : 2); + if (len < header_size) { + ac_log(ctx, AV_LOG_ERROR, "Error parsing ADTS header\n"); + return -1; + } + + buf += header_size; + len -= header_size; + + if ((ret = av_new_packet(pkt, len)) < 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;