[Live-devel] How to free memory in the function ByteStreamFileSource::doReadFromFile()

杜时 dushi310 at 163.com
Sun Nov 15 07:34:18 PST 2009


Hi,Ross
Thanks for your help.
I use live555 Server to stream H.264 live data which receive from the IP camera.
If there is no data from the IP camera, I want to close this ServerMediaSession. 
But this situation just occured in the function ByteStreamFileSource::doReadFromFile() as the follow code.

I have read some answer from the pipermail, you have said when fFrameSize ==0 invoke the
handleClosure(this) function can not free anything.
>"FramedSource::handleClosure" doesn't delete anything.  Instead, its 
>purpose is to tell the downstream object that the flow of data has ended.
>To actually reclaim a 'media' object (i.e., a subclass of "Medium"), call 
>"Medium::close()" on it.
Question:
   You said reclaim a 'media' object and call "Medium::close()" on it,
Does you mean use the following code
if(fFrameSize==0)
{
	Medium::close(this);
}
instead of
if(fFrame)
{
	handleClosure(this);
}



So I want to know what should I do when I want to close this ServerMediaSession.
especially, how to free the memory whick allocated before.

When the fFrameSize=0,I trace the code, I found that it will enter the following function
void StreamState::reclaim()
{
  // Delete allocated media objects
  Medium::close(fRTCPInstance) /* will send a RTCP BYE */; fRTCPInstance = NULL;
  Medium::close(fRTPSink); fRTPSink = NULL;
  Medium::close(fUDPSink); fUDPSink = NULL;
  fMaster.closeStreamSource(fMediaSource); fMediaSource = NULL;
  delete fRTPgs; fRTPgs = NULL;
  delete fRTCPgs; fRTCPgs = NULL;
}
It seems that It could free some memory which allocated before.But I can not sure all the memory allocated before are free .


Beacause my bad english, So I want to explain by code.
Thanks in advance.

void ByteStreamFileSource::doReadFromFile() 
{
  // Try to read as many bytes as will fit in the buffer provided
  // (or "fPreferredFrameSize" if less)
  DATAPACKETHEADER DataPacket;
  int port_i,ret;
  if (fPreferredFrameSize > 0 && fPreferredFrameSize < fMaxSize) 
  {
    fMaxSize = fPreferredFrameSize;
  }
  
  if (m_live_s==1234)
  {
	  port_i=m_h264_port_num;
  }

  if(port_i>=0&&port_i<MP4Sys_MAX_SUPPORTS&&m_live_s==1234)
  {
	if (g_Mp4PlayStream[port_i]->m_nPacketNum>0)
	{
		Get_Frame_Data[port_i]=0;
		GetPacket(port_i,&DataPacket,0,NULL);
	}
	else
	{
		while(g_Mp4PlayStream[port_i]->m_nPacketNum<=0)
		{
			Get_Frame_Data[port_i]++;
			if (Get_Frame_Data[port_i]>30)
			{
				fFrameSize=0;
				Get_Frame_Data[port_i]=0;
				printf("port=%d will goto clost the stream\n",port_i);
				goto Frame_End;
			}
		    usleep(33000);
		}
		GetPacket(port_i,&DataPacket,0,NULL);
		if((DataPacket.DataPacketStartCode)==0xc7010000)
		{
			memcpy(fTo,g_Mp4PlayStream[port_i]->m_DecodeSrc,DataPacket.nOverloadLen);
			fFrameSize=DataPacket.nOverloadLen;
		}
	}
  }

Frame_End:
  if (fFrameSize == 0) 
  {
////////////////////////////////////////////////////////////////////////////////
/////////////////here what should I do to free the memory whick allocated before
////////////////////////////////////////////////////////////////////////////////
    handleClosure(this);
    return;
  }
  // Set the 'presentation time':
  if (fPlayTimePerFrame > 0 && fPreferredFrameSize > 0) 
.............
}



--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20091115/0a0f7289/attachment-0001.html>


More information about the live-devel mailing list