Change Scte35 to use double for time

Change-Id: I2588d3c86d48dc2d9f3692aa0aab28b9de63d109
This commit is contained in:
Aaron Vaage 2018-03-15 17:19:01 -07:00
parent 834ceffd18
commit 833b8165f1
4 changed files with 10 additions and 14 deletions

View File

@ -50,8 +50,8 @@ Status AdCueGenerator::DispatchScte35Events(size_t stream_index,
Status status; Status status;
for (const auto& cue_point : ad_cue_generator_params_.cue_points) { for (const auto& cue_point : ad_cue_generator_params_.cue_points) {
std::shared_ptr<Scte35Event> scte35_event = std::make_shared<Scte35Event>(); std::shared_ptr<Scte35Event> scte35_event = std::make_shared<Scte35Event>();
scte35_event->start_time = cue_point.start_time_in_seconds * time_scale; scte35_event->start_time_in_seconds = cue_point.start_time_in_seconds;
scte35_event->duration = cue_point.duration_in_seconds * time_scale; scte35_event->duration_in_seconds = cue_point.duration_in_seconds;
status.Update(DispatchScte35Event(stream_index, std::move(scte35_event))); status.Update(DispatchScte35Event(stream_index, std::move(scte35_event)));
if (!status.ok()) { if (!status.ok()) {
return status; return status;

View File

@ -35,8 +35,8 @@ struct Scte35Event {
std::string id; std::string id;
// Segmentation type id from SCTE35 segmentation descriptor. // Segmentation type id from SCTE35 segmentation descriptor.
int type = 0; int type = 0;
int64_t start_time = 0; double start_time_in_seconds = 0;
int64_t duration = 0; double duration_in_seconds = 0;
std::string cue_data; std::string cue_data;
}; };

View File

@ -16,10 +16,6 @@ namespace shaka {
namespace media { namespace media {
namespace { namespace {
int64_t kThreadIdUnset = -1; int64_t kThreadIdUnset = -1;
double TimeInSeconds(const Scte35Event& event, int64_t timescale) {
return static_cast<double>(event.start_time) / timescale;
}
} // namespace } // namespace
ChunkingHandler::ChunkingHandler(const ChunkingParams& chunking_params) ChunkingHandler::ChunkingHandler(const ChunkingParams& chunking_params)
@ -200,7 +196,7 @@ Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) {
// We use 'while' instead of 'if' to make sure to pop off multiple SCTE35 // We use 'while' instead of 'if' to make sure to pop off multiple SCTE35
// events that may be very close to each other. // events that may be very close to each other.
while (!scte35_events_.empty() && while (!scte35_events_.empty() &&
TimeInSeconds(*scte35_events_.top(), time_scale) <= dts_in_seconds) { scte35_events_.top()->start_time_in_seconds <= dts_in_seconds) {
// For simplicity, don't change |current_segment_index_|. // For simplicity, don't change |current_segment_index_|.
current_subsegment_index_ = 0; current_subsegment_index_ = 0;
new_segment = true; new_segment = true;
@ -343,7 +339,7 @@ bool ChunkingHandler::Scte35EventTimestampGreater::operator()(
const std::shared_ptr<const Scte35Event>& rhs) const { const std::shared_ptr<const Scte35Event>& rhs) const {
DCHECK(lhs); DCHECK(lhs);
DCHECK(rhs); DCHECK(rhs);
return lhs->start_time > rhs->start_time; return lhs->start_time_in_seconds > rhs->start_time_in_seconds;
} }
} // namespace media } // namespace media

View File

@ -282,9 +282,11 @@ TEST_F(ChunkingHandlerTest, Scte35Event) {
kStreamIndex0, GetVideoStreamInfo(kTimeScale1)))); kStreamIndex0, GetVideoStreamInfo(kTimeScale1))));
const int64_t kVideoStartTimestamp = 12345; const int64_t kVideoStartTimestamp = 12345;
const double kScte35TimeInSeconds =
static_cast<double>(kVideoStartTimestamp + kDuration1) / kTimeScale1;
auto scte35_event = std::make_shared<Scte35Event>(); auto scte35_event = std::make_shared<Scte35Event>();
scte35_event->start_time = kVideoStartTimestamp + kDuration1; scte35_event->start_time_in_seconds = kScte35TimeInSeconds;
ASSERT_OK(Process(StreamData::FromScte35Event(kStreamIndex0, scte35_event))); ASSERT_OK(Process(StreamData::FromScte35Event(kStreamIndex0, scte35_event)));
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
@ -303,9 +305,7 @@ TEST_F(ChunkingHandlerTest, Scte35Event) {
// A new segment is created due to the existance of Cue. // A new segment is created due to the existance of Cue.
IsSegmentInfo(kStreamIndex0, kVideoStartTimestamp, kDuration1, IsSegmentInfo(kStreamIndex0, kVideoStartTimestamp, kDuration1,
!kIsSubsegment, !kEncrypted), !kIsSubsegment, !kEncrypted),
IsCueEvent( IsCueEvent(kStreamIndex0, kScte35TimeInSeconds),
kStreamIndex0,
static_cast<double>(kVideoStartTimestamp + kDuration1) / 1000),
IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 1, IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 1,
kDuration1, !kEncrypted), kDuration1, !kEncrypted),
IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 2, IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 2,