From patchwork Tue Dec 5 23:00:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 6559 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp6253363jah; Tue, 5 Dec 2017 15:00:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMZGdZtYAFZ0uyxWgcFWRkL0TWjbFu2YZOg2JxFRn/gniMQ0kIUIDQk45p7Drz+Z86QEXhcq X-Received: by 10.28.70.131 with SMTP id t125mr7462610wma.92.1512514845279; Tue, 05 Dec 2017 15:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512514845; cv=none; d=google.com; s=arc-20160816; b=MkSiNrf0jwaeRB21eNuUIV2iqWpf66Mjj+SRq3nSyuK6M2s4Ijr/hdrYbrtkwHugtC uLEh/9Buv4c1Q+A35fG7/OcRoZgAX1Mn7ZhaEEYzrK/ucVW5Cqc8yqIB3PeujgLXzOUC 5HeJLDcZ3z9vDmN7I4ZH8emBl3RL89fD6q5IzWQML1AZdaB1WKD+ZggdpeMk2zjjMCpY VKbWwRqPxGKjHFnKS8wCrpX35tHCHWxuF4TOl9RkoyfB4MvbbOjWW/vHzN6JfaXA4vdP to7s0bo3CAZuu8Dd93R5Q+pXuVtdeGVKBQuvOiMkowt+IIJQKQGG6qIijocaAjZz0yaX 4/zA== 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:mime-version:dkim-signature:delivered-to :arc-authentication-results; bh=wzv40hADGSVaPO3D5kcQZse4CDQ/XIPlqTUNHlYEF8g=; b=ft8dxocG+8P89lL9btksKPyb9FImqzuGqqsJUnDSTzqieIv78+GHNvF/JV32+1pEug 769YGyeZNbI3Y+ChvJ660NCb1AB9F723dvhrIi3OkCbulD24oVIL5JAHka2ltysYuXOW vTLVG0eF4hIxiG4iWnYufd3p5xH9jMmEiTUb++Q1GNPMP3t/Bg7jfdqhJjYPfqXKwTnI zlHVsMynAoTZukYkn9Uzm/W3lPHMSC33mbeqRLU7d2FdC5bsmCMMiMmLH8y69QhFfB+V g74k5B4IGHPGiDh9z+ScTlVEp+AREEp9DD4O/AVtlxLYMpOrN2rFlaBRnOn1zlz2IFI8 h/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=YUwY68Z0; 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 e20si883198wrg.526.2017.12.05.15.00.44; Tue, 05 Dec 2017 15:00:45 -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=YUwY68Z0; 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 3CC54689BD3; Wed, 6 Dec 2017 01:00:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua0-f172.google.com (mail-ua0-f172.google.com [209.85.217.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C99A680D53 for ; Wed, 6 Dec 2017 01:00:31 +0200 (EET) Received: by mail-ua0-f172.google.com with SMTP id e10so1515669uah.10 for ; Tue, 05 Dec 2017 15:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=BNdkKNOHiIVbHHUZi/3pI8viN5vkkr8eg0bjEQ/3kwI=; b=YUwY68Z0y3WGtbm8KI168dqqdyzR0my1GndwDihEhu0pzH7Ny10o6DuFueLMSLahXM g7JdZjDwW8DWFFpz7/6ElnwMbuNOAuRS1YKUhMzGTLeAXzben09lt/KXlR85pr07YVgx QNrZtnDwsczq57ehf8ENCz66U2mRvAUy6zGsYlIabnsH4Db0DTUcwSWoH9zwf90GPGNC ukP/Lc9YORIxQ9LDJhJXNc290Yk5erjmZwCbF0CaMJjdzPzMQXpXiOm4Bp2yH68QS/oe q9vAK7vblRgSBDnEKbPZc4RHut4PwMEoaXc0TQkfnIj5ip97u1wEMaT16Fzs+KyRTJSk aLZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=BNdkKNOHiIVbHHUZi/3pI8viN5vkkr8eg0bjEQ/3kwI=; b=VJruxYaOikMUMj+dOSmPtVad1CKPoVyVcBu694GiniTi0VpflPtnuxpOnxsj9W72BR sfujKrNx0lT5cKvAfpesuzrRXyNKsdBeoZE2Px5FGAG+QG56yVxBA/FNA1kE+IJe3vVY xtU4BqP5KUjV7o3gPXh6mH/WyzJ1gVH8FZR979Z2qIOgIqm3fxZdWJOO2S801nE3w1+y jN4DiRshFD4WWzjxiEklzOPzgJrLVthrhpxDF3g3xQvtu6L0doKVwOOXPKzCoaQwke9Q q0WBFeSvgly0tBtUvJHIh9mf79S4Hx38ZhWMGmmonR09pLDsyIUDP68oFdho+AoEPFzg 5fkw== X-Gm-Message-State: AKGB3mJa2xC010KN/sqB8ul3evdAzv80Lmo1mi43XJ03Fn2zjDgkL4/N Las6eqSaR5EgQ4Ikau9bX5HZ2GOqI//pogeZ7c358x21 X-Received: by 10.159.36.1 with SMTP id 1mr7254931uaq.84.1512514834529; Tue, 05 Dec 2017 15:00:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.214.138 with HTTP; Tue, 5 Dec 2017 15:00:33 -0800 (PST) From: Jacob Trimble Date: Tue, 5 Dec 2017 15:00:33 -0800 Message-ID: To: FFmpeg development discussions and patches Subject: [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" I am trying to playback encrypted content. I know that libavformat handles decryption already when using clearkey, but I want to handle the decryption myself. The encryption info is parsed in mov.c but not exposed to the app. This adds some structures to hold new side-data that will hold the info needed to decrypt. I wanted to post this first before I implemented the code in mov.c (and probably eventually matroskadec.c for webm). Also, can I use the flexible array member feature, it was introduced in C99? Would a 0-length array be better? From 608524d302bec8a8339e8389cfbdebfd573cf75b Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Tue, 5 Dec 2017 14:52:22 -0800 Subject: [PATCH] avpacket: Add encryption info side data. Signed-off-by: Jacob Trimble --- libavcodec/avcodec.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5db6a81320..7c9b071c48 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1112,6 +1112,58 @@ 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. + * + * Since this uses a flexible array member, the size and layout of this type + * is part of the public API/ABI. + */ +typedef struct AVPacketEncryptionInfo { + /** The fourcc encryption scheme. */ + char scheme[4]; + + /** The ID of the key used to encrypt the packet. */ + uint8_t key_id[16]; + + /** The initialization vector. */ + uint8_t iv[16]; + + /** The size of the IV, this will either be 8 or 16. */ + int iv_size; + + /** + * Only used for pattern encryption. This is the number of 16-byte blocks + * that are encrypted. + */ + unsigned int crypt_byte_size; + + /** + * Only used for pattern encryption. This is the number of 16-byte blocks + * that are clear. + */ + unsigned int skip_byte_size; + + /** + * 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; + /** * The decoder will keep a reference to the frame and may reuse it later. */ @@ -1327,6 +1379,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 -- 2.15.1.424.g9478a66081-goog