对live555封装的比较好的一个类,网上找到的,觉得不错,给大家共享

来源:互联网 发布:怎样查看linux登录锁定 编辑:程序博客网 时间:2024/06/03 20:37

对live555封装的比较好的一个类,网上找到的,觉得不错,给大家共享,也不记得从哪里下载的了,版权归原作者!

 

这个类的主要特点是可以创建多个客户端,连接多路码流;我们可以参考他的设计,在sink中将码流回调出来,在外部解码;

 

文件如下:

[cpp] view plain copy
  1. #pragma once  
  2.   
  3. #include "BasicUsageEnvironment\BasicUsageEnvironment.hh"  
  4. #include "groupsock\GroupsockHelper.hh"  
  5. #include "liveMedia\liveMedia.hh"  
  6. #include <iostream>  
  7. #include <list>  
  8. #include <map>  
  9.   
  10. struct YHRTSPClient  
  11. {  
  12.     TaskScheduler* pTaskScheduler;  
  13.     UsageEnvironment* pEnv;  
  14.     RTSPClient* pClient;  
  15.     MediaSession *pMediaSession;  
  16.     MediaSubsessionIterator *iter;  
  17.     Boolean bMadeProgress;  
  18.     unsigned fileSinkBufferSize;  
  19.     unsigned socketInputBufferSize;  
  20.     Boolean  bStreamUsingTCP;  
  21.     Authenticator* pAuthenticator;  
  22.     char     m_cEventLoop;  
  23.     YHRTSPClient()  
  24.     {  
  25.         pClient = NULL;  
  26.         pMediaSession = NULL;  
  27.         iter = NULL;  
  28.         bMadeProgress = False;  
  29.         fileSinkBufferSize = 100000;  
  30.         socketInputBufferSize = 524288;  
  31.         bStreamUsingTCP = False;  
  32.         pAuthenticator = NULL;  
  33.         m_cEventLoop = 0;  
  34.   
  35.     }  
  36.     YHRTSPClient(RTSPClient *client)  
  37.     {  
  38.         pClient = client;  
  39.         pMediaSession = NULL;  
  40.         iter = NULL;  
  41.         bMadeProgress = False;  
  42.         fileSinkBufferSize = 100000;  
  43.         socketInputBufferSize = 524288;  
  44.         bStreamUsingTCP = False;  
  45.         pAuthenticator = NULL;  
  46.         m_cEventLoop = 0;  
  47.     }  
  48. };  
  49.   
  50. class CYHMediaClient  
  51. {  
  52. public:  
  53.     static CYHMediaClient* GetInstance();  
  54.     CYHMediaClient(void);  
  55.     ~CYHMediaClient(void);  
  56. public:  
  57.     BOOL CreateRTPClient(LONG lID, const char *chServerURL);  
  58.     //BOOL StartStreaming(char *chWatchVariable = NULL);  
  59.     void StopStreaming(int nClientID);  
  60.   
  61.     void GetSDPDescription(RTSPClient* pRTSPClient, RTSPClient::responseHandler* afterFunc);  
  62.     void SetupStreams(RTSPClient* pRTSPClient);  
  63.     void SetupSubsession(RTSPClient* pRTSPClient,MediaSubsession* subsession, Boolean streamUsingTCP, RTSPClient::responseHandler* afterFunc);  
  64.     void StartPlayingSession(RTSPClient* pRTSPClient,MediaSession* session, double start, double end, float scale, RTSPClient::responseHandler* afterFunc);  
  65.     void TearDownSession(RTSPClient* pRTSPClient,MediaSession* session, RTSPClient::responseHandler* afterFunc);  
  66.   
  67.     void SetFileSinkAndSocket(YHRTSPClient *pYHClient,unsigned fileSinkBufferSize,unsigned socketInputBufferSize);  
  68.     void SetStreamUsingTCP(YHRTSPClient* pYHClient, Boolean bStreamUsingTCP){pYHClient->bStreamUsingTCP = bStreamUsingTCP;};  
  69.   
  70.     UsageEnvironment *GetEnvironment(RTSPClient* pRTSPClient)  
  71.     {  
  72.         UsageEnvironment *pEnv = NULL;  
  73.         if (NULL == pRTSPClient)  
  74.         {  
  75.             return pEnv;  
  76.         }  
  77.         YHRTSPClient *pYHClient = GetYHRTSPClient(pRTSPClient);  
  78.         if (NULL != pYHClient)  
  79.         {  
  80.             pEnv = pYHClient->pEnv;  
  81.         }  
  82.           
  83.         return pEnv;  
  84.     };  
  85.   
  86. private:  
  87.     void GetOptions(RTSPClient* pRTSPClient, RTSPClient::responseHandler* afterFunc);  
  88.     void Shutdown(RTSPClient *pClient = NULL);  
  89.     YHRTSPClient* GetYHRTSPClient(RTSPClient *pClient);  
  90.     void EraseYHRTSPClient(RTSPClient *pClient);  
  91.     LONG GetRTSPClientID(RTSPClient* pClient);  
  92.     void CloseMediaSinks(RTSPClient *pClient);  
  93.           
  94.     static void ContinueAfterOptions(RTSPClient* pClient, int resultCode, char* resultString);  
  95.     static void ContinueAfterDescribe(RTSPClient* pClient, int resultCode, char* resultString);  
  96.     static void ContinueAfterSetup(RTSPClient* pClient, int resultCode, char* resultString);  
  97.     static void ContinueAfterPlay(RTSPClient* pClient, int resultCode, char* resultString);  
  98.     static void SubsessionAfterPlaying(void* clientData);  
  99.     static void SubsessionByeHandler(void* clientData);  
  100.     static void ContinueAfterTearDown(RTSPClient* pClient, int resultCode, char* resultString) ;  
  101.       
  102. public:  
  103.     std::list<YHRTSPClient*> m_listRTSPClient;  
  104.     std::map<int, RTSPClient*> m_mapClientID;  
  105. private:  
  106.     static CYHMediaClient* pYHMediaClient;  
  107.     //TaskScheduler* pTaskScheduler;  
  108.     //UsageEnvironment* pEnv;  
  109. };  
  110.   
  111.   
  112.   
  113. 源文件如下:  
