Added TextSample

Added a text sample type that can be passed between media handlers.
This will allow text samples to safely be moved between media
handlers before converting to their final format.

Bug: 36138902
Change-Id: Ic4946f774a7d37c43066b9ea46596d5c5f3c05a8
This commit is contained in:
Aaron Vaage 2017-06-09 08:30:16 -07:00
parent d28b19788d
commit 2d2825290c
4 changed files with 95 additions and 0 deletions

View File

@ -84,6 +84,8 @@
'status.h',
'stream_info.cc',
'stream_info.h',
'text_sample.cc',
'text_sample.h',
'text_stream_info.cc',
'text_stream_info.h',
'text_track.h',

View File

@ -14,6 +14,7 @@
#include "packager/media/base/media_sample.h"
#include "packager/media/base/status.h"
#include "packager/media/base/stream_info.h"
#include "packager/media/base/text_sample.h"
namespace shaka {
namespace media {
@ -23,6 +24,7 @@ enum class StreamDataType {
kPeriodInfo,
kStreamInfo,
kMediaSample,
kTextSample,
kMediaEvent,
kSegmentInfo,
};
@ -49,6 +51,7 @@ struct StreamData {
std::shared_ptr<PeriodInfo> period_info;
std::shared_ptr<StreamInfo> stream_info;
std::shared_ptr<MediaSample> media_sample;
std::shared_ptr<TextSample> text_sample;
std::shared_ptr<MediaEvent> media_event;
std::shared_ptr<SegmentInfo> segment_info;
};
@ -140,6 +143,17 @@ class MediaHandler {
return Dispatch(std::move(stream_data));
}
/// Dispatch the text sample to downsream handlers.
// DispatchTextSample should only be override for testing.
Status DispatchTextSample(size_t stream_index,
std::shared_ptr<TextSample> text_sample) {
std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kTextSample;
stream_data->text_sample = std::move(text_sample);
return Dispatch(std::move(stream_data));
}
/// Dispatch the media event to downstream handlers.
Status DispatchMediaEvent(size_t stream_index,
std::shared_ptr<MediaEvent> media_event) {

View File

@ -0,0 +1,32 @@
// 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
#include "packager/media/base/text_sample.h"
#include "packager/base/logging.h"
namespace shaka {
namespace media {
uint64_t TextSample::EndTime() const {
return start_time_ + duration_;
}
void TextSample::SetTime(uint64_t start_time, uint64_t end_time) {
DCHECK_LT(start_time, end_time);
start_time_ = start_time;
duration_ = end_time - start_time;
}
void TextSample::AppendPayload(const std::string& payload) {
if (payload_.length()) {
payload_ += "\n";
}
payload_ += payload;
}
} // namespace media
} // namespace shaka

View File

@ -0,0 +1,47 @@
// 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
#ifndef PACKAGER_MEDIA_BASE_TEXT_SAMPLE_H_
#define PACKAGER_MEDIA_BASE_TEXT_SAMPLE_H_
#include <stdint.h>
#include <string>
namespace shaka {
namespace media {
class TextSample {
public:
TextSample() = default;
const std::string& id() const { return id_; }
uint64_t start_time() const { return start_time_; }
uint64_t duration() const { return duration_; }
const std::string& settings() const { return settings_; }
const std::string& payload() const { return payload_; }
uint64_t EndTime() const;
void set_id(const std::string& id) { id_ = id; }
void set_settings(const std::string& settings) { settings_ = settings; }
void SetTime(uint64_t start_time, uint64_t end_time);
void AppendPayload(const std::string& payload);
private:
TextSample(const TextSample&) = delete;
TextSample& operator=(const TextSample&) = delete;
std::string id_;
uint64_t start_time_ = 0;
uint64_t duration_ = 0;
std::string settings_;
std::string payload_;
};
} // namespace media
} // namespace shaka
#endif // MEDIA_BASE_TEXT_SAMPLE_H_