From patchwork Mon May 9 18:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35707 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp3038463pzb; Mon, 9 May 2022 11:17:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7IGhpU9dsRUcUx3CgtOQKw19dpavE/PjIYyJ+RxH+XpkaXHHXcbJ819pJGyPp34BQnzer X-Received: by 2002:a17:907:3faa:b0:6f4:da62:6729 with SMTP id hr42-20020a1709073faa00b006f4da626729mr15250327ejc.747.1652120255613; Mon, 09 May 2022 11:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652120255; cv=none; d=google.com; s=arc-20160816; b=Yk1W/lkivMyhY52gGHDlfXGToovnEW+QP2VKj4eaYPjC54UDCXs1YEqB/HCZHLl9xf OefaxZwoVk1Xo9Meek3atFP6AhEvpjgQ1VYPp21UsZpLhm4jRiaL9vunHXyByfzzzluY IAcJ5fILCU4I6u9uTYmFjaHYmonW15Yq0nWkvETV5+ifUn6/XGDiFCrjRhs9CcUlkbdT 9lLJhiD2gme7ABGA291vEmquttTmR0Ug0iwjV02Psv8gxDYoScwohD6fEuqfOlwzj0Dv yYCNdh1xSDtqa/earwOz+kpt4xb/KDiMYWxSYXVp9MMm5qlDilB/yzbjZXM6jQkF75n6 7CKQ== 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:to:mime-version:fcc:date:references:in-reply-to :message-id:from:dkim-signature:delivered-to; bh=hYkLliijgTNfGZkOoUyNAKxZNabNuzJ6sPmEtMemwB0=; b=PeGhpTtiZtzG9/BDyJN+hDYyTtIY+y2swfnS//BRZ8XwXFbD5JsG1S8q+t1ncDDGFk J4ksqpyFHwMcLWvNVahJkO6IaHEYlAWL3s1npwgWe5qfqI+JVZxn1EvcH+WsuZpxKuf7 pTx7X70NlqE8XR9z9tRur/ku/drgyTfMWK/x+etZIif2lXGJq9xzo2nnIS8a82o73pGI FyhlH6HJhvRmhtF1EtrXm1t+Rh9ZdNATFjmtCpqNTcMttEaRWR83J9H6r0W7T8HGLoFA cifXCts0EF+HxluZGsm4wKv5mhK/GfVBzSIew6qFCGwb4p6iSjugHdJq/L8oM5UfVsn5 LbMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nQPDw0VE; 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 cb26-20020a170906a45a00b006e7ee599274si15822233ejb.235.2022.05.09.11.17.35; Mon, 09 May 2022 11:17:35 -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=20210112 header.b=nQPDw0VE; 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 B412C68B3F7; Mon, 9 May 2022 21:16:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A47B168B3C0 for ; Mon, 9 May 2022 21:16:33 +0300 (EEST) Received: by mail-pj1-f44.google.com with SMTP id c1-20020a17090a558100b001dca2694f23so83337pji.3 for ; Mon, 09 May 2022 11:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DMN3NoxUCpq5srr2DgFFUcKEGDvP131KE+o6w7c+E3o=; b=nQPDw0VErrN1QaESDfOZG/OCvddHmD+KGkEaqDBVfJ7nOT2SPPVBtz8esp1BgQ0O5P tmdrWbfBE413/0WT4r26BzhFbpK/xvrm+JQ0yQbNFuA0f4VwITpsAPv3QciQhH8o+AN0 f1x8Z6vGuD/hsMS141wkdZ/TyXLZmuHrbkFtAkHkfi1h0R1OalpuMF8IZxDyHr2G+xCW 1183sy/3bb9hr5C2WnidSziiXlDze1MagjW6+ZNQTYWSGCgWLGxyNTKbtNNy22G8Kz+R 8Yxbv295Qnua4sZOYaGeeSfk4lumdinUpiX0iD4fzv/VIMsHJ5bsk07yIUWq+ZfcGjVl GW1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=DMN3NoxUCpq5srr2DgFFUcKEGDvP131KE+o6w7c+E3o=; b=KtXxJwPnZWyb9fYUKs7xEPSwGKNwdlb6VlQ/q4AqRuW5DaTIqHFNxdyjI0a4w2LC0I I7JMsIXDZeq/5ebdcpXVAps/iKIxKlEho6hz/DnWvH4UscY6NOA4RUndqxRvfxWk9cO/ zomeqsTJm4kavSoI+Spf6FT9Zk6BT6rV/A0o9j4yEmgAbej6nSOjRq8v7CCGOVjnWmLZ VCVqqcLUfuoBcGn68r4ek1RsyzonEMiztWBWNpLPvPRC7XqrTqPPryf8JAmB+1eQATtK yLhbdZgrCEpc5msH41KE2viUvLVTsoGk1rRi0vUR7UmYVOp8Ajm81BFTsS3MpFxwvbwM FuDg== X-Gm-Message-State: AOAM530kUpMYBYw8wgBtyoc9CnNH6DZhmoh6y+/htusdj3bRCaZyNi+f CFw5k8zq5f98zCHOuWL7GiedD5gtpcsZEw== X-Received: by 2002:a17:90b:4d90:b0:1dc:c03e:3a39 with SMTP id oj16-20020a17090b4d9000b001dcc03e3a39mr23974769pjb.116.1652120192138; Mon, 09 May 2022 11:16:32 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id h27-20020a056a00001b00b0050dc76281d7sm9245132pfk.177.2022.05.09.11.16.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 May 2022 11:16:31 -0700 (PDT) From: rcombs X-Google-Original-From: rcombs Message-Id: In-Reply-To: References: Date: Mon, 09 May 2022 18:16:24 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 6/6] lavc/h264_ps: always include the stop bit in [s|p]ps->data 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: le2tf6zfEckc From: rcombs The VideoToolbox hwaccel needs the entire NAL (including the stop bit), but ff_h2645_packet_split may remove it. Detect this case by looking for bit counts divisible by 8 and insert a stop-bit-only 0x80 byte. Signed-off-by: rcombs --- libavcodec/h264_ps.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index 051f06692c..e16da68dec 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -351,6 +351,10 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, } memcpy(sps->data, gb->buffer, sps->data_size); + // Re-add the removed stop bit (may be used by hwaccels). + if (!(gb->size_in_bits & 7) && sps->data_size < sizeof(sps->data)) + sps->data[sps->data_size++] = 0x80; + profile_idc = get_bits(gb, 8); constraint_set_flags |= get_bits1(gb) << 0; // constraint_set0_flag constraint_set_flags |= get_bits1(gb) << 1; // constraint_set1_flag @@ -775,6 +779,10 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct } memcpy(pps->data, gb->buffer, pps->data_size); + // Re-add the removed stop bit (may be used by hwaccels). + if (!(bit_length & 7) && pps->data_size < sizeof(pps->data)) + pps->data[pps->data_size++] = 0x80; + pps->sps_id = get_ue_golomb_31(gb); if ((unsigned)pps->sps_id >= MAX_SPS_COUNT || !ps->sps_list[pps->sps_id]) {