IMediaplayer + socket + streaming | developer.brewmp.com IMediaplayer + socket + streaming | developer.brewmp.com

Developer

IMediaplayer + socket + streaming

Forums:

Hi All,
Is it a way to steam the data using socket and play the song parallely using ImediaPlayer. As I know we can collect the whole data as steam using socket and then play the same using IMEDIAPLAYER interface as follows.

md.clsData = MMD_BUFFER ;
md.pData = (void *)pMe->m_BodyBuffer;
md.dwSize = pMe->tempBodySize;

IMEDIA_SetMediaData(pMe->m_pMedia, &md);
result = IMEDIA_Play(pMe->m_pMedia);
In the above code, I have collected the whole song data into m_BodyBuffer and set it as stream for media instance. Now the requirement is we need to collect the data say pMe->m_BodyBuffer1,pMe->m_BodyBuffer2 .... pMe->m_BodyBufferN and play the streams one by one parallely...

Regards
V. Anand

You can do the following:
You can have a pool of buffer(say 2 or 3).
In your network download read data, as you have mentioned, call IMEDIA_RegisterNotify and then IMEDIA_SetMediaData.
In your callback function, call IMEDIA_Play and after successful play, call ISOURCE_Readable to read more data.
If you want to avoid choppiness of audio streaming, then you can implement buffer queue, whereby, your network code will download data as long as there is free buffer in the free buffer queue, if there is none it will not call readable interface.
Upon completion of your playback, you place the buffer in the free buffer queue, and notify your network code to call readable interface.
ruben

You can do the following:
You can have a pool of buffer(say 2 or 3).
In your network download read data, as you have mentioned, call IMEDIA_RegisterNotify and then IMEDIA_SetMediaData.
In your callback function, call IMEDIA_Play and after successful play, call ISOURCE_Readable to read more data.
If you want to avoid choppiness of audio streaming, then you can implement buffer queue, whereby, your network code will download data as long as there is free buffer in the free buffer queue, if there is none it will not call readable interface.
Upon completion of your playback, you place the buffer in the free buffer queue, and notify your network code to call readable interface.
ruben

Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.

Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.

/***************************************************/
If you want to avoid choppiness of audio streaming, then you can implement buffer queue, whereby, your network code will download data as long as there is free buffer in the free buffer queue, if there is none it will not call readable interface.
Upon completion of your playback, you place the buffer in the free buffer queue, and notify your network code to call readable interface
/***************************************************/
How are u notified that u are about to finish the play back so that u could set another buffer, while avoiding Chopping

/***************************************************/
If you want to avoid choppiness of audio streaming, then you can implement buffer queue, whereby, your network code will download data as long as there is free buffer in the free buffer queue, if there is none it will not call readable interface.
Upon completion of your playback, you place the buffer in the free buffer queue, and notify your network code to call readable interface
/***************************************************/
How are u notified that u are about to finish the play back so that u could set another buffer, while avoiding Chopping

kurquhar wrote:Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.
could u pls attach the pseudo code for that..? I tried some experiemnts with Sockets,but, its al failing.. One confusing point about Sockets is, when we open a socket, we dont specify the Port number.. but,during the connect, we need to specify the port number.. How do we get the port number.. I tried the fn "ISOCKET_GetSockName" , but it return 0xCCCCCCCC and 0xCCCC for the IP address and port number.. Its the same even after a "ISOCKET_Realize" call..
could some one pls attach a simple Socket example.. ie opening two sockets and sending some junk buffer from one Socket to another..
Using Socket in ISours.. oh..sound scary for me.. becos, both Sockets and Isourse remains as a mistory for me until now.... Any useful forum pages or external links..? :(
This is the Socket code I tried..
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEENet.h" // Socket interface definitions
#include "AEESound.h" // Sound Interface definitions
#include "AEEStdLib.h" // The Std library, for DBGPRINTF
#include "isocketapp.bid" // the BID file genrated from Quallcomm site
typedef struct _MYAPPDATA
{
AEEApplet m_applet;
IMedia* lpIMediaPlayer;
AEEMediaData mediaData;
IShell* lpShell;
INetMgr* lpInetMngr;
ISocket* lpSocketTx;
ISocket* lpSocketRx;
INAddr lMyIpAddr;
char cBuffer[100];
MYAPPDATA, *LPMYAPPDATA;
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_ISOCKETAPP){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)isocketapp_HandleEvent,NULL)
== TRUE)
{
InitApp((IApplet*)*ppObj);
return (AEE_SUCCESS);
}
}
return (EFAILED);

static boolean isocketapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
StartPlaying(pi);
return(TRUE);
case EVT_APP_STOP:
CloseApp(pi);
return TRUE;
default:
break;
}
return FALSE;

static int InitApp(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_MEDIAADPCM,(void**)&lpME->lpIMediaPlayer);
if (iRet != SUCCESS || lpME->lpIMediaPlayer == NULL)
return -1;
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_NET,(void**)&lpME->lpInetMngr);
if (iRet != SUCCESS || lpME->lpInetMngr == NULL)
return -1;
lpME->lpShell = lpME->m_applet.m_pIShell;
return 0;

