diff --git a/packager/mpd/base/mpd_notifier.h b/packager/mpd/base/mpd_notifier.h index 27b0a29543..8b81631a17 100644 --- a/packager/mpd/base/mpd_notifier.h +++ b/packager/mpd/base/mpd_notifier.h @@ -58,8 +58,8 @@ class MpdNotifier { virtual bool NotifySampleDuration(uint32_t container_id, uint32_t sample_duration) = 0; - /// Notifies MpdBuilder that there is a new segment ready. Used only for live - /// profile. + /// Notifies MpdBuilder that there is a new segment ready. For live, this + /// is usually a new segment, for VOD this is usually a subsegment. /// @param container_id Container ID obtained from calling /// NotifyNewContainer(). /// @param start_time is the start time of the new segment, in units of the diff --git a/packager/mpd/base/simple_mpd_notifier.cc b/packager/mpd/base/simple_mpd_notifier.cc index 4241da533f..cefee2a64f 100644 --- a/packager/mpd/base/simple_mpd_notifier.cc +++ b/packager/mpd/base/simple_mpd_notifier.cc @@ -66,12 +66,11 @@ bool SimpleMpdNotifier::NotifyNewContainer(const MediaInfo& media_info, // generate a valid MPD. AddContentProtectionElements(media_info, representation); *container_id = representation->id(); + DCHECK(!ContainsKey(representation_map_, representation->id())); + representation_map_[representation->id()] = representation; if (mpd_builder_->type() == MpdBuilder::kStatic) return WriteMpdToFile(output_path_, mpd_builder_.get()); - - DCHECK(!ContainsKey(representation_map_, representation->id())); - representation_map_[representation->id()] = representation; return true; } @@ -83,8 +82,10 @@ bool SimpleMpdNotifier::NotifySampleDuration(uint32_t container_id, LOG(ERROR) << "Unexpected container_id: " << container_id; return false; } + // This sets the right frameRate for Representation or AdaptationSet, so + // write out the new MPD. it->second->SetSampleDuration(sample_duration); - return true; + return WriteMpdToFile(output_path_, mpd_builder_.get()); } bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id, @@ -92,12 +93,13 @@ bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id, uint64_t duration, uint64_t size) { base::AutoLock auto_lock(lock_); - RepresentationMap::iterator it = representation_map_.find(container_id); if (it == representation_map_.end()) { LOG(ERROR) << "Unexpected container_id: " << container_id; return false; } + // For live, the timeline and segmentAlignment gets updated. For VOD, + // subsegmentAlignment gets updated. So write out the MPD. it->second->AddNewSegment(start_time, duration, size); return WriteMpdToFile(output_path_, mpd_builder_.get()); } @@ -105,8 +107,14 @@ bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id, bool SimpleMpdNotifier::AddContentProtectionElement( uint32_t container_id, const ContentProtectionElement& content_protection_element) { - NOTIMPLEMENTED(); - return false; + base::AutoLock auto_lock(lock_); + RepresentationMap::iterator it = representation_map_.find(container_id); + if (it == representation_map_.end()) { + LOG(ERROR) << "Unexpected container_id: " << container_id; + return false; + } + it->second->AddContentProtectionElement(content_protection_element); + return WriteMpdToFile(output_path_, mpd_builder_.get()); } } // namespace edash_packager diff --git a/packager/mpd/base/simple_mpd_notifier_unittest.cc b/packager/mpd/base/simple_mpd_notifier_unittest.cc index f8a1294643..19a45bbc1f 100644 --- a/packager/mpd/base/simple_mpd_notifier_unittest.cc +++ b/packager/mpd/base/simple_mpd_notifier_unittest.cc @@ -133,6 +133,7 @@ TEST_F(SimpleMpdNotifierTest, LiveNotifySampleDuration) { .WillOnce(Return(default_mock_adaptation_set_.get())); EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_)) .WillOnce(Return(mock_representation.get())); + EXPECT_CALL(*mock_mpd_builder, ToString(_)).WillOnce(Return(true)); uint32_t container_id; SetMpdBuilder(¬ifier, mock_mpd_builder.PassAs()); @@ -214,8 +215,7 @@ TEST_F(SimpleMpdNotifierTest, LiveNotifyNewSegment) { } // Verify AddContentProtectionElement() works. Profile doesn't matter. -// TODO(rkuroiwa): Not implemented yet, enable once it is implemented. -TEST_F(SimpleMpdNotifierTest, DISABLED_AddContentProtectionElement) { +TEST_F(SimpleMpdNotifierTest, AddContentProtectionElement) { SimpleMpdNotifier notifier(kOnDemandProfile, empty_mpd_option_, empty_base_urls_, output_path_); @@ -228,7 +228,9 @@ TEST_F(SimpleMpdNotifierTest, DISABLED_AddContentProtectionElement) { .WillOnce(Return(default_mock_adaptation_set_.get())); EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_)) .WillOnce(Return(mock_representation.get())); - EXPECT_CALL(*mock_mpd_builder, ToString(_)).WillOnce(Return(true)); + EXPECT_CALL(*mock_mpd_builder, ToString(_)) + .Times(2) + .WillRepeatedly(Return(true)); uint32_t container_id; SetMpdBuilder(¬ifier, mock_mpd_builder.PassAs());