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;
for (const auto& cue_point : ad_cue_generator_params_.cue_points) {
std::shared_ptr<Scte35Event> scte35_event = std::make_shared<Scte35Event>();
scte35_event->start_time = cue_point.start_time_in_seconds * time_scale;
scte35_event->duration = cue_point.duration_in_seconds * time_scale;
scte35_event->start_time_in_seconds = cue_point.start_time_in_seconds;
scte35_event->duration_in_seconds = cue_point.duration_in_seconds;
status.Update(DispatchScte35Event(stream_index, std::move(scte35_event)));
if (!status.ok()) {
return status;

View File

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

View File

@ -16,10 +16,6 @@ namespace shaka {
namespace media {
namespace {
int64_t kThreadIdUnset = -1;
double TimeInSeconds(const Scte35Event& event, int64_t timescale) {
return static_cast<double>(event.start_time) / timescale;
}
} // namespace
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
// events that may be very close to each other.
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_|.
current_subsegment_index_ = 0;
new_segment = true;
@ -343,7 +339,7 @@ bool ChunkingHandler::Scte35EventTimestampGreater::operator()(
const std::shared_ptr<const Scte35Event>& rhs) const {
DCHECK(lhs);
DCHECK(rhs);
return lhs->start_time > rhs->start_time;
return lhs->start_time_in_seconds > rhs->start_time_in_seconds;
}
} // namespace media

View File

@ -282,9 +282,11 @@ TEST_F(ChunkingHandlerTest, Scte35Event) {
kStreamIndex0, GetVideoStreamInfo(kTimeScale1))));
const int64_t kVideoStartTimestamp = 12345;
const double kScte35TimeInSeconds =
static_cast<double>(kVideoStartTimestamp + kDuration1) / kTimeScale1;
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)));
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.
IsSegmentInfo(kStreamIndex0, kVideoStartTimestamp, kDuration1,
!kIsSubsegment, !kEncrypted),
IsCueEvent(
kStreamIndex0,
static_cast<double>(kVideoStartTimestamp + kDuration1) / 1000),
IsCueEvent(kStreamIndex0, kScte35TimeInSeconds),
IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 1,
kDuration1, !kEncrypted),
IsMediaSample(kStreamIndex0, kVideoStartTimestamp + kDuration1 * 2,