7 #include "packager/media/formats/mp4/key_rotation_fragmenter.h"
9 #include "packager/media/base/aes_encryptor.h"
10 #include "packager/media/formats/mp4/box_definitions.h"
12 namespace edash_packager {
17 const bool kInitialEncryptionInfo =
true;
21 scoped_refptr<StreamInfo> info,
24 KeySource::TrackType track_type,
25 int64_t crypto_period_duration,
33 encryption_key_source_(encryption_key_source),
34 track_type_(track_type),
35 crypto_period_duration_(crypto_period_duration),
36 prev_crypto_period_index_(-1),
37 muxer_listener_(muxer_listener) {
39 DCHECK(encryption_key_source);
42 KeyRotationFragmenter::~KeyRotationFragmenter() {}
45 bool enable_encryption) {
46 bool need_to_refresh_encryptor = !encryptor();
48 size_t current_crypto_period_index =
49 traf()->decode_time.decode_time / crypto_period_duration_;
50 if (current_crypto_period_index != prev_crypto_period_index_) {
51 scoped_ptr<EncryptionKey> encryption_key(
new EncryptionKey());
53 current_crypto_period_index, track_type_, encryption_key.get());
56 set_encryption_key(encryption_key.Pass());
57 prev_crypto_period_index_ = current_crypto_period_index;
58 need_to_refresh_encryptor =
true;
61 DCHECK(encryption_key());
62 const std::vector<ProtectionSystemSpecificInfo>& system_info =
63 encryption_key()->key_system_info;
64 moof_->pssh.resize(system_info.size());
65 for (
size_t i = 0; i < system_info.size(); i++) {
66 moof_->pssh[i].raw_box = system_info[i].CreateBox();
69 if (muxer_listener_) {
70 muxer_listener_->OnEncryptionInfoReady(!kInitialEncryptionInfo,
71 encryption_key()->key_id,
72 encryption_key()->key_system_info);
82 if (!enable_encryption) {
87 if (need_to_refresh_encryptor) {
98 traf()->sample_group_description.grouping_type = FOURCC_SEIG;
99 traf()->sample_group_description.entries.resize(1);
100 traf()->sample_group_description.entries[0].is_encrypted =
true;
101 traf()->sample_group_description.entries[0].iv_size =
102 encryptor()->iv().size();
103 traf()->sample_group_description.entries[0].key_id = encryption_key()->key_id;
106 traf()->sample_to_group.grouping_type = FOURCC_SEIG;
107 traf()->sample_to_group.entries.resize(1);
109 traf()->sample_to_group.entries[0].group_description_index =
110 SampleToGroupEntry::kTrackFragmentGroupDescriptionIndexBase + 1;
117 DCHECK_EQ(1u, traf()->sample_to_group.entries.size());
118 traf()->sample_to_group.entries[0].sample_count =
119 traf()->auxiliary_size.sample_count;