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/base/fourccs.h"
13 #include "packager/media/filters/vpx_parser.h"
14 #include "packager/media/formats/mp4/fragmenter.h"
15 #include "packager/media/formats/mp4/video_slice_header_parser.h"
16 
17 namespace edash_packager {
18 namespace media {
19 
20 class AesCryptor;
21 class StreamInfo;
22 struct EncryptionKey;
23 
24 namespace mp4 {
25 
28  public:
35  EncryptingFragmenter(scoped_refptr<StreamInfo> info,
36  TrackFragment* traf,
37  scoped_ptr<EncryptionKey> encryption_key,
38  int64_t clear_time,
39  FourCC protection_scheme);
40 
41  ~EncryptingFragmenter() override;
42 
45  Status AddSample(scoped_refptr<MediaSample> sample) override;
46  Status InitializeFragment(int64_t first_sample_dts) override;
47  void FinalizeFragment() override;
49 
50  protected:
53  virtual Status PrepareFragmentForEncryption(bool enable_encryption);
55  virtual void FinalizeFragmentForEncryption();
56 
61 
62  const EncryptionKey* encryption_key() const { return encryption_key_.get(); }
63  AesCryptor* encryptor() { return encryptor_.get(); }
64  FourCC protection_scheme() const { return protection_scheme_; }
65 
66  void set_encryption_key(scoped_ptr<EncryptionKey> encryption_key) {
67  encryption_key_ = encryption_key.Pass();
68  }
69 
70  private:
71  void EncryptBytes(uint8_t* data, uint32_t size);
72  Status EncryptSample(scoped_refptr<MediaSample> sample);
73 
74  // Should we enable subsample encryption?
75  bool IsSubsampleEncryptionRequired();
76 
77  scoped_refptr<StreamInfo> info_;
78  scoped_ptr<EncryptionKey> encryption_key_;
79  scoped_ptr<AesCryptor> encryptor_;
80  // If this stream contains AVC, subsample encryption specifies that the size
81  // and type of NAL units remain unencrypted. This function returns the size of
82  // the size field in bytes. Can be 1, 2 or 4 bytes.
83  const uint8_t nalu_length_size_;
84  const VideoCodec video_codec_;
85  int64_t clear_time_;
86  FourCC protection_scheme_;
87 
88  scoped_ptr<VPxParser> vpx_parser_;
89  scoped_ptr<VideoSliceHeaderParser> header_parser_;
90 
91  DISALLOW_COPY_AND_ASSIGN(EncryptingFragmenter);
92 };
93 
94 } // namespace mp4
95 } // namespace media
96 } // namespace edash_packager
97 
98 #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, FourCC protection_scheme)
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.