2017-05-31 19:23:44 +00:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-08-24 22:23:15 +00:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
2017-05-31 19:23:44 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "packager/base/strings/string_piece.h"
|
2020-08-24 22:23:15 +00:00
|
|
|
#include "packager/media/base/text_sample.h"
|
2020-08-26 21:21:09 +00:00
|
|
|
#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 : ##:##:###
|
2021-08-04 18:56:44 +00:00
|
|
|
bool WebVttTimestampToMs(const base::StringPiece& 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_
|