Isolate OnScte35Event in ChunkerHandler
Change-Id: I9b34f959c22df498a338eb49c87b67003617ead2
This commit is contained in:
parent
71c589b5fb
commit
f125a4e91a
|
@ -42,14 +42,9 @@ Status ChunkingHandler::Process(std::unique_ptr<StreamData> stream_data) {
|
||||||
switch (stream_data->stream_data_type) {
|
switch (stream_data->stream_data_type) {
|
||||||
case StreamDataType::kStreamInfo:
|
case StreamDataType::kStreamInfo:
|
||||||
return OnStreamInfo(stream_data->stream_index, stream_data->stream_info);
|
return OnStreamInfo(stream_data->stream_index, stream_data->stream_info);
|
||||||
case StreamDataType::kScte35Event: {
|
case StreamDataType::kScte35Event:
|
||||||
if (stream_data->stream_index != main_stream_index_) {
|
return OnScte35Event(stream_data->stream_index,
|
||||||
VLOG(3) << "Dropping scte35 event from non main stream.";
|
stream_data->scte35_event);
|
||||||
return Status::OK;
|
|
||||||
}
|
|
||||||
scte35_events_.push(std::move(stream_data));
|
|
||||||
return Status::OK;
|
|
||||||
}
|
|
||||||
case StreamDataType::kSegmentInfo:
|
case StreamDataType::kSegmentInfo:
|
||||||
VLOG(3) << "Droppping existing segment info.";
|
VLOG(3) << "Droppping existing segment info.";
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
|
@ -165,6 +160,18 @@ Status ChunkingHandler::OnStreamInfo(uint64_t stream_index,
|
||||||
return DispatchStreamInfo(stream_index, std::move(info));
|
return DispatchStreamInfo(stream_index, std::move(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status ChunkingHandler::OnScte35Event(
|
||||||
|
uint64_t stream_index,
|
||||||
|
std::shared_ptr<const Scte35Event> event) {
|
||||||
|
if (stream_index == main_stream_index_) {
|
||||||
|
scte35_events_.push(std::move(event));
|
||||||
|
} else {
|
||||||
|
VLOG(3) << "Dropping scte35 event from non main stream.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) {
|
Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) {
|
||||||
const bool is_key_frame = sample->is_key_frame();
|
const bool is_key_frame = sample->is_key_frame();
|
||||||
const int64_t timestamp = sample->dts();
|
const int64_t timestamp = sample->dts();
|
||||||
|
@ -183,7 +190,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() &&
|
||||||
(scte35_events_.top()->scte35_event->start_time <= timestamp)) {
|
(scte35_events_.top()->start_time <= timestamp)) {
|
||||||
// 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;
|
||||||
|
@ -191,7 +198,7 @@ Status ChunkingHandler::ProcessMainMediaSample(const MediaSample* sample) {
|
||||||
cue_event = std::make_shared<CueEvent>();
|
cue_event = std::make_shared<CueEvent>();
|
||||||
// Use PTS instead of DTS for cue event timestamp.
|
// Use PTS instead of DTS for cue event timestamp.
|
||||||
cue_event->timestamp = sample->pts();
|
cue_event->timestamp = sample->pts();
|
||||||
cue_event->cue_data = scte35_events_.top()->scte35_event->cue_data;
|
cue_event->cue_data = scte35_events_.top()->cue_data;
|
||||||
LOG(INFO) << "Chunked at " << timestamp << " for Ad Cue.";
|
LOG(INFO) << "Chunked at " << timestamp << " for Ad Cue.";
|
||||||
|
|
||||||
scte35_events_.pop();
|
scte35_events_.pop();
|
||||||
|
@ -325,13 +332,11 @@ double ChunkingHandler::MediaSampleTimestampGreater::GetSampleTimeInSeconds(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChunkingHandler::Scte35EventTimestampGreater::operator()(
|
bool ChunkingHandler::Scte35EventTimestampGreater::operator()(
|
||||||
const std::unique_ptr<StreamData>& lhs,
|
const std::shared_ptr<const Scte35Event>& lhs,
|
||||||
const std::unique_ptr<StreamData>& rhs) const {
|
const std::shared_ptr<const Scte35Event>& rhs) const {
|
||||||
DCHECK(lhs);
|
DCHECK(lhs);
|
||||||
DCHECK(rhs);
|
DCHECK(rhs);
|
||||||
DCHECK(lhs->scte35_event);
|
return lhs->start_time > rhs->start_time;
|
||||||
DCHECK(rhs->scte35_event);
|
|
||||||
return lhs->scte35_event->start_time > rhs->scte35_event->start_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
|
|
|
@ -64,6 +64,8 @@ class ChunkingHandler : public MediaHandler {
|
||||||
|
|
||||||
Status OnStreamInfo(uint64_t stream_index,
|
Status OnStreamInfo(uint64_t stream_index,
|
||||||
std::shared_ptr<const StreamInfo> info);
|
std::shared_ptr<const StreamInfo> info);
|
||||||
|
Status OnScte35Event(uint64_t stream_index,
|
||||||
|
std::shared_ptr<const Scte35Event> event);
|
||||||
|
|
||||||
// Processes main media sample and apply chunking if needed.
|
// Processes main media sample and apply chunking if needed.
|
||||||
Status ProcessMainMediaSample(const MediaSample* sample);
|
Status ProcessMainMediaSample(const MediaSample* sample);
|
||||||
|
@ -126,14 +128,14 @@ class ChunkingHandler : public MediaHandler {
|
||||||
std::vector<int64_t> last_sample_end_timestamps_;
|
std::vector<int64_t> last_sample_end_timestamps_;
|
||||||
|
|
||||||
struct Scte35EventTimestampGreater {
|
struct Scte35EventTimestampGreater {
|
||||||
bool operator()(const std::unique_ptr<StreamData>& lhs,
|
bool operator()(const std::shared_ptr<const Scte35Event>& lhs,
|
||||||
const std::unique_ptr<StreamData>& rhs) const;
|
const std::shared_ptr<const Scte35Event>& rhs) const;
|
||||||
};
|
};
|
||||||
// Captures all incoming SCTE35 events to identify chunking points. Events
|
// Captures all incoming SCTE35 events to identify chunking points. Events
|
||||||
// will be removed from this queue one at a time as soon as the correct
|
// will be removed from this queue one at a time as soon as the correct
|
||||||
// chunking point is identified in the incoming samples.
|
// chunking point is identified in the incoming samples.
|
||||||
std::priority_queue<std::unique_ptr<StreamData>,
|
std::priority_queue<std::shared_ptr<const Scte35Event>,
|
||||||
std::vector<std::unique_ptr<StreamData>>,
|
std::vector<std::shared_ptr<const Scte35Event>>,
|
||||||
Scte35EventTimestampGreater>
|
Scte35EventTimestampGreater>
|
||||||
scte35_events_;
|
scte35_events_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue