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_
|
|
|
|
|
|
|
|
#include "packager/base/memory/ref_counted.h"
|
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
|
|
|
#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.
|
|
|
|
Status EncryptFrame(scoped_refptr<MediaSample> sample,
|
|
|
|
bool encrypt_frame);
|
|
|
|
|
|
|
|
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:
|
|
|
|
scoped_ptr<EncryptionKey> key_;
|
|
|
|
scoped_ptr<AesCtrEncryptor> encryptor_;
|
2016-07-27 00:51:08 +00:00
|
|
|
scoped_ptr<VPxParser> vpx_parser_;
|
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_
|