小弟刚学Brew不久,碰到如下问题,
首先在从网络接收到amr-nb数据流,实现边接收, 边解码, 边播放, 但是听到的声音断断续续..
如果把解完码之后的数据保存成大文件, 播放, 能正常听到声音, 网络速度正常!!!
所以定位到播放有问题, 不知如何解决........
望请高手指点...
播放的部分代码如下:
Step 1:
ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_MEDIAPCM, (void **)&pMe->m_pIMedia);
ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_SOURCEUTIL, (void**)&pMe->m_pISourceUtil);
ISOURCEUTIL_SourceFromMemory(
pMe->m_pISourceUtil,
pMe->pMediaBuffer, // 放从网络接收到的,解完码之后的raw PCM数据
pMe->dwMediaBufferSize, // 数据大小
NULL,
NULL,
&pMe->m_pISource
);
MEMSET(&pMe->spec, (int)0, sizeof(pMe->spec));
pMe->spec.wSize = sizeof(pMe->spec);
pMe->spec.clsMedia = AEECLSID_MEDIAPCM;
pMe->spec.wChannels = 1;
pMe->spec.dwSamplesPerSec = 8000;
pMe->spec.wBitsPerSample = 16;
pMe->spec.bUnsigned= FALSE;
// Set up AEEMediaDataEx
pMe->mde.clsData = MMD_ISOURCE;
pMe->mde.pData = (void *)pMe->m_pISource;
pMe->mde.dwSize = 0;
pMe->mde.dwStructSize = sizeof(pMe->mde);
pMe->mde.dwCaps = 0;
pMe->mde.bRaw = TRUE;
pMe->mde.dwBufferSize = 0;
pMe->mde.pSpec = &pMe->spec;
pMe->mde.dwSpecSize = sizeof(pMe->spec);
IMEDIA_SetMediaDataEx(pMe->m_pIMedia, &pMe->mde, 1);
IMEDIA_RegisterNotify(pMe->m_pIMedia, MediaNotifyCallback, pMe);
IMEDIA_Play(pMe->m_pIMedia);
STEP 2:
在回调函数MediaNotifyCallback的MM_STATUS_DONE状态中重新设置播放函数,
ISHELL_Resume(pMe->a.m_pIShell,&pMe->m_cbAudio);
其中pMe->m_cbAudio重新调用1
听到的声音断断续续....
请有经验的朋友帮帮忙, 提出解决方案, 列出部分示例代码,先在这里谢过了...
------解决方案--------------------------------------------------------
今天下午尝试用FIFO播放MP3文件,基本前几秒保持连续,使用方法:
ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FIFO, (void**)&pMe->m_pFIFO);
IFIFO_OpenEx(pMe->m_pFIFO, “fifo:/shared/foobar”, AEEFIFO_MODE_RW);//注意,在对应的文件系统中有:fs:/shared/foobar这个目录
IFIFO_SetBufSize(pMe->m_pFIFO, 2048*4);//这个buff可以适当开的大些
IFIFO_Write(pMe->m_pFIFO, (char *)pMe->pMediaBuffer, pMe->dwMediaBufferSize);
其他一样,只需要修改:
pMe->mde.pData = (void *)pMe->m_pFIFO;//pMe->m_pISource;
然后网络数据到来时,只需要调用IFIFO_Write(pMe->m_pFIFO, (char *)pMe->pMediaBuffer, pMe->dwMediaBufferSize);
在读写数据时间恰当的情况下,基本上能保证播放的连续性