From patchwork Fri Dec 8 18:06:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 6615 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp850039jah; Fri, 8 Dec 2017 10:06:30 -0800 (PST) X-Google-Smtp-Source: AGs4zMYGCzcee5J9hW6E+o5PmWLrWCAAWIpC6xdPyVq+UHc7I+7DecW7KKslYhbUKA5AhLYpl+z0 X-Received: by 10.223.161.14 with SMTP id o14mr28660431wro.111.1512756390008; Fri, 08 Dec 2017 10:06:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512756389; cv=none; d=google.com; s=arc-20160816; b=M6riVmLffFLQ4OljJaJ+DCOt6YUaVxNoL+aTNwAo0vH+aMNOco2JNy3/5xVD8hfvLh wuKIPCTd4oIG8RKuMyicrtNHOTI8Ph6EqiynzPi1hrrFgWxztfUoCv1REhpJvxH8KOE0 MyCiY/8+9gom1zyQy5SPus3MQ4a94mR2jKpA50qQqYzqqN2pk/GG++WXCpt3U68inVvX mRJvG0OnxiJXkLTi2OL/2KBMubDXa9l1DzEag9Nz6Q1RxygmPmrJRSPHa5HgM1Do7Vu1 2K0uomC0FVI0brkP1d19U+NWfERFiXClLLC5+8hVU6GTUa4NYc45/AOcK+NpxC1fKbyR OZ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=CPGTPd0wJNowUDP9uLsPj8vHwNtAASgoK+7TPf9FNvE=; b=uucmV9fW2TpG9+SwPnaqLvg+9XmAmwUX++FEw0LygEYHcDQlZndA0Dc6doHiuCFSp6 6gkoQ/t/sQKDbnDhQtTwMqjPUEOcwOdKLBnnSSjvXqzIdEDuzdrrLZS/Qcdx86vQl/YE JKUEFa/aFqAXW0hTw+Dg2cjFvNUaYHzH3WXl7r0JlgVYV3Q1kODR5XcoJsI2DPuzLXmi atmBEsWS7/FIlZMOan/UFsX90CAuqBaCHeekHcL1LElt/qO2jrQsoZYUSGtOeJ9pdvum N51XAly/5gMdIlwd6y1DSF6qBOADadKBJhxlAbVEEgZoVGUdtFeV8RPQSVT6Gtt/asmm gj7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=a2C35u2f; 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 z72si1487782wmz.39.2017.12.08.10.06.23; Fri, 08 Dec 2017 10:06:29 -0800 (PST) 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=a2C35u2f; 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 56115689EC3; Fri, 8 Dec 2017 20:06:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E71F6689EC3 for ; Fri, 8 Dec 2017 20:06:09 +0200 (EET) Received: by mail-ua0-f174.google.com with SMTP id i20so8030075uak.6 for ; Fri, 08 Dec 2017 10:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=KJzqpoKBku3cvNPlswhEkgFZID/KHfZsBSSz1DA9Hg8=; b=a2C35u2ff4OSWVIhxzfqFYCNXslKjWmjWVafrnAVjVIvRRlyJUAWE7+Bu87yZkLSXn Pv0RD3DKO9iJ/2sxArQ5L6JcOIfDKipFmMIyxEqwuaLjTrsGN1+rEWyjbu2hVnFG9eNI lDDX3JAQcs7Ag+2zXxGg5QxF/BAq154pLqwouWh3z8OWBV83xrpi6UWSmyh1pVUJ+Xdv /2ViZOhEmJWSB3rO+kbNf+N/7gdWTFjDANfpLsttxM1n88Qzq3E+IT9FkOHAmHvEeCPR TtEasgw9fDrUp5aTqrG55q7kg51vQU3Ff2MlCa5TVjDPzZoPoUU9rHSMGuoMDdikGW9I bR1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=KJzqpoKBku3cvNPlswhEkgFZID/KHfZsBSSz1DA9Hg8=; b=i2DlumMjIiLtDdGjuXczfpf8jNzqBnPV9+QyuLRKtqxxmFCMawc3zijuX1GN/8r+c/ ybnARuku91tIrmrPsxUauqnqmlolpz9Q9hZuxUdGmffZI9+42PQPNUMObQt0dQOuPP+n kxE0wTskdQ8AZRBtkd6iXsSqGm34ZW8gJO8MNVtKp4zOqnJ6x3z/Hw5MHhw3itJnkI4q HJvCuIH3MfptTLR8z4KtVNPtmwgAAQoM0LytNryrivikYEAO5tSDuQ/eROUqmO+nIfE0 /3yg9IZ1J1t9s6tViggDikW+73LyX3VucAkym2a4fMj6n+omYpH6rtUEEwajEYrE1/Qs 12Bw== X-Gm-Message-State: AKGB3mLnNomb1JYxySCO4PR0gPfcI47Ee43tU+tY3cuvP+2/5YRgBBaM WJfyX4juY7AsG1W1eH1VnFOFDtGYBK/yAxgDVgdVSWwE X-Received: by 10.159.51.85 with SMTP id a21mr18149801uac.11.1512756374616; Fri, 08 Dec 2017 10:06:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.214.138 with HTTP; Fri, 8 Dec 2017 10:06:13 -0800 (PST) In-Reply-To: <7fb333c3-36aa-7aef-6a46-349fc49b3a75@gmail.com> References: <7fb333c3-36aa-7aef-6a46-349fc49b3a75@gmail.com> From: Jacob Trimble Date: Fri, 8 Dec 2017 10:06:13 -0800 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [RFC] avcodec/avcodec.h: Add encryption info side data 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Tue, Dec 5, 2017 at 5:22 PM, Derek Buitenhuis wrote: > On 12/6/2017 12:36 AM, Jacob Trimble wrote: >> Would a 0-length array work? Otherwise I would need to have it be a >> 1-length array and have to account for that when calculating the size >> to allocate; it would also require a comment to ignore the size of the >> array. > > Aren't 0-length arrays a GNU extensions? If so, I would gather that it > probably is not OK in a public header, either. Yeah. > I'm not entirely sure what way we prefer nowadays, but you can see > we've had side data with variable length members before with e.g. > AV_PKT_DATA_QUALITY_STATS, but that doesn't have a struct associated > with it. I'm hoping someone more up to date with the side data stuff > can chime in with a suggestion on what our current best practices > are for it. I would prefer to avoid requiring the app to "parse" the side data, using a plain struct would be better. I've updated the patch to include my other plan of allocating a larger bock and having the struct followed by the subsample array. I have also renamed the file, I think the mailing list rejected my attachment before since gmail sent the MIME type as text/x-patch. Hopefully with the .txt extension gmail will send the correct MIME type. From 740c0ccf3ed90b3d417ea25ec26cfefb93974461 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Tue, 5 Dec 2017 14:52:22 -0800 Subject: [PATCH] avcodec/avcodec.h: Add encryption info side data. This new side-data will contain info on how a packet is encrypted. This allows the app to handle packet decryption. To allow for a variable number of subsamples, the buffer for the side-data will be allocated to hold both the structure and the array of subsamples. So the |subsamples| member will point to right after the struct. Signed-off-by: Jacob Trimble --- libavcodec/avcodec.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5db6a81320..6f5c387556 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1112,6 +1112,53 @@ typedef struct AVCPBProperties { uint64_t vbv_delay; } AVCPBProperties; +/** + * This describes encryption info for a packet. This contains frame-specific + * info for how to decrypt the packet before passing it to the decoder. If this + * side-data is present, then the packet is encrypted. + */ +typedef struct AVPacketEncryptionInfo { + /** The fourcc encryption scheme. */ + int scheme; + + /** The ID of the key used to encrypt the packet. */ + uint8_t key_id[16]; + + /** The initialization vector. */ + uint8_t iv[16]; + + /** + * Only used for pattern encryption. This is the number of 16-byte blocks + * that are encrypted. + */ + unsigned int crypt_byte_block; + + /** + * Only used for pattern encryption. This is the number of 16-byte blocks + * that are clear. + */ + unsigned int skip_byte_block; + + /** + * The number of sub-samples in this packet. If 0, then the whole sample + * is encrypted. + */ + unsigned int subsample_count; + + struct { + /** The number of bytes that are clear. */ + unsigned int bytes_of_clear_data; + + /** + * The number of bytes that are protected. If using pattern encryption, + * the pattern applies to only the protected bytes; if not using pattern + * encryption, all these bytes are encrypted. + */ + unsigned int bytes_of_protected_data; + } *subsamples; +} AVPacketEncryptionInfo; +#define FF_PACKET_ENCRYPTION_INFO_SIZE(a) (sizeof(AVPacketEncryptionInfo) + sizeof(unsigned int) * a * 2) + /** * The decoder will keep a reference to the frame and may reuse it later. */ @@ -1327,6 +1374,19 @@ enum AVPacketSideDataType { */ AV_PKT_DATA_A53_CC, + /** + * This side data is encryption "initialization data". + * For MP4 this is the entire 'pssh' box. + * For WebM this is the key ID. + */ + AV_PKT_DATA_ENCRYPTION_INIT_DATA, + + /** + * This side data is an AVPacketEncryptionInfo structure and contains info + * about how the packet is encrypted. + */ + AV_PKT_DATA_PACKET_ENCRYPTION_INFO, + /** * The number of side data types. * This is not part of the public API/ABI in the sense that it may