Commit 30ab1259 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: lock stream output queue

parent 2a59243d
...@@ -261,6 +261,8 @@ AbstractStreamOutput::AbstractStreamOutput(demux_t *demux) ...@@ -261,6 +261,8 @@ AbstractStreamOutput::AbstractStreamOutput(demux_t *demux)
if (!fakeesout) if (!fakeesout)
throw VLC_ENOMEM; throw VLC_ENOMEM;
vlc_mutex_init(&lock);
fakeesout->pf_add = esOutAdd; fakeesout->pf_add = esOutAdd;
fakeesout->pf_control = esOutControl; fakeesout->pf_control = esOutControl;
fakeesout->pf_del = esOutDel; fakeesout->pf_del = esOutDel;
...@@ -274,6 +276,13 @@ AbstractStreamOutput::~AbstractStreamOutput() ...@@ -274,6 +276,13 @@ AbstractStreamOutput::~AbstractStreamOutput()
if (demuxstream) if (demuxstream)
stream_Delete(demuxstream); stream_Delete(demuxstream);
delete fakeesout; delete fakeesout;
vlc_mutex_destroy(&lock);
/* shouldn't be any */
std::list<Demuxed *>::const_iterator it;
for(it=queues.begin(); it!=queues.end();++it)
delete *it;
} }
mtime_t AbstractStreamOutput::getPCR() const mtime_t AbstractStreamOutput::getPCR() const
...@@ -303,6 +312,7 @@ bool AbstractStreamOutput::seekAble() const ...@@ -303,6 +312,7 @@ bool AbstractStreamOutput::seekAble() const
void AbstractStreamOutput::setPosition(mtime_t nztime) void AbstractStreamOutput::setPosition(mtime_t nztime)
{ {
vlc_mutex_lock(&lock);
std::list<Demuxed *>::const_iterator it; std::list<Demuxed *>::const_iterator it;
for(it=queues.begin(); it!=queues.end();++it) for(it=queues.begin(); it!=queues.end();++it)
{ {
...@@ -311,12 +321,14 @@ void AbstractStreamOutput::setPosition(mtime_t nztime) ...@@ -311,12 +321,14 @@ void AbstractStreamOutput::setPosition(mtime_t nztime)
pair->drop(); pair->drop();
} }
pcr = VLC_TS_0; pcr = VLC_TS_0;
vlc_mutex_unlock(&lock);
es_out_Control(realdemux->out, ES_OUT_SET_NEXT_DISPLAY_TIME, es_out_Control(realdemux->out, ES_OUT_SET_NEXT_DISPLAY_TIME,
VLC_TS_0 + nztime); VLC_TS_0 + nztime);
} }
void AbstractStreamOutput::sendToDecoder(mtime_t nzdeadline) void AbstractStreamOutput::sendToDecoder(mtime_t nzdeadline)
{ {
vlc_mutex_lock(&lock);
std::list<Demuxed *>::const_iterator it; std::list<Demuxed *>::const_iterator it;
for(it=queues.begin(); it!=queues.end();++it) for(it=queues.begin(); it!=queues.end();++it)
{ {
...@@ -333,13 +345,7 @@ void AbstractStreamOutput::sendToDecoder(mtime_t nzdeadline) ...@@ -333,13 +345,7 @@ void AbstractStreamOutput::sendToDecoder(mtime_t nzdeadline)
realdemux->out->pf_send(realdemux->out, pair->es_id, p_block); realdemux->out->pf_send(realdemux->out, pair->es_id, p_block);
} }
} }
} vlc_mutex_unlock(&lock);
void AbstractStreamOutput::dropQueues()
{
std::list<Demuxed *>::const_iterator it;
for(it=queues.begin(); it!=queues.end();++it)
(*it)->drop();
} }
AbstractStreamOutput::Demuxed::Demuxed() AbstractStreamOutput::Demuxed::Demuxed()
...@@ -368,12 +374,14 @@ es_out_id_t * AbstractStreamOutput::esOutAdd(es_out_t *fakees, const es_format_t ...@@ -368,12 +374,14 @@ es_out_id_t * AbstractStreamOutput::esOutAdd(es_out_t *fakees, const es_format_t
es_out_id_t *p_es = me->realdemux->out->pf_add(me->realdemux->out, p_fmt); es_out_id_t *p_es = me->realdemux->out->pf_add(me->realdemux->out, p_fmt);
if(p_es) if(p_es)
{ {
vlc_mutex_lock(&me->lock);
Demuxed *pair = new (std::nothrow) Demuxed(); Demuxed *pair = new (std::nothrow) Demuxed();
if(pair) if(pair)
{ {
pair->es_id = p_es; pair->es_id = p_es;
me->queues.push_back(pair); me->queues.push_back(pair);
} }
vlc_mutex_unlock(&me->lock);
} }
return p_es; return p_es;
} }
...@@ -381,6 +389,7 @@ es_out_id_t * AbstractStreamOutput::esOutAdd(es_out_t *fakees, const es_format_t ...@@ -381,6 +389,7 @@ es_out_id_t * AbstractStreamOutput::esOutAdd(es_out_t *fakees, const es_format_t
int AbstractStreamOutput::esOutSend(es_out_t *fakees, es_out_id_t *p_es, block_t *p_block) int AbstractStreamOutput::esOutSend(es_out_t *fakees, es_out_id_t *p_es, block_t *p_block)
{ {
AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys; AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
vlc_mutex_lock(&me->lock);
std::list<Demuxed *>::const_iterator it; std::list<Demuxed *>::const_iterator it;
for(it=me->queues.begin(); it!=me->queues.end();++it) for(it=me->queues.begin(); it!=me->queues.end();++it)
{ {
...@@ -391,12 +400,14 @@ int AbstractStreamOutput::esOutSend(es_out_t *fakees, es_out_id_t *p_es, block_t ...@@ -391,12 +400,14 @@ int AbstractStreamOutput::esOutSend(es_out_t *fakees, es_out_id_t *p_es, block_t
break; break;
} }
} }
vlc_mutex_unlock(&me->lock);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void AbstractStreamOutput::esOutDel(es_out_t *fakees, es_out_id_t *p_es) void AbstractStreamOutput::esOutDel(es_out_t *fakees, es_out_id_t *p_es)
{ {
AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys; AbstractStreamOutput *me = (AbstractStreamOutput *) fakees->p_sys;
vlc_mutex_lock(&me->lock);
std::list<Demuxed *>::iterator it; std::list<Demuxed *>::iterator it;
for(it=me->queues.begin(); it!=me->queues.end();++it) for(it=me->queues.begin(); it!=me->queues.end();++it)
{ {
...@@ -408,6 +419,7 @@ void AbstractStreamOutput::esOutDel(es_out_t *fakees, es_out_id_t *p_es) ...@@ -408,6 +419,7 @@ void AbstractStreamOutput::esOutDel(es_out_t *fakees, es_out_id_t *p_es)
break; break;
} }
} }
vlc_mutex_unlock(&me->lock);
me->realdemux->out->pf_del(me->realdemux->out, p_es); me->realdemux->out->pf_del(me->realdemux->out, p_es);
} }
......
...@@ -97,7 +97,6 @@ namespace adaptative ...@@ -97,7 +97,6 @@ namespace adaptative
bool seekAble() const; bool seekAble() const;
void setPosition(mtime_t); void setPosition(mtime_t);
void sendToDecoder(mtime_t); void sendToDecoder(mtime_t);
void dropQueues();
protected: protected:
mtime_t pcr; mtime_t pcr;
...@@ -125,6 +124,7 @@ namespace adaptative ...@@ -125,6 +124,7 @@ namespace adaptative
block_t **pp_queue_last; block_t **pp_queue_last;
}; };
std::list<Demuxed *> queues; std::list<Demuxed *> queues;
vlc_mutex_t lock;
}; };
class MP4StreamOutput : public AbstractStreamOutput class MP4StreamOutput : public AbstractStreamOutput
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment