[vlc-commits] demux: adaptive: change commands factory ownership

Francois Cartegnie git at videolan.org
Mon Apr 19 14:15:42 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Mar 18 17:34:21 2021 +0100| [5924cb42a5c71a2583b606ec4c49c4c9ddb5f2c4] | committer: Francois Cartegnie

demux: adaptive: change commands factory ownership

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5924cb42a5c71a2583b606ec4c49c4c9ddb5f2c4
---

 modules/demux/adaptive/Streams.cpp                 | 50 ++++++++++------------
 modules/demux/adaptive/plumbing/CommandsQueue.cpp  |  9 +---
 modules/demux/adaptive/plumbing/CommandsQueue.hpp  |  4 +-
 modules/demux/adaptive/plumbing/FakeESOut.cpp      | 26 +++++++----
 modules/demux/adaptive/plumbing/FakeESOut.hpp      |  5 ++-
 .../demux/adaptive/test/plumbing/CommandsQueue.cpp | 34 +++++++--------
 modules/demux/hls/HLSStreams.cpp                   |  2 +-
 7 files changed, 63 insertions(+), 67 deletions(-)

diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 0cc5afadc5..6628d67879 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -70,38 +70,32 @@ bool AbstractStream::init(const StreamFormat &format_, SegmentTracker *tracker,
     if(demuxersource)
     {
         CommandsFactory *factory = new (std::nothrow) CommandsFactory();
-        if(factory)
+        CommandsQueue *commandsqueue = new (std::nothrow) CommandsQueue();
+        if(factory && commandsqueue)
         {
-            CommandsQueue *commandsqueue = new (std::nothrow) CommandsQueue(factory);
-            if(commandsqueue)
+            fakeesout = new (std::nothrow) FakeESOut(p_realdemux->out,
+                                                     commandsqueue, factory);
+            if(fakeesout)
             {
-                fakeesout = new (std::nothrow) FakeESOut(p_realdemux->out, commandsqueue);
-                if(fakeesout)
-                {
-                    /* All successfull */
-                    fakeesout->setExtraInfoProvider( this );
-                    const Role & streamRole = tracker->getStreamRole();
-                    if(streamRole.isDefault() && streamRole.autoSelectable())
-                        fakeesout->setPriority(ES_PRIORITY_MIN + 10);
-                    else if(!streamRole.autoSelectable())
-                        fakeesout->setPriority(ES_PRIORITY_NOT_DEFAULTABLE);
-                    format = format_;
-                    segmentTracker = tracker;
-                    segmentTracker->registerListener(this);
-                    segmentTracker->notifyBufferingState(true);
-                    connManager = conn;
-                    fakeesout->setExpectedTimestamp(segmentTracker->getPlaybackTime());
-                    declaredCodecs();
-                    return true;
-                }
-                delete commandsqueue;
-                commandsqueue = nullptr;
-            }
-            else
-            {
-                delete factory;
+                /* All successfull */
+                fakeesout->setExtraInfoProvider( this );
+                const Role & streamRole = tracker->getStreamRole();
+                if(streamRole.isDefault() && streamRole.autoSelectable())
+                    fakeesout->setPriority(ES_PRIORITY_MIN + 10);
+                else if(!streamRole.autoSelectable())
+                    fakeesout->setPriority(ES_PRIORITY_NOT_DEFAULTABLE);
+                format = format_;
+                segmentTracker = tracker;
+                segmentTracker->registerListener(this);
+                segmentTracker->notifyBufferingState(true);
+                connManager = conn;
+                fakeesout->setExpectedTimestamp(segmentTracker->getPlaybackTime());
+                declaredCodecs();
+                return true;
             }
         }
+        delete factory;
+        delete commandsqueue;
         delete demuxersource;
     }
 
diff --git a/modules/demux/adaptive/plumbing/CommandsQueue.cpp b/modules/demux/adaptive/plumbing/CommandsQueue.cpp
index 28f61108c1..3f2ddd4677 100644
--- a/modules/demux/adaptive/plumbing/CommandsQueue.cpp
+++ b/modules/demux/adaptive/plumbing/CommandsQueue.cpp
@@ -239,21 +239,19 @@ std::ostream& operator<<(std::ostream& ostr, const std::list<AbstractCommand *>&
 }
 #endif
 
-CommandsQueue::CommandsQueue( CommandsFactory *f )
+CommandsQueue::CommandsQueue()
 {
     bufferinglevel = VLC_TICK_INVALID;
     pcr = VLC_TICK_INVALID;
     b_drop = false;
     b_draining = false;
     b_eof = false;
-    commandsFactory = f;
     nextsequence = 0;
 }
 
 CommandsQueue::~CommandsQueue()
 {
     Abort( false );
-    delete commandsFactory;
 }
 
 static bool compareCommands( const Queueentry &a, const Queueentry &b )
@@ -297,11 +295,6 @@ void CommandsQueue::Schedule( AbstractCommand *command )
     }
 }
 
