From 5c07ff6b1cb26c46e2442a93ff841b460c305710 Mon Sep 17 00:00:00 2001 From: Rintaro Kuroiwa Date: Mon, 13 Feb 2017 14:25:34 -0800 Subject: [PATCH] Move and rename webvtt fragmenter to webvtt sample converter - The class should be used to generate samples from the demuxer. Change-Id: If7f245e5809de8773c0b1cf08673ae62dfeffe09 --- packager/media/formats/mp4/mp4.gyp | 4 - packager/media/formats/webvtt/cue.cc | 60 +++++++++ packager/media/formats/webvtt/cue.h | 38 ++++++ packager/media/formats/webvtt/webvtt.gyp | 6 + .../formats/webvtt/webvtt_media_parser.cc | 53 +------- .../formats/webvtt/webvtt_media_parser.h | 26 +--- .../webvtt_sample_converter.cc} | 36 +++--- .../webvtt_sample_converter.h} | 30 ++--- .../webvtt_sample_converter_unittest.cc} | 122 +++++++++--------- 9 files changed, 196 insertions(+), 179 deletions(-) create mode 100644 packager/media/formats/webvtt/cue.cc create mode 100644 packager/media/formats/webvtt/cue.h rename packager/media/formats/{mp4/webvtt_fragmenter.cc => webvtt/webvtt_sample_converter.cc} (91%) rename packager/media/formats/{mp4/webvtt_fragmenter.h => webvtt/webvtt_sample_converter.h} (81%) rename packager/media/formats/{mp4/webvtt_fragmenter_unittest.cc => webvtt/webvtt_sample_converter_unittest.cc} (82%) diff --git a/packager/media/formats/mp4/mp4.gyp b/packager/media/formats/mp4/mp4.gyp index 9a37f6cffd..2ebc5f2636 100644 --- a/packager/media/formats/mp4/mp4.gyp +++ b/packager/media/formats/mp4/mp4.gyp @@ -46,15 +46,12 @@ 'sync_sample_iterator.h', 'track_run_iterator.cc', 'track_run_iterator.h', - 'webvtt_fragmenter.cc', - 'webvtt_fragmenter.h', ], 'dependencies': [ '../../../third_party/boringssl/boringssl.gyp:boringssl', '../../base/media_base.gyp:media_base', '../../codecs/codecs.gyp:codecs', '../../event/media_event.gyp:media_event', - '../../formats/webvtt/webvtt.gyp:webvtt', ], }, { @@ -69,7 +66,6 @@ 'mp4_media_parser_unittest.cc', 'sync_sample_iterator_unittest.cc', 'track_run_iterator_unittest.cc', - 'webvtt_fragmenter_unittest.cc', ], 'dependencies': [ '../../../testing/gtest.gyp:gtest', diff --git a/packager/media/formats/webvtt/cue.cc b/packager/media/formats/webvtt/cue.cc new file mode 100644 index 0000000000..1be1a9ca52 --- /dev/null +++ b/packager/media/formats/webvtt/cue.cc @@ -0,0 +1,60 @@ +#include "packager/media/formats/webvtt/cue.h" + +#include "packager/base/strings/string_util.h" + +namespace shaka { +namespace media { + +Cue::Cue() : start_time(0), duration(0) {} +Cue::~Cue() {} + +// Mapping: +// comment --> side data (and side data only sample) +// settings --> side data +// start_time --> pts +std::shared_ptr CueToMediaSample(const Cue& cue) { + const bool kKeyFrame = true; + if (!cue.comment.empty()) { + const std::string comment = base::JoinString(cue.comment, "\n"); + return MediaSample::FromMetadata( + reinterpret_cast(comment.data()), comment.size()); + } + + const std::string payload = base::JoinString(cue.payload, "\n"); + std::shared_ptr media_sample = MediaSample::CopyFrom( + reinterpret_cast(payload.data()), payload.size(), + reinterpret_cast(cue.settings.data()), + cue.settings.size(), !kKeyFrame); + + media_sample->set_config_id(cue.identifier); + media_sample->set_pts(cue.start_time); + media_sample->set_duration(cue.duration); + return media_sample; +} + +// TODO(rkuroiwa): Cue gets converted to MediaSample in WebVttMediaParser and +// then back to Cue in the muxer. Consider making MediaSample a protobuf or make +// Cue a protobuf and (ab)use MediaSample::data() to store serialized Cue. +Cue MediaSampleToCue(const MediaSample& sample) { + Cue cue; + if (sample.data_size() == 0) { + std::string comment(sample.side_data(), + sample.side_data() + sample.side_data_size()); + cue.comment.push_back(comment); + return cue; + } + + std::string payload(sample.data(), sample.data() + sample.data_size()); + cue.payload.push_back(payload); + cue.identifier.assign(sample.config_id()); + cue.start_time = sample.pts(); + cue.duration = sample.duration(); + if (sample.side_data_size() != 0) { + cue.settings.assign(sample.side_data(), + sample.side_data() + sample.side_data_size()); + } + return cue; +} + +} // namespace media +} // namespace shaka diff --git a/packager/media/formats/webvtt/cue.h b/packager/media/formats/webvtt/cue.h new file mode 100644 index 0000000000..26eafb8d68 --- /dev/null +++ b/packager/media/formats/webvtt/cue.h @@ -0,0 +1,38 @@ +#include + +#include +#include +#include + +#include "packager/media/base/media_sample.h" + +namespace shaka { +namespace media { + +// If comment is not empty, then this is metadata and other fields must +// be empty. +// Data that can be multiline are vector of strings. +struct Cue { + Cue(); + ~Cue(); + + std::string identifier; + uint64_t start_time; + uint64_t duration; + std::string settings; + std::vector payload; + std::vector comment; +}; + +/// Convert Cue to MediaSample. +/// @param cue data. +/// @return @a cue converted to a MediaSample. +std::shared_ptr CueToMediaSample(const Cue& cue); + +/// Convert MediaSample to Cue. +/// @param sample to be converted. +/// @return @a sample converted to Cue. +Cue MediaSampleToCue(const MediaSample& sample); + +} // namespace media +} // namespace shaka diff --git a/packager/media/formats/webvtt/webvtt.gyp b/packager/media/formats/webvtt/webvtt.gyp index 2f686be703..c909fb1564 100644 --- a/packager/media/formats/webvtt/webvtt.gyp +++ b/packager/media/formats/webvtt/webvtt.gyp @@ -13,12 +13,17 @@ 'target_name': 'webvtt', 'type': '<(component)', 'sources': [ + 'cue.cc', + 'cue.h', 'webvtt_media_parser.cc', 'webvtt_media_parser.h', + 'webvtt_sample_converter.cc', + 'webvtt_sample_converter.h', ], 'dependencies': [ '../../../base/base.gyp:base', '../../base/media_base.gyp:media_base', + '../../formats/mp4/mp4.gyp:mp4', ], }, { @@ -26,6 +31,7 @@ 'type': '<(gtest_target_type)', 'sources': [ 'webvtt_media_parser_unittest.cc', + 'webvtt_sample_converter_unittest.cc', ], 'dependencies': [ '../../../testing/gmock.gyp:gmock', diff --git a/packager/media/formats/webvtt/webvtt_media_parser.cc b/packager/media/formats/webvtt/webvtt_media_parser.cc index 22126ad0fc..119b26d0e2 100644 --- a/packager/media/formats/webvtt/webvtt_media_parser.cc +++ b/packager/media/formats/webvtt/webvtt_media_parser.cc @@ -186,57 +186,6 @@ bool ParseTimingAndSettingsLine(const std::string& line, } // namespace -Cue::Cue() : start_time(0), duration(0) {} -Cue::~Cue() {} - -// Mapping: -// comment --> side data (and side data only sample) -// settings --> side data -// start_time --> pts -std::shared_ptr CueToMediaSample(const Cue& cue) { - const bool kKeyFrame = true; - if (!cue.comment.empty()) { - const std::string comment = base::JoinString(cue.comment, "\n"); - return MediaSample::FromMetadata( - reinterpret_cast(comment.data()), comment.size()); - } - - const std::string payload = base::JoinString(cue.payload, "\n"); - std::shared_ptr media_sample = MediaSample::CopyFrom( - reinterpret_cast(payload.data()), payload.size(), - reinterpret_cast(cue.settings.data()), - cue.settings.size(), !kKeyFrame); - - media_sample->set_config_id(cue.identifier); - media_sample->set_pts(cue.start_time); - media_sample->set_duration(cue.duration); - return media_sample; -} - -// TODO(rkuroiwa): Cue gets converted to MediaSample in WebVttMediaParser and -// then back to Cue in the muxer. Consider making MediaSample a protobuf or make -// Cue a protobuf and (ab)use MediaSample::data() to store serialized Cue. -Cue MediaSampleToCue(const MediaSample& sample) { - Cue cue; - if (sample.data_size() == 0) { - std::string comment(sample.side_data(), - sample.side_data() + sample.side_data_size()); - cue.comment.push_back(comment); - return cue; - } - - std::string payload(sample.data(), sample.data() + sample.data_size()); - cue.payload.push_back(payload); - cue.identifier.assign(sample.config_id()); - cue.start_time = sample.pts(); - cue.duration = sample.duration(); - if (sample.side_data_size() != 0) { - cue.settings.assign(sample.side_data(), - sample.side_data() + sample.side_data_size()); - } - return cue; -} - WebVttMediaParser::WebVttMediaParser() : state_(kHeader) {} WebVttMediaParser::~WebVttMediaParser() {} @@ -340,7 +289,7 @@ bool WebVttMediaParser::Parse(const uint8_t* buf, int size) { if (!has_arrow) { if (base::StartsWith(line, "NOTE", - base::CompareCase::INSENSITIVE_ASCII)) { + base::CompareCase::INSENSITIVE_ASCII)) { state_ = kComment; current_cue_.comment.push_back(line); } else { diff --git a/packager/media/formats/webvtt/webvtt_media_parser.h b/packager/media/formats/webvtt/webvtt_media_parser.h index a6aa8a6f25..c8071fa0e7 100644 --- a/packager/media/formats/webvtt/webvtt_media_parser.h +++ b/packager/media/formats/webvtt/webvtt_media_parser.h @@ -13,35 +13,11 @@ #include "packager/base/compiler_specific.h" #include "packager/media/base/media_parser.h" +#include "packager/media/formats/webvtt/cue.h" namespace shaka { namespace media { -// If comment is not empty, then this is metadata and other fields must -// be empty. -// Data that can be multiline are vector of strings. -struct Cue { - Cue(); - ~Cue(); - - std::string identifier; - uint64_t start_time; - uint64_t duration; - std::string settings; - std::vector payload; - std::vector comment; -}; - -/// Convert Cue to MediaSample. -/// @param cue data. -/// @return @a cue converted to a MediaSample. -std::shared_ptr CueToMediaSample(const Cue& cue); - -/// Convert MediaSample to Cue. -/// @param sample to be converted. -/// @return @a sample converted to Cue. -Cue MediaSampleToCue(const MediaSample& sample); - // WebVTT parser. // The input may not be encrypted so decryption_key_source is ignored. class WebVttMediaParser : public MediaParser { diff --git a/packager/media/formats/mp4/webvtt_fragmenter.cc b/packager/media/formats/webvtt/webvtt_sample_converter.cc similarity index 91% rename from packager/media/formats/mp4/webvtt_fragmenter.cc rename to packager/media/formats/webvtt/webvtt_sample_converter.cc index be0dc6e11c..561b1ba3d4 100644 --- a/packager/media/formats/mp4/webvtt_fragmenter.cc +++ b/packager/media/formats/webvtt/webvtt_sample_converter.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/formats/mp4/webvtt_fragmenter.h" +#include "packager/media/formats/webvtt/webvtt_sample_converter.h" #include #include @@ -18,14 +18,13 @@ namespace shaka { namespace media { -namespace mp4 { namespace { std::shared_ptr CreateEmptyCueSample(uint64_t start_time, uint64_t end_time) { DCHECK_GT(end_time, start_time); - VTTEmptyCueBox empty_cue_box; + mp4::VTTEmptyCueBox empty_cue_box; std::vector serialized; AppendBoxToVector(&empty_cue_box, &serialized); @@ -37,8 +36,8 @@ std::shared_ptr CreateEmptyCueSample(uint64_t start_time, return empty_cue_sample; } -VTTCueBox CueBoxFromCue(const Cue& cue) { - VTTCueBox cue_box; +mp4::VTTCueBox CueBoxFromCue(const Cue& cue) { + mp4::VTTCueBox cue_box; if (!cue.identifier.empty()) { cue_box.cue_id.cue_id = cue.identifier; } @@ -77,7 +76,7 @@ std::shared_ptr CreateVTTCueBoxesSample( BufferWriter writer; for (const Cue* cue : cues) { - VTTCueBox cue_box = CueBoxFromCue(*cue); + mp4::VTTCueBox cue_box = CueBoxFromCue(*cue); // If there is internal timing, i.e. WebVTT cue timestamp, then // cue_current_time should be populated // "which gives the VTT timestamp associated with the start time of sample." @@ -115,7 +114,7 @@ uint64_t GetMinimumPastSweepLine(uint64_t cue_start_time, } // namespace -void AppendBoxToVector(Box* box, std::vector* output_vector) { +void AppendBoxToVector(mp4::Box* box, std::vector* output_vector) { BufferWriter writer; box->Write(&writer); output_vector->insert(output_vector->end(), @@ -123,15 +122,15 @@ void AppendBoxToVector(Box* box, std::vector* output_vector) { writer.Buffer() + writer.Size()); } -WebVttFragmenter::WebVttFragmenter() : next_cue_start_time_(0u) {} -WebVttFragmenter::~WebVttFragmenter() {} +WebVttSampleConverter::WebVttSampleConverter() : next_cue_start_time_(0u) {} +WebVttSampleConverter::~WebVttSampleConverter() {} // Note that this |sample| is either a cue or a comment. It does not have any // info on whether the next cue is overlapping or not. -void WebVttFragmenter::PushSample(std::shared_ptr sample) { +void WebVttSampleConverter::PushSample(std::shared_ptr sample) { if (sample->data_size() == 0u) { // A comment. Put it in the buffer and skip. - VTTAdditionalTextBox comment; + mp4::VTTAdditionalTextBox comment; comment.cue_additional_text.assign( sample->side_data(), sample->side_data() + sample->side_data_size()); additional_texts_.push_back(comment); @@ -164,7 +163,7 @@ void WebVttFragmenter::PushSample(std::shared_ptr sample) { cues_.erase(cues_.begin(), erase_last_iterator); } -void WebVttFragmenter::Flush() { +void WebVttSampleConverter::Flush() { if (cues_.empty()) return; if (cues_.size() == 1) { @@ -185,11 +184,11 @@ void WebVttFragmenter::Flush() { cues_.clear(); } -size_t WebVttFragmenter::ReadySamplesSize() { +size_t WebVttSampleConverter::ReadySamplesSize() { return ready_samples_.size(); } -std::shared_ptr WebVttFragmenter::PopSample() { +std::shared_ptr WebVttSampleConverter::PopSample() { CHECK(!ready_samples_.empty()); std::shared_ptr ret = ready_samples_.front(); ready_samples_.pop_front(); @@ -208,7 +207,7 @@ std::shared_ptr WebVttFragmenter::PopSample() { // Change algorithm to create A,B,C samples right away. // Note that this requires change to the caller on which cues // to remove. -bool WebVttFragmenter::HandleAllCuesButLatest() { +bool WebVttSampleConverter::HandleAllCuesButLatest() { DCHECK_GE(cues_.size(), 2u); const Cue& latest_cue = cues_.back(); @@ -246,7 +245,7 @@ bool WebVttFragmenter::HandleAllCuesButLatest() { return processed_cues; } -bool WebVttFragmenter::HandleAllCues() { +bool WebVttSampleConverter::HandleAllCues() { uint64_t latest_time = 0u; for (const Cue& cue : cues_) { if (cue.start_time + cue.duration > latest_time) @@ -259,8 +258,8 @@ bool WebVttFragmenter::HandleAllCues() { return processed; } -bool WebVttFragmenter::SweepCues(uint64_t sweep_line, - uint64_t sweep_stop_time) { +bool WebVttSampleConverter::SweepCues(uint64_t sweep_line, + uint64_t sweep_stop_time) { bool processed_cues = false; // This is a sweep line algorithm. For every iteration, it determines active // cues and makes a sample. @@ -308,6 +307,5 @@ bool WebVttFragmenter::SweepCues(uint64_t sweep_line, return processed_cues; } -} // namespace mp4 } // namespace media } // namespace shaka diff --git a/packager/media/formats/mp4/webvtt_fragmenter.h b/packager/media/formats/webvtt/webvtt_sample_converter.h similarity index 81% rename from packager/media/formats/mp4/webvtt_fragmenter.h rename to packager/media/formats/webvtt/webvtt_sample_converter.h index 2088e5921c..56b819adc4 100644 --- a/packager/media/formats/mp4/webvtt_fragmenter.h +++ b/packager/media/formats/webvtt/webvtt_sample_converter.h @@ -4,24 +4,24 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_ -#define PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_ +#ifndef PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_ +#define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_ #include #include #include "packager/media/base/status.h" +#include "packager/media/formats/mp4/box.h" #include "packager/media/formats/mp4/box_definitions.h" -#include "packager/media/formats/webvtt/webvtt_media_parser.h" +#include "packager/media/formats/webvtt/cue.h" namespace shaka { namespace media { -namespace mp4 { /// Appends box to vector. /// @param box is the box to be serialized. /// @param output_vector is where the data is appended. -void AppendBoxToVector(Box* box, std::vector* output_vector); +void AppendBoxToVector(mp4::Box* box, std::vector* output_vector); /// According to the spec, when cues overlap, samples must be created.\n /// The example below has 2 WebVTT cues:\n @@ -51,15 +51,10 @@ void AppendBoxToVector(Box* box, std::vector* output_vector); ///\n /// This class buffers the samples that are passed to AddSample() and creates /// more samples as necessary. -// TODO(rkuroiwa): Rename this to WebVttSampleConverter, and put this in -// webvtt parser. -// For now, the output (from PopSample()) should still be in ISO-BMFF box form; -// and also to signal that, should have different types for TextStreamInfo. e.g. -// TextStreamInfo::type() returns kIsoBmffStreamText. -class WebVttFragmenter { +class WebVttSampleConverter { public: - WebVttFragmenter(); - ~WebVttFragmenter(); + WebVttSampleConverter(); + ~WebVttSampleConverter(); /// Add a sample. /// @param sample is the sample to be added. It should contain one VTT cue. @@ -104,7 +99,7 @@ class WebVttFragmenter { std::list cues_; // For comment samples. - std::list additional_texts_; + std::list additional_texts_; // Samples that are ready to be processed. std::list> ready_samples_; @@ -114,11 +109,10 @@ class WebVttFragmenter { // or an empty cue (gap) has to be added. uint64_t next_cue_start_time_; - DISALLOW_COPY_AND_ASSIGN(WebVttFragmenter); + DISALLOW_COPY_AND_ASSIGN(WebVttSampleConverter); }; -} // namespace shaka } // namespace media -} // namespace edash_packager +} // namespace shaka -#endif // PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_ +#endif // PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_ diff --git a/packager/media/formats/mp4/webvtt_fragmenter_unittest.cc b/packager/media/formats/webvtt/webvtt_sample_converter_unittest.cc similarity index 82% rename from packager/media/formats/mp4/webvtt_fragmenter_unittest.cc rename to packager/media/formats/webvtt/webvtt_sample_converter_unittest.cc index 4eb647c37c..82410bace0 100644 --- a/packager/media/formats/mp4/webvtt_fragmenter_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_sample_converter_unittest.cc @@ -1,4 +1,4 @@ -#include "packager/media/formats/mp4/webvtt_fragmenter.h" +#include "packager/media/formats/webvtt/webvtt_sample_converter.h" #include #include @@ -32,7 +32,7 @@ MATCHER_P3(MatchesStartTimeEndTimeAndData, start_time, end_time, data, "") { class WebVttFragmenterTest : public ::testing::Test { protected: - WebVttFragmenter webvtt_fragmenter_; + WebVttSampleConverter webvtt_sample_converter_; }; // Verify that AppednBoxToVector works. @@ -89,7 +89,7 @@ TEST_F(WebVttFragmenterTest, NoOverlapContiguous) { sample1->set_dts(0); sample1->set_duration(2000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -98,22 +98,22 @@ TEST_F(WebVttFragmenterTest, NoOverlapContiguous) { sample2->set_dts(2000); sample2->set_duration(1000); - webvtt_fragmenter_.PushSample(sample2); - webvtt_fragmenter_.Flush(); - EXPECT_EQ(2u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.PushSample(sample2); + webvtt_sample_converter_.Flush(); + EXPECT_EQ(2u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_cue_data; first_cue_data.cue_payload.cue_text = kCueMessage1; std::vector expected; AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 2000, expected)); VTTCueBox second_cue_data; second_cue_data.cue_payload.cue_text = kCueMessage2; expected.clear(); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2000, 3000, expected)); } @@ -126,7 +126,7 @@ TEST_F(WebVttFragmenterTest, Gap) { sample1->set_dts(0); sample1->set_duration(1000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -135,30 +135,30 @@ TEST_F(WebVttFragmenterTest, Gap) { sample2->set_dts(2000); sample2->set_duration(1000); - webvtt_fragmenter_.PushSample(sample2); - EXPECT_EQ(2u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.PushSample(sample2); + EXPECT_EQ(2u, webvtt_sample_converter_.ReadySamplesSize()); - webvtt_fragmenter_.Flush(); - EXPECT_EQ(3u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.Flush(); + EXPECT_EQ(3u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_cue_data; first_cue_data.cue_payload.cue_text = kCueMessage1; std::vector expected; AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 1000, expected)); VTTEmptyCueBox empty_cue; expected.clear(); AppendBoxToVector(&empty_cue, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1000, 2000, expected)); VTTCueBox second_cue_data; second_cue_data.cue_payload.cue_text = kCueMessage2; expected.clear(); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2000, 3000, expected)); } @@ -172,7 +172,7 @@ TEST_F(WebVttFragmenterTest, OverlappingCuesSequential) { sample1->set_dts(0); sample1->set_duration(2000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -180,7 +180,7 @@ TEST_F(WebVttFragmenterTest, OverlappingCuesSequential) { sample2->set_pts(1000); sample2->set_dts(1000); sample2->set_duration(2000); - webvtt_fragmenter_.PushSample(sample2); + webvtt_sample_converter_.PushSample(sample2); std::shared_ptr sample3 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage3), @@ -188,18 +188,18 @@ TEST_F(WebVttFragmenterTest, OverlappingCuesSequential) { sample3->set_pts(1500); sample3->set_dts(1500); sample3->set_duration(4000); - webvtt_fragmenter_.PushSample(sample3); + webvtt_sample_converter_.PushSample(sample3); - webvtt_fragmenter_.Flush(); + webvtt_sample_converter_.Flush(); // There should be 5 samples for [0,1000], [1000,1500], [1500,2000], // [2000,3000], and [3000, 5500]. - EXPECT_EQ(5u, webvtt_fragmenter_.ReadySamplesSize()); + EXPECT_EQ(5u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_cue_data; first_cue_data.cue_payload.cue_text = kCueMessage1; std::vector expected; AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 1000, expected)); VTTCueBox second_cue_data; @@ -207,7 +207,7 @@ TEST_F(WebVttFragmenterTest, OverlappingCuesSequential) { expected.clear(); AppendBoxToVector(&first_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1000, 1500, expected)); VTTCueBox third_cue_data; @@ -216,18 +216,18 @@ TEST_F(WebVttFragmenterTest, OverlappingCuesSequential) { AppendBoxToVector(&first_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); AppendBoxToVector(&third_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1500, 2000, expected)); expected.clear(); AppendBoxToVector(&second_cue_data, &expected); AppendBoxToVector(&third_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2000, 3000, expected)); expected.clear(); AppendBoxToVector(&third_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(3000, 5500, expected)); } @@ -239,7 +239,7 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { sample1->set_dts(0); sample1->set_duration(10000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -247,7 +247,7 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { sample2->set_pts(1000); sample2->set_dts(1000); sample2->set_duration(5000); - webvtt_fragmenter_.PushSample(sample2); + webvtt_sample_converter_.PushSample(sample2); std::shared_ptr sample3 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage3), @@ -255,7 +255,7 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { sample3->set_pts(2000); sample3->set_dts(2000); sample3->set_duration(1000); - webvtt_fragmenter_.PushSample(sample3); + webvtt_sample_converter_.PushSample(sample3); std::shared_ptr sample4 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage4), @@ -263,18 +263,18 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { sample4->set_pts(8000); sample4->set_dts(8000); sample4->set_duration(1000); - webvtt_fragmenter_.PushSample(sample4); - webvtt_fragmenter_.Flush(); + webvtt_sample_converter_.PushSample(sample4); + webvtt_sample_converter_.Flush(); // There should be 7 samples for [0,1000], [1000,2000], [2000,3000], // [3000,6000], [6000, 8000], [8000, 9000], [9000, 10000]. - EXPECT_EQ(7u, webvtt_fragmenter_.ReadySamplesSize()); + EXPECT_EQ(7u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_long_cue_data; first_long_cue_data.cue_payload.cue_text = kCueMessage1; std::vector expected; AppendBoxToVector(&first_long_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 1000, expected)); VTTCueBox second_cue_data; @@ -282,7 +282,7 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { expected.clear(); AppendBoxToVector(&first_long_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1000, 2000, expected)); VTTCueBox third_cue_data; @@ -291,18 +291,18 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { AppendBoxToVector(&first_long_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); AppendBoxToVector(&third_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2000, 3000, expected)); expected.clear(); AppendBoxToVector(&first_long_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(3000, 6000, expected)); expected.clear(); AppendBoxToVector(&first_long_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(6000, 8000, expected)); VTTCueBox fourth_cue_data; @@ -310,12 +310,12 @@ TEST_F(WebVttFragmenterTest, OverlappingLongCue) { expected.clear(); AppendBoxToVector(&first_long_cue_data, &expected); AppendBoxToVector(&fourth_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(8000, 9000, expected)); expected.clear(); AppendBoxToVector(&first_long_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(9000, 10000, expected)); } @@ -326,16 +326,16 @@ TEST_F(WebVttFragmenterTest, GapAtBeginning) { sample1->set_pts(1200); sample1->set_dts(1200); sample1->set_duration(2000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); - webvtt_fragmenter_.Flush(); - EXPECT_EQ(1u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.Flush(); + EXPECT_EQ(1u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox cue_data; cue_data.cue_payload.cue_text = kCueMessage1; std::vector expected; AppendBoxToVector(&cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1200, 3200, expected)); } @@ -348,7 +348,7 @@ TEST_F(WebVttFragmenterTest, SameStartTime) { sample1->set_dts(0); sample1->set_duration(2000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -357,9 +357,9 @@ TEST_F(WebVttFragmenterTest, SameStartTime) { sample2->set_dts(0); sample2->set_duration(1500); - webvtt_fragmenter_.PushSample(sample2); - webvtt_fragmenter_.Flush(); - EXPECT_EQ(2u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.PushSample(sample2); + webvtt_sample_converter_.Flush(); + EXPECT_EQ(2u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_cue_data; first_cue_data.cue_payload.cue_text = kCueMessage1; @@ -369,12 +369,12 @@ TEST_F(WebVttFragmenterTest, SameStartTime) { std::vector expected; AppendBoxToVector(&first_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 1500, expected)); expected.clear(); AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1500, 2000, expected)); } @@ -387,7 +387,7 @@ TEST_F(WebVttFragmenterTest, MoreCases) { sample1->set_dts(0); sample1->set_duration(2000); - webvtt_fragmenter_.PushSample(sample1); + webvtt_sample_converter_.PushSample(sample1); std::shared_ptr sample2 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage2), @@ -396,7 +396,7 @@ TEST_F(WebVttFragmenterTest, MoreCases) { sample2->set_dts(100); sample2->set_duration(100); - webvtt_fragmenter_.PushSample(sample2); + webvtt_sample_converter_.PushSample(sample2); std::shared_ptr sample3 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage3), @@ -404,7 +404,7 @@ TEST_F(WebVttFragmenterTest, MoreCases) { sample3->set_pts(1500); sample3->set_dts(1500); sample3->set_duration(1000); - webvtt_fragmenter_.PushSample(sample3); + webvtt_sample_converter_.PushSample(sample3); std::shared_ptr sample4 = MediaSample::CopyFrom(reinterpret_cast(kCueMessage4), @@ -412,10 +412,10 @@ TEST_F(WebVttFragmenterTest, MoreCases) { sample4->set_pts(1500); sample4->set_dts(1500); sample4->set_duration(800); - webvtt_fragmenter_.PushSample(sample4); + webvtt_sample_converter_.PushSample(sample4); - webvtt_fragmenter_.Flush(); - EXPECT_EQ(6u, webvtt_fragmenter_.ReadySamplesSize()); + webvtt_sample_converter_.Flush(); + EXPECT_EQ(6u, webvtt_sample_converter_.ReadySamplesSize()); VTTCueBox first_cue_data; first_cue_data.cue_payload.cue_text = kCueMessage1; @@ -428,36 +428,36 @@ TEST_F(WebVttFragmenterTest, MoreCases) { std::vector expected; AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(0, 100, expected)); expected.clear(); AppendBoxToVector(&first_cue_data, &expected); AppendBoxToVector(&second_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(100, 200, expected)); expected.clear(); AppendBoxToVector(&first_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(200, 1500, expected)); expected.clear(); AppendBoxToVector(&first_cue_data, &expected); AppendBoxToVector(&third_cue_data, &expected); AppendBoxToVector(&fourth_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(1500, 2000, expected)); expected.clear(); AppendBoxToVector(&third_cue_data, &expected); AppendBoxToVector(&fourth_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2000, 2300, expected)); expected.clear(); AppendBoxToVector(&third_cue_data, &expected); - EXPECT_THAT(webvtt_fragmenter_.PopSample(), + EXPECT_THAT(webvtt_sample_converter_.PopSample(), MatchesStartTimeEndTimeAndData(2300, 2500, expected)); }