Re: [OpenSIPStack] Playing Data on a mediastream / synchronize data
Brought to you by:
joegenbaclor
From: Joegen E. B. <joe...@gm...> - 2008-05-17 03:57:05
|
Christian, I am not sure what you meant by "The only one problem is the syncing of the data...". I have implemented a similar class in the past to be used UA that needs to send file. See the implementation of the VoiceFileChannel class. It supports RAW input from preencoded G.723.1 and G.729 File. You can use this class as your reference and create a RAW G.711 handler. You may then attach it to the OpalMediaStream. HTH, Joegen Christian Wallukat wrote: > Hi Ilian, > > > I already modified it, so i only use the SIPEndPoint which is derived > >From OpalOSSEndPoint. > > I don’t wanna play files, I get a block of i.e. 2048 bytes of g.711 > Alaw data which I then need to send over the connection ... > > If the SIPEndPoint got the answer the RTP will be made and for each > Direction I get a Stream. If the Stream is opened the callback > > BOOL SoftPhoneManager::OnOpenMediaStream(OpalConnection & connection, > OpalMediaStream & stream) > > will be called. > > I store the streams inside another class and wait until both streams are > Active. If they are active I send the data (which comes from a file for > Test purpose) on the stream where IsSource() == false. > > I don’t know what to derive, since all functionality I need is already > There. The only one problem is the syncing of the data... > > > Attached you find the code I use for testing: > > > void someclass::StreamHandler(void) > { > //variables > /////////// > OpalMediaStream *pSourceStream = NULL; > OpalMediaStream *pDestStream = NULL; > BYTE *pData = NULL; > int nRead = 0; > HANDLE hFile = > CreateFile(_T("c:\\temp\\rec.cal\0"), FILE_WRITE_DATA, FILE_SHARE_READ, > NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); > HANDLE hFile2 = > CreateFile(_T("c:\\temp\\play.cal\0"), FILE_READ_DATA, FILE_SHARE_READ, > NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); > DWORD dwWrite = 0; > int nReadSize = 0; > bool bHasBuff = false; > int nBuff = 0; > PAdaptiveDelay paDelay; > CArray carray; > int nArrayPos = 0; > PTimeInterval delay; > RTP_DataFrame packet; > RTP_DataFrame inpacket; > RTP_DataFrame pcktout; > OpalMediaFormat src("G.711-ALaw-64k"); > OpalTranscoder *pTranscoderIn = NULL; > OpalTranscoder *pTranscoderOut = NULL; > > > > > //init play buffers > for(int n = 0; n < 10; ++n) > { > pData = new BYTE[this->m_nDataSize + 10]; > carray.SetAt(n, pData); > }; > > while(this->m_bAct == true) > { > if(this->m_nStreams > 0) > { > if((pDestStream == NULL) || (pSourceStream == NULL)) > { > //get the source stream > for(int n = 0; n < this->m_nStreams; ++n) > { > > if(((OpalMediaStream*)this->m_pStreams->GetAt(n))->IsSource() == TRUE) > { > pSourceStream = > (OpalMediaStream*)this->m_pStreams->GetAt(n); > > if(pTranscoderIn == NULL) > { > //create transcoder > for convert input > pTranscoderIn = > OpalTranscoder::Create(pSourceStream->GetMediaFormat(), src); > }; > } > else > { > pDestStream = > (OpalMediaStream*)this->m_pStreams->GetAt(n); > > if(pTranscoderOut == NULL) > { > //create transcoder > for convert output > pTranscoderOut = > OpalTranscoder::Create(src, pDestStream->GetMediaFormat()); > }; > }; > }; > }; > > //if the source stream is established > if(pSourceStream != NULL) > { > if(pSourceStream->ReadPacket(inpacket) == > TRUE) > { > /* > for(int n = 0; n < nRead; ++n) > { > pData[n] = > bitdreher[pData[n]]; > }; > > WriteFile(hFile, pData, nRead, > &dwWrite, NULL); > */ > > if(pDestStream != NULL) > { > nReadSize = > pSourceStream->GetDataSize(); > pData = > (BYTE*)carray.GetAt(nArrayPos++); > > if(nArrayPos >= 9) > { > nArrayPos = 0; > }; > > if((ReadFile(hFile2, pData, > nReadSize, &dwWrite, NULL) == TRUE) && (dwWrite > 0)) > { > for(int n = 0; n < > dwWrite; ++n) > { > pData[n] = > bitdreher[pData[n]]; > }; > > > packet.SetPayloadSize(dwWrite); > > packet.SetTimestamp(CalculateTimestamp(dwWrite, src)); > > packet.SetPayloadType(RTP_DataFrame::PCMA); > > memcpy(packet.GetPayloadPtr(), pData, dwWrite); > > if(pTranscoderOut != > NULL) > { > > pTranscoderOut->Convert(packet, pcktout); > > > pDestStream->WritePacket(pcktout);//(pData, dwWrite, nRead); > > } > else > { > > > ((PDelayChannel*)((OpalRawMediaStream*)pDestStream)->GetChannel())->Write(pD > ata, dwWrite); > }; > }; > }; > }; > }; > }; > > Sleep(10); > }; > > CloseHandle(hFile); > CloseHandle(hFile2); > > for(int n = 0; n < 10; ++n) > { > pData = (BYTE*)carray.GetAt(n); > delete pData; > }; > }; > > > > > -----Ursprüngliche Nachricht----- > Von: ope...@li... > [mailto:ope...@li...] Im Auftrag von > Ilian Jeri C. Pinzon > Gesendet: Donnerstag, 15. Mai 2008 12:21 > An: ope...@li... > Betreff: Re: [OpenSIPStack] Playing Data on a mediastream / synchronize data > > Hi, > > You mentioned earlier that you wanted to play to or record from a > source/target other than the PC's sound system? The Softphone is using > the PC sound system endpoint (i.e. OpalPCSSEndPoint) by default. But > since you mentioned that your target environment may not necessarily > have a mic or speaker, you will need to change that. > > If for example you need to play to or record from a file, you will need > to create classes like OpalFileEndPoint, OpalFileConnection, and > OpalFileMediaStream which are analogous to OpalPCSSEndPoint, > OpalPCSSConnection, and OpalAudioMediaStream. Just to refer to the said > classes and pattern your implementation to their interfaces. > > Then use your OpalFileEndPoint instance as as endpoint in SoftPhone. > > Christian Wallukat wrote: > >> Hi Ilian, >> >> >> Thanks for the response, but I don't understand where to override it ? >> >> I use the SoftPhone code to get it running and this is my last problem. >> The MediaStream was already created if this function >> >> BOOL SoftPhoneManager::OnOpenMediaStream(OpalConnection & connection, >> OpalMediaStream & stream) >> >> Is called. >> >> Do you mean, that I need to change it in OpalConnection or where should I >> > do > >> so ? >> >> >> Kind regards >> >> >> Christian >> >> -----Ursprüngliche Nachricht----- >> Von: ope...@li... >> [mailto:ope...@li...] Im Auftrag von >> Ilian Jeri C. Pinzon >> Gesendet: Donnerstag, 15. Mai 2008 05:51 >> An: ope...@li... >> Betreff: Re: [OpenSIPStack] Playing Data on a mediastream / synchronize >> > data > >> Hi, >> >> Christian Wallukat wrote: >> >> >>> Hi all, >>> >>> >>> I try to send G711 Alaw data on the destination media stream but it >>> Is snatchy if the delay between the packets doesn’t match... >>> >>> The delay of 20ms is not always right, how can I time the packets ? >>> >>> I use OpalMediaStream::WriteFrame() for sending the data ... >>> >>> >>> >> The OpalMediaPatch thread should do this for you automatically. You >> don't have to call WriteFrame(). What you just need to do is implement >> your derived OpalMediaStream interfaces properly (if they are not yet >> implemented that is). >> >> >>> Kind regards >>> >>> >>> Christian >>> >>> No virus found in this outgoing message. >>> Checked by AVG. >>> Version: 7.5.524 / Virus Database: 269.23.11/1422 - Release Date: >>> >>> >> 08.05.2008 >> >> >>> 17:24 >>> >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Microsoft >>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> _______________________________________________ >>> opensipstack-devel mailing list >>> ope...@li... >>> https://lists.sourceforge.net/lists/listinfo/opensipstack-devel >>> >>> ------------------------------------------------------------------------ >>> >>> No virus found in this incoming message. >>> Checked by AVG. >>> Version: 7.5.524 / Virus Database: 269.23.16/1431 - Release Date: >>> >>> >> 5/13/2008 7:55 PM >> >> >>> >>> >>> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> opensipstack-devel mailing list >> ope...@li... >> https://lists.sourceforge.net/lists/listinfo/opensipstack-devel >> >> No virus found in this incoming message. >> Checked by AVG. >> Version: 7.5.524 / Virus Database: 269.23.11/1422 - Release Date: >> > 08.05.2008 > >> 17:24 >> >> >> No virus found in this outgoing message. >> Checked by AVG. >> Version: 7.5.524 / Virus Database: 269.23.11/1422 - Release Date: >> > 08.05.2008 > >> 17:24 >> >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> opensipstack-devel mailing list >> ope...@li... >> https://lists.sourceforge.net/lists/listinfo/opensipstack-devel >> >> >> >> > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > opensipstack-devel mailing list > ope...@li... > https://lists.sourceforge.net/lists/listinfo/opensipstack-devel > > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.524 / Virus Database: 269.23.11/1422 - Release Date: 08.05.2008 > 17:24 > > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.524 / Virus Database: 269.23.16/1434 - Release Date: 15.05.2008 > 07:24 > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > opensipstack-devel mailing list > ope...@li... > https://lists.sourceforge.net/lists/listinfo/opensipstack-devel > > > |