-const CommandsFactory * CommandsQueue::factory() const
-{
-    return commandsFactory;
-}
-
 vlc_tick_t CommandsQueue::Process( vlc_tick_t barrier )
 {
     vlc_tick_t lastdts = barrier;
diff --git a/modules/demux/adaptive/plumbing/CommandsQueue.hpp b/modules/demux/adaptive/plumbing/CommandsQueue.hpp
index 96c8a46167..75ce359d58 100644
--- a/modules/demux/adaptive/plumbing/CommandsQueue.hpp
+++ b/modules/demux/adaptive/plumbing/CommandsQueue.hpp
@@ -154,9 +154,8 @@ namespace adaptive
     class CommandsQueue
     {
         public:
-            CommandsQueue( CommandsFactory * );
+            CommandsQueue();
             ~CommandsQueue();
-            const CommandsFactory * factory() const;
             void Schedule( AbstractCommand * );
             vlc_tick_t Process( vlc_tick_t );
             void Abort( bool b_reset );
@@ -173,7 +172,6 @@ namespace adaptive
             vlc_tick_t getPCR() const;
 
         private:
-            CommandsFactory *commandsFactory;
             void LockedCommit();
             void LockedSetDraining();
             std::list<Queueentry> incoming;
diff --git a/modules/demux/adaptive/plumbing/FakeESOut.cpp b/modules/demux/adaptive/plumbing/FakeESOut.cpp
index 841f81dc18..6ff849e222 100644
--- a/modules/demux/adaptive/plumbing/FakeESOut.cpp
+++ b/modules/demux/adaptive/plumbing/FakeESOut.cpp
@@ -135,11 +135,13 @@ FakeESOut * FakeESOut::LockedFakeEsOut::operator ->()
     return p;
 }
 
-FakeESOut::FakeESOut( es_out_t *es, CommandsQueue *queue )
+FakeESOut::FakeESOut( es_out_t *es, CommandsQueue *queue,
+                      CommandsFactory *cf )
     : AbstractFakeEsOut()
     , real_es_out( es )
     , extrainfo( nullptr )
     , commandsqueue( queue )
+    , commandsfactory( cf )
     , timestamps_offset( 0 )
 {
     associated.b_timestamp_set = false;
@@ -160,12 +162,18 @@ CommandsQueue * FakeESOut::commandsQueue()
     return commandsqueue;
 }
 
+CommandsFactory * FakeESOut::commandsFactory() const
+{
+    return commandsfactory;
+}
+
 FakeESOut::~FakeESOut()
 {
     recycleAll();
     gc();
 
     delete commandsqueue;
+    delete commandsfactory;
 }
 
 void FakeESOut::resetTimestamps()
@@ -327,7 +335,7 @@ size_t FakeESOut::esCount() const
 
 void FakeESOut::schedulePCRReset()
 {
-    AbstractCommand *command = commandsqueue->factory()->creatEsOutControlResetPCRCommand();
+    AbstractCommand *command = commandsfactory->creatEsOutControlResetPCRCommand();
     if( likely(command) )
         commandsqueue->Schedule( command );
 }
@@ -340,7 +348,7 @@ void FakeESOut::scheduleAllForDeletion()
         FakeESOutID *es_id = *it;
         if(!es_id->scheduledForDeletion())
         {
-            AbstractCommand *command = commandsqueue->factory()->createEsOutDelCommand( es_id );
+            AbstractCommand *command = commandsfactory->createEsOutDelCommand( es_id );
             if( likely(command) )
             {
                 commandsqueue->Schedule( command );
@@ -493,7 +501,7 @@ es_out_id_t * FakeESOut::esOutAdd(const es_format_t *p_fmt)
     if( likely(es_id) )
     {
         assert(!es_id->scheduledForDeletion());
-        AbstractCommand *command = commandsqueue->factory()->createEsOutAddCommand( es_id );
+        AbstractCommand *command = commandsfactory->createEsOutAddCommand( es_id );
         if( likely(command) )
         {
             fakeesidlist.push_back(es_id);
@@ -518,7 +526,7 @@ int FakeESOut::esOutSend(es_out_id_t *p_es, block_t *p_block)
     p_block->i_dts = fixTimestamp( p_block->i_dts );
     p_block->i_pts = fixTimestamp( p_block->i_pts );
 
-    AbstractCommand *command = commandsqueue->factory()->createEsOutSendCommand( es_id, p_block );
+    AbstractCommand *command = commandsfactory->createEsOutSendCommand( es_id, p_block );
     if( likely(command) )
     {
         commandsqueue->Schedule( command );
@@ -532,7 +540,7 @@ void FakeESOut::esOutDel(es_out_id_t *p_es)
     vlc_mutex_locker locker(&lock);
 
     FakeESOutID *es_id = reinterpret_cast<FakeESOutID *>( p_es );
-    AbstractCommand *command = commandsqueue->factory()->createEsOutDelCommand( es_id );
+    AbstractCommand *command = commandsfactory->createEsOutDelCommand( es_id );
     if( likely(command) )
     {
         es_id->setScheduledForDeletion();
@@ -556,7 +564,7 @@ int FakeESOut::esOutControl(int i_query, va_list args)
                 i_group = 0;
             vlc_tick_t  pcr = va_arg( args, vlc_tick_t );
             pcr = fixTimestamp( pcr );
-            AbstractCommand *command = commandsqueue->factory()->createEsOutControlPCRCommand( i_group, pcr );
+            AbstractCommand *command = commandsfactory->createEsOutControlPCRCommand( i_group, pcr );
             if( likely(command) )
             {
                 commandsqueue->Schedule( command );
@@ -569,7 +577,7 @@ int FakeESOut::esOutControl(int i_query, va_list args)
         {
             static_cast<void>(va_arg( args, int )); /* ignore group */
             const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );
-            AbstractCommand *command = commandsqueue->factory()->createEsOutMetaCommand( this,-1, p_meta );
+            AbstractCommand *command = commandsfactory->createEsOutMetaCommand( this,-1, p_meta );
             if( likely(command) )
             {
                 commandsqueue->Schedule( command );
@@ -600,7 +608,7 @@ void FakeESOut::esOutDestroy()
 {
     vlc_mutex_locker locker(&lock);
 
-    AbstractCommand *command = commandsqueue->factory()->createEsOutDestroyCommand();
+    AbstractCommand *command = commandsfactory->createEsOutDestroyCommand();
     if( likely(command) )
         commandsqueue->Schedule( command );
 }
diff --git a/modules/demux/adaptive/plumbing/FakeESOut.hpp b/modules/demux/adaptive/plumbing/FakeESOut.hpp
index d31d2c0fae..e173bfe9af 100644
--- a/modules/demux/adaptive/plumbing/FakeESOut.hpp
+++ b/modules/demux/adaptive/plumbing/FakeESOut.hpp
@@ -33,6 +33,7 @@ namespace adaptive
     };
 
     class CommandsQueue;
+    class CommandsFactory;
     class AbstractFakeESOutID;
     class FakeESOutID;
 
@@ -74,10 +75,11 @@ namespace adaptive
                     FakeESOut *p;
                     LockedFakeEsOut(FakeESOut &q);
             };
-            FakeESOut( es_out_t *, CommandsQueue * );
+            FakeESOut( es_out_t *, CommandsQueue *, CommandsFactory * );
             virtual ~FakeESOut();
             LockedFakeEsOut WithLock();
             CommandsQueue * commandsQueue();
+            CommandsFactory *commandsFactory() const;
             void setAssociatedTimestamp( vlc_tick_t );
             void setExpectedTimestamp( vlc_tick_t );
             void resetTimestamps();
@@ -115,6 +117,7 @@ namespace adaptive
             FakeESOutID * createNewID( const es_format_t * );
             ExtraFMTInfoInterface *extrainfo;
             CommandsQueue *commandsqueue;
+            CommandsFactory *commandsfactory;
             struct
             {
                 vlc_tick_t timestamp;
diff --git a/modules/demux/adaptive/test/plumbing/CommandsQueue.cpp b/modules/demux/adaptive/test/plumbing/CommandsQueue.cpp
index bba807e416..c70847b220 100644
--- a/modules/demux/adaptive/test/plumbing/CommandsQueue.cpp
+++ b/modules/demux/adaptive/test/plumbing/CommandsQueue.cpp
@@ -93,8 +93,8 @@ int CommandsQueue_test()
     TestEsOutID *id1 = nullptr;
     try
     {
-        CommandsFactory *factory = new CommandsFactory();
-        CommandsQueue queue(factory);
+        CommandsFactory factory;
+        CommandsQueue queue;
 
         id0 = new TestEsOutID(&esout);
         AbstractCommand *cmd = nullptr;
@@ -106,9 +106,9 @@ int CommandsQueue_test()
         Expect(queue.getBufferingLevel() == VLC_TICK_INVALID);
         Expect(queue.getFirstDTS() == VLC_TICK_INVALID);
         Expect(queue.getPCR() == VLC_TICK_INVALID);
-        cmd = queue.factory()->createEsOutAddCommand(id0);
+        cmd = factory.createEsOutAddCommand(id0);
         queue.Schedule(cmd);
-        cmd = queue.factory()->createEsOutDelCommand(id0);
+        cmd = factory.createEsOutDelCommand(id0);
         queue.Schedule(cmd);
         for(size_t i=0; i<3; i++) /* Add / Del will return in between */
             queue.Process(std::numeric_limits<vlc_tick_t>::max());
@@ -132,7 +132,7 @@ int CommandsQueue_test()
             block_t *data = block_Alloc(0);
             Expect(data);
             data->i_dts = VLC_TICK_0 + vlc_tick_from_sec(i);
-            cmd = queue.factory()->createEsOutSendCommand(id0, data);
+            cmd = factory.createEsOutSendCommand(id0, data);
             queue.Schedule(cmd);
         }
         Expect(queue.getPCR() == VLC_TICK_INVALID);
@@ -140,7 +140,7 @@ int CommandsQueue_test()
         Expect(queue.getDemuxedAmount(VLC_TICK_0) == 0);
         Expect(queue.getBufferingLevel() == VLC_TICK_INVALID);
         /* commit some */
-        cmd = queue.factory()->createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(8));
+        cmd = factory.createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(8));
         queue.Schedule(cmd);
         Expect(queue.getDemuxedAmount(VLC_TICK_0) == vlc_tick_from_sec(8)); /* PCR committed data up to 8s */
         Expect(queue.getBufferingLevel() == VLC_TICK_0 + vlc_tick_from_sec(8));
@@ -148,7 +148,7 @@ int CommandsQueue_test()
         Expect(queue.getDemuxedAmount(VLC_TICK_0 + vlc_tick_from_sec(7)) == vlc_tick_from_sec(1));
         Expect(queue.getPCR() == VLC_TICK_INVALID);
         /* extend through PCR */
-        cmd = queue.factory()->createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(10));
+        cmd = factory.createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(10));
         queue.Schedule(cmd);
         Expect(queue.getBufferingLevel() == VLC_TICK_0 + vlc_tick_from_sec(10));
         Expect(queue.getDemuxedAmount(VLC_TICK_0) == vlc_tick_from_sec(10));
@@ -167,10 +167,10 @@ int CommandsQueue_test()
             block_t *data = block_Alloc(0);
             Expect(data);
             data->i_dts = VLC_TICK_0 + vlc_tick_from_sec(11);
-            cmd = queue.factory()->createEsOutSendCommand(id0, data);
+            cmd = factory.createEsOutSendCommand(id0, data);
             queue.Schedule(cmd);
         } while(0);
-        cmd = queue.factory()->createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(11));
+        cmd = factory.createEsOutControlPCRCommand(0, VLC_TICK_0 + vlc_tick_from_sec(11));
         queue.Schedule(cmd);
         Expect(queue.getPCR() == VLC_TICK_0 + vlc_tick_from_sec(3)); /* should be unchanged */
         Expect(queue.getDemuxedAmount(VLC_TICK_0 + vlc_tick_from_sec(3)) == vlc_tick_from_sec(7));
@@ -196,12 +196,12 @@ int CommandsQueue_test()
                 block_t *data = block_Alloc(0);
                 Expect(data);
                 data->i_dts = VLC_TICK_0 + OFFSET + vlc_tick_from_sec(i);
-                cmd = queue.factory()->createEsOutSendCommand(id, data);
+                cmd = factory.createEsOutSendCommand(id, data);
                 queue.Schedule(cmd);
             }
         }
 
