2015-11-18 21:11:31 +00:00
|
|
|
// Copyright 2015 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_WEBM_ENCRYPTOR_H_
|
|
|
|
#define MEDIA_FORMATS_WEBM_ENCRYPTOR_H_
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
|
|
|
#include "packager/base/macros.h"
|
2015-11-18 21:11:31 +00:00
|
|
|
#include "packager/media/base/key_source.h"
|
|
|
|
#include "packager/media/base/status.h"
|
2016-07-27 00:51:08 +00:00
|
|
|
#include "packager/media/base/stream_info.h"
|
|
|
|
#include "packager/media/codecs/vpx_parser.h"
|
2015-11-18 21:11:31 +00:00
|
|
|
#include "packager/media/event/muxer_listener.h"
|
|
|
|
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-11-18 21:11:31 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class AesCtrEncryptor;
|
|
|
|
class MediaSample;
|
|
|
|
|
|
|
|
namespace webm {
|
|
|
|
|
|
|
|
/// A helper class used to encrypt WebM frames before being written to the
|
|
|
|
/// Cluster. This can also handle unencrypted frames.
|
|
|
|
class Encryptor {
|
|
|
|
public:
|
|
|
|
Encryptor();
|
|
|
|
~Encryptor();
|
|
|
|
|
|
|
|
/// Initializes the encryptor with the given key source.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status Initialize(MuxerListener* muxer_listener,
|
|
|
|
KeySource::TrackType track_type,
|
2016-07-27 00:51:08 +00:00
|
|
|
Codec codec,
|
|
|
|
KeySource* key_source,
|
|
|
|
bool webm_subsample_encryption);
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
/// Adds the encryption info to the given track. Initialize must be called
|
|
|
|
/// first.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status AddTrackInfo(mkvmuxer::Track* track);
|
|
|
|
|
|
|
|
/// Encrypt the data. This needs to be told whether the current frame will
|
|
|
|
/// be encrypted (e.g. for a clear lead).
|
|
|
|
/// @return OK on success, an error status otherwise.
|
2017-01-24 00:55:02 +00:00
|
|
|
Status EncryptFrame(std::shared_ptr<MediaSample> sample, bool encrypt_frame);
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Create the encryptor for the internal encryption key.
|
|
|
|
Status CreateEncryptor(MuxerListener* muxer_listener,
|
|
|
|
KeySource::TrackType track_type,
|
2016-07-27 00:51:08 +00:00
|
|
|
Codec codec,
|
|
|
|
KeySource* key_source,
|
|
|
|
bool webm_subsample_encryption);
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<EncryptionKey> key_;
|
|
|
|
std::unique_ptr<AesCtrEncryptor> encryptor_;
|
|
|
|
std::unique_ptr<VPxParser> vpx_parser_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Encryptor);
|
2015-11-18 21:11:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace webm
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_WEBM_ENCRYPTOR_H_
|