Shaka Packager SDK
webvtt_segmenter.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_FORMATS_WEBVTT_WEBVTT_SEGMENTER_H_
8 #define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SEGMENTER_H_
9 
10 #include <stdint.h>
11 
12 #include <map>
13 #include <vector>
14 
15 #include "packager/media/base/media_handler.h"
16 #include "packager/status.h"
17 
18 namespace shaka {
19 namespace media {
20 
21 class WebVttSegmenter : public MediaHandler {
22  public:
23  explicit WebVttSegmenter(uint64_t segment_duration_ms);
24 
25  protected:
26  Status Process(std::unique_ptr<StreamData> stream_data) override;
27  Status OnFlushRequest(size_t input_stream_index) override;
28 
29  private:
30  WebVttSegmenter(const WebVttSegmenter&) = delete;
31  WebVttSegmenter& operator=(const WebVttSegmenter&) = delete;
32 
33  using WebVttSample = std::shared_ptr<const TextSample>;
34  using WebVttSegmentSamples = std::vector<WebVttSample>;
35 
36  Status InitializeInternal() override;
37 
38  Status OnTextSample(std::shared_ptr<const TextSample> sample);
39 
40  Status DispatchSegmentWithSamples(uint64_t segment,
41  const WebVttSegmentSamples& samples);
42 
43  uint64_t segment_duration_ms_;
44 
45  // Mapping of segment number to segment.
46  std::map<uint64_t, WebVttSegmentSamples> segment_map_;
47  uint64_t head_segment_ = 0;
48 };
49 
50 } // namespace media
51 } // namespace shaka
52 
53 #endif // PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SEGMENTER_H_
Status Process(std::unique_ptr< StreamData > stream_data) override
All the methods that are virtual are virtual for mocking.
Status OnFlushRequest(size_t input_stream_index) override
Event handler for flush request at the specific input stream index.