Shaka Packager SDK
webvtt_parser.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_PARSER_H_
8 #define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
9 
10 #include <stdint.h>
11 
12 #include <vector>
13 
14 #include "packager/media/formats/webvtt/text_readers.h"
15 #include "packager/media/origin/origin_handler.h"
16 
17 namespace shaka {
18 namespace media {
19 
20 // Used to parse a WebVTT source into Cues that will be sent downstream.
21 class WebVttParser : public OriginHandler {
22  public:
23  WebVttParser(std::unique_ptr<FileReader> source, const std::string& language);
24 
25  Status Run() override;
26  void Cancel() override;
27 
28  private:
29  WebVttParser(const WebVttParser&) = delete;
30  WebVttParser& operator=(const WebVttParser&) = delete;
31 
32  Status InitializeInternal() override;
33  bool ValidateOutputStreamIndex(size_t stream_index) const override;
34 
35  bool Parse();
36  bool ParseCueWithNoId(const std::vector<std::string>& block);
37  bool ParseCueWithId(const std::vector<std::string>& block);
38  Status ParseCue(const std::string& id,
39  const std::string* block,
40  size_t block_size);
41 
42  Status DispatchTextStreamInfo();
43 
44  BlockReader reader_;
45  std::string language_;
46  bool keep_reading_ = true;
47 };
48 
49 } // namespace media
50 } // namespace shaka
51 
52 #endif // MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
All the methods that are virtual are virtual for mocking.