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;
23 KeySource::TrackType track_type,
24 int64_t crypto_period_duration,
26 VideoCodec video_codec,
27 uint8_t nalu_length_size,
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;
64 if (moof_->pssh.empty())
65 moof_->pssh.resize(1);
66 DCHECK(encryption_key());
67 moof_->pssh[0].raw_box = encryption_key()->pssh;
69 if (muxer_listener_) {
70 muxer_listener_->OnEncryptionInfoReady(
71 !kInitialEncryptionInfo,
72 encryption_key_source_->
UUID(), encryption_key_source_->
SystemName(),
73 encryption_key()->key_id, encryption_key()->pssh);
83 if (!enable_encryption) {
88 if (need_to_refresh_encryptor) {
99 traf()->sample_group_description.grouping_type = FOURCC_SEIG;
100 traf()->sample_group_description.entries.resize(1);
101 traf()->sample_group_description.entries[0].is_encrypted =
true;
102 traf()->sample_group_description.entries[0].iv_size =
103 encryptor()->iv().size();
104 traf()->sample_group_description.entries[0].key_id = encryption_key()->key_id;
107 traf()->sample_to_group.grouping_type = FOURCC_SEIG;
108 traf()->sample_to_group.entries.resize(1);
110 traf()->sample_to_group.entries[0].group_description_index =
111 SampleToGroupEntry::kTrackFragmentGroupDescriptionIndexBase + 1;
118 DCHECK_EQ(1u, traf()->sample_to_group.entries.size());
119 traf()->sample_to_group.entries[0].sample_count =
120 traf()->auxiliary_size.sample_count;