[cpp] view plain copy
  1. <pre class="cpp" name="code">//#include "stdafx.h"  
  2. #include "YHMediaClient.h"  
  3. #include "WinCriticalSection.h"  
  4. #include "MetMediaSink.h"  
  5. //#include "YHWMPlayDemoDlg.h"  
  6. char const* clientProtocolName = "RTSP";  
  7. CYHMediaClient* CYHMediaClient::pYHMediaClient = NULL;  
  8. WinCriticalSection g_cs;  
  9.   
  10. CYHMediaClient* CYHMediaClient::GetInstance()  
  11. {  
  12.     Mutex mutex(g_cs);  
  13.     if (CYHMediaClient::pYHMediaClient == NULL)  
  14.     {  
  15.         pYHMediaClient = new CYHMediaClient;  
  16.     }  
  17.     return pYHMediaClient;  
  18. }  
  19.   
  20. CYHMediaClient::CYHMediaClient(void)  
  21. {  
  22.       
  23. }  
  24.   
  25. CYHMediaClient::~CYHMediaClient(void)  
  26. {  
  27.     m_listRTSPClient.empty();  
  28. }  
  29.   
  30. BOOL CYHMediaClient::CreateRTPClient(LONG lID, const char *chServerURL)  
  31. {  
  32.     g_cs.Enter();  
  33.     TaskScheduler *pTaskScheduler = BasicTaskScheduler::createNew();  
  34.     UsageEnvironment *pEnv = BasicUsageEnvironment::createNew(*pTaskScheduler);  
  35.     RTSPClient* pRTSPClient = (RTSPClient*)RTSPClient::createNew(*pEnv, chServerURL, 0, NULL, 0);  
  36.     if (NULL == pRTSPClient)  
  37.     {  
  38.         *pEnv << "Failed to create" << clientProtocolName << " client: " << pEnv->getResultMsg() << "\n";  
  39.         return FALSE;  
  40.     }  
  41.     m_mapClientID.insert(std::make_pair(lID, pRTSPClient));  
  42.     YHRTSPClient *stucClient = new YHRTSPClient(pRTSPClient);  
  43.     stucClient->pTaskScheduler = pTaskScheduler;  
  44.     stucClient->pEnv = pEnv;  
  45.     CYHMediaClient::GetInstance()->m_listRTSPClient.push_back(stucClient);  
  46.     GetOptions(pRTSPClient, ContinueAfterOptions);  
  47.     g_cs.Leave();  
  48.     stucClient->pEnv->taskScheduler().doEventLoop(&stucClient->m_cEventLoop);  
  49.     if (pTaskScheduler)  
  50.     {  
  51.         delete pTaskScheduler;  
  52.         pTaskScheduler = NULL;  
  53.     }  
  54.     if(stucClient)  
  55.     {  
  56.         delete stucClient;  
  57.         stucClient = NULL;  
  58.     }  
  59.     return TRUE;  
  60. }  
  61.   
  62. void CYHMediaClient::StopStreaming(int nClientID)  
  63. {  
  64.     Mutex mutex(g_cs);  
  65.     std::map<int, RTSPClient*>::iterator iter = m_mapClientID.find(nClientID);  
  66.     if (iter != m_mapClientID.end())  
  67.     {  
  68.         RTSPClient* pRTSPClient = iter->second;  
  69.         Shutdown(pRTSPClient);  
  70.         EraseYHRTSPClient(pRTSPClient);  
  71.         m_mapClientID.erase(iter);        
  72.     }  
  73. }  
  74.   
  75. void CYHMediaClient::Shutdown(RTSPClient *pClient)  
  76. {  
  77.     YHRTSPClient* pYHRTSPClient = GetYHRTSPClient(pClient);  
  78.     if (pYHRTSPClient != NULL)  
  79.     {  
  80.         if (pYHRTSPClient->pMediaSession != NULL)   
  81.         {  
  82.             TearDownSession(pClient,pYHRTSPClient->pMediaSession, ContinueAfterTearDown);  
  83.         }   
  84.         else  
  85.         {  
  86.             ContinueAfterTearDown(NULL, 0, NULL);  
  87.         }         
  88.         CYHMediaClient::GetInstance()->CloseMediaSinks(pClient);  
  89.         if (pYHRTSPClient->pMediaSession)  
  90.         {  
  91.             Medium::close(pYHRTSPClient->pMediaSession);  
  92.             pYHRTSPClient->pMediaSession = NULL;  
  93.         }  
  94.         // Finally, shut down our client:  
  95.         if (pClient)  
  96.         {  
  97.             Medium::close(pClient);   
  98.             pClient = NULL;  
  99.         }  
  100.         pYHRTSPClient->m_cEventLoop = 1;  
  101.               
  102.     }  
  103.       
  104. }  
  105.   
  106. void CYHMediaClient::GetOptions(RTSPClient* pRTSPClient, RTSPClient::responseHandler* afterFunc)  
  107. {  
  108.     Mutex mutex(g_cs);  
  109.     if (pRTSPClient)  
  110.     {  
  111.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pRTSPClient);  
  112.         pRTSPClient->sendOptionsCommand(afterFunc, pYHClient->pAuthenticator);  
  113.     }     
  114. }  
  115.   
  116. void CYHMediaClient::GetSDPDescription(RTSPClient* pRTSPClient,RTSPClient::responseHandler* afterFunc)  
  117. {  
  118.     Mutex mutex(g_cs);  
  119.     if (pRTSPClient)  
  120.     {  
  121.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pRTSPClient);  
  122.         pRTSPClient->sendDescribeCommand(afterFunc, pYHClient->pAuthenticator);  
  123.     }  
  124. }  
  125.   
  126. void CYHMediaClient::SetupSubsession(RTSPClient* pRTSPClient,MediaSubsession* subsession, Boolean streamUsingTCP, RTSPClient::responseHandler* afterFunc)  
  127. {  
  128.     Mutex mutex(g_cs);  
  129.     Boolean forceMulticastOnUnspecified = False;  
  130.     if (pRTSPClient)  
  131.     {  
  132.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pRTSPClient);  
  133.         pRTSPClient->sendSetupCommand(*subsession, afterFunc, False, streamUsingTCP, forceMulticastOnUnspecified, pYHClient->pAuthenticator);  
  134.     }  
  135. }  
  136.   
  137. void CYHMediaClient::StartPlayingSession(RTSPClient* pRTSPClient,MediaSession* session, double start, double end, float scale, RTSPClient::responseHandler* afterFunc)   
  138. {  
  139.     //Mutex mutex(g_cs);  
  140.     if (pRTSPClient)  
  141.     {  
  142.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pRTSPClient);  
  143.         pRTSPClient->sendPlayCommand(*session, afterFunc, start, end, scale, pYHClient->pAuthenticator);  
  144.     }  
  145. }  
  146.   
  147. void CYHMediaClient::TearDownSession(RTSPClient* pRTSPClient,MediaSession* session, RTSPClient::responseHandler* afterFunc)  
  148. {  
  149.     Mutex mutex(g_cs);  
  150.     if (pRTSPClient)  
  151.     {  
  152.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pRTSPClient);  
  153.         pRTSPClient->sendTeardownCommand(*session, afterFunc, pYHClient->pAuthenticator);  
  154.     }  
  155. }  
  156.   
  157. void CYHMediaClient::ContinueAfterOptions(RTSPClient* pClient, int resultCode, char* resultString)  
  158. {  
  159.     Mutex mutex(g_cs);  
  160.     if(CYHMediaClient::GetInstance() != NULL)  
  161.     {  
  162.         if (resultCode != 0)  
  163.         {  
  164.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << clientProtocolName << " \"OPTIONS\" request failed: " << resultString << "\n";  
  165.             return;  
  166.         }  
  167.         else  
  168.         {  
  169.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << clientProtocolName << " \"OPTIONS\" request returned: " << resultString << "\n";  
  170.         }  
  171.         delete[] resultString;  
  172.   
  173.         CYHMediaClient::GetInstance()->GetSDPDescription(pClient, ContinueAfterDescribe);  
  174.     }     
  175.     return;  
  176. }  
  177.   
  178. void CYHMediaClient::ContinueAfterDescribe(RTSPClient* pClient, int resultCode, char* resultString)  
  179. {  
  180.     Mutex mutex(g_cs);  
  181.     if (CYHMediaClient::GetInstance() != NULL)  
  182.     {  
  183.         if (resultCode != 0)   
  184.         {  
  185.             CYHMediaClient::GetInstance()->Shutdown();  
  186.             return;  
  187.         }  
  188.   
  189.         char* sdpDescription = resultString;  
  190.         // Create a media session object from this SDP description:  
  191.         MediaSession *pMediaSession = MediaSession::createNew(*(CYHMediaClient::GetInstance()->GetEnvironment(pClient)), sdpDescription);  
  192.         delete[] sdpDescription;  
  193.   
  194.         if (pMediaSession == NULL)   
  195.         {  
  196.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "Failed to create a MediaSession object from the SDP description: " << CYHMediaClient::GetInstance()->GetEnvironment(pClient)->getResultMsg() << "\n";    
  197.             CYHMediaClient::GetInstance()->Shutdown(pClient);  
  198.             return;  
  199.         }   
  200.         else if (!pMediaSession->hasSubsessions())   
  201.         {  
  202.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "This session has no media subsessions (i.e., \"m=\" lines)\n";  
  203.             CYHMediaClient::GetInstance()->Shutdown(pClient);  
  204.             return;  
  205.         }  
  206.   
  207.         // Then, setup the "RTPSource"s for the session:  
  208.         MediaSubsessionIterator iter(*pMediaSession);  
  209.   
  210.         MediaSubsession *subsession;  
  211.         YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pClient);  
  212.         pYHClient->bMadeProgress = False;  
  213.         pYHClient->pMediaSession = pMediaSession;  
  214.   
  215.         while ((subsession = iter.next()) != NULL)  
  216.         {  
  217.             if (!subsession->initiate())   
  218.             {  
  219.                 *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "Unable to create receiver for \"" << subsession->mediumName()  
  220.                     << "/" << subsession->codecName()  
  221.                     << "\" subsession: " << CYHMediaClient::GetInstance()->GetEnvironment(pClient)->getResultMsg() << "\n";  
  222.             }   
  223.             else  
  224.             {  
  225.                 *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "Created receiver for \"" << subsession->mediumName()  
  226.                     << "/" << subsession->codecName()  
  227.                     << "\" subsession (client ports " << subsession->clientPortNum()  
  228.                     << "-" << subsession->clientPortNum()+1 << ")\n";  
  229.   
  230.                 pYHClient->bMadeProgress = True;  
  231.                 if (subsession->rtpSource() != NULL)  
  232.                 {  
  233.                     // Because we're saving the incoming data, rather than playing  
  234.                     // it in real time, allow an especially large time threshold  
  235.                     // (1 second) for reordering misordered incoming packets:  
  236.                     unsigned const thresh = 500000; // 0.5 second  
  237.                     subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);  
  238.   
  239.                     // Set the RTP source's OS socket buffer size as appropriate - either if we were explicitly asked (using -B),  
  240.                     // or if the desired FileSink buffer size happens to be larger than the current OS socket buffer size.  
  241.                     // (The latter case is a heuristic, on the assumption that if the user asked for a large FileSink buffer size,  
  242.                     // then the input data rate may be large enough to justify increasing the OS socket buffer size also.)  
  243.                     int socketNum = subsession->rtpSource()->RTPgs()->socketNum();  
  244.                     unsigned curBufferSize = getReceiveBufferSize(*CYHMediaClient::GetInstance()->GetEnvironment(pClient), socketNum);  
  245.                     if (pYHClient->socketInputBufferSize > 0 || pYHClient->fileSinkBufferSize > curBufferSize)  
  246.                     {  
  247.                         unsigned newBufferSize = pYHClient->socketInputBufferSize > 0 ? pYHClient->socketInputBufferSize : pYHClient->fileSinkBufferSize;  
  248.                         newBufferSize = setReceiveBufferTo(*CYHMediaClient::GetInstance()->GetEnvironment(pClient), socketNum, newBufferSize);  
  249.                     }  
  250.                 }  
  251.             }  
  252.         }  
  253.         if (!pYHClient->bMadeProgress)   
  254.         {  
  255.             CYHMediaClient::GetInstance()->Shutdown(pClient);  
  256.             return;  
  257.         }  
  258.   
  259.         // Perform additional 'setup' on each subsession, before playing them:  
  260.         CYHMediaClient::GetInstance()->SetupStreams(pClient);  
  261.     }  
  262. }  
  263.   
  264. void CYHMediaClient::SetupStreams(RTSPClient* pRTSPClient)  
  265. {  
  266.     Mutex mutex(g_cs);  
  267.     YHRTSPClient *struClient = GetYHRTSPClient(pRTSPClient);  
  268.     if (struClient->iter == NULL)   
  269.         struClient->iter = new MediaSubsessionIterator(*(struClient->pMediaSession));  
  270.     MediaSubsession *subsession = NULL;  
  271.     while ((subsession = struClient->iter->next()) != NULL)   
  272.     {  
  273.         // We have another subsession left to set up:  
  274.         if (subsession->clientPortNum() == 0)   
  275.             continue// port # was not set  
  276.         if (pRTSPClient != NULL)  
  277.         {  
  278.             SetupSubsession(pRTSPClient, subsession, /*struClient->bStreamUsingTCP*/True, ContinueAfterSetup);  
  279.         }  
  280.         return;  
  281.     }  
  282.   
  283.     // We're done setting up subsessions.  
  284.     if (!struClient->bMadeProgress)   
  285.     {  
  286.         Shutdown(pRTSPClient);  
  287.         return;  
  288.     }  
  289.   
  290.     // Create and start "FileSink"s for each subsession:  
  291.     struClient->bMadeProgress = False;  
  292.     MediaSubsessionIterator iter(*(struClient->pMediaSession));  
  293.     while ((subsession = iter.next()) != NULL)   
  294.     {  
  295.         if (subsession->readSource() == NULL)   
  296.             continue// was not initiated  
  297.   
  298.         // Create an output file for each desired stream:  
  299.         CMetMediaSink* pMediaSink;  
  300.         unsigned int requestedBufferSize = 524288;  
  301.         pMediaSink = CMetMediaSink::createNew(*struClient->pEnv, struClient->socketInputBufferSize);  
  302.         pMediaSink->SetMediaSession(struClient->pMediaSession);  
  303.         pMediaSink->SetPlayHandle(GetRTSPClientID(pRTSPClient));  
  304.         subsession->sink = pMediaSink;  
  305.         if (subsession->sink == NULL)   
  306.         {  
  307.             *struClient->pEnv << "Failed to create MediaSink for \"" << "MediaClient"<< "\": " << struClient->pEnv->getResultMsg() << "\n";  
  308.         }   
  309.         else   
  310.         {  
  311.             subsession->sink->startPlaying(*(subsession->readSource()),SubsessionAfterPlaying,subsession);  
  312.   
  313.             // Also set a handler to be called if a RTCP "BYE" arrives  
  314.             // for this subsession:  
  315.             if (subsession->rtcpInstance() != NULL)   
  316.             {  
  317.                 subsession->rtcpInstance()->setByeHandler(SubsessionByeHandler, subsession);  
  318.             }  
  319.             struClient->bMadeProgress = True;  
  320.         }  
  321.     }  
  322.     if (!struClient->bMadeProgress)   
  323.     {  
  324.         Shutdown(pRTSPClient);  
  325.         return;  
  326.     }  
  327.     double duration = 0;  
  328.     YHRTSPClient* pYHRTSPClient = GetYHRTSPClient(pRTSPClient);  
  329.     duration = pYHRTSPClient->pMediaSession->playEndTime();  
  330.     if (duration < 0)   
  331.         duration = 0.0;  
  332.   
  333.     double dwEnd = duration;  
  334.     StartPlayingSession(pRTSPClient,pYHRTSPClient->pMediaSession, 0, dwEnd, 1.0, ContinueAfterPlay);  
  335. }  
  336.   
  337. void CYHMediaClient::ContinueAfterSetup(RTSPClient* pClient, int resultCode, char* resultString)  
  338. {  
  339.     Mutex mutex(g_cs);  
  340.     if (pClient == NULL)  
  341.     {  
  342.         return;  
  343.     }  
  344.   
  345.     if (CYHMediaClient::GetInstance() != NULL)  
  346.     {  
  347.         if (resultCode == 0)   
  348.         {  
  349.             YHRTSPClient *pYHClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pClient);  
  350.             pYHClient->bMadeProgress = True;  
  351.         }   
  352.         // Set up the next subsession, if any:  
  353.         CYHMediaClient::GetInstance()->SetupStreams(pClient);  
  354.     }  
  355. }  
  356.   
  357. void CYHMediaClient::ContinueAfterPlay(RTSPClient* pClient, int resultCode, char* resultString)  
  358. {  
  359.     Mutex mutex(g_cs);  
  360.     if (CYHMediaClient::GetInstance() != NULL)  
  361.     {  
  362.         if (resultCode != 0)   
  363.         {  
  364.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "Failed to start playing session: " << resultString << "\n";  
  365.             CYHMediaClient::GetInstance()->Shutdown(pClient);  
  366.             return;  
  367.         }  
  368.         else   
  369.         {  
  370.             *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << "Started playing session\n";  
  371.         }  
  372.         char const* actionString ="Receiving streamed data...";  
  373.         *(CYHMediaClient::GetInstance()->GetEnvironment(pClient)) << actionString << "...\n";  
  374.     }  
  375. }  
  376.   
  377. void CYHMediaClient::SubsessionAfterPlaying(void* clientData)  
  378. {  
  379.     Mutex mutex(g_cs);  
  380.     MediaSubsession* subsession = (MediaSubsession*)clientData;  
  381.     Medium::close(subsession->sink);  
  382.     subsession->sink = NULL;  
  383. }  
  384.   
  385. void CYHMediaClient::SubsessionByeHandler(void* clientData)  
  386. {  
  387.     Mutex mutex(g_cs);  
  388.     MediaSubsession* subsession = (MediaSubsession*)clientData;  
  389.     if (subsession != NULL)  
  390.     {  
  391.         // Act now as if the subsession had closed:  
  392.         SubsessionAfterPlaying(subsession);  
  393.     }  
  394. }  
  395.   
  396. void CYHMediaClient::ContinueAfterTearDown(RTSPClient* pClient, int resultCode, char* resultString)   
  397. {  
  398.     /* 
  399.     Mutex mutex(g_cs); 
  400.         // Now that we've stopped any more incoming data from arriving, close our output files: 
  401.         if (CYHMediaClient::GetInstance()!= NULL) 
  402.         { 
  403.             CYHMediaClient::GetInstance()->CloseMediaSinks(pClient); 
  404.             YHRTSPClient *struClient = CYHMediaClient::GetInstance()->GetYHRTSPClient(pClient); 
  405.             if (struClient->pMediaSession) 
  406.             { 
  407.                 Medium::close(struClient->pMediaSession); 
  408.             } 
  409.             // Finally, shut down our client: 
  410.             if (struClient->pAuthenticator) 
  411.             { 
  412.                 delete struClient->pAuthenticator; 
  413.             }        
  414.             Medium::close(pClient); 
  415.             struClient->m_cEventLoop = 1; 
  416.         }*/  
  417.       
  418. }  
  419.   
  420. void CYHMediaClient::CloseMediaSinks(RTSPClient *pClient)  
  421. {  
  422.     YHRTSPClient* pYHRTSPClient = GetYHRTSPClient(pClient);  
  423.     if (pYHRTSPClient->pMediaSession == NULL)  
  424.         return;  
  425.     MediaSubsessionIterator iter(*pYHRTSPClient->pMediaSession);  
  426.     MediaSubsession* subsession;  
  427.     while ((subsession = iter.next()) != NULL)   
  428.     {  
  429.         Medium::close(subsession->sink);  
  430.         subsession->sink = NULL;  
  431.     }  
  432. }  
  433.   
  434. YHRTSPClient* CYHMediaClient::GetYHRTSPClient(RTSPClient *pClient)  
  435. {  
  436.     if (m_listRTSPClient.size() == 0)  
  437.     {  
  438.         return NULL;  
  439.     }  
  440.     std::list<YHRTSPClient*>::iterator iter;  
  441.     for (iter = m_listRTSPClient.begin(); iter != m_listRTSPClient.end(); ++iter)  
  442.     {  
  443.         if (pClient == (*iter)->pClient)  
  444.         {  
  445.             return *iter;  
  446.         }  
  447.         else  
  448.             continue;  
  449.     }  
  450.     return NULL;  
  451. }  
  452.   
  453. void CYHMediaClient::EraseYHRTSPClient(RTSPClient *pClient)  
  454. {  
  455.     if (m_listRTSPClient.size() == 0)  
  456.     {  
  457.         return ;  
  458.     }  
  459.     std::list<YHRTSPClient*>::iterator iter;  
  460.     for (iter = m_listRTSPClient.begin(); iter != m_listRTSPClient.end(); ++iter)  
  461.     {  
  462.         if (pClient == (*iter)->pClient)  
  463.         {  
  464.             break;  
  465.         }  
  466.         else  
  467.             continue;  
  468.     }  
  469.     m_listRTSPClient.erase(iter);  
  470. }  
  471. LONG CYHMediaClient::GetRTSPClientID(RTSPClient* pClient)  
  472. {  
  473.     std::map<int, RTSPClient*>::iterator iter = m_mapClientID.begin();  
  474.     int nClientID = -1;  
  475.     for (; iter != m_mapClientID.end(); ++iter)  
  476.     {  
  477.         if (pClient == iter->second)  
  478.         {  
  479.             nClientID = iter->first;  
  480.         }  
  481.     }  
  482.     return nClientID;  
  483. }  
  484.   
  485. void CYHMediaClient::SetFileSinkAndSocket(YHRTSPClient *pYHClient,unsigned fileSinkBufferSize,unsigned socketInputBufferSize)  
  486. {  
  487.     if (NULL == pYHClient)  
  488.     {  
  489.         return;  
  490.     }  
  491.     pYHClient->fileSinkBufferSize = fileSinkBufferSize;  
  492.     pYHClient->socketInputBufferSize = socketInputBufferSize;  
  493.   
  494.     return;  
  495. }  
阅读全文
0 0