Shaka Packager SDK
webvtt_parser.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_FORMATS_WEBVTT_WEBVTT_PARSER_H_
8 #define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 #include <packager/media/base/media_parser.h>
15 #include <packager/media/base/text_sample.h>
16 #include <packager/media/base/text_stream_info.h>
17 #include <packager/media/formats/webvtt/text_readers.h>
18 
19 namespace shaka {
20 namespace media {
21 
22 // Used to parse a WebVTT source into Cues that will be sent downstream.
23 class WebVttParser : public MediaParser {
24  public:
25  WebVttParser();
26 
27  void Init(const InitCB& init_cb,
28  const NewMediaSampleCB& new_media_sample_cb,
29  const NewTextSampleCB& new_text_sample_cb,
30  KeySource* decryption_key_source) override;
31  bool Flush() override;
32  bool Parse(const uint8_t* buf, int size) override;
33 
34  private:
35  bool Parse();
36  bool ParseBlock(const std::vector<std::string>& block);
37  bool ParseRegion(const std::vector<std::string>& block);
38  bool ParseCueWithNoId(const std::vector<std::string>& block);
39  bool ParseCueWithId(const std::vector<std::string>& block);
40  bool ParseCue(const std::string& id,
41  const std::string* block,
42  size_t block_size);
43 
44  void DispatchTextStreamInfo();
45 
46  InitCB init_cb_;
47  NewTextSampleCB new_text_sample_cb_;
48 
49  BlockReader reader_;
50  std::map<std::string, TextRegion> regions_;
51  std::string css_styles_;
52  bool saw_cue_ = false;
53  bool stream_info_dispatched_ = false;
54  bool initialized_ = false;
55 };
56 
57 } // namespace media
58 } // namespace shaka
59 
60 #endif // MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:52
std::function< bool(uint32_t track_id, std::shared_ptr< MediaSample > media_sample)> NewMediaSampleCB
Definition: media_parser.h:45
std::function< bool(uint32_t track_id, std::shared_ptr< TextSample > text_sample)> NewTextSampleCB
Definition: media_parser.h:54
std::function< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:36
void Init(const InitCB &init_cb, const NewMediaSampleCB &new_media_sample_cb, const NewTextSampleCB &new_text_sample_cb, KeySource *decryption_key_source) override
bool Parse(const uint8_t *buf, int size) override
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66