Rename WebVttSegmenter To TextChunker

Renamed the webvtt segmenter to text chunker as there is nothing
webvtt specific in the code.

Change-Id: I0111c50d545fa168d945b39bc8a78c46c62678be
This commit is contained in:
Aaron Vaage 2018-03-23 15:28:30 -07:00
parent 2dd198a9d2
commit 56caecd073
5 changed files with 37 additions and 39 deletions

View File

@ -19,8 +19,8 @@
'cue_alignment_handler.h', 'cue_alignment_handler.h',
'sync_point_queue.cc', 'sync_point_queue.cc',
'sync_point_queue.h', 'sync_point_queue.h',
'webvtt_segmenter.cc', 'text_chunker.cc',
'webvtt_segmenter.h', 'text_chunker.h',
], ],
'dependencies': [ 'dependencies': [
'../base/media_base.gyp:media_base', '../base/media_base.gyp:media_base',
@ -32,7 +32,7 @@
'sources': [ 'sources': [
'chunking_handler_unittest.cc', 'chunking_handler_unittest.cc',
'cue_alignment_handler_unittest.cc', 'cue_alignment_handler_unittest.cc',
'webvtt_segmenter_unittest.cc', 'text_chunker_unittest.cc',
], ],
'dependencies': [ 'dependencies': [
'../../testing/gtest.gyp:gtest', '../../testing/gtest.gyp:gtest',

View File

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // 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 shaka {
namespace media { namespace media {
@ -12,14 +12,14 @@ namespace {
const size_t kStreamIndex = 0; const size_t kStreamIndex = 0;
} // namespace } // namespace
WebVttSegmenter::WebVttSegmenter(uint64_t segment_duration_ms) TextChunker::TextChunker(uint64_t segment_duration_ms)
: segment_duration_ms_(segment_duration_ms) {} : segment_duration_ms_(segment_duration_ms) {}
Status WebVttSegmenter::InitializeInternal() { Status TextChunker::InitializeInternal() {
return Status::OK; return Status::OK;
} }
Status WebVttSegmenter::Process(std::unique_ptr<StreamData> stream_data) { Status TextChunker::Process(std::unique_ptr<StreamData> stream_data) {
switch (stream_data->stream_data_type) { switch (stream_data->stream_data_type) {
case StreamDataType::kStreamInfo: case StreamDataType::kStreamInfo:
return DispatchStreamInfo(kStreamIndex, return DispatchStreamInfo(kStreamIndex,
@ -32,7 +32,7 @@ Status WebVttSegmenter::Process(std::unique_ptr<StreamData> 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 // 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. // segments, all we need to do is run through all of them.
for (const auto& pair : segment_map_) { for (const auto& pair : segment_map_) {
@ -48,7 +48,7 @@ Status WebVttSegmenter::OnFlushRequest(size_t input_stream_index) {
return FlushAllDownstreams(); return FlushAllDownstreams();
} }
Status WebVttSegmenter::OnTextSample(std::shared_ptr<const TextSample> sample) { Status TextChunker::OnTextSample(std::shared_ptr<const TextSample> sample) {
const uint64_t start_segment = sample->start_time() / segment_duration_ms_; const uint64_t start_segment = sample->start_time() / segment_duration_ms_;
// Find the last segment that overlaps the sample. Adjust the sample by one // Find the last segment that overlaps the sample. Adjust the sample by one
@ -80,7 +80,7 @@ Status WebVttSegmenter::OnTextSample(std::shared_ptr<const TextSample> sample) {
Status status; Status status;
if (it == segment_map_.end()) { if (it == segment_map_.end()) {
const WebVttSegmentSamples kNoSamples; const SegmentSamples kNoSamples;
status.Update(DispatchSegmentWithSamples(segment, kNoSamples)); status.Update(DispatchSegmentWithSamples(segment, kNoSamples));
} else { } else {
// We found a segment, output all the samples. Remove it from the map as // We found a segment, output all the samples. Remove it from the map as
@ -102,9 +102,8 @@ Status WebVttSegmenter::OnTextSample(std::shared_ptr<const TextSample> sample) {
return Status::OK; return Status::OK;
} }
Status WebVttSegmenter::DispatchSegmentWithSamples( Status TextChunker::DispatchSegmentWithSamples(uint64_t segment,
uint64_t segment, const SegmentSamples& samples) {
const WebVttSegmentSamples& samples) {
Status status; Status status;
for (const auto& sample : samples) { for (const auto& sample : samples) {
status.Update(DispatchTextSample(kStreamIndex, sample)); status.Update(DispatchTextSample(kStreamIndex, sample));

View File

@ -4,8 +4,8 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // https://developers.google.com/open-source/licenses/bsd
#ifndef PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ #ifndef PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
#define PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ #define PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
#include <stdint.h> #include <stdint.h>
@ -18,36 +18,35 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
class WebVttSegmenter : public MediaHandler { class TextChunker : public MediaHandler {
public: public:
explicit WebVttSegmenter(uint64_t segment_duration_ms); explicit TextChunker(uint64_t segment_duration_ms);
protected: protected:
Status Process(std::unique_ptr<StreamData> stream_data) override; Status Process(std::unique_ptr<StreamData> stream_data) override;
Status OnFlushRequest(size_t input_stream_index) override; Status OnFlushRequest(size_t input_stream_index) override;
private: private:
WebVttSegmenter(const WebVttSegmenter&) = delete; TextChunker(const TextChunker&) = delete;
WebVttSegmenter& operator=(const WebVttSegmenter&) = delete; TextChunker& operator=(const TextChunker&) = delete;
using WebVttSample = std::shared_ptr<const TextSample>; using SegmentSamples = std::vector<std::shared_ptr<const TextSample>>;
using WebVttSegmentSamples = std::vector<WebVttSample>;
Status InitializeInternal() override; Status InitializeInternal() override;
Status OnTextSample(std::shared_ptr<const TextSample> sample); Status OnTextSample(std::shared_ptr<const TextSample> sample);
Status DispatchSegmentWithSamples(uint64_t segment, Status DispatchSegmentWithSamples(uint64_t segment,
const WebVttSegmentSamples& samples); const SegmentSamples& samples);
uint64_t segment_duration_ms_; uint64_t segment_duration_ms_;
// Mapping of segment number to segment. // Mapping of segment number to segment.
std::map<uint64_t, WebVttSegmentSamples> segment_map_; std::map<uint64_t, SegmentSamples> segment_map_;
uint64_t head_segment_ = 0; uint64_t head_segment_ = 0;
}; };
} // namespace media } // namespace media
} // namespace shaka } // namespace shaka
#endif // PACKAGER_MEDIA_CHUNKING_WEBVTT_SEGMENTER_H_ #endif // PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_

View File

@ -8,7 +8,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "packager/media/base/media_handler_test_base.h" #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" #include "packager/status_test_util.h"
namespace shaka { namespace shaka {
@ -35,12 +35,12 @@ const char* kPayload[] = {"cue 1 payload", "cue 2 payload"};
const std::string kNoSettings = ""; const std::string kNoSettings = "";
} // namespace } // namespace
class WebVttSegmenterTest : public MediaHandlerTestBase { class TextChunkerTest : public MediaHandlerTestBase {
protected: protected:
void SetUp() { void SetUp() {
ASSERT_OK(SetUpAndInitializeGraph( ASSERT_OK(
std::make_shared<WebVttSegmenter>(kSegmentDuration), kInputCount, SetUpAndInitializeGraph(std::make_shared<TextChunker>(kSegmentDuration),
kOutputCount)); kInputCount, kOutputCount));
} }
}; };
@ -49,7 +49,7 @@ class WebVttSegmenterTest : public MediaHandlerTestBase {
// | | // | |
// |[---A---]| // |[---A---]|
// | | // | |
TEST_F(WebVttSegmenterTest, CueEndingOnSegmentStart) { TEST_F(TextChunkerTest, CueEndingOnSegmentStart) {
const uint64_t kSampleDuration = kSegmentDuration; const uint64_t kSampleDuration = kSegmentDuration;
{ {
@ -86,7 +86,7 @@ TEST_F(WebVttSegmenterTest, CueEndingOnSegmentStart) {
// [---A---] | // [---A---] |
// | [---B---] // | [---B---]
// | // |
TEST_F(WebVttSegmenterTest, CreatesSegmentsForCues) { TEST_F(TextChunkerTest, CreatesSegmentsForCues) {
// Divide segment duration by 2 so that the sample duration won't be a full // Divide segment duration by 2 so that the sample duration won't be a full
// segment. // segment.
const uint64_t kSampleDuration = kSegmentDuration / 2; const uint64_t kSampleDuration = kSegmentDuration / 2;
@ -142,7 +142,7 @@ TEST_F(WebVttSegmenterTest, CreatesSegmentsForCues) {
// | | // | |
// | | [---B---] // | | [---B---]
// | | // | |
TEST_F(WebVttSegmenterTest, OutputsEmptySegments) { TEST_F(TextChunkerTest, OutputsEmptySegments) {
const uint64_t kSampleDuration = kSegmentDuration / 2; const uint64_t kSampleDuration = kSegmentDuration / 2;
const int64_t kSegment1Start = kStartTime; const int64_t kSegment1Start = kStartTime;
@ -207,7 +207,7 @@ TEST_F(WebVttSegmenterTest, OutputsEmptySegments) {
// | // |
// [-----A-----|---------] // [-----A-----|---------]
// | // |
TEST_F(WebVttSegmenterTest, CueCrossesSegments) { TEST_F(TextChunkerTest, CueCrossesSegments) {
const uint64_t kSampleDuration = 2 * kSegmentDuration; const uint64_t kSampleDuration = 2 * kSegmentDuration;
{ {
@ -249,9 +249,9 @@ TEST_F(WebVttSegmenterTest, CueCrossesSegments) {
ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams()); 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 kInputs = 1;
const size_t kOutputs = 1; const size_t kOutputs = 1;
@ -262,8 +262,8 @@ TEST_F(WebVttSegmenterOrderTest, PreservesOrder) {
const int64_t kSegmentStart1 = 0; const int64_t kSegmentStart1 = 0;
const int64_t kSegmentStart2 = kDuration; const int64_t kSegmentStart2 = kDuration;
ASSERT_OK(SetUpAndInitializeGraph( ASSERT_OK(SetUpAndInitializeGraph(std::make_shared<TextChunker>(kDuration),
std::make_shared<WebVttSegmenter>(kDuration), kInputs, kOutputs)); kInputs, kOutputs));
{ {
testing::InSequence s; testing::InSequence s;

View File

@ -34,7 +34,7 @@
#include "packager/media/base/muxer_util.h" #include "packager/media/base/muxer_util.h"
#include "packager/media/chunking/chunking_handler.h" #include "packager/media/chunking/chunking_handler.h"
#include "packager/media/chunking/cue_alignment_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/crypto/encryption_handler.h"
#include "packager/media/demuxer/demuxer.h" #include "packager/media/demuxer/demuxer.h"
#include "packager/media/event/muxer_listener_factory.h" #include "packager/media/event/muxer_listener_factory.h"
@ -457,7 +457,7 @@ Status CreateHlsTextJob(const StreamDescriptor& stream,
auto parser = auto parser =
std::make_shared<WebVttParser>(std::move(reader), stream.language); std::make_shared<WebVttParser>(std::move(reader), stream.language);
auto segmenter = std::make_shared<WebVttSegmenter>(segment_length_in_ms); auto segmenter = std::make_shared<TextChunker>(segment_length_in_ms);
// Build in reverse to allow us to move the pointers. // Build in reverse to allow us to move the pointers.
Status status; Status status;