int GetEpgList(JNIEnv* env, jobject thiz)
{
	ALI_MSG msg;
	int epgsize;
	char* pbuf;
	char* plastbuf;
	int ret = -1;
	ALI_EPG_DATA* pepg;

	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "request epgdata\n");
	pthread_mutex_lock(&pplay->m_lock);
	if(pplay->curstbsock > 0)
	{
		msg.type = (short)ALI_MSG_EPG;
		if(tcp_send(pplay->curstbsock, (char *)&msg, sizeof(ALI_MSG), NORMAL_DELAY) == sizeof(ALI_MSG))
		{
			__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "send epg msg ok\n");
			if(tcp_recv(pplay->curstbsock, (char *)&epgsize, 4, NORMAL_DELAY) == 4)
			{
				__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "epgsize %d\n", epgsize);
				pbuf = (char*)malloc(epgsize);
				memset(pbuf, 0, epgsize);
				if(tcp_recv(pplay->curstbsock, pbuf, epgsize- 4, EPG_DELAY) == (epgsize- 4))
					ret = 0;
				else
				{
					__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "request epgdata fail\n");
					free(pbuf);
				}
			}
		}
	}
	pthread_mutex_unlock(&pplay->m_lock);
	if(ret < 0)
		return ret;
	if((pplay->pdata_size == epgsize- 4)
		&& (pplay->plastepg != NULL)
		&& (memcmp(pplay->plastepg, pbuf, epgsize - 4) == 0))
	{
		__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "epg data same as last\n");
		free(pbuf);
		return 0;
	}
	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "parse epg data\n");
	plastbuf = (char*)malloc(epgsize);
	memset(plastbuf, 0, epgsize);
	memcpy(plastbuf, pbuf, epgsize - 4);
	pepg = epg_parse(pbuf);
	pthread_mutex_lock(&pplay->m_lock);
	epg_free(pplay);
	pplay->m_pepg = pepg;
	pplay->pdata = pbuf;
	pplay->plastepg = plastbuf;
	pplay->pdata_size = epgsize- 4;
	pthread_mutex_unlock(&pplay->m_lock);
	return true;
}
void PlayUnInit(JNIEnv* env, jobject thiz)
{
	if(pplay != NULL)
	{
		if(pplay->curstbsock != 0)
		{
			tcp_close(pplay->curstbsock);
			pplay->curstbsock = 0;
		}
		epg_free(pplay);
		pthread_mutex_destroy(&pplay->m_lock);
		free(pplay);
		pplay = NULL;
	}
}
Exemple #3
0
/** epg **/
struct epg *
epg_alloc()
{
    struct epg *epg = (struct epg *) malloc(sizeof(struct epg));
    error_if(epg == NULL, error, "Error Allocating Memory");

    epg->channels = list_create();
    error_if(epg->channels == NULL, error, "Cannot create list");

    epg->programmes = list_create();
    error_if(epg->programmes == NULL, error, "Cannot create list");

    return epg;

 error:
    if (epg)
        epg_free(epg);
    return NULL;
}
bool ConnectStb(JNIEnv* env, jobject thiz, int index)
{
	int consock;
	bool ret = false;

	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "connect stb %s\n", pplay->stbip[index]);
	pthread_mutex_lock(&pplay->m_lock);
	consock = tcp_connect(pplay->stbip[index], 6280, 3000);
	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "connect stb 111 %d\n", consock);
	if(consock > 0)
	{
		if(pplay->curstbsock != 0)
			tcp_close(pplay->curstbsock);
		pplay->curstbsock = consock;
		ret = true;
	}
	epg_free(pplay);
	pthread_mutex_unlock(&pplay->m_lock);
	__android_log_print(ANDROID_LOG_INFO, JNIDEC_TAG, "connect stb 222 %d\n", ret);
	return ret;
}