static void StartPlaying(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
INAddr Addr;
INPort Port;
lpME->lpSocketTx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
lpME->lpSocketRx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
iRet = ISOCKET_Realize(lpME->lpSocketTx);
iRet = ISOCKET_Realize(lpME->lpSocketRx);
iRet = ISOCKET_GetSockName(lpME->lpSocketTx,&Addr,&Port);
iRet = ISOCKET_GetSockName(lpME->lpSocketRx,&Addr,&Port);
iRet = ISOCKET_Connect(lpME->lpSocketTx,AEE_INADDR_ANY,?????, CallBack,lpme);
iRet = ISOCKET_Write(lpME->lpSocketTx,(byte*)lpME->cBuffer,100);
lpME->lMyIpAddr = INETMGR_GetMyIPAddr(lpME->lpInetMngr);
}
static void CallBack(void *pconn, int nerror)
{
DBGPRINTF("****--Callback Fn, error : %d",nerror);

static void CloseApp(IApplet* lpme)
{
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
IMEDIA_Stop(lpME->lpIMediaPlayer);
IMEDIA_RegisterNotify(lpME->lpIMediaPlayer, NULL, NULL);
FREE(lpME->mediaData.pData);
INETMGR_Release(lpME->lpInetMngr);
}

kurquhar wrote:Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.
could u pls attach the pseudo code for that..? I tried some experiemnts with Sockets,but, its al failing.. One confusing point about Sockets is, when we open a socket, we dont specify the Port number.. but,during the connect, we need to specify the port number.. How do we get the port number.. I tried the fn "ISOCKET_GetSockName" , but it return 0xCCCCCCCC and 0xCCCC for the IP address and port number.. Its the same even after a "ISOCKET_Realize" call..
could some one pls attach a simple Socket example.. ie opening two sockets and sending some junk buffer from one Socket to another..
Using Socket in ISours.. oh..sound scary for me.. becos, both Sockets and Isourse remains as a mistory for me until now.... Any useful forum pages or external links..? :(
This is the Socket code I tried..
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEENet.h" // Socket interface definitions
#include "AEESound.h" // Sound Interface definitions
#include "AEEStdLib.h" // The Std library, for DBGPRINTF
#include "isocketapp.bid" // the BID file genrated from Quallcomm site
typedef struct _MYAPPDATA
{
AEEApplet m_applet;
IMedia* lpIMediaPlayer;
AEEMediaData mediaData;
IShell* lpShell;
INetMgr* lpInetMngr;
ISocket* lpSocketTx;
ISocket* lpSocketRx;
INAddr lMyIpAddr;
char cBuffer[100];
MYAPPDATA, *LPMYAPPDATA;
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_ISOCKETAPP){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)isocketapp_HandleEvent,NULL)
== TRUE)
{
InitApp((IApplet*)*ppObj);
return (AEE_SUCCESS);
}
}
return (EFAILED);

static boolean isocketapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
StartPlaying(pi);
return(TRUE);
case EVT_APP_STOP:
CloseApp(pi);
return TRUE;
default:
break;
}
return FALSE;

static int InitApp(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_MEDIAADPCM,(void**)&lpME->lpIMediaPlayer);
if (iRet != SUCCESS || lpME->lpIMediaPlayer == NULL)
return -1;
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_NET,(void**)&lpME->lpInetMngr);
if (iRet != SUCCESS || lpME->lpInetMngr == NULL)
return -1;
lpME->lpShell = lpME->m_applet.m_pIShell;
return 0;

static void StartPlaying(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
INAddr Addr;
INPort Port;
lpME->lpSocketTx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
lpME->lpSocketRx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
iRet = ISOCKET_Realize(lpME->lpSocketTx);
iRet = ISOCKET_Realize(lpME->lpSocketRx);
iRet = ISOCKET_GetSockName(lpME->lpSocketTx,&Addr,&Port);
iRet = ISOCKET_GetSockName(lpME->lpSocketRx,&Addr,&Port);
iRet = ISOCKET_Connect(lpME->lpSocketTx,AEE_INADDR_ANY,?????, CallBack,lpme);
iRet = ISOCKET_Write(lpME->lpSocketTx,(byte*)lpME->cBuffer,100);
lpME->lMyIpAddr = INETMGR_GetMyIPAddr(lpME->lpInetMngr);
}
static void CallBack(void *pconn, int nerror)
{
DBGPRINTF("****--Callback Fn, error : %d",nerror);

static void CloseApp(IApplet* lpme)
{
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
IMEDIA_Stop(lpME->lpIMediaPlayer);
IMEDIA_RegisterNotify(lpME->lpIMediaPlayer, NULL, NULL);
FREE(lpME->mediaData.pData);
INETMGR_Release(lpME->lpInetMngr);
}

Quote:Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.
Are we talking about SDK 2.0 here? Because we tried every conceivable method available in SDK 2.0 to no avail. IMedia took the source alright, but just ate it and produce no single iota of sound. ...smiff... :( If this actually worked for you, can you give us a code sample please?
Saludos,
Alhiem

Quote:Use ISOURCEUTIL_SourceFromSocket() to get an ISource from your ISocket, and then use type MMD_RT_ISOURCE for the clsData field in your AEEMediaData. Then IMEDIA_Play() will read directly from the socket.
Are we talking about SDK 2.0 here? Because we tried every conceivable method available in SDK 2.0 to no avail. IMedia took the source alright, but just ate it and produce no single iota of sound. ...smiff... :( If this actually worked for you, can you give us a code sample please?
Saludos,
Alhiem

Hello alhiem,
Yes we successfully streamed audio in BREW 2.0 devices in past.
Procedures are combination of methods suggested by Anand and anjul_jain.

Hello alhiem,
Yes we successfully streamed audio in BREW 2.0 devices in past.
Procedures are combination of methods suggested by Anand and anjul_jain.