2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-05-31 19:23:44 +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
|
|
|
|
|
2020-08-24 22:23:15 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_WEBVTT_UTILS_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBVTT_UTILS_H_
|
2017-05-31 19:23:44 +00:00
|
|
|
|
2023-10-11 08:49:50 +00:00
|
|
|
#include <cstdint>
|
2020-08-24 22:23:15 +00:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
2017-05-31 19:23:44 +00:00
|
|
|
#include <string>
|
2023-10-11 08:49:50 +00:00
|
|
|
#include <string_view>
|
2017-05-31 19:23:44 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/text_sample.h>
|
|
|
|
#include <packager/media/base/text_stream_info.h>
|
2017-05-31 19:23:44 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
2020-08-24 22:23:15 +00:00
|
|
|
|
2017-05-31 19:23:44 +00:00
|
|
|
// Parse a timestamp into milliseconds using the two patterns defined by WebVtt:
|
|
|
|
// LONG : ##:##:##.### (long can have 2 or more hour digits)
|
|
|
|
// SHORT : ##:##:###
|
2023-08-31 23:59:46 +00:00
|
|
|
bool WebVttTimestampToMs(const std::string_view& source, int64_t* out);
|
2017-08-17 18:09:34 +00:00
|
|
|
|
|
|
|
// Create a long form timestamp encoded as a string.
|
|
|
|
std::string MsToWebVttTimestamp(uint64_t ms);
|
2020-08-24 22:23:15 +00:00
|
|
|
|
|
|
|
/// Converts the given text settings to a WebVTT settings string.
|
|
|
|
std::string WebVttSettingsToString(const TextSettings& settings);
|
|
|
|
|
|
|
|
/// Converts the given TextFragment to a WebVTT cue body string.
|
|
|
|
std::string WebVttFragmentToString(const TextFragment& fragment);
|
|
|
|
|
2020-08-26 21:21:09 +00:00
|
|
|
/// Converts the common fields in the stream into WebVTT text. This pulls out
|
|
|
|
/// the REGION and STYLE blocks.
|
|
|
|
std::string WebVttGetPreamble(const TextStreamInfo& stream_info);
|
|
|
|
|
2017-05-31 19:23:44 +00:00
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|
|
|
|
|
2020-08-24 22:23:15 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_WEBVTT_UTILS_H_
|