<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Arial","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Arial","sans-serif"'> Hi Ross,<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Thanks a lot for your great support.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Demuxing a matroska file, I meet problem releasing the memory. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Because the medium table is not empty, the reclaim of UsageEnvironment doesnot delete it.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>I made investigations with valgrind running on the following code that extract the first stream from test.mkv:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>#include "liveMedia.hh"<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>#include "BasicUsageEnvironment.hh"<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>static char watchVariable = 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>static MatroskaFile* matroskaFile = NULL;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>static void onMatroskaFileCreation(MatroskaFile* newFile, void* /*clientData*/) <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>{<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> matroskaFile = newFile;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> watchVariable = 1;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>}<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>static void afterPlaying(void* clientData) <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>{<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> watchVariable = 1;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>}<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>int main(int argc, char** argv) <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>{<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> TaskScheduler* scheduler = BasicTaskScheduler::createNew();<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // Open a Matroska file:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> char const* inputFileName = "test.mkv";<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> MatroskaFile::createNew(*env, inputFileName, onMatroskaFileCreation, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> env->taskScheduler().doEventLoop(&watchVariable);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // Create a demultiplexor from the file:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> MatroskaDemux* demux = matroskaFile->newDemux();<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // And start copying each track:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> unsigned trackNumber = 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> FramedSource* source = demux->newDemuxedTrack(trackNumber); <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> MediaSink* sink = FileSink::createNew(*env, "track", 300000, False);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> sink->startPlaying(*source,afterPlaying,NULL); <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // Print medium names<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> fprintf(stderr, "Medium name MkvFile:%s Demux:%s Source:%s Sink:%s\n", matroskaFile->name(), demux->name(), source->name(), sink->name());<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> watchVariable = 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> env->taskScheduler().doEventLoop(&watchVariable);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // Clean up<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> Medium::close(source);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> Medium::close(sink);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>// Released in MatroskaDemux::removeTrack Medium::close(demux);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> Medium::close(matroskaFile);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // Check Media table<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> </span><span style='font-family:"Arial","sans-serif"'>_Tables* ourTables = _Tables::getOurTables(*env, false);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span style='font-family:"Arial","sans-serif"'> </span><span lang=EN-US style='font-family:"Arial","sans-serif"'>if (ourTables != NULL)<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> fprintf(stderr, "Private structure are not empty\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> HashTable::Iterator* iter = HashTable::Iterator::create(ourTables->mediaTable->getTable());<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> char const* key = NULL; <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> Medium * medium = NULL;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> while ((medium = (Medium*)(iter->next(key))) != NULL) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> fprintf(stderr, "Still registered %s\n", medium->name());<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> delete iter;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> } <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> else<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> fprintf(stderr, "_Tables are empties\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> env->reclaim(); <o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> delete scheduler;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> return 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>It appears that releasing the last source, MatroskaDemux object is deleted, but doesnot remove from the mediaTable, and when the program print demux name, it use memory that is no more allocated.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>I made a try modifying MatroskaDemux::removeTrack :<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>void MatroskaDemux::removeTrack(unsigned trackNumber) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> fDemuxedTracksTable->Remove((char const*)trackNumber);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> if (fDemuxedTracksTable->numEntries() == 0) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> // We no longer have any demuxed tracks, so delete ourselves now:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>- delete this;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>+ Medium::close(this);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'> }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:35.4pt'><span lang=EN-US style='font-family:"Arial","sans-serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>With this modification, reclaim on UsageEnvironment delete it and valgrind do not report memory leakage or corruption.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Do you think it could be a way to solve my problem ?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Another way, I find more explicit, could be to not delete the demuxer and let the caller to close it, but this has an impact upgrading library used by legacy code.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>This will avoid to manage in a different way when there is no track parsed.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Best Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'> Michel.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif";mso-fareast-language:FR'>[@@ THALES GROUP INTERNAL @@]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></body></html>