DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
encrypting_fragmenter.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
8 #define MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
9 
10 #include "packager/media/formats/mp4/fragmenter.h"
11 
12 namespace edash_packager {
13 namespace media {
14 
15 class AesCtrEncryptor;
16 struct EncryptionKey;
17 
18 namespace mp4 {
19 
22  public:
30  scoped_ptr<EncryptionKey> encryption_key,
31  int64_t clear_time,
32  uint8_t nalu_length_size);
33 
34  virtual ~EncryptingFragmenter();
35 
38  virtual Status AddSample(scoped_refptr<MediaSample> sample) OVERRIDE;
39  virtual Status InitializeFragment(int64_t first_sample_dts) OVERRIDE;
40  virtual void FinalizeFragment() OVERRIDE;
42 
43  protected:
46  virtual Status PrepareFragmentForEncryption(bool enable_encryption);
48  virtual void FinalizeFragmentForEncryption();
49 
54 
55  EncryptionKey* encryption_key() { return encryption_key_.get(); }
56  AesCtrEncryptor* encryptor() { return encryptor_.get(); }
57 
58  void set_encryption_key(scoped_ptr<EncryptionKey> encryption_key) {
59  encryption_key_ = encryption_key.Pass();
60  }
61 
62  private:
63  void EncryptBytes(uint8_t* data, uint32_t size);
64  Status EncryptSample(scoped_refptr<MediaSample> sample);
65 
66  // Should we enable subsample encryption?
67  bool IsSubsampleEncryptionRequired() { return nalu_length_size_ != 0; }
68 
69  scoped_ptr<EncryptionKey> encryption_key_;
70  scoped_ptr<AesCtrEncryptor> encryptor_;
71  // If this stream contains AVC, subsample encryption specifies that the size
72  // and type of NAL units remain unencrypted. This field specifies the size of
73  // the size field. Can be 1, 2 or 4 bytes.
74  const uint8_t nalu_length_size_;
75  int64_t clear_time_;
76 
77  DISALLOW_COPY_AND_ASSIGN(EncryptingFragmenter);
78 };
79 
80 } // namespace mp4
81 } // namespace media
82 } // namespace edash_packager
83 
84 #endif // MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
EncryptingFragmenter generates MP4 fragments with sample encrypted.
virtual Status AddSample(scoped_refptr< MediaSample > sample) OVERRIDE
virtual Status PrepareFragmentForEncryption(bool enable_encryption)
EncryptingFragmenter(TrackFragment *traf, scoped_ptr< EncryptionKey > encryption_key, int64_t clear_time, uint8_t nalu_length_size)
virtual void FinalizeFragmentForEncryption()
Finalize current fragment for encryption.
virtual void FinalizeFragment() OVERRIDE
Finalize and optimize the fragment.
virtual Status InitializeFragment(int64_t first_sample_dts) OVERRIDE