20 #include <unordered_map> 32 std::string ShortContainerName(
const std::string& mime) {
37 DCHECK_LT(subtype.size(), 8u) <<
"Container needs a short name";
38 return subtype.substr(0, 8);
45 : mutex_(
"DemuxerThread"),
46 new_data_(
"New demuxed data"),
54 window_end_(HUGE_VAL),
55 need_key_frame_(true),
57 thread_(ShortContainerName(mime) +
" demuxer",
72 double window_end,
const uint8_t* data,
74 std::function<
void(
bool)> on_complete) {
76 DCHECK_GT(data_size, 0u);
78 std::unique_lock<Mutex> lock(mutex_);
80 data_size_ = data_size;
81 timestamp_offset_ = timestamp_offset;
82 window_start_ = window_start;
83 window_end_ = window_end;
84 on_complete_ = std::move(on_complete);
89 void DemuxerThread::ThreadMain() {
93 demuxer_ = factory->Create(mime_, client_);
98 std::unique_lock<Mutex> lock(mutex_);
99 if (!on_complete_ && !shutdown_) {
100 new_data_.ResetAndWaitWhileUnlocked(lock);
102 CallOnComplete(
false);
107 std::unique_lock<Mutex> lock(mutex_);
108 std::vector<std::shared_ptr<EncodedFrame>>
frames;
109 if (!demuxer_->Demux(timestamp_offset_, data_, data_size_, &frames)) {
110 CallOnComplete(
false);
114 for (
auto&
frame : frames) {
115 if (
frame->pts < window_start_ ||
117 need_key_frame_ =
true;
118 VLOG(2) <<
"Dropping frame outside append window, pts=" <<
frame->pts;
121 if (need_key_frame_) {
122 if (
frame->is_key_frame) {
123 need_key_frame_ =
false;
125 VLOG(2) <<
"Dropping frame while looking for key frame, pts=" 130 stream_->AddFrame(
frame);
132 CallOnComplete(
true);
133 new_data_.ResetAndWaitWhileUnlocked(lock);
137 void DemuxerThread::CallOnComplete(
bool success) {
142 std::bind(on_complete_, success));
143 on_complete_ = std::function<void(bool)>();
std::shared_ptr< shaka::media::DecodedFrame > frame
static JsManagerImpl * Instance()
std::shared_ptr< ThreadEvent< impl::RetOf< Func > > > AddInternalTask(TaskPriority priority, const std::string &name, Func &&callback)
std::list< std::shared_ptr< BaseFrame > > frames
TaskRunner * MainThread()