Shaka Packager SDK
text_chunker.h
1 // Copyright 2017 Google LLC. 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  int64_t start_segment_number);
25 
26  private:
27  TextChunker(const TextChunker&) = delete;
28  TextChunker& operator=(const TextChunker&) = delete;
29 
30  Status InitializeInternal() override { return Status::OK; }
31 
32  Status Process(std::unique_ptr<StreamData> stream_data) override;
33  Status OnFlushRequest(size_t input_stream_index) override;
34 
35  Status OnStreamInfo(std::shared_ptr<const StreamInfo> info);
36  Status OnCueEvent(std::shared_ptr<const CueEvent> cue);
37  Status OnTextSample(std::shared_ptr<const TextSample> sample);
38 
39  // This does two things that should always happen together:
40  // 1. Dispatch all the samples and a segment info for the time range
41  // segment_start_ to segment_start_ + duration
42  // 2. Set the next segment to start at segment_start_ + duration and
43  // remove all samples that don't last into that segment.
44  Status DispatchSegment(int64_t duration);
45 
46  int64_t ScaleTime(double seconds) const;
47 
48  double segment_duration_in_seconds_;
49 
50  int64_t time_scale_ = -1; // Set in OnStreamInfo
51 
52  // Time values are in scaled units.
53  int64_t segment_start_ = -1; // Set when the first sample comes in.
54  int64_t segment_duration_ = -1; // Set in OnStreamInfo.
55 
56  // Segment number that keeps monotically increasing.
57  // Set to start_segment_number in constructor.
58  int64_t segment_number_ = 1;
59 
60  // All samples that make up the current segment. We must store the samples
61  // until the segment ends because a cue event may end the segment sooner
62  // than we expected.
63  std::list<std::shared_ptr<const TextSample>> samples_in_current_segment_;
64 };
65 
66 } // namespace media
67 } // namespace shaka
68 
69 #endif // PACKAGER_MEDIA_CHUNKING_TEXT_CHUNKER_H_
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66