DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
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/base/memory/ref_counted.h"
11 #include "packager/base/memory/scoped_ptr.h"
12 #include "packager/media/filters/vpx_parser.h"
13 #include "packager/media/formats/mp4/fragmenter.h"
14 #include "packager/media/formats/mp4/video_slice_header_parser.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 class AesCtrEncryptor;
20 class StreamInfo;
21 struct EncryptionKey;
22 
23 namespace mp4 {
24 
27  public:
32  EncryptingFragmenter(scoped_refptr<StreamInfo> info,
33  TrackFragment* traf,
34  scoped_ptr<EncryptionKey> encryption_key,
35  int64_t clear_time);
36 
37  ~EncryptingFragmenter() override;
38 
41  Status AddSample(scoped_refptr<MediaSample> sample) override;
42  Status InitializeFragment(int64_t first_sample_dts) override;
43  void FinalizeFragment() override;
45 
46  protected:
49  virtual Status PrepareFragmentForEncryption(bool enable_encryption);
51  virtual void FinalizeFragmentForEncryption();
52 
57 
58  EncryptionKey* encryption_key() { return encryption_key_.get(); }
59  AesCtrEncryptor* encryptor() { return encryptor_.get(); }
60 
61  void set_encryption_key(scoped_ptr<EncryptionKey> encryption_key) {
62  encryption_key_ = encryption_key.Pass();
63  }
64 
65  private:
66  void EncryptBytes(uint8_t* data, uint32_t size);
67  Status EncryptSample(scoped_refptr<MediaSample> sample);
68 
69  // Should we enable subsample encryption?
70  bool IsSubsampleEncryptionRequired();
71 
72  scoped_refptr<StreamInfo> info_;
73  scoped_ptr<EncryptionKey> encryption_key_;
74  scoped_ptr<AesCtrEncryptor> encryptor_;
75  // If this stream contains AVC, subsample encryption specifies that the size
76  // and type of NAL units remain unencrypted. This function returns the size of
77  // the size field in bytes. Can be 1, 2 or 4 bytes.
78  const uint8_t nalu_length_size_;
79  int64_t clear_time_;
80 
81  scoped_ptr<VPxParser> vpx_parser_;
82  scoped_ptr<VideoSliceHeaderParser> header_parser_;
83 
84  DISALLOW_COPY_AND_ASSIGN(EncryptingFragmenter);
85 };
86 
87 } // namespace mp4
88 } // namespace media
89 } // namespace edash_packager
90 
91 #endif // MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
EncryptingFragmenter generates MP4 fragments with sample encrypted.
Status InitializeFragment(int64_t first_sample_dts) override
EncryptingFragmenter(scoped_refptr< StreamInfo > info, TrackFragment *traf, scoped_ptr< EncryptionKey > encryption_key, int64_t clear_time)
Status AddSample(scoped_refptr< MediaSample > sample) override
void FinalizeFragment() override
Finalize and optimize the fragment.
virtual Status PrepareFragmentForEncryption(bool enable_encryption)
virtual void FinalizeFragmentForEncryption()
Finalize current fragment for encryption.