Shaka Packager SDK
text_chunker.h
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
8 #define PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
9 
10 #include <list>
11 
12 #include "packager/media/base/media_handler.h"
13 
14 namespace shaka {
15 namespace media {
16 
17 // Media handler for taking a single stream of text samples and inserting
18 // segment info based on a fixed segment duration and on cue events. The
19 // only time a segment's duration will not match the fixed segment duration
20 // is when a cue event is seen.
21 class TextChunker : public MediaHandler {
22  public:
23  explicit TextChunker(double segment_duration_in_seconds);
24 
25  private:
26  TextChunker(const TextChunker&) = delete;
27  TextChunker& operator=(const TextChunker&) = delete;
28 
29  Status InitializeInternal() override { return Status::OK; }
30 
31  Status Process(std::unique_ptr<StreamData> stream_data) override;
32  Status OnFlushRequest(size_t input_stream_index) override;
33 
34  Status OnStreamInfo(std::shared_ptr<const StreamInfo> info);
35  Status OnCueEvent(std::shared_ptr<const CueEvent> cue);
36  Status OnTextSample(std::shared_ptr<const TextSample> sample);
37 
38  // This does two things that should always happen together:
39  // 1. Dispatch all the samples and a segment info for the time range
40  // segment_start_ to segment_start_ + duration
41  // 2. Set the next segment to start at segment_start_ + duration and
42  // remove all samples that don't last into that segment.
43  Status DispatchSegment(int64_t duration);
44 
45  int64_t ScaleTime(double seconds) const;
46 
47  double segment_duration_in_seconds_;
48 
49  int64_t time_scale_ = -1; // Set in OnStreamInfo
50 
51  // Time values are in scaled units.
52  int64_t segment_start_ = -1; // Set when the first sample comes in.
53  int64_t segment_duration_ = -1; // Set in OnStreamInfo.
54 
55  // All samples that make up the current segment. We must store the samples
56  // until the segment ends because a cue event may end the segment sooner
57  // than we expected.
58  std::list<std::shared_ptr<const TextSample>> samples_in_current_segment_;
59 };
60 
61 } // namespace media
62 } // namespace shaka
63 
64 #endif // PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::Status
Definition: status.h:110
shaka::media::MediaHandler
Definition: media_handler.h:154
shaka::media::TextChunker
Definition: text_chunker.h:21