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)
}
未完待续。。。