2014-05-08 20:53:08 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
|
|
|
|
#define MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
|
|
|
|
|
2016-02-03 22:13:57 +00:00
|
|
|
#include "packager/base/memory/ref_counted.h"
|
2015-11-18 19:51:15 +00:00
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
2015-11-20 19:28:45 +00:00
|
|
|
#include "packager/media/filters/vpx_parser.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/formats/mp4/fragmenter.h"
|
2016-02-03 22:13:57 +00:00
|
|
|
#include "packager/media/formats/mp4/video_slice_header_parser.h"
|
2014-05-08 20:53:08 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-05-08 20:53:08 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class AesCtrEncryptor;
|
2016-02-03 22:13:57 +00:00
|
|
|
class StreamInfo;
|
2014-05-08 20:53:08 +00:00
|
|
|
struct EncryptionKey;
|
|
|
|
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
/// EncryptingFragmenter generates MP4 fragments with sample encrypted.
|
|
|
|
class EncryptingFragmenter : public Fragmenter {
|
|
|
|
public:
|
|
|
|
/// @param traf points to a TrackFragment box.
|
|
|
|
/// @param encryption_key contains the encryption parameters.
|
|
|
|
/// @param clear_time specifies clear lead duration in units of the current
|
|
|
|
/// track's timescale.
|
2016-02-03 22:13:57 +00:00
|
|
|
EncryptingFragmenter(scoped_refptr<StreamInfo> info,
|
|
|
|
TrackFragment* traf,
|
2014-05-08 20:53:08 +00:00
|
|
|
scoped_ptr<EncryptionKey> encryption_key,
|
2016-02-03 22:13:57 +00:00
|
|
|
int64_t clear_time);
|
2014-05-08 20:53:08 +00:00
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
~EncryptingFragmenter() override;
|
2014-05-08 20:53:08 +00:00
|
|
|
|
|
|
|
/// @name Fragmenter implementation overrides.
|
|
|
|
/// @{
|
2015-07-22 23:40:45 +00:00
|
|
|
Status AddSample(scoped_refptr<MediaSample> sample) override;
|
|
|
|
Status InitializeFragment(int64_t first_sample_dts) override;
|
|
|
|
void FinalizeFragment() override;
|
2014-05-08 20:53:08 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Prepare current fragment for encryption.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
2014-05-08 21:50:38 +00:00
|
|
|
virtual Status PrepareFragmentForEncryption(bool enable_encryption);
|
2014-05-08 20:53:08 +00:00
|
|
|
/// Finalize current fragment for encryption.
|
|
|
|
virtual void FinalizeFragmentForEncryption();
|
|
|
|
|
|
|
|
/// Create the encryptor for the internal encryption key. The existing
|
|
|
|
/// encryptor will be reset if it is not NULL.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status CreateEncryptor();
|
|
|
|
|
|
|
|
EncryptionKey* encryption_key() { return encryption_key_.get(); }
|
|
|
|
AesCtrEncryptor* encryptor() { return encryptor_.get(); }
|
|
|
|
|
|
|
|
void set_encryption_key(scoped_ptr<EncryptionKey> encryption_key) {
|
|
|
|
encryption_key_ = encryption_key.Pass();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-30 21:52:21 +00:00
|
|
|
void EncryptBytes(uint8_t* data, uint32_t size);
|
2014-05-08 20:53:08 +00:00
|
|
|
Status EncryptSample(scoped_refptr<MediaSample> sample);
|
|
|
|
|
2016-02-03 22:13:57 +00:00
|
|
|
// If this stream contains AVC, subsample encryption specifies that the size
|
|
|
|
// and type of NAL units remain unencrypted. This function returns the size of
|
|
|
|
// the size field in bytes. Can be 1, 2 or 4 bytes.
|
|
|
|
uint8_t GetNaluLengthSize();
|
2014-05-08 20:53:08 +00:00
|
|
|
// Should we enable subsample encryption?
|
2016-02-03 22:13:57 +00:00
|
|
|
bool IsSubsampleEncryptionRequired();
|
2014-05-08 20:53:08 +00:00
|
|
|
|
2016-02-03 22:13:57 +00:00
|
|
|
scoped_refptr<StreamInfo> info_;
|
2014-05-08 20:53:08 +00:00
|
|
|
scoped_ptr<EncryptionKey> encryption_key_;
|
|
|
|
scoped_ptr<AesCtrEncryptor> encryptor_;
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t clear_time_;
|
2014-05-08 20:53:08 +00:00
|
|
|
|
2015-11-20 19:28:45 +00:00
|
|
|
scoped_ptr<VPxParser> vpx_parser_;
|
2016-02-03 22:13:57 +00:00
|
|
|
scoped_ptr<VideoSliceHeaderParser> header_parser_;
|
2015-11-18 19:51:15 +00:00
|
|
|
|
2014-05-08 20:53:08 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(EncryptingFragmenter);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2014-05-08 20:53:08 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
|