构成nuplayer的过程,无非就是初始化一些状态,标志位,重要的是起了消息队列,也就是我们上篇写的AHandler消息机制:http://blog.csdn.net/tjy1985/article/details/8063484,我们也不多说了,直接进入setdataSource,先来个概图吧:
setDataSource分三步来走:
1:创建相应的消息
2:根据URL创建对应的source
3:onmessageReceive处理对应的消息
voidNuPlayer::setDataSource(
const char *url, constKeyedVector<String8, String8> *headers) {
(1)sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());----构建一个kWhatSetDataSource的消息
sp<Source> source;
if (IsHTTPLiveURL(url)) {
(2) source = newHTTPLiveSource(url, headers, mUIDValid, mUID);----创建的HTTPLiveSource
} else if (!strncasecmp(url,"rtsp://", 7)) {
source = newRTSPSource(url, headers, mUIDValid, mUID);-----创建RTSPSource实例
} else {
source = new GenericSource(url,headers, mUIDValid, mUID);
}
msg->setObject("source",source);
msg->post();-----post刚才构建的kWhatSetDataSource消息
}
voidNuPlayer::onMessageReceived(const sp<AMessage> &msg) {
switch (msg->what()) {
(3) case kWhatSetDataSource:------------处理kWhatSetDataSource消息
{
ALOGV("kWhatSetDataSource");
CHECK(mSource == NULL);
sp<RefBase> obj;
CHECK(msg->findObject("source", &obj));
mSource = static_cast<Source*>(obj.get());
break;
}