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_TEXT_READERS_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBVTT_TEXT_READERS_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/media/base/byte_queue.h>
|
|
|
|
#include <packager/status.h>
|
2018-01-03 00:35:38 +00:00
|
|
|
|
2017-09-14 16:15:24 +00:00
|
|
|
namespace shaka {
|
2018-01-03 00:35:38 +00:00
|
|
|
class File;
|
|
|
|
|
2017-09-14 16:15:24 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class LineReader {
|
|
|
|
public:
|
2020-06-30 21:31:07 +00:00
|
|
|
LineReader();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
2020-06-30 21:31:07 +00:00
|
|
|
/// Pushes data onto the end of the buffer.
|
|
|
|
void PushData(const uint8_t* data, size_t data_size);
|
|
|
|
/// Reads the next line from the buffer.
|
|
|
|
/// @return True if a line is read, false if there's no line in the buffer.
|
2017-09-14 16:15:24 +00:00
|
|
|
bool Next(std::string* out);
|
2020-06-30 21:31:07 +00:00
|
|
|
/// Indicates that no more data is coming and that calls to Next should
|
|
|
|
/// return even possibly-incomplete data.
|
|
|
|
void Flush();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
LineReader(const LineReader&) = delete;
|
|
|
|
LineReader operator=(const LineReader&) = delete;
|
|
|
|
|
2020-06-30 21:31:07 +00:00
|
|
|
ByteQueue buffer_;
|
|
|
|
bool should_flush_;
|
2017-09-14 16:15:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BlockReader {
|
|
|
|
public:
|
2020-06-30 21:31:07 +00:00
|
|
|
BlockReader();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
2020-06-30 21:31:07 +00:00
|
|
|
/// Pushes data onto the end of the buffer.
|
|
|
|
void PushData(const uint8_t* data, size_t data_size);
|
|
|
|
/// Reads the next block from the buffer.
|
|
|
|
/// @return True if a block is read, false if there is no block in the buffer.
|
2017-09-14 16:15:24 +00:00
|
|
|
bool Next(std::vector<std::string>* out);
|
2020-06-30 21:31:07 +00:00
|
|
|
/// Indicates that no more data is coming and that calls to Next should
|
|
|
|
/// return even possibly-incomplete data.
|
|
|
|
void Flush();
|
2017-09-14 16:15:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BlockReader(const BlockReader&) = delete;
|
|
|
|
BlockReader operator=(const BlockReader&) = delete;
|
|
|
|
|
|
|
|
LineReader source_;
|
2020-06-30 21:31:07 +00:00
|
|
|
std::vector<std::string> temp_;
|
|
|
|
bool should_flush_;
|
2017-09-14 16:15:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_WEBVTT_TEXT_READERS_H_
|