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,
28 EncryptionMode encryption_mode)
35 encryption_key_source_(encryption_key_source),
36 track_type_(track_type),
37 crypto_period_duration_(crypto_period_duration),
38 prev_crypto_period_index_(-1),
39 muxer_listener_(muxer_listener) {
41 DCHECK(encryption_key_source);
44 KeyRotationFragmenter::~KeyRotationFragmenter() {}
47 bool enable_encryption) {
48 bool need_to_refresh_encryptor = !encryptor();
50 size_t current_crypto_period_index =
51 traf()->decode_time.decode_time / crypto_period_duration_;
52 if (current_crypto_period_index != prev_crypto_period_index_) {
53 scoped_ptr<EncryptionKey> encryption_key(
new EncryptionKey());
55 current_crypto_period_index, track_type_, encryption_key.get());
58 set_encryption_key(encryption_key.Pass());
59 prev_crypto_period_index_ = current_crypto_period_index;
60 need_to_refresh_encryptor =
true;
63 DCHECK(encryption_key());
64 const std::vector<ProtectionSystemSpecificInfo>& system_info =
65 encryption_key()->key_system_info;
66 moof_->pssh.resize(system_info.size());
67 for (
size_t i = 0; i < system_info.size(); i++) {
68 moof_->pssh[i].raw_box = system_info[i].CreateBox();
71 if (muxer_listener_) {
72 muxer_listener_->OnEncryptionInfoReady(!kInitialEncryptionInfo,
73 encryption_key()->key_id,
74 encryption_key()->key_system_info);
84 if (!enable_encryption) {
89 if (need_to_refresh_encryptor) {
100 traf()->sample_group_description.grouping_type = FOURCC_SEIG;
101 traf()->sample_group_description.entries.resize(1);
102 traf()->sample_group_description.entries[0].is_encrypted =
true;
103 traf()->sample_group_description.entries[0].iv_size =
104 encryptor()->iv().size();
105 traf()->sample_group_description.entries[0].key_id = encryption_key()->key_id;
108 traf()->sample_to_group.grouping_type = FOURCC_SEIG;
109 traf()->sample_to_group.entries.resize(1);
111 traf()->sample_to_group.entries[0].group_description_index =
112 SampleToGroupEntry::kTrackFragmentGroupDescriptionIndexBase + 1;
119 DCHECK_EQ(1u, traf()->sample_to_group.entries.size());
120 traf()->sample_to_group.entries[0].sample_count =
121 traf()->auxiliary_size.sample_count;