-        cmd = queue.factory()->createEsOutControlPCRCommand(0, VLC_TICK_0 + OFFSET + vlc_tick_from_sec(10));
+        cmd = factory.createEsOutControlPCRCommand(0, VLC_TICK_0 + OFFSET + vlc_tick_from_sec(10));
         queue.Schedule(cmd);
         Expect(esout.output.empty());
         queue.Process(VLC_TICK_0 + OFFSET - 1);
@@ -236,11 +236,11 @@ int CommandsQueue_test()
                     block_t *data = block_Alloc(0);
                     Expect(data);
                     data->i_dts = VLC_TICK_0 + OFFSET + vlc_tick_from_sec(k * 2 + i);
-                    cmd = queue.factory()->createEsOutSendCommand(id, data);
+                    cmd = factory.createEsOutSendCommand(id, data);
                     queue.Schedule(cmd);
                 }
             }
-            cmd = queue.factory()->createEsOutControlPCRCommand(0,
+            cmd = factory.createEsOutControlPCRCommand(0,
                     VLC_TICK_0 + OFFSET + vlc_tick_from_sec( (k*2)+1 ));
             queue.Schedule(cmd);
         }
@@ -271,11 +271,11 @@ int CommandsQueue_test()
                     Expect(data);
                     if(i==0)
                         data->i_dts = VLC_TICK_0 + OFFSET + vlc_tick_from_sec(k);
