2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-06-09 15:30:16 +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_BASE_TEXT_SAMPLE_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_TEXT_SAMPLE_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
#include <optional>
|
2017-06-09 15:30:16 +00:00
|
|
|
#include <string>
|
2020-08-26 19:31:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-06-09 15:30:16 +00:00
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
|
2020-08-26 19:31:58 +00:00
|
|
|
enum class TextUnitType {
|
|
|
|
/// The units are absolute units in pixels.
|
|
|
|
kPixels,
|
|
|
|
/// The units are absolute units in number of lines.
|
|
|
|
kLines,
|
|
|
|
/// The units are relative to some size, in percent (i.e. 0-100).
|
|
|
|
kPercent,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class WritingDirection {
|
|
|
|
kHorizontal,
|
|
|
|
kVerticalGrowingLeft,
|
|
|
|
kVerticalGrowingRight,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class TextAlignment {
|
|
|
|
/// Align the text at the start, based on the Unicode text direction.
|
|
|
|
kStart,
|
|
|
|
/// Align the text in the center of the box.
|
|
|
|
kCenter,
|
|
|
|
/// Align the text at the end, based on the Unicode text direction.
|
|
|
|
kEnd,
|
|
|
|
/// Align the text at the left side (or top for non-horizontal).
|
|
|
|
kLeft,
|
|
|
|
/// Align the text at the right side (or bottom for non-horizontal).
|
|
|
|
kRight,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextNumber {
|
|
|
|
TextNumber(float value, TextUnitType type) : value(value), type(type) {}
|
|
|
|
|
|
|
|
float value;
|
|
|
|
TextUnitType type;
|
|
|
|
};
|
|
|
|
|
2020-08-24 22:23:15 +00:00
|
|
|
struct TextSettings {
|
2020-08-26 19:31:58 +00:00
|
|
|
/// The line offset of the cue. For horizontal cues, this is the vertical
|
|
|
|
/// offset. Percent units are relative to the window.
|
2022-11-04 22:46:41 +00:00
|
|
|
std::optional<TextNumber> line;
|
2020-08-26 19:31:58 +00:00
|
|
|
/// The position offset of the cue. For horizontal cues, this is the
|
|
|
|
/// horizontal offset. Percent units are relative to the window.
|
2022-11-04 22:46:41 +00:00
|
|
|
std::optional<TextNumber> position;
|
2020-12-01 19:32:39 +00:00
|
|
|
/// For horizontal cues, this is the width of the area to draw cues. For
|
|
|
|
/// vertical cues, this is the height. Percent units are relative to the
|
|
|
|
/// window.
|
2022-11-04 22:46:41 +00:00
|
|
|
std::optional<TextNumber> width;
|
2020-12-01 19:32:39 +00:00
|
|
|
/// For horizontal cues, this is the height of the area to draw cues. For
|
|
|
|
/// vertical cues, this is the width. Percent units are relative to the
|
|
|
|
/// window.
|
2022-11-04 22:46:41 +00:00
|
|
|
std::optional<TextNumber> height;
|
2020-08-26 19:31:58 +00:00
|
|
|
|
|
|
|
/// The region to draw the cue in.
|
|
|
|
std::string region;
|
|
|
|
|
|
|
|
/// The direction to draw text. This is also used to determine how cues are
|
|
|
|
/// positioned within the region.
|
|
|
|
WritingDirection writing_direction = WritingDirection::kHorizontal;
|
|
|
|
/// How to align the text within the cue box.
|
|
|
|
TextAlignment text_alignment = TextAlignment::kCenter;
|
2020-08-24 22:23:15 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 20:47:14 +00:00
|
|
|
struct TextFragmentStyle {
|
2022-11-04 22:46:41 +00:00
|
|
|
std::optional<bool> underline;
|
|
|
|
std::optional<bool> bold;
|
|
|
|
std::optional<bool> italic;
|
2020-08-26 20:47:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Represents a recursive structure of styled blocks of text. Only one of
|
2020-11-20 21:03:16 +00:00
|
|
|
/// sub_fragments, body, image, or newline will be set.
|
2020-08-24 22:23:15 +00:00
|
|
|
struct TextFragment {
|
2020-08-26 20:47:14 +00:00
|
|
|
TextFragment() {}
|
|
|
|
TextFragment(const TextFragmentStyle& style,
|
|
|
|
const std::vector<TextFragment>& sub_fragments)
|
|
|
|
: style(style), sub_fragments(sub_fragments) {}
|
|
|
|
TextFragment(const TextFragmentStyle& style, const char* body)
|
|
|
|
: style(style), body(body) {}
|
|
|
|
TextFragment(const TextFragmentStyle& style, const std::string& body)
|
|
|
|
: style(style), body(body) {}
|
2020-11-20 21:03:16 +00:00
|
|
|
TextFragment(const TextFragmentStyle& style,
|
|
|
|
const std::vector<uint8_t>& image)
|
|
|
|
: style(style), image(image) {}
|
2020-08-26 20:47:14 +00:00
|
|
|
TextFragment(const TextFragmentStyle& style, bool newline)
|
|
|
|
: style(style), newline(newline) {}
|
|
|
|
|
|
|
|
TextFragmentStyle style;
|
|
|
|
|
|
|
|
std::vector<TextFragment> sub_fragments;
|
2020-08-24 22:23:15 +00:00
|
|
|
std::string body;
|
2020-11-20 21:03:16 +00:00
|
|
|
/// PNG image data.
|
|
|
|
std::vector<uint8_t> image;
|
2020-08-26 20:47:14 +00:00
|
|
|
bool newline = false;
|
2020-08-24 22:23:15 +00:00
|
|
|
|
|
|
|
bool is_empty() const;
|
|
|
|
};
|
|
|
|
|
2017-06-09 15:30:16 +00:00
|
|
|
class TextSample {
|
|
|
|
public:
|
2020-08-24 22:23:15 +00:00
|
|
|
TextSample(const std::string& id,
|
|
|
|
int64_t start_time,
|
|
|
|
int64_t end_time,
|
|
|
|
const TextSettings& settings,
|
|
|
|
const TextFragment& body);
|
2017-06-09 15:30:16 +00:00
|
|
|
|
|
|
|
const std::string& id() const { return id_; }
|
2018-03-26 18:04:09 +00:00
|
|
|
int64_t start_time() const { return start_time_; }
|
|
|
|
int64_t duration() const { return duration_; }
|
2020-08-24 22:23:15 +00:00
|
|
|
const TextSettings& settings() const { return settings_; }
|
|
|
|
const TextFragment& body() const { return body_; }
|
2018-03-26 18:04:09 +00:00
|
|
|
int64_t EndTime() const;
|
2017-06-09 15:30:16 +00:00
|
|
|
|
2020-12-11 20:58:26 +00:00
|
|
|
int32_t sub_stream_index() const { return sub_stream_index_; }
|
|
|
|
void set_sub_stream_index(int32_t idx) { sub_stream_index_ = idx; }
|
|
|
|
|
2017-06-09 15:30:16 +00:00
|
|
|
private:
|
2017-05-22 16:35:49 +00:00
|
|
|
// Allow the compiler generated copy constructor and assignment operator
|
|
|
|
// intentionally. Since the text data is typically small, the performance
|
|
|
|
// impact is minimal.
|
2017-06-09 15:30:16 +00:00
|
|
|
|
2020-08-24 22:23:15 +00:00
|
|
|
const std::string id_;
|
|
|
|
const int64_t start_time_ = 0;
|
|
|
|
const int64_t duration_ = 0;
|
|
|
|
const TextSettings settings_;
|
|
|
|
const TextFragment body_;
|
2020-12-11 20:58:26 +00:00
|
|
|
int32_t sub_stream_index_ = -1;
|
2017-06-09 15:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_TEXT_SAMPLE_H_
|