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',
'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',

View File

@ -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<StreamData> stream_data) {
Status TextChunker::Process(std::unique_ptr<StreamData> stream_data) {
switch (stream_data->stream_data_type) {
case StreamDataType::kStreamInfo:
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
// 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<const TextSample> sample) {
Status TextChunker::OnTextSample(std::shared_ptr<const TextSample> 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<const TextSample> 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<const TextSample> 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));

View File

@ -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 <stdint.h>
@ -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<StreamData> 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<const TextSample>;
using WebVttSegmentSamples = std::vector<WebVttSample>;
using SegmentSamples = std::vector<std::shared_ptr<const TextSample>>;
Status InitializeInternal() override;
Status OnTextSample(std::shared_ptr<const TextSample> 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<uint64_t, WebVttSegmentSamples> segment_map_;
std::map<uint64_t, SegmentSamples> 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_

View File

@ -8,7 +8,7 @@
#include <gtest/gtest.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"
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<WebVttSegmenter>(kSegmentDuration), kInputCount,
kOutputCount));
ASSERT_OK(
SetUpAndInitializeGraph(std::make_shared<TextChunker>(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<WebVttSegmenter>(kDuration), kInputs, kOutputs));
ASSERT_OK(SetUpAndInitializeGraph(std::make_shared<TextChunker>(kDuration),
kInputs, kOutputs));
{
testing::InSequence s;

View File

@ -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<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.
Status status;