content/media/fmp4/demuxer/decrypt_config.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #ifndef MEDIA_BASE_DECRYPT_CONFIG_H_
     6 #define MEDIA_BASE_DECRYPT_CONFIG_H_
     8 #include <string>
     9 #include <vector>
    11 #include "mp4_demuxer/basictypes.h"
    13 namespace mp4_demuxer {
    15 // The Common Encryption spec provides for subsample encryption, where portions
    16 // of a sample are set in cleartext. A SubsampleEntry specifies the number of
    17 // clear and encrypted bytes in each subsample. For decryption, all of the
    18 // encrypted bytes in a sample should be considered a single logical stream,
    19 // regardless of how they are divided into subsamples, and the clear bytes
    20 // should not be considered as part of decryption. This is logically equivalent
    21 // to concatenating all 'cypher_bytes' portions of subsamples, decrypting that
    22 // result, and then copying each byte from the decrypted block over the
    23 // position of the corresponding encrypted byte.
    24 struct SubsampleEntry {
    25   uint32_t clear_bytes;
    26   uint32_t cypher_bytes;
    27 };
    29 // Contains all information that a decryptor needs to decrypt a media sample.
    30 class DecryptConfig {
    31  public:
    32   // Keys are always 128 bits.
    33   static const int kDecryptionKeySize = 16;
    35   // |key_id| is the ID that references the decryption key for this sample.
    36   // |iv| is the initialization vector defined by the encrypted format.
    37   //   Currently |iv| must be 16 bytes as defined by WebM and ISO. Or must be
    38   //   empty which signals an unencrypted frame.
    39   // |data_offset| is the amount of data that should be discarded from the
    40   //   head of the sample buffer before applying subsample information. A
    41   //   decrypted buffer will be shorter than an encrypted buffer by this amount.
    42   // |subsamples| defines the clear and encrypted portions of the sample as
    43   //   described above. A decrypted buffer will be equal in size to the sum
    44   //   of the subsample sizes.
    45   //
    46   // |data_offset| is applied before |subsamples|.
    47   DecryptConfig(const std::string& key_id,
    48                 const std::string& iv,
    49                 const int data_offset,
    50                 const std::vector<SubsampleEntry>& subsamples);
    51   ~DecryptConfig();
    53   const std::string& key_id() const { return key_id_; }
    54   const std::string& iv() const { return iv_; }
    55   int data_offset() const { return data_offset_; }
    56   const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }
    58  private:
    59   const std::string key_id_;
    61   // Initialization vector.
    62   const std::string iv_;
    64   // TODO(fgalligan): Remove |data_offset_| if there is no plan to use it in
    65   // the future.
    66   // Amount of data to be discarded before applying subsample information.
    67   const int data_offset_;
    69   // Subsample information. May be empty for some formats, meaning entire frame
    70   // (less data ignored by data_offset_) is encrypted.
    71   const std::vector<SubsampleEntry> subsamples_;
    73   DISALLOW_COPY_AND_ASSIGN(DecryptConfig);
    74 };
    76 }  // namespace mp4_demuxer
    78 #endif  // MEDIA_BASE_DECRYPT_CONFIG_H_

mercurial