From patchwork Mon Sep 17 21:35:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 10350 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp3985283jap; Mon, 17 Sep 2018 14:44:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbF+S3Xdq/FET0jHYkZQyk21gkrmVLbYxbKsoFvLMvKHDra+XJbWVNjC7rIgyeVaXrKQPbK X-Received: by 2002:a1c:48d:: with SMTP id 135-v6mr12379637wme.128.1537220649984; Mon, 17 Sep 2018 14:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537220649; cv=none; d=google.com; s=arc-20160816; b=nn9rDu9pdFHjilpcNtk0VnbfiipZEQnxEP0+wSOmilOk9vbtlHujAahHgiINUWKER9 IRewIJo1qeHuL1C8oEehLczv6xh2hjTYih3WKfr2h9JZmZGfP/RcfDES+RnV5hEfndJA SjZAvl+NJbTN8CuRKMyMyzwDJnLVsaT6oUw6PSEvimFOFmPCtZxTYxcp03sC9B1U6Ata 9tNLtMXbKksB//vcKs7B7MWLqfM2vgUw6SZzUzNnNtl00HrA9f0yW2+8tpS0Tl2fooFq SMaC+6A15AR6zJdYIDAVU6j3CJeyuklxVCtVobWxmAKY2BEFoM/q1IWmvMgNPyOhD+98 8bhw== 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:in-reply-to:references:mime-version :dkim-signature:delivered-to; bh=AXqVDbWi4+sTKyunj8fTS+nIQoiPu4ljhZADtM/lOrw=; b=FS/jFXoRqa+6RAE1QSt7Fh8nmSes7PltisET4Qi6AL7w9SyKBO7mBvL0+y5PRCj2zK cE/7Xomyok19Kv8EC4unVlKq9vHiQAdcmcazuzA5MZmBebxXq2FPjygpVAQFoLrr8bMV fe9m57dc53Wwetiuf+bkOZpdlxQeRQvvZYL3/Y70BhKFl+pHZd+obdWR5sTE0xD77bzZ vc0LnQhA+QpCiyz9rbCfswoGAKnZFj1yCb7ZO023tpvv9Xv1n8JxwHkyboOx5DCdmANA 1jedzidxlDYrl0gBBj9yCSyNvHaFR3ndEOTDGWdpZWT7HdC1fZW603iX86bM6vKJiQuc FSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b="DE/QP6ME"; 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 d15-v6si15593031wri.23.2018.09.17.14.44.08; Mon, 17 Sep 2018 14:44:09 -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="DE/QP6ME"; 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 C3FFA68A77E; Tue, 18 Sep 2018 00:43:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8ECC168A273 for ; Tue, 18 Sep 2018 00:43:48 +0300 (EEST) Received: by mail-lf1-f67.google.com with SMTP id g24-v6so9756864lfb.11 for ; Mon, 17 Sep 2018 14:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Mw723XNlYrndu2A5F1RAvurchjlwrMvoSN0lxD0N7Ew=; b=DE/QP6MEfxLN/H4pxGQg+Xen1uU+5Rr1+IpGz2KzzlYkEL7XvnrNr03ZVosdsEDnFD cZ/zabRX6R+pSYtL0KpldSmzZa5dc0ZhHeAZJnEJfQmJMkDIU0sp2XvcL9O0za3xIhAH QdSUgHl7gV6fVoAdWuv6fs0OcmBJfLGGvK/im9GBUYr2FoOB8a8bzU1m4JW7/r5vSD3d N0B3+MrJFcGKLBvtvC/SE5W4Ze2FameCoe8pDM83APeV06hM/0h2u9/hw41acgKP5wqp QOOHnufYoOYyoDEbWS0f8+5JzZtVQS8rdCDNFCCkE0pZtP9piJQRpniNIryUQZJc3RVM uftw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Mw723XNlYrndu2A5F1RAvurchjlwrMvoSN0lxD0N7Ew=; b=LXy45YTNhuMshPDxdmUKayGP9ZgVwzNVeEQhe0gtWRsRibWTAEP+p/hXcM6UFjwh+c XHAWB19XEfXgAYdOVx2qLpSz0aKyhInUW8qUeVOEgfhBuqkECphSp2V1Ul/zeRcC5nm1 WGWoARYiCzYdSMj//L5GCxrrGaLWOsqgke+T/7Ilo/4UgNDwIxDCwA3YWwsofdLuqw6i HXec5+KUPF29O4DUAmEC2LvBUq+XPpKP/PXAjF9ZCYmtv0rHxpkuE8jIwPKWqWg8QQvo ZO4flV7xYF4w3keerK320rx5PZX7MI6uW5Z+S4d4TdQfyBXQNhBjyyW0OFQ7AguNZN3w QhKw== X-Gm-Message-State: APzg51C+NBMc9jP49zu+QXIs/CU3z/a3B65F3Dce1V30amK6hCe/Iz1w lCldCdUDsjlr0IIdpi+z2tNd389L2rTi6l+XAdijrp7Y X-Received: by 2002:a19:e44c:: with SMTP id b73-v6mr16781219lfh.117.1537220156116; Mon, 17 Sep 2018 14:35:56 -0700 (PDT) MIME-Version: 1.0 References: <20180828175843.15296-1-modmaker@google.com> <20180829220740.GL19650@michaelspb> <9f0a9a8f-fac6-c873-7a1b-ee16758aa629@gmail.com> <20180829233712.GN19650@michaelspb> <20180911204844.GQ3200@michaelspb> <20180912185015.GS3200@michaelspb> In-Reply-To: <20180912185015.GS3200@michaelspb> From: Jacob Trimble Date: Mon, 17 Sep 2018 14:35:44 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/utils: Don't parse encrypted packets. 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 Wed, Sep 12, 2018 at 11:50 AM Michael Niedermayer wrote: > > On Tue, Sep 11, 2018 at 03:50:57PM -0700, Jacob Trimble wrote: > > [...] > > > > So how about, when we see an encrypted frame, we flush the parser > > before skipping the frame? Can we just flush the parser and then > > reuse it later? Or would we need to create a new parser if we saw > > clear frames later? > > try/test it and review the code. only way to know for sure what works > > thanks > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > The bravest are surely those who have the clearest vision > of what is before them, glory and danger alike, and yet > notwithstanding go out to meet it. -- Thucydides > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Here is a new patch that flushes the parser before returning the encrypted packets. It also logs when it does this. From 3955dad8070c28b021afc3304939500a09c86fcd Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Tue, 28 Aug 2018 10:40:29 -0700 Subject: [PATCH] avformat/utils: Don't parse encrypted packets. If a packet is full-sample encrypted, then packet data can't be parsed without decrypting it. So this skips the packet parsing for those packets. If the packet has sub-sample encryption, it is assumed that the headers are in the clear and the parser will only need that info. Signed-off-by: Jacob Trimble --- libavformat/utils.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index a72f0a482e..8d84674797 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -27,6 +27,7 @@ #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/dict.h" +#include "libavutil/encryption_info.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" @@ -1576,6 +1577,9 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) while (!got_packet && !s->internal->parse_queue) { AVStream *st; AVPacket cur_pkt; + uint8_t *enc_side_data; + int enc_side_data_size; + int is_full_encrypted = 0; /* read next packet */ ret = ff_read_packet(s, &cur_pkt); @@ -1643,7 +1647,23 @@ FF_ENABLE_DEPRECATION_WARNINGS av_ts2str(cur_pkt.dts), cur_pkt.size, cur_pkt.duration, cur_pkt.flags); - if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { + /* if the packet is full-sample encrypted, we can't parse it. If the + * packet uses sub-sample encryption, assume the headers are clear and + * can still be parsed. + */ + enc_side_data = av_packet_get_side_data( + &cur_pkt, AV_PKT_DATA_ENCRYPTION_INFO, &enc_side_data_size); + if (enc_side_data) { + AVEncryptionInfo *enc_info = + av_encryption_info_get_side_data(enc_side_data, enc_side_data_size); + if (enc_info) { + is_full_encrypted = enc_info->subsample_count == 0; + av_encryption_info_free(enc_info); + } + } + + if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE) && + !is_full_encrypted) { st->parser = av_parser_init(st->codecpar->codec_id); if (!st->parser) { av_log(s, AV_LOG_VERBOSE, "parser not found for codec " @@ -1659,6 +1679,25 @@ FF_ENABLE_DEPRECATION_WARNINGS st->parser->flags |= PARSER_FLAG_USE_CODEC_TS; } + if (st->parser && is_full_encrypted) { + av_log(s, AV_LOG_VERBOSE, "skipping parsing of encrypted packets.\n"); + + /* flush any packets from the parser. */ + parse_packet(s, NULL, cur_pkt.stream_index); + if (s->internal->parse_queue) { + /* if we have other packets, append this packet to the end and read + * from the queue instead. */ + compute_pkt_fields(s, st, NULL, &cur_pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); + ret = ff_packet_list_put(&s->internal->parse_queue, + &s->internal->parse_queue_end, + &cur_pkt, 0); + if (ret < 0) + return ret; + break; + } + av_assert2(!st->parser); + } + if (!st->need_parsing || !st->parser) { /* no parsing needed: we just output the packet as is */ *pkt = cur_pkt; -- 2.19.0.397.gdd90340f6a-goog