From 56caecd0738ccd2aea41952aa958b65f65e99fa6 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Fri, 23 Mar 2018 15:28:30 -0700 Subject: [PATCH] Rename WebVttSegmenter To TextChunker Renamed the webvtt segmenter to text chunker as there is nothing webvtt specific in the code. Change-Id: I0111c50d545fa168d945b39bc8a78c46c62678be --- packager/media/chunking/chunking.gyp | 6 ++--- .../{webvtt_segmenter.cc => text_chunker.cc} | 19 +++++++------- .../{webvtt_segmenter.h => text_chunker.h} | 21 +++++++-------- ...r_unittest.cc => text_chunker_unittest.cc} | 26 +++++++++---------- packager/packager.cc | 4 +-- 5 files changed, 37 insertions(+), 39 deletions(-) rename packager/media/chunking/{webvtt_segmenter.cc => text_chunker.cc} (86%) rename packager/media/chunking/{webvtt_segmenter.h => text_chunker.h} (58%) rename packager/media/chunking/{webvtt_segmenter_unittest.cc => text_chunker_unittest.cc} (93%) diff --git a/packager/media/chunking/chunking.gyp b/packager/media/chunking/chunking.gyp index 65d653ff2a..ea34ac3f0d 100644 --- a/packager/media/chunking/chunking.gyp +++ b/packager/media/chunking/chunking.gyp @@ -19,8 +19,8 @@ 'cue_alignment_handler.h', 'sync_point_queue.cc', 'sync_point_queue.h', - 'webvtt_segmenter.cc', - 'webvtt_segmenter.h', + 'text_chunker.cc', + 'text_chunker.h', ], 'dependencies': [ '../base/media_base.gyp:media_base', @@ -32,7 +32,7 @@ 'sources': [ 'chunking_handler_unittest.cc', 'cue_alignment_handler_unittest.cc', - 'webvtt_segmenter_unittest.cc', + 'text_chunker_unittest.cc', ], 'dependencies': [ '../../testing/gtest.gyp:gtest', diff --git a/packager/media/chunking/webvtt_segmenter.cc b/packager/media/chunking/text_chunker.cc similarity index 86% rename from packager/media/chunking/webvtt_segmenter.cc rename to packager/media/chunking/text_chunker.cc index e6eb320c53..43161a18ef 100644 --- a/packager/media/chunking/webvtt_segmenter.cc +++ b/packager/media/chunking/text_chunker.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/chunking/webvtt_segmenter.h" +#include "packager/media/chunking/text_chunker.h" namespace shaka { namespace media { @@ -12,14 +12,14 @@ namespace { const size_t kStreamIndex = 0; } // namespace -WebVttSegmenter::WebVttSegmenter(uint64_t segment_duration_ms) +TextChunker::TextChunker(uint64_t segment_duration_ms) : segment_duration_ms_(segment_duration_ms) {} -Status WebVttSegmenter::InitializeInternal() { +Status TextChunker::InitializeInternal() { return Status::OK; } -Status WebVttSegmenter::Process(std::unique_ptr stream_data) { +Status TextChunker::Process(std::unique_ptr stream_data) { switch (stream_data->stream_data_type) { case StreamDataType::kStreamInfo: return DispatchStreamInfo(kStreamIndex, @@ -32,7 +32,7 @@ Status WebVttSegmenter::Process(std::unique_ptr stream_data) { } } -Status WebVttSegmenter::OnFlushRequest(size_t input_stream_index) { +Status TextChunker::OnFlushRequest(size_t input_stream_index) { // At this point we know that there is a single series of consecutive // segments, all we need to do is run through all of them. for (const auto& pair : segment_map_) { @@ -48,7 +48,7 @@ Status WebVttSegmenter::OnFlushRequest(size_t input_stream_index) { return FlushAllDownstreams(); } -Status WebVttSegmenter::OnTextSample(std::shared_ptr sample) { +Status TextChunker::OnTextSample(std::shared_ptr sample) { const uint64_t start_segment = sample->start_time() / segment_duration_ms_; // Find the last segment that overlaps the sample. Adjust the sample by one @@ -80,7 +80,7 @@ Status WebVttSegmenter::OnTextSample(std::shared_ptr sample) { Status status; if (it == segment_map_.end()) { - const WebVttSegmentSamples kNoSamples; + const SegmentSamples kNoSamples; status.Update(DispatchSegmentWithSamples(segment, kNoSamples)); } else { // We found a segment, output all the samples. Remove it from the map as @@ -102,9 +102,8 @@ Status WebVttSegmenter::OnTextSample(std::shared_ptr sample) { return Status::OK; } -Status WebVttSegmenter::DispatchSegmentWithSamples( - uint64_t segment, - const WebVttSegmentSamples& samples) { +Status TextChunker::DispatchSegmentWithSamples(uint64_t segment, + const SegmentSamples& samples) { Status status; for (const auto& sample : samples) { status.Update(DispatchTextSample(kStreamIndex, sample)); diff --git a/packager/media/chunking/webvtt_segmenter.h b/packager/media/chunking/text_chunker.h similarity index 58% rename from packager/media/chunking/webvtt_segmenter.h rename to packager/media/chunking/text_chunker.h index b0d18b3ec4..bd8f05f018 100644 --- a/packager/media/chunking/webvtt_segmenter.h +++ b/packager/media/chunking/text_chunker.h @@ -4,8 +4,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ -#define PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ +#ifndef PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_ +#define PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_ #include @@ -18,36 +18,35 @@ namespace shaka { namespace media { -class WebVttSegmenter : public MediaHandler { +class TextChunker : public MediaHandler { public: - explicit WebVttSegmenter(uint64_t segment_duration_ms); + explicit TextChunker(uint64_t segment_duration_ms); protected: Status Process(std::unique_ptr stream_data) override; Status OnFlushRequest(size_t input_stream_index) override; private: - WebVttSegmenter(const WebVttSegmenter&) = delete; - WebVttSegmenter& operator=(const WebVttSegmenter&) = delete; + TextChunker(const TextChunker&) = delete; + TextChunker& operator=(const TextChunker&) = delete; - using WebVttSample = std::shared_ptr; - using WebVttSegmentSamples = std::vector; + using SegmentSamples = std::vector>; Status InitializeInternal() override; Status OnTextSample(std::shared_ptr sample); Status DispatchSegmentWithSamples(uint64_t segment, - const WebVttSegmentSamples& samples); + const SegmentSamples& samples); uint64_t segment_duration_ms_; // Mapping of segment number to segment. - std::map segment_map_; + std::map segment_map_; uint64_t head_segment_ = 0; }; } // namespace media } // namespace shaka -#endif // PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ +#endif // PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_ diff --git a/packager/media/chunking/webvtt_segmenter_unittest.cc b/packager/media/chunking/text_chunker_unittest.cc similarity index 93% rename from packager/media/chunking/webvtt_segmenter_unittest.cc rename to packager/media/chunking/text_chunker_unittest.cc index be8b919dda..3427e4556b 100644 --- a/packager/media/chunking/webvtt_segmenter_unittest.cc +++ b/packager/media/chunking/text_chunker_unittest.cc @@ -8,7 +8,7 @@ #include #include "packager/media/base/media_handler_test_base.h" -#include "packager/media/chunking/webvtt_segmenter.h" +#include "packager/media/chunking/text_chunker.h" #include "packager/status_test_util.h" namespace shaka { @@ -35,12 +35,12 @@ const char* kPayload[] = {"cue 1 payload", "cue 2 payload"}; const std::string kNoSettings = ""; } // namespace -class WebVttSegmenterTest : public MediaHandlerTestBase { +class TextChunkerTest : public MediaHandlerTestBase { protected: void SetUp() { - ASSERT_OK(SetUpAndInitializeGraph( - std::make_shared(kSegmentDuration), kInputCount, - kOutputCount)); + ASSERT_OK( + SetUpAndInitializeGraph(std::make_shared(kSegmentDuration), + kInputCount, kOutputCount)); } }; @@ -49,7 +49,7 @@ class WebVttSegmenterTest : public MediaHandlerTestBase { // | | // |[---A---]| // | | -TEST_F(WebVttSegmenterTest, CueEndingOnSegmentStart) { +TEST_F(TextChunkerTest, CueEndingOnSegmentStart) { const uint64_t kSampleDuration = kSegmentDuration; { @@ -86,7 +86,7 @@ TEST_F(WebVttSegmenterTest, CueEndingOnSegmentStart) { // [---A---] | // | [---B---] // | -TEST_F(WebVttSegmenterTest, CreatesSegmentsForCues) { +TEST_F(TextChunkerTest, CreatesSegmentsForCues) { // Divide segment duration by 2 so that the sample duration won't be a full // segment. const uint64_t kSampleDuration = kSegmentDuration / 2; @@ -142,7 +142,7 @@ TEST_F(WebVttSegmenterTest, CreatesSegmentsForCues) { // | | // | | [---B---] // | | -TEST_F(WebVttSegmenterTest, OutputsEmptySegments) { +TEST_F(TextChunkerTest, OutputsEmptySegments) { const uint64_t kSampleDuration = kSegmentDuration / 2; const int64_t kSegment1Start = kStartTime; @@ -207,7 +207,7 @@ TEST_F(WebVttSegmenterTest, OutputsEmptySegments) { // | // [-----A-----|---------] // | -TEST_F(WebVttSegmenterTest, CueCrossesSegments) { +TEST_F(TextChunkerTest, CueCrossesSegments) { const uint64_t kSampleDuration = 2 * kSegmentDuration; { @@ -249,9 +249,9 @@ TEST_F(WebVttSegmenterTest, CueCrossesSegments) { ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams()); } -class WebVttSegmenterOrderTest : public MediaHandlerTestBase {}; +class TextChunkerOrderTest : public MediaHandlerTestBase {}; -TEST_F(WebVttSegmenterOrderTest, PreservesOrder) { +TEST_F(TextChunkerOrderTest, PreservesOrder) { const size_t kInputs = 1; const size_t kOutputs = 1; @@ -262,8 +262,8 @@ TEST_F(WebVttSegmenterOrderTest, PreservesOrder) { const int64_t kSegmentStart1 = 0; const int64_t kSegmentStart2 = kDuration; - ASSERT_OK(SetUpAndInitializeGraph( - std::make_shared(kDuration), kInputs, kOutputs)); + ASSERT_OK(SetUpAndInitializeGraph(std::make_shared(kDuration), + kInputs, kOutputs)); { testing::InSequence s; diff --git a/packager/packager.cc b/packager/packager.cc index 95d23aeb40..540a66c3d9 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -34,7 +34,7 @@ #include "packager/media/base/muxer_util.h" #include "packager/media/chunking/chunking_handler.h" #include "packager/media/chunking/cue_alignment_handler.h" -#include "packager/media/chunking/webvtt_segmenter.h" +#include "packager/media/chunking/text_chunker.h" #include "packager/media/crypto/encryption_handler.h" #include "packager/media/demuxer/demuxer.h" #include "packager/media/event/muxer_listener_factory.h" @@ -457,7 +457,7 @@ Status CreateHlsTextJob(const StreamDescriptor& stream, auto parser = std::make_shared(std::move(reader), stream.language); - auto segmenter = std::make_shared(segment_length_in_ms); + auto segmenter = std::make_shared(segment_length_in_ms); // Build in reverse to allow us to move the pointers. Status status;