live555 client多執行緒化
阿新 • • 發佈:2019-01-06
2014-03-11 22:18:54
為了讓live555 client線上程中使用,就必須讓env/task之類的獨立化。做法是把相關的內容放在一個class/struct內,必要的地方lock就好了。
一、大概
如下:
//global,live555庫的一些基本類 struct MYRTSPClient { TaskScheduler* pTaskScheduler; UsageEnvironment* pEnv; RTSPClient* pClient; MediaSession *pMediaSession; MediaSubsessionIterator *iter; Boolean bMadeProgress; unsigned fileSinkBufferSize; unsigned socketInputBufferSize; Boolean bStreamUsingTCP; Authenticator* pAuthenticator; char m_cEventLoop; ploginfo pLogInfo; MYRTSPClient() { pClient = NULL; pMediaSession = NULL; iter = NULL; bMadeProgress = False; fileSinkBufferSize = MAX_VGA_LEN; socketInputBufferSize = 524288; bStreamUsingTCP = False; pAuthenticator = NULL; m_cEventLoop = 0; pLogInfo = new loginfo(); } MYRTSPClient(RTSPClient *client) { pClient = client; pMediaSession = NULL; iter = NULL; bMadeProgress = False; fileSinkBufferSize = MAX_VGA_LEN; socketInputBufferSize = 524288; bStreamUsingTCP = False; pAuthenticator = NULL; m_cEventLoop = 0; pLogInfo = new loginfo(); } };
二、細節
live555中有太多的static func,初衷是為了方便客戶不必關心類就可以定製自己的需求。但在多執行緒環境中,就要考慮了,static func要麼可重入(幸運的是live555的static func都是可重入的),要麼在具有"類原子操作"的地方加鎖。
從重要的static func說起。
1、static void afterGetting(FramedSource* source)
class FramedSource: public MediaSource { static void afterGetting(FramedSource* source); // doGetNextFrame() should arrange for this to be called after the // frame has been read (*iff* it is read successfully) }
未完待續。。。