2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-09-18 15:43:21 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2018-03-23 22:28:30 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
|
|
|
|
#define PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
|
2017-09-18 15:43:21 +00:00
|
|
|
|
2018-03-23 01:33:01 +00:00
|
|
|
#include <list>
|
2017-09-18 15:43:21 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/media_handler.h>
|
2017-09-18 15:43:21 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
|
2018-06-06 18:41:21 +00:00
|
|
|
// Media handler for taking a single stream of text samples and inserting
|
|
|
|
// segment info based on a fixed segment duration and on cue events. The
|
|
|
|
// only time a segment's duration will not match the fixed segment duration
|
|
|
|
// is when a cue event is seen.
|
2018-03-23 22:28:30 +00:00
|
|
|
class TextChunker : public MediaHandler {
|
2017-09-18 15:43:21 +00:00
|
|
|
public:
|
2018-06-06 18:41:21 +00:00
|
|
|
explicit TextChunker(double segment_duration_in_seconds);
|
2017-09-18 15:43:21 +00:00
|
|
|
|
|
|
|
private:
|
2018-03-23 22:28:30 +00:00
|
|
|
TextChunker(const TextChunker&) = delete;
|
|
|
|
TextChunker& operator=(const TextChunker&) = delete;
|
2017-09-18 15:43:21 +00:00
|
|
|
|
2018-06-06 18:41:21 +00:00
|
|
|
Status InitializeInternal() override { return Status::OK; }
|
2017-09-18 15:43:21 +00:00
|
|
|
|
2018-03-23 01:33:01 +00:00
|
|
|
Status Process(std::unique_ptr<StreamData> stream_data) override;
|
|
|
|
Status OnFlushRequest(size_t input_stream_index) override;
|
|
|
|
|
|
|
|
Status OnStreamInfo(std::shared_ptr<const StreamInfo> info);
|
|
|
|
Status OnCueEvent(std::shared_ptr<const CueEvent> cue);
|
2017-09-18 15:43:21 +00:00
|
|
|
Status OnTextSample(std::shared_ptr<const TextSample> sample);
|
|
|
|
|
2018-06-06 18:41:21 +00:00
|
|
|
// This does two things that should always happen together:
|
|
|
|
// 1. Dispatch all the samples and a segment info for the time range
|
|
|
|
// segment_start_ to segment_start_ + duration
|
|
|
|
// 2. Set the next segment to start at segment_start_ + duration and
|
|
|
|
// remove all samples that don't last into that segment.
|
|
|
|
Status DispatchSegment(int64_t duration);
|
2018-01-31 19:10:13 +00:00
|
|
|
|
2018-06-06 18:41:21 +00:00
|
|
|
int64_t ScaleTime(double seconds) const;
|
2018-02-05 17:55:58 +00:00
|
|
|
|
2018-06-06 18:41:21 +00:00
|
|
|
double segment_duration_in_seconds_;
|
|
|
|
|
|
|
|
int64_t time_scale_ = -1; // Set in OnStreamInfo
|
|
|
|
|
|
|
|
// Time values are in scaled units.
|
2018-06-21 18:31:09 +00:00
|
|
|
int64_t segment_start_ = -1; // Set when the first sample comes in.
|
|
|
|
int64_t segment_duration_ = -1; // Set in OnStreamInfo.
|
2018-06-06 18:41:21 +00:00
|
|
|
|
|
|
|
// All samples that make up the current segment. We must store the samples
|
|
|
|
// until the segment ends because a cue event may end the segment sooner
|
|
|
|
// than we expected.
|
|
|
|
std::list<std::shared_ptr<const TextSample>> samples_in_current_segment_;
|
2017-09-18 15:43:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|
|
|
|
|
2018-03-23 22:28:30 +00:00
|
|
|
#endif // PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
|