Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,
I am facing problem with downloading a video file from server. I have a function make request which sends the request and initiate the callback. The callback function is called when i get the response. Here the bytecount is showing 1246 whereas the buffer is "". I dont know where i have done the mistake. Please provide the solution

Thanks in advance.

Here is the sample code for that.
int CWebMgr_MakeRequest(CWebMgr *pWebMgr, WebReqType *pWebReq)
{
int nLen = 0;

FREEIF(pWebMgr->m_PostData);
MEMCPY(&(pWebMgr->CurrentReq), pWebReq, sizeof(WebReqType));
nLen = STRLEN (pWebMgr->m_PostData);
if ( SUCCESS != ISHELL_CreateInstance ( pWebMgr->pIShell,
AEECLSID_SOURCEUTIL,
(void**) &pWebMgr->m_pSourceUtil ) )
return FALSE;
if ( ISOURCEUTIL_SourceFromMemory ( pWebMgr->m_pSourceUtil, pWebMgr->m_PostData, nLen, NULL, NULL, &pWebMgr->m_pSource ) != SUCCESS )
return FALSE;
DBGPRINTF("Request : %s", pWebMgr->m_PostData);
CALLBACK_Init(&pWebMgr->callback, WebMgr_GotResponse, pWebMgr);
IWEB_GetResponse(pWebMgr->pIWeb,
(pWebMgr->pIWeb, &pWebMgr->pIWebResp, &pWebMgr->callback, "http://serverip/media.mp4",
WEBOPT_HANDLERDATA, pWebMgr,
//WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_HEADER, "X-Method: GET\r\n",
//WEBOPT_METHOD,"POST",
WEBOPT_METHOD,"GET",
WEBOPT_BODY, pWebMgr->m_pSource,
WEBOPT_CONTENTLENGTH, nLen,
//WEBOPT_STATUSHANDLER, WebMgr_PrintStatus,
WEBOPT_HANDLERDATA, (void*)pWebMgr,
WEBOPT_END));
return TRUE;

int WebMgr_GotResponse(CWebMgr *pWebMgr)
{
WebRespInfo *pWebRespInfo = NULL;
ISource *pISource = NULL;
int nByteCount = 0;
char *pszRecData ;

pWebRespInfo = IWEBRESP_GetInfo(pWebMgr->pIWebResp);
pISource = pWebRespInfo->pisMessage;
pszRecData=(char*)MALLOC (sizeof(char) * 1500);

DBGPRINTF("**Got Response...\n** info Code : %d\n", pWebRespInfo->nCode);
if (pWebRespInfo && WEB_ERROR_SUCCEEDED(pWebRespInfo->nCode))
{
if (pWebRespInfo->nCode==200)
{
nByteCount = ISOURCE_Read(pISource, pszRecData, sizeof(char)*1500);
switch (nByteCount)
{
case ISOURCE_WAIT:
ISOURCE_Readable(pISource, &pWebMgr->callback);
FREEIF(pszRecData);
return 0;
case ISOURCE_ERROR:
break;
case ISOURCE_END:
if (pWebMgr->pIWebResp!=NULL)
{
IWEBRESP_Release(pWebMgr->pIWebResp);
pWebMgr->pIWebResp = NULL;
}
CWebMgr_CancelRequest(pWebMgr);
break;
default:
if (nByteCount>0)
{
DBGPRINTF("Response : %s", pszRecData);
//Here i want to use the data in pszRecData CWebMgr_CancelRequest(pWebMgr);
FREEIF(pszRecData);
ISOURCE_Readable(pISource, &pWebMgr->callback);
ISHELL_PostEvent(pWebMgr->pIShell, AEECLSID_FIRSTAPP, EVT_WEBMGR, WEBMGR_EVT_SUCCESS, 0);
return TRUE;

break;

}

FREEIF(pszRecData);
CWebMgr_CancelRequest(pWebMgr);
ISHELL_PostEvent(pWebMgr->pIShell, AEECLSID_FIRSTAPP, EVT_WEBMGR, WEBMGR_EVT_FAILED, 0);

return FALSE;

Please help me in solving this problem....

Hi,
This problem got solved.
Just the modification needed is in calling IWEB_GetResponse function.
I changed it to
IWEB_GetResponse(pWebMgr->pIWeb,
(pWebMgr->pIWeb, &pWebMgr->pIWebResp, &pWebMgr->callback, "http://serverip/media.mp4",
WEBOPT_END));
And now i can able to get the data in the buffer pszRecData.
This data i can able to write into a file.
Now my problem is its getting repeated. I mean, the content which i got for the first time i am getting several times. Later when i try to play by quick time player( on my PC without BREW code) the file its giving some error which is strange. It shows Error -2002: a bad public movie atom was found in the movie dialog box.
I need help regarding this now. Any idea where i am doing mistake?

Hi,
This problem got solved.
Just the modification needed is in calling IWEB_GetResponse function.
I changed it to
IWEB_GetResponse(pWebMgr->pIWeb,
(pWebMgr->pIWeb, &pWebMgr->pIWebResp, &pWebMgr->callback, "http://serverip/media.mp4",
WEBOPT_END));
And now i can able to get the data in the buffer pszRecData.
This data i can able to write into a file.
Now my problem is its getting repeated. I mean, the content which i got for the first time i am getting several times. Later when i try to play by quick time player( on my PC without BREW code) the file its giving some error which is strange. It shows Error -2002: a bad public movie atom was found in the movie dialog box.
I need help regarding this now. Any idea where i am doing mistake?

This error is also solved. This error occurs because the player cannot able to recognize the file. Reason for this is that the file which i copied is not copied properly.When i edited that file using notepad, i can able to see the contents are repeated. Which means i am not copying the file in the proper manner. I changed the code such that releasing of resources should not be done till, the end of the source file. When the end of the source file is reached, control goes to Isource_End. Here i did the releasing stuff.
I hope the following code will be helpful to new programmers like me :)
static int WebMgr_GotResponse(CWebMgr *pWebMgr)
{
WebRespInfo *pWebRespInfo = NULL;
ISource *pISource = NULL;
int nByteCount = 0;
char *pszRecData;
MobiStream *pApp = pWebMgr->m_pApp;
ISHELL_CancelTimer( ((MobiStream*)pApp)->a.m_pIShell, (PFNNOTIFY)WebMgr_Timeout, pWebMgr);
pWebMgr->blsWaiting = 0;
pWebRespInfo = IWEBRESP_GetInfo(pWebMgr->pIWebResp);
pISource = pWebRespInfo->pisMessage;
pszRecData=(char*)MALLOC (sizeof(char) * 1500);
DBGPRINTF("**Got Response...\n** info Code : %d\n", pWebRespInfo->nCode);
if (pWebRespInfo && WEB_ERROR_SUCCEEDED(pWebRespInfo->nCode))
{
if (pWebRespInfo->nCode==200)
{
nByteCount = ISOURCE_Read(pISource, pszRecData, sizeof(char)*1500);
switch (nByteCount)
{
case ISOURCE_WAIT:
ISOURCE_Readable(pISource, &pWebMgr->callback);
FREEIF(pszRecData);
return 0;
case ISOURCE_ERROR:
break;
case ISOURCE_END:
if (pWebMgr->pIWebResp!=NULL)
{
IWEBRESP_Release(pWebMgr->pIWebResp);
pWebMgr->pIWebResp = NULL;
}
CWebMgr_CancelRequest(pWebMgr);
break;
default:
if (nByteCount>0)
{
DBGPRINTF("Response : %s", pszRecData);
if(STRLEN(pszRecData) != 0)
{
WebMgr_ParseResponse(pWebMgr, pszRecData);
CWebMgr_CancelRequest(pWebMgr);
ISHELL_PostEvent(((MobiStream*)pApp)->a.m_pIShell, AEECLSID_FIRSTAPP, EVT_WEBMGR, WEBMGR_EVT_SUCCESS, 0);
}
FREEIF(pszRecData);
return TRUE;
}
break;
}
}
}
return FALSE;

This error is also solved. This error occurs because the player cannot able to recognize the file. Reason for this is that the file which i copied is not copied properly.When i edited that file using notepad, i can able to see the contents are repeated. Which means i am not copying the file in the proper manner. I changed the code such that releasing of resources should not be done till, the end of the source file. When the end of the source file is reached, control goes to Isource_End. Here i did the releasing stuff.
I hope the following code will be helpful to new programmers like me :)
static int WebMgr_GotResponse(CWebMgr *pWebMgr)
{
WebRespInfo *pWebRespInfo = NULL;
ISource *pISource = NULL;
int nByteCount = 0;
char *pszRecData;
MobiStream *pApp = pWebMgr->m_pApp;
ISHELL_CancelTimer( ((MobiStream*)pApp)->a.m_pIShell, (PFNNOTIFY)WebMgr_Timeout, pWebMgr);
pWebMgr->blsWaiting = 0;
pWebRespInfo = IWEBRESP_GetInfo(pWebMgr->pIWebResp);
pISource = pWebRespInfo->pisMessage;
pszRecData=(char*)MALLOC (sizeof(char) * 1500);
DBGPRINTF("**Got Response...\n** info Code : %d\n", pWebRespInfo->nCode);
if (pWebRespInfo && WEB_ERROR_SUCCEEDED(pWebRespInfo->nCode))
{
if (pWebRespInfo->nCode==200)
{
nByteCount = ISOURCE_Read(pISource, pszRecData, sizeof(char)*1500);
switch (nByteCount)
{
case ISOURCE_WAIT:
ISOURCE_Readable(pISource, &pWebMgr->callback);
FREEIF(pszRecData);
return 0;
case ISOURCE_ERROR:
break;
case ISOURCE_END:
if (pWebMgr->pIWebResp!=NULL)
{
IWEBRESP_Release(pWebMgr->pIWebResp);
pWebMgr->pIWebResp = NULL;
}
CWebMgr_CancelRequest(pWebMgr);
break;
default:
if (nByteCount>0)
{
DBGPRINTF("Response : %s", pszRecData);
if(STRLEN(pszRecData) != 0)
{
WebMgr_ParseResponse(pWebMgr, pszRecData);
CWebMgr_CancelRequest(pWebMgr);
ISHELL_PostEvent(((MobiStream*)pApp)->a.m_pIShell, AEECLSID_FIRSTAPP, EVT_WEBMGR, WEBMGR_EVT_SUCCESS, 0);
}
FREEIF(pszRecData);
return TRUE;
}
break;
}
}
}
return FALSE;