-                    cmd = queue.factory()->createEsOutSendCommand(id, data);
+                    cmd = factory.createEsOutSendCommand(id, data);
                     queue.Schedule(cmd);
                 }
             }
-            cmd = queue.factory()->createEsOutControlPCRCommand(0,
+            cmd = factory.createEsOutControlPCRCommand(0,
                     VLC_TICK_0 + OFFSET + vlc_tick_from_sec(k));
             queue.Schedule(cmd);
         }
@@ -303,12 +303,12 @@ int CommandsQueue_test()
         for(size_t i=0; i<2; i++)
         {
             const vlc_tick_t now = VLC_TICK_0 + OFFSET + vlc_tick_from_sec(i);
-            cmd = queue.factory()->createEsOutControlPCRCommand(0, now);
+            cmd = factory.createEsOutControlPCRCommand(0, now);
             queue.Schedule(cmd);
             block_t *data = block_Alloc(0);
             Expect(data);
             data->i_dts = now;
-            cmd = queue.factory()->createEsOutSendCommand(id0, data);
+            cmd = factory.createEsOutSendCommand(id0, data);
             queue.Schedule(cmd);
         }
         queue.Process(VLC_TICK_0 + OFFSET + vlc_tick_from_sec(0));
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index a612c98586..022c940e9c 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -116,7 +116,7 @@ block_t * HLSStream::checkBlock(block_t *p_block, bool b_first)
     if( b_meta_updated )
     {
         b_meta_updated = false;
-        AbstractCommand *command = fakeEsOut()->commandsQueue()->factory()->createEsOutMetaCommand( fakeesout, -1, p_meta );
+        AbstractCommand *command = fakeEsOut()->commandsFactory()->createEsOutMetaCommand( fakeesout, -1, p_meta );
         if( command )
             fakeEsOut()->commandsQueue()->Schedule( command );
     }



More information about the vlc-commits mailing list