2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-09-14 16:15:24 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
|
|
|
|
|
2020-08-26 21:21:09 +00:00
|
|
|
#include <map>
|
2020-07-07 21:29:43 +00:00
|
|
|
#include <string>
|
2017-09-14 16:15:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/media/base/media_parser.h>
|
|
|
|
#include <packager/media/base/text_sample.h>
|
|
|
|
#include <packager/media/base/text_stream_info.h>
|
|
|
|
#include <packager/media/formats/webvtt/text_readers.h>
|
2017-09-14 16:15:24 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
// Used to parse a WebVTT source into Cues that will be sent downstream.
|
2020-07-07 21:29:43 +00:00
|
|
|
class WebVttParser : public MediaParser {
|
2017-09-14 16:15:24 +00:00
|
|
|
public:
|
2020-07-07 21:29:43 +00:00
|
|
|
WebVttParser();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
2020-07-07 21:29:43 +00:00
|
|
|
void Init(const InitCB& init_cb,
|
|
|
|
const NewMediaSampleCB& new_media_sample_cb,
|
|
|
|
const NewTextSampleCB& new_text_sample_cb,
|
|
|
|
KeySource* decryption_key_source) override;
|
|
|
|
bool Flush() override;
|
|
|
|
bool Parse(const uint8_t* buf, int size) override;
|
2017-09-14 16:15:24 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-07 21:29:43 +00:00
|
|
|
bool Parse();
|
|
|
|
bool ParseBlock(const std::vector<std::string>& block);
|
2020-08-26 21:21:09 +00:00
|
|
|
bool ParseRegion(const std::vector<std::string>& block);
|
2017-09-14 16:15:24 +00:00
|
|
|
bool ParseCueWithNoId(const std::vector<std::string>& block);
|
|
|
|
bool ParseCueWithId(const std::vector<std::string>& block);
|
2020-07-07 21:29:43 +00:00
|
|
|
bool ParseCue(const std::string& id,
|
|
|
|
const std::string* block,
|
|
|
|
size_t block_size);
|
2017-09-14 16:15:24 +00:00
|
|
|
|
2020-07-07 21:29:43 +00:00
|
|
|
void DispatchTextStreamInfo();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
2020-07-07 21:29:43 +00:00
|
|
|
InitCB init_cb_;
|
|
|
|
NewTextSampleCB new_text_sample_cb_;
|
2020-03-19 20:54:55 +00:00
|
|
|
|
2020-07-07 21:29:43 +00:00
|
|
|
BlockReader reader_;
|
2020-08-26 21:21:09 +00:00
|
|
|
std::map<std::string, TextRegion> regions_;
|
|
|
|
std::string css_styles_;
|
2020-07-07 21:29:43 +00:00
|
|
|
bool saw_cue_ = false;
|
2018-08-17 20:27:59 +00:00
|
|
|
bool stream_info_dispatched_ = false;
|
2020-07-07 21:29:43 +00:00
|
|
|
bool initialized_ = false;
|
2017-09-14 16:15:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_WEBVTT_WEBVTT_PARSER_H_
|