From patchwork Fri Aug 4 20:35:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 4626 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp2728611vsu; Fri, 4 Aug 2017 13:36:43 -0700 (PDT) X-Received: by 10.28.212.10 with SMTP id l10mr2004263wmg.40.1501879002213; Fri, 04 Aug 2017 13:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501879002; cv=none; d=google.com; s=arc-20160816; b=rMLCP1PlY1bERvvFrtDfLaGCnd9/mUc3HwS2TGpMwcuLBuUvMLNqGWgMotJ6mzsZf8 Cf451qjviQH/14Wwr5Yb+a1M/bvbrM+5IokpP01NmrtiA2iJwOHq3bzx+XVDHn6k/mUb H2Id3x0U0UWAad3HpPKqXff9J3pbqxtC8GsoAGeTaevNf8SmVYIdTZbcX8PG94cefMTt qZuU9ZMCzVCF9xxFdyHjGux7uXRYCMwdUALwCf/RyM6dkjL1nx1pxheZCoRzugsW0n8K ISdQBHaKgEfWerDnSfniWRI1sa4e19PYNmrnbO85qajNvGyme6dL8MTFSuJAXrsNsqR7 ej1g== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=IXpO+k8xATvhDBmNl396WbY6dFu1ceEoJVXMQlig2ew=; b=smu4apJ/RKvfXEP3+aczznWN3U5ze3sxuDRNneIMJAumd4WFfHR7tPUncB4cOCdTpY opVlq+r/tBrgY5cD1hRSs6Xn3GATYGNCpq2jJKuaIEPvw4KmLle+kiRt9Ro8k4P0bnZD 5mg0AvBkGTzJq33I62SSEAcLSyq2rJH7yhcgZKraZH/PGuptdu89b3ur2+GLhk0Jw9fx znym0Szh6m3rLhpi4hBz9GFsXqAZiSAWmls0yFOKwCMRi/8CMhmbuHiqJktYDFWk9BXh DTdNKGgiy0JNdraJfxO06wbHKMqG7GR0ikejdSAEkqjnp56hLazPbuag+/bvjquFDkiT codQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=ZsyHHM5H; 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 r3si3677297wme.259.2017.08.04.13.36.41; Fri, 04 Aug 2017 13:36:42 -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=@google.com header.s=20161025 header.b=ZsyHHM5H; 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 3B1C0680756; Fri, 4 Aug 2017 23:36:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f182.google.com (mail-pf0-f182.google.com [209.85.192.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89B006805C3 for ; Fri, 4 Aug 2017 23:36:32 +0300 (EEST) Received: by mail-pf0-f182.google.com with SMTP id o86so11942465pfj.1 for ; Fri, 04 Aug 2017 13:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hCpMaq2UFhR6RHUL7Gjl+zFE5E3odip3Z9xqXSSG50E=; b=ZsyHHM5Hhk2YwmcDBVJVQxnPAodfNSwscpEG4aqf4IUrItAsSDv2Z1BfivQwZ9ty1a s6mfe6PN8x7G2CdgVVagAKqae2AYZpayYbYRGP5xjVvCXa/7X+cNQ/V0dTITVpgYib9e sVQIAOwuAL+Hh3v9bHfYFTdGOc67TpRWSxEkHgit9Fpa8M7WtVjmj3umEb6l7JYowbux VLyE5nComb8o3th6EajZA4ZY9Z2bWAm9irkLEZYlH/NxwqL/8nmLIfr6onLuUuq1SAGT f4Y24enXugihZy/VobvsfllYFQNR8IOLnH2TlVvx5A5CyHTCclHglEUD1vNoiCxE/oN9 TX9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hCpMaq2UFhR6RHUL7Gjl+zFE5E3odip3Z9xqXSSG50E=; b=eN6eiPgEEKKGG8NZbCHpeTlC3UMlX/+X5Cy80olQRvlcz/yAVn/GWv9e/CitL0Mi25 khSoRhfcv4qS0B0Cnt85gk/RY0BrzZSK23atHHJ4UCiTkwscp8M/xti20SZ3pWpgPTSV L/+T98ZWhDFVXpO7RsY+IvpAU2ieMVF26/HQ7eAFDgnMo/lljhDdI1/+DEXp0Yszm0lm VCVpjkAE5vm8GLb94BsPyCzums7RtKvWeiB9u5o8JRISWYliQ+iejcKuFzVCpkDoCjfV DGST3b8g4Hk0e8DxNfeNjrn3ndFh6y6+sgxcD8OXY0kzzLZE9V7PZ6gga8BHmEy95Ofz OLSQ== X-Gm-Message-State: AIVw111B4pu2GnkQtvJhf3jdrDhbmGmbknfNP57X+Y6M3m7bEDf32uHv 1bTw/z0tFeBs/i2FC2hD4Q== X-Received: by 10.99.121.72 with SMTP id u69mr3507064pgc.33.1501878990514; Fri, 04 Aug 2017 13:36:30 -0700 (PDT) Received: from isasi.mtv.corp.google.com ([172.27.196.44]) by smtp.gmail.com with ESMTPSA id l132sm5297097pfc.150.2017.08.04.13.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Aug 2017 13:36:29 -0700 (PDT) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Aug 2017 13:35:37 -0700 Message-Id: <20170804203537.552-1-isasi@google.com> X-Mailer: git-send-email 2.14.0.rc1.383.gd1ce394fe2-goog In-Reply-To: <4c4eaec3-fc9c-6840-0dca-b28af2fd7d23@gmail.com> References: <4c4eaec3-fc9c-6840-0dca-b28af2fd7d23@gmail.com> Subject: [FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Sasi Inguva MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" According to https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html and ISO-IEC-14496-12 Section 10.1.1.1 and 10.1.1.3 Signed-off-by: Sasi Inguva --- libavformat/movenc.c | 70 +++++++++++++++++++++---------------- tests/ref/fate/adtstoasc_ticket3715 | 4 +-- tests/ref/fate/copy-psp | 4 +-- tests/ref/fate/movenc | 12 +++---- 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 0e5b45d150..10b959ad02 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2208,39 +2208,47 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track) (AVRational){1, 1000}, (AVRational){1, 48000}); - if (track->entry) { - sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries)); - if (!sgpd_entries) - return AVERROR(ENOMEM); - } + if (!track->entry) + return 0; - av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS); + sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries)); + if (!sgpd_entries) + return AVERROR(ENOMEM); - for (i = 0; i < track->entry; i++) { - int roll_samples_remaining = roll_samples; - int distance = 0; - for (j = i - 1; j >= 0; j--) { - roll_samples_remaining -= get_cluster_duration(track, j); - distance++; - if (roll_samples_remaining <= 0) - break; - } - /* We don't have enough preceeding samples to compute a valid - roll_distance here, so this sample can't be independently - decoded. */ - if (roll_samples_remaining > 0) - distance = 0; - /* Verify distance is a minimum of 2 (60ms) packets and a maximum of - 32 (2.5ms) packets. */ - av_assert0(distance == 0 || (distance >= 2 && distance <= 32)); - if (i && distance == sgpd_entries[entries].roll_distance) { - sgpd_entries[entries].count++; - } else { - entries++; - sgpd_entries[entries].count = 1; - sgpd_entries[entries].roll_distance = distance; - sgpd_entries[entries].group_description_index = distance ? ++group : 0; + av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == AV_CODEC_ID_AAC); + + if (track->par->codec_id == AV_CODEC_ID_OPUS) { + for (i = 0; i < track->entry; i++) { + int roll_samples_remaining = roll_samples; + int distance = 0; + for (j = i - 1; j >= 0; j--) { + roll_samples_remaining -= get_cluster_duration(track, j); + distance++; + if (roll_samples_remaining <= 0) + break; + } + /* We don't have enough preceeding samples to compute a valid + roll_distance here, so this sample can't be independently + decoded. */ + if (roll_samples_remaining > 0) + distance = 0; + /* Verify distance is a minimum of 2 (60ms) packets and a maximum of + 32 (2.5ms) packets. */ + av_assert0(distance == 0 || (distance >= 2 && distance <= 32)); + if (i && distance == sgpd_entries[entries].roll_distance) { + sgpd_entries[entries].count++; + } else { + entries++; + sgpd_entries[entries].count = 1; + sgpd_entries[entries].roll_distance = distance; + sgpd_entries[entries].group_description_index = distance ? ++group : 0; + } } + } else { + entries++; + sgpd_entries[entries].count = track->sample_count; + sgpd_entries[entries].roll_distance = 1; + sgpd_entries[entries].group_description_index = ++group; } entries++; @@ -2304,7 +2312,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext if (track->cenc.aes_ctr) { ff_mov_cenc_write_stbl_atoms(&track->cenc, pb); } - if (track->par->codec_id == AV_CODEC_ID_OPUS) { + if (track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == AV_CODEC_ID_AAC) { mov_preroll_write_stbl_atoms(pb, track); } return update_size(pb, pos); diff --git a/tests/ref/fate/adtstoasc_ticket3715 b/tests/ref/fate/adtstoasc_ticket3715 index 949b565c2f..96795a2ca3 100644 --- a/tests/ref/fate/adtstoasc_ticket3715 +++ b/tests/ref/fate/adtstoasc_ticket3715 @@ -1,5 +1,5 @@ -ef8ce3cbd1d86113e7c991a816086068 *tests/data/fate/adtstoasc_ticket3715.mov -33270 tests/data/fate/adtstoasc_ticket3715.mov +0221e04333e6ac432fa42960502f0d5a *tests/data/fate/adtstoasc_ticket3715.mov +33324 tests/data/fate/adtstoasc_ticket3715.mov #extradata 0: 2, 0x00340022 #tb 0: 1/44100 #media_type 0: audio diff --git a/tests/ref/fate/copy-psp b/tests/ref/fate/copy-psp index 6603d3ff26..81eb172549 100644 --- a/tests/ref/fate/copy-psp +++ b/tests/ref/fate/copy-psp @@ -1,5 +1,5 @@ -6889223644fc560069c8591984175a62 *tests/data/fate/copy-psp.psp -2041379 tests/data/fate/copy-psp.psp +cada61453a2483ef8ba1fb82c8bbff25 *tests/data/fate/copy-psp.psp +2041433 tests/data/fate/copy-psp.psp #extradata 0: 51, 0xaf6d1012 #extradata 1: 2, 0x00b200a1 #tb 0: 1/90000 diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc index 09e603aeb7..47bcf9d515 100644 --- a/tests/ref/fate/movenc +++ b/tests/ref/fate/movenc @@ -1,18 +1,18 @@ write_data len 36, time nopts, type header atom ftyp -write_data len 2335, time nopts, type header atom - +write_data len 2389, time nopts, type header atom - write_data len 788, time 1000000, type sync atom moof write_data len 110, time nopts, type trailer atom - -214242e9c7c93171d2f47f5b47776559 3269 non-empty-moov +17a37691eba8b858cf15e60aa9a7dbf7 3323 non-empty-moov write_data len 36, time nopts, type header atom ftyp -write_data len 2667, time nopts, type header atom - +write_data len 2721, time nopts, type header atom - write_data len 908, time 966667, type sync atom moof write_data len 110, time nopts, type trailer atom - -44467d568a3cc38d414fd8ed4b2a968f 3721 non-empty-moov-elst +0026ffe059c06c592021f972bf2c5e79 3775 non-empty-moov-elst write_data len 36, time nopts, type header atom ftyp -write_data len 2575, time nopts, type header atom - +write_data len 2629, time nopts, type header atom - write_data len 908, time 1000000, type sync atom moof write_data len 110, time nopts, type trailer atom - -de22b98a3885f9b4b83cdd48ff46aeb9 3629 non-empty-moov-no-elst +c184e168ac1e5bb3d9c70e580ab6179c 3683 non-empty-moov-no-elst write_data len 20, time nopts, type header atom ftyp write_data len 1171, time nopts, type header atom - write_data len 728, time 0, type sync atom moof