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 =
false;
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;
62 if (moof_->pssh.empty())
63 moof_->pssh.resize(1);
64 DCHECK(encryption_key());
65 moof_->pssh[0].raw_box = encryption_key()->pssh;
67 if (muxer_listener_) {
68 muxer_listener_->OnEncryptionInfoReady(
69 !kInitialEncryptionInfo,
70 encryption_key_source_->
UUID(), encryption_key_source_->
SystemName(),
71 encryption_key()->key_id, encryption_key()->pssh);
81 if (!enable_encryption) {
86 if (need_to_refresh_encryptor) {
97 traf()->sample_group_description.grouping_type = FOURCC_SEIG;
98 traf()->sample_group_description.entries.resize(1);
99 traf()->sample_group_description.entries[0].is_encrypted =
true;
100 traf()->sample_group_description.entries[0].iv_size =
101 encryptor()->iv().size();
102 traf()->sample_group_description.entries[0].key_id = encryption_key()->key_id;
105 traf()->sample_to_group.grouping_type = FOURCC_SEIG;
106 traf()->sample_to_group.entries.resize(1);
108 traf()->sample_to_group.entries[0].group_description_index =
109 SampleToGroupEntry::kTrackFragmentGroupDescriptionIndexBase + 1;
116 DCHECK_EQ(1u, traf()->sample_to_group.entries.size());
117 traf()->sample_to_group.entries[0].sample_count =
118 traf()->auxiliary_size.sample_count;