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