diff --git a/packager/app/test/testdata/bear-640x360-vp9-altref-dec-golden.webm b/packager/app/test/testdata/bear-640x360-vp9-altref-dec-golden.webm index 29aae257b3..d5df056ea4 100644 Binary files a/packager/app/test/testdata/bear-640x360-vp9-altref-dec-golden.webm and b/packager/app/test/testdata/bear-640x360-vp9-altref-dec-golden.webm differ diff --git a/packager/app/test/testdata/bear-640x360-vp9-altref-enc-golden.webm b/packager/app/test/testdata/bear-640x360-vp9-altref-enc-golden.webm index a9a1e21725..06b7a34567 100644 Binary files a/packager/app/test/testdata/bear-640x360-vp9-altref-enc-golden.webm and b/packager/app/test/testdata/bear-640x360-vp9-altref-enc-golden.webm differ diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index b94ae57ab3..70b5e446c1 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -135,26 +135,20 @@ Status Segmenter::AddSample(scoped_refptr sample) { Status status; bool wrote_frame = false; + bool new_segment = false; if (!cluster_) { status = NewSegment(sample->pts()); + new_segment = true; // First frame, so no previous frame to write. wrote_frame = true; } else if (segment_length_sec_ >= options_.segment_duration) { if (sample->is_key_frame() || !options_.segment_sap_aligned) { status = WriteFrame(true /* write_duration */); status.Update(NewSegment(sample->pts())); + new_segment = true; segment_length_sec_ = 0; cluster_length_sec_ = 0; wrote_frame = true; - - if (encryptor_ && !enable_encryption_) { - if (sample->pts() - first_timestamp_ >= - clear_lead_ * info_->time_scale()) { - enable_encryption_ = true; - if (muxer_listener_) - muxer_listener_->OnEncryptionStart(); - } - } } } else if (cluster_length_sec_ >= options_.fragment_duration) { if (sample->is_key_frame() || !options_.fragment_sap_aligned) { @@ -172,6 +166,17 @@ Status Segmenter::AddSample(scoped_refptr sample) { // Encrypt the frame. if (encryptor_) { + // Don't enable encryption in the middle of a segment, i.e. only at the + // first frame of a segment. + if (new_segment && !enable_encryption_) { + if (sample->pts() - first_timestamp_ >= + clear_lead_ * info_->time_scale()) { + enable_encryption_ = true; + if (muxer_listener_) + muxer_listener_->OnEncryptionStart(); + } + } + status = encryptor_->EncryptFrame(sample, enable_encryption_); if (!status.ok()) { LOG(ERROR) << "Error encrypting frame."; diff --git a/packager/media/test/data/bear-640x360-vp9-altref.webm b/packager/media/test/data/bear-640x360-vp9-altref.webm index 4c2efd7ead..060f8705b8 100644 Binary files a/packager/media/test/data/bear-640x360-vp9-altref.webm and b/packager/media/test/data/bear-640x360-vp9-altref.webm differ