[Live-devel] Struggling with a stange behavior
chieppa at elmaxsrl.it
chieppa at elmaxsrl.it
Fri Nov 21 05:26:00 PST 2014
Dear All,
I'm using Live555 to realize a C++ RTPS client for IP cameras. I'm using most of the testRTSPClient code.I used Poco library and Poco::Thread class too.In other words any client for each camera runs in a separate thread that owns his instance of Live555 objects (any thread uses an instance with his UsageEnvironment and TaskScheduler).. This to avoid shared variables and synchronization stuff. It seems to works well and fast.My runnable (following the Poco library requirements) object IPCamera has the run method as simple as:void IPCamera::run()
{
openURL(_myEnv, "", _myRtspCommand.c_str(), *this); //taken from the testRTSPClient example
_myEnv->TaskScheduler().doEventLoop(&_watchEventLoopVariable);
//it runs until _watchEventLoopVariable change to a value != 0
//exit from the run;
}When the run is finished I call also the join() to close the thread (by the way I find out that if I don't call myThread->join() the memory is not freed totaly).When I make the shutdown, following the requirments in Live555-devel I put in my code: void IPCamera::shutdown()
{
...
_myEnv->reclaim();
delete _myScheduler;
}Using Valgrind to detect memory leaks I saw a strange behaviour:1) case: Run the program - Close the program with all the IPCameras that run in the proper manner.a) At the end of the program all the distrucotors are invoked.b) exit from doEvenLoop().c) join the thread (actually is terminated because it exits from run method.d) destroy the _myEnv and _myScheduler as showed.e) destroy all the others objects, including IPCamera and Thread associated.-> no memory leaks are found by Valgrind. OkNow comes the problem.2) case: I'm implementing a use case where a Poco::Timer checks every X seconds if the camera is alive using ICMP ping. It raises an event (using Poco events) in case it doesn't answer because the network is down and I do the follow:IPCamera down or network down :a) put the _watchEventLoopVariable = 1 to exit from the run method;b) shutdown the client associated to the IPCamera as showedc) join the threadAt this point I don't destroy the thread because I would like to reuse it when the network cames up again and the camera works again.in this case: a)I set the _eventWatchVariable = 0. b) Let start again the thread with: myThread->run()
Valgrind tells me that memory leaks (or something else that lost bytes) are found: 60 bytes direct, 20.000 indirect bytes are lost in the thread, in the H264BufferdPackedFactory::createNewPacket(...) by ReorederingPacketBuffer::getFreePacket() by SocketDescriptor::tcpReadHandler() by BasicTaskScheduler::singleStep().I'm going crazy. Why this behaviour in this case? Does someone solve this case? How to avoid this? 3 days of debugging and alternative solutions, but...nothing. If the nwtwork is always on, the memory is ok. If the network goes down, the memory leak is there. And the same logic is applied to my sw.Thank you.
Cristiano ChieppaElmax
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20141121/5eb71283/attachment-0001.html>
More information about the live-devel
mailing list