1 #include "packager/media/formats/webvtt/cue.h"
3 #include "packager/base/strings/string_util.h"
8 Cue::Cue() : start_time(0), duration(0) {}
15 std::shared_ptr<MediaSample> CueToMediaSample(
const Cue& cue) {
16 const bool kKeyFrame =
true;
17 if (!cue.comment.empty()) {
18 const std::string comment = base::JoinString(cue.comment,
"\n");
20 reinterpret_cast<const uint8_t*>(comment.data()), comment.size());
23 const std::string payload = base::JoinString(cue.payload,
"\n");
25 reinterpret_cast<const uint8_t*>(payload.data()), payload.size(),
26 reinterpret_cast<const uint8_t*
>(cue.settings.data()),
27 cue.settings.size(), !kKeyFrame);
29 media_sample->set_config_id(cue.identifier);
30 media_sample->set_pts(cue.start_time);
31 media_sample->set_duration(cue.duration);
38 Cue MediaSampleToCue(
const MediaSample& sample) {
40 if (sample.data_size() == 0) {
41 std::string comment(sample.side_data(),
42 sample.side_data() + sample.side_data_size());
43 cue.comment.push_back(comment);
47 std::string payload(sample.data(), sample.data() + sample.data_size());
48 cue.payload.push_back(payload);
49 cue.identifier.assign(sample.config_id());
50 cue.start_time = sample.pts();
51 cue.duration = sample.duration();
52 if (sample.side_data_size() != 0) {
53 cue.settings.assign(sample.side_data(),
54 sample.side_data() + sample.side_data_size());