Esempio n. 1
0
File: rmac.c Progetto: ieei/rlib
RHmac *
r_hmac_new (RHashType type, rconstpointer key, rsize keysize)
{
  RHmac * hmac;

  if ((hmac = r_mem_new (RHmac)) != NULL) {
    hmac->inner = r_hash_new (type);
    hmac->outer = r_hash_new (type);
    hmac->blocksize = r_hash_blocksize (hmac->inner);
    hmac->keyblock = r_malloc0 (hmac->blocksize);

    if (hmac->inner == NULL || hmac->outer == NULL ||
        hmac->blocksize == 0 || hmac->keyblock == NULL) {
      r_hmac_free (hmac);
      return NULL;
    }

    if (keysize > hmac->blocksize) {
      r_hash_update (hmac->inner, key, keysize);
      r_hash_get_data (hmac->inner, (ruint8 *)hmac->keyblock, &keysize);
    } else {
      r_memcpy (hmac->keyblock, key, keysize);
    }

    r_hmac_reset (hmac);
  }

  return hmac;
}
Esempio n. 2
0
static int
rrextract(u_char *msg, int msglen, u_char *rrp, u_char *dname, int namelen)
{
  u_char *eom, *cp, *cp1, *rdatap;
  u_int class, type, dlen;
  int n;
  u_char data[MAXDATA*2 + SPACE_FOR_VARS];
  data [(MAXDATA*2 + SPACE_FOR_VARS)-1] = EOS;  cp = rrp;
  eom = msg + msglen;

  GETSHORT(dlen, cp);
  BOUNDS_CHECK(cp, dlen);

  /* Cut a bunch of stuff which we can reintroduce later. */

  n = dn_expand(msg, eom, cp, (char *)data, sizeof data);
	   
  if (n < 0) {
    return (-1);
  }

  if (nondet_int()) {
    return (-1);
  }
  cp += n;
  cp1 = data + strlen((char *)data) + 1;

  /* BAD */
  r_memcpy(cp1, cp, dlen - n);

  return 0;
}
Esempio n. 3
0
long r_map_setvalue(rmap_t *map, long index, rconstpointer pval)
{
	r_mapnode_t *node = r_map_node(map, index);
	if (!node)
		return -1;
	r_memcpy(node->value.data, pval, map->elt_size);
	return index;
}
Esempio n. 4
0
unsigned long r_carray_replace(rcarray_t *carray, unsigned long index, rconstpointer data)
{
	if (data)
		r_memcpy(r_carray_slot_expand(carray, index), data, carray->elt_size);
	else
		r_memset(r_carray_slot_expand(carray, index), 0, carray->elt_size);
	return index;
}
Esempio n. 5
0
static int
rrextract(u_char *msg, int msglen, u_char *rrp, u_char *dname, int namelen)
{
  /* cp is used to read data from rrp[] (the Resource Record)
   * cp1 is used to write data into data[]
   * However, we sometimes abuse cp1 and use it for reading too. :-/
   */
  u_char *eom, *cp, *cp1, *rdatap;
  u_int class, type, dlen;
  int n;
  long origTTL;
  u_char data[MAXDATA*2+SPACE_FOR_VARS];
  data [(MAXDATA*2)-1+SPACE_FOR_VARS] = EOS;

  cp = rrp;
  eom = msg + msglen;

  GETSHORT(dlen, cp);
  BOUNDS_CHECK(cp, dlen);


  /* Begin case T_SIG: */

  /* Just read one variable --- the original reads several. */
  BOUNDS_CHECK(cp, SPACE_FOR_VARS);
  cp1 = cp;
  GETLONG(origTTL, cp1);

  /* Skip checks on times which are present in the original. */

  /* Copy over initial fields, which we read above. */
  cp1 = (u_char *)data;
  BOUNDS_CHECK(cp, SPACE_FOR_VARS);
  memcpy(cp1, cp, SPACE_FOR_VARS);
  cp += SPACE_FOR_VARS;
  cp1 += SPACE_FOR_VARS;

  /* Expand the domain name, set cp1 past the end of the uncompressed 
   * domain name. 
   */
  n = dn_expand(msg, eom, cp, (char *)cp1, (sizeof data));		
  if (n < 0) {
    return (-1);
  }
  cp += n;
  cp1 += strlen((char*)cp1)+1;

  /* Figure out the length of the "signature" to copy over and copy it. */
  n = dlen - (SPACE_FOR_VARS + n);
  if (n > (sizeof data) - (cp1 - (u_char *)data)) {
    return (-1);  /* out of room! */
  }
  /* OK */
  r_memcpy(cp1, cp, n);


  return 0;
}
Esempio n. 6
0
int r_buffer_append(rbuffer_t *buffer, void *src, unsigned long size)
{
	char *s;

	s = (char *)r_realloc(buffer->s, size + 1);
	if (!s)
		return -1;
	buffer->s = s;
	buffer->size = size;
	r_memcpy(buffer->s, src, size);
	buffer->s[buffer->size] = '\0';
	return 0;
}
Esempio n. 7
0
long r_map_gckey_add(rmap_t *map, rgc_t* gc, const char *name, unsigned int namesize, rconstpointer pval)
{
	r_mapnode_t *node;

	node = r_map_getfreenode(map, name, namesize);
	if (pval)
		r_memcpy(node->value.data, pval, map->elt_size);
	node->nbucket = (r_map_rstrhash(R_STRING2RSTR(node->key)) & r_map_hashmask(map));
	r_list_addt(&map->hash[node->nbucket], &node->hash);
	r_list_addt(&map->active, &node->active);
	if (gc)
		r_gc_add(gc, (robject_t*)node->key);
	return node->index;
}
Esempio n. 8
0
static int
giwscan_cb(const struct ieee80211_scan_entry *se)
{
  char buf[IESZ];

  /* Everything up to this point seems irrelevant to the following. */

  if (se->se_rsn_ie != NULL) {
    /* BAD */
    r_memcpy(buf, se->se_rsn_ie, se->se_rsn_ie[1] + 2);
  }
  
  return 0;
}
Esempio n. 9
0
rstr_t *rjs_file_map(const char *filename)
{
	rstr_t *buf = NULL;
	char *pMappedView = NULL;
	HANDLE hFile = INVALID_HANDLE_VALUE;
	HANDLE hMapping = 0;
	unsigned __int64 fileSize;
	DWORD sizeLo, sizeHi;

	buf = (rstr_t*)r_malloc(sizeof(*buf));
	if (!buf)
		return NULL;
	hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
	if (INVALID_HANDLE_VALUE == hFile)
		goto error;
	sizeLo = GetFileSize(hFile, &sizeHi);
	fileSize = (UINT64)sizeLo | ((UINT64)sizeHi << 32);
	hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, sizeHi, sizeLo, 0);
	if (!hMapping)
		goto error;
	pMappedView = (char*)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
	if (NULL == pMappedView)
		goto error;
	buf->size = (unsigned long)fileSize;
	buf->str = (char*)r_zmalloc((unsigned long)fileSize + 1);
	if (!buf->str)
		goto error;
	r_memcpy(buf->str, pMappedView, (unsigned long)fileSize);
	if (hMapping)
		CloseHandle(hMapping);
	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle(hFile);
	if (pMappedView)
		UnmapViewOfFile(pMappedView);
	return buf;

error:
	if (hMapping)
		CloseHandle(hMapping);
	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle(hFile);
	if (pMappedView)
		UnmapViewOfFile(pMappedView);
	r_free(buf->str);
	r_free(buf);
	return NULL;
}
Esempio n. 10
0
robject_t *r_carray_copy(const robject_t *obj)
{
	unsigned long i;
	rcarray_t *dst;
	const rcarray_t *carray = (const rcarray_t *)obj;

	if (!carray)
		return NULL;
	dst = r_carray_create(carray->elt_size);
	if (!dst)
		return NULL;
	r_carray_add_chunks(dst, r_array_length(carray->array));
	for (i = 0; i < r_array_length(carray->array); i++)
		r_memcpy(r_carray_get_chunk(dst, i), r_carray_get_chunk(carray, i), R_CARRAY_CHUNKSIZE * carray->elt_size);
	dst->len = carray->len;
	dst->oncopy = carray->oncopy;
	dst->oncleanup = carray->oncleanup;
	if (dst->oncopy)
		dst->oncopy(dst);
	return (robject_t *)dst;
}
Esempio n. 11
0
static int SendRtpNalu(NALU_t *nalu , unsigned short *seq_num, unsigned int ts_current , int roomid, int end, int mtu,void *info, FRAMEHEAD *data_info)
{
	int 	rtp_mtu = mtu;
	char				 sendbuf[1500] = {0};
	RTP_FIXED_HEADER			*rtp_hdr;
	rtp_extension_head_t		*rtp_exten_head;
	char                        *nalu_payload;
	FU_INDICATOR	            *fu_ind;
	FU_HEADER		            *fu_hdr;
	int                          bytes = 0;

	int total_len = 0;
	memset(sendbuf, 0, 20);
	//设置RTP HEADER,
	rtp_hdr 							= (RTP_FIXED_HEADER *)&sendbuf[0];
	rtp_hdr->payload	                = H264;
	rtp_hdr->version	                = 2;
	rtp_hdr->marker                    = 0;
	rtp_hdr->extension					= 1;			// zhengyb 标示含有rtp 扩展头
//	rtp_hdr->extension					= 0;

	rtp_hdr->ssrc		                = htonl(10);
	rtp_hdr->timestamp		            = htonl(ts_current);
//	nslog(NS_INFO,"<R_VIDEO>  ________________ <SEND_TIME_BEFORE : %u>	<SEND_TIME_AFTER : %u>\n",ts_current,rtp_hdr->timestamp);
//	printf(" time is  ---------------- %lld +==================== %d\n",rtp_hdr->timestamp,ts_current);
//	rtp_hdr->scrc						= htonl(0);			// zhengyb ???

	// 添加rtp 扩展头以及扩展头信息中的帧头信息zhengyb

#if 1

	rtp_debug_head_t 					*debug_head;

	debug_head = (rtp_debug_head_t *)&sendbuf[12];
	
	debug_head->profile_defined			= htons(0);
	debug_head->length					= htons(3);
	
#endif
	FRAMEHEAD							*frame_head;
	frame_head = (FRAMEHEAD *)&sendbuf[16];
	frame_head->codec		= data_info->codec;
	frame_head->samplerate	= data_info->samplerate;
	frame_head->framerate	= data_info->framerate;

#if 1
	frame_head->height   	= htons(data_info->height);
	frame_head->width 		= htons(data_info->width);
	frame_head->Iframe		= data_info->Iframe;
	frame_head->reserve		= data_info->reserve;
	frame_head->framelength = htonl(data_info->framelength);
#endif
#if 0
	frame_head->height   	= data_info->height;
	frame_head->width 		= data_info->width;
	frame_head->resever		= data_info->resever;
	frame_head->framelength = data_info->framelength;
#endif	
#if 0
	printf("framelength  ---- %d ---- \n",data_info->framelength);
	printf("codec  ---- %d ---- \n",frame_head->codec);
	printf("framerate  ---- %d ---- \n",frame_head->framerate);
	printf("height  ---- %d---- \n",frame_head->height);
	printf("width  ---- %d---- \n",frame_head->width);
	printf("resever  ---- %d---- \n",frame_head->reserve);
	printf("Iframe  ---- %d---- \n",frame_head->Iframe);
	printf("samplerate  ---- %d---- \n\n\n",frame_head->samplerate);

	
#endif
#if 0
	if(frame_head->Iframe != 0)
	{
		printf("find the I frame!\n");
		printf("Iframe  ---- %d---- \n",frame_head->Iframe);
	}
#endif
	
	if((nalu->len - 1) <= rtp_mtu) {
		//设置rtp M 位;

		rtp_hdr->marker = 1;
		rtp_hdr->seq_no 	= htons((*seq_num)++); //序列号,每发送一个RTP包增1
		r_memcpy(&sendbuf[28], nalu->buf, nalu->len);
		bytes = nalu->len + 28 ; 					//获得sendbuf的长度,为nalu的长度(包含NALU头但除去起始前缀)加上rtp_header的固定长度12字节
		//	SendRtspVideoData(sendbuf, bytes,nalu->nal_unit_type,roomid);
	//	SendMultCastVideoData(sendbuf, bytes,info);
		if(send_rtp_video(info,sendbuf,bytes) < 0)
		{
			//printf("send_rtp_video is eror!\n");
			return -1;
		}
		
		total_len = nalu->len;
	} else if((nalu->len - 1) > rtp_mtu) {
		//得到该nalu需要用多少长度为1400字节的RTP包来发送
		int k = 0, l = 0;
		int t = 0; //用于指示当前发送的是第几个分片RTP包

		l = (nalu->len - 1) % rtp_mtu; //最后一个RTP包的需要装载的字节数

		if(l == 0) {
			k = (nalu->len - 1) / rtp_mtu - 1; //需要k个1400字节的RTP包
			l = rtp_mtu;
		} else {
			k = (nalu->len - 1) / rtp_mtu; //需要k个1400字节的RTP包
		}

		while(t <= k) {
			rtp_hdr->seq_no = htons((*seq_num)++); //序列号,每发送一个RTP包增1

			if(!t) { //发送一个需要分片的NALU的第一个分片,置FU HEADER的S位
				//设置rtp M 位;
				rtp_hdr->marker = 0;
				//设置FU INDICATOR,并将这个HEADER填入sendbuf[12]
				fu_ind = (FU_INDICATOR *)&sendbuf[28]; //将sendbuf[12]的地址赋给fu_ind,之后对fu_ind的写入就将写入sendbuf中;
				fu_ind->F = nalu->forbidden_bit;
				fu_ind->NRI = nalu->nal_reference_idc >> 5;
				fu_ind->TYPE = 28;

				//设置FU HEADER,并将这个HEADER填入sendbuf[13]
				fu_hdr = (FU_HEADER *)&sendbuf[29];
				fu_hdr->E = 0;
				fu_hdr->R = 0;
				fu_hdr->S = 1;
				fu_hdr->TYPE = nalu->nal_unit_type;

				nalu_payload = &sendbuf[30]; //同理将sendbuf[14]赋给nalu_payload
				r_memcpy(nalu_payload, nalu->buf + 1, rtp_mtu); //去掉NALU头

				//	nslog(NS_ERROR,"%x,ser_no=%d\n",nalu_payload[0],*seq_num);
				bytes = rtp_mtu + 30;						//获得sendbuf的长度,为nalu的长度(除去起始前缀和NALU头)加上rtp_header,fu_ind,fu_hdr的固定长度14字节
			//	SendRtspVideoData(sendbuf, bytes,0,roomid);
		//		SendMultCastVideoData(sendbuf, bytes,info);

				if(send_rtp_video(info,sendbuf,bytes) < 0)
				{
					//printf("send_rtp_video is eror!\n");
					return -1;
				}
			
				total_len += rtp_mtu;
				t++;
			}
			//发送一个需要分片的NALU的非第一个分片,清零FU HEADER的S位,如果该分片是该NALU的最后一个分片,置FU HEADER的E位
			else if(k == t) { //发送的是最后一个分片,注意最后一个分片的长度可能超过1400字节(当l>1386时)。
Esempio n. 12
0
int rtp_build_jpeg_data(RTP_BUILD_HANDLE handle,int nLen, unsigned char *pData,unsigned int ts_current,int rtp_mtu, void *info ,FRAMEHEAD *data_info)
{

//	printf("usernum ----- %d \n",data_user_info->user_num);

//	int32_t  							temp_len		= 

	int32_t 							send_total_len	= 0;
	int32_t								send_buf_num	= 0;
	int32_t 							bytes			= 0;

	unsigned short *seq = (unsigned short *)(&(handle->seq_num));
	unsigned char                   	sendbuf[1500] = {0};
	
	RTP_FIXED_HEADER					*rtp_hdr;
	rtp_hdr 							= (RTP_FIXED_HEADER *)&sendbuf[0];
	rtp_hdr->payload	                = H264;
	rtp_hdr->version	                = 2;
	rtp_hdr->marker                    	= 0;
	rtp_hdr->extension					= 1;			// zhengyb 标示含有rtp 扩展头
//	rtp_hdr->extension					= 0;

	rtp_hdr->ssrc		                = htonl(10);
	rtp_hdr->timestamp		            = htonl(ts_current);
//	rtp_hdr->scrc						= htonl(0);			// zhengyb ???

	// 添加rtp 扩展头以及扩展头信息中的帧头信息zhengyb

#if 1

	rtp_debug_head_t 					*debug_head;

	debug_head = (rtp_debug_head_t *)&sendbuf[12];
	
	debug_head->profile_defined			= htons(0);
	debug_head->length					= htons(3);
	
#endif
	FRAMEHEAD							*frame_head;
	frame_head = (FRAMEHEAD *)&sendbuf[16];
	frame_head->codec		= data_info->codec;
//	frame_head->samplerate	= data_info->samplerate;
	frame_head->framerate	= data_info->framerate;
	frame_head->Iframe		= data_info->Iframe;


#if 1
	frame_head->height   	= htons(data_info->height);
	frame_head->width 		= htons(data_info->width);
	frame_head->reserve		= data_info->reserve;
	frame_head->framelength = htonl(data_info->framelength);
#endif
#if 0
	frame_head->height   	= data_info->height;
	frame_head->width 		= data_info->width;
	frame_head->resever		= data_info->resever;
	frame_head->framelength = data_info->framelength;
#endif	
#if 0
	printf("framelength  ---- %d ---- \n",data_info->framelength);
	printf("codec  ---- %d ---- \n",frame_head->codec);
	printf("framerate  ---- %d ---- \n",frame_head->framerate);
	printf("height  ---- %d---- \n",frame_head->height);
	printf("width  ---- %d---- \n",frame_head->width);
	printf("resever  ---- %d---- \n",frame_head->reserve);
	printf("samplerate  ---- %d---- \n",frame_head->samplerate);
#endif
	if(nLen <= rtp_mtu - 28) 
	{
		//设置rtp M 位;
		rtp_hdr->marker = 1;

		rtp_hdr->seq_no 	= htons((*seq)++); //序列号,每发送一个RTP包增1
		frame_head->samplerate = 3;
		r_memcpy(&sendbuf[28], pData, nLen);
		bytes	= nLen + 28;
	//	printf("samplerate  ---- %d---- \n",frame_head->samplerate);
	//	data_user_info = (video_data_user_t *)info;
	//	printf("usernum ----- %d \n",data_user_info->user_num);
		if(send_rtp_video(info,sendbuf,bytes) < 0)
		{
			//printf("send_rtp_video is eror!\n");
			return -1;
		}
	}
	 else if(nLen > rtp_mtu - 28)
	{
		//得到该nalu需要用多少长度为1400字节的RTP包来发送
		int k = 0, l = 0;
		int t = 0; //用于指示当前发送的是第几个分片RTP包

		l = nLen % (rtp_mtu- 28); //最后一个RTP包的需要装载的字节数

		if(l == 0) {
			k = nLen / (rtp_mtu - 28) -1; //需要k个1400字节的RTP包
			l = (rtp_mtu - 28);
		} else {
			k = nLen / (rtp_mtu - 28) ; //需要k个1400字节的RTP包
		}

		while(t <= k)
		{
		//	r_memset(&sendbuf[28] , 0 ,1472);
			rtp_hdr->seq_no = htons((*seq)++); //序列号,每发送一个RTP包增1

			if(!t)								//发送第一个分片包
			{
				rtp_hdr->marker = 0;
				
				
				frame_head->samplerate = 2;
				r_memcpy(&sendbuf[28], pData, (rtp_mtu - 28));
				
				t++;
				bytes = rtp_mtu;
				// 发送
		//	printf("samplerate	---- %d---- \n",frame_head->samplerate);
				if(send_rtp_video(info,sendbuf,bytes) < 0)
				{
					//printf("send_rtp_video is eror!\n");
					return -1;
				}
				
			}
			else if(k == t)						//发送最后一个分片包
			{
				rtp_hdr->marker = 1;
				frame_head->samplerate = 1;
			//	printf("222_bengin  ----%d ----- %d ----- %d!\n",t*(rtp_mtu-28),l,nLen);
			//	printf("data_addr : ----- %p\n",(pData + t*(rtp_mtu-28)));
				
				r_memcpy(&sendbuf[28], pData + t*(rtp_mtu-28), l);
			//	printf("222_stop !\n");
				t++;
				bytes = l + 28;
				// 发送
			//	printf("samplerate	---- %d---- \n",frame_head->samplerate);
				if(send_rtp_video(info,sendbuf,bytes) < 0)
				{
					//printf("send_rtp_video is eror!\n");
					return -1;
				}
			}
			else if(t < k && 0!= t) 			// 发送中间的分片包
			{
				rtp_hdr->marker = 0;
				frame_head->samplerate = 0;
				r_memcpy(&sendbuf[28], pData + t*(rtp_mtu-28) , (rtp_mtu - 28));
				t++;
				bytes = rtp_mtu;
				// 发送
			//	printf("samplerate	---- %d---- \n",frame_head->samplerate);
				if(send_rtp_video(info,sendbuf,bytes) < 0)
				{
					//printf("send_rtp_video is eror!\n");
					return -1;
				}
			}
			
		}
	
	}
	return 0;
}
Esempio n. 13
0
// add zl callback func
int recv_deal_udp_recv_data(udp_recv_stream_info_t *p_stream_info, char *data, int len)
{
	if(NULL == p_stream_info || NULL == data) {
		nslog(NS_ERROR, "M_handle = %p, data = %p", p_stream_info, data);
		return OPERATION_ERR;
	}

	if(NULL == p_stream_info->user_data) {
		nslog(NS_ERROR, "p_stream_info->user_data = %p", p_stream_info->user_data);
		return OPERATION_ERR;
	}

	//nslog(NS_WARN, "len:[%d]\n", len);
	stream_handle *M_handle = p_stream_info->user_data;
	int32_t return_code = 0;
	hdb_freame_head_t fh;

	memset(&fh, 0, sizeof(hdb_freame_head_t));


	fh.m_data_codec = p_stream_info->type;
	fh.m_hight = p_stream_info->height;
	fh.m_width = p_stream_info->width;
	fh.m_dw_flags = p_stream_info->IDR_FLAG;
	fh.m_others = !(p_stream_info->is_blue);
	fh.m_colors = p_stream_info->m_colors;
	fh.m_frame_rate = p_stream_info->frame_rate;
	fh.m_frame_length = len;



	if(AAC_CODEC_TYPE == fh.m_data_codec) {

		fh.m_frame_rate = p_stream_info->samplerate;
		M_handle->recv_time_t.time_audio_tick = p_stream_info->timestamp;

#if 1
		M_handle->recv_pri.stream_type = 2;
		M_handle->recv_pri.data_type = R_AUDIO;
		M_handle->recv_pri.code_rate = fh.m_colors;
		M_handle->recv_pri.sample_rate = fh.m_frame_rate;
		M_handle->recv_pri.is_data = 1;
		M_handle->recv_pri.frame_rate = fh.m_frame_rate;
#endif
//	 	nslog(NS_ERROR,"FUCK_GOD_1014  AAC RATE :%d   %d\n",fh.m_frame_rate,M_handle->recv_pri.frame_rate);
		r_memcpy(M_handle->audio_data, data, fh.m_frame_length);// 都写两个函数可以少10次拷贝。


		#if 0
		// 音频  add zl question
		if(START_REC == get_rec_status(M_handle))
		{
			return_code = send_msg_to_rec_res(&fh, M_handle);
		}
		else
		{
			M_handle->recv_pri.to_rec = 0;
		}

		if(START_USB_REC == get_usb_rec_status(M_handle))
		{
			return_code = send_msg_to_rec_movie(&fh, M_handle);
		}

		if(START_LIVE == get_live_status(M_handle))
		{
			return_code = send_msg_to_live(&fh, M_handle);
		}
		else
		{
			M_handle->recv_pri.to_live = 0;
		}
		#endif
		send_msg_to_rec_res(&fh, M_handle);
		send_msg_to_rec_movie(&fh, M_handle);
		send_msg_to_live(&fh, M_handle);


	}

	if(H264_CODEC_TYPE == fh.m_data_codec || JPEG_CODEC_TYPE == fh.m_data_codec) {

#if 1
		M_handle->recv_pri.stream_type = 0;
		M_handle->recv_pri.data_type = R_VIDEO;
		M_handle->recv_pri.is_data = 1;
		M_handle->recv_pri.width = fh.m_width;
		M_handle->recv_pri.hight = fh.m_hight;
		M_handle->recv_pri.frame_rate = fh.m_frame_rate;
#endif
		M_handle->recv_time_t.time_video_tick = p_stream_info->timestamp;
		r_memcpy(M_handle->frame_data, data, fh.m_frame_length);
		if(JPEG_CODEC_TYPE == fh.m_data_codec)
	 		nslog(NS_ERROR,"FUCK_GOD_1014[%d]  H264 RATE :%d   %d\n", fh.m_data_codec, fh.m_frame_rate,M_handle->recv_pri.frame_rate);

		#if 0
		if(START_REC == get_rec_status(M_handle) )
		{
			if(M_handle->rec_mode == RECODE_MODE_RES || M_handle->rec_mode == RECODE_MODE_ALL)
			{
				return_code = send_msg_to_rec_res(&fh, M_handle);
			}
		}
		else
		{
			M_handle->recv_pri.to_rec = 0;
		}

		if(START_USB_REC == get_usb_rec_status(M_handle))
		{
			if(M_handle->rec_mode == RECODE_MODE_MOVIE || M_handle->rec_mode == RECODE_MODE_ALL)
			{
				return_code = send_msg_to_rec_movie(&fh, M_handle);
			}
		}

		if(START_LIVE == get_live_status(M_handle))
		{
			return_code = send_msg_to_live(&fh, M_handle);
		}
		else
		{
			M_handle->recv_pri.to_live = 0;
		}
		#endif
		send_msg_to_rec_res(&fh, M_handle);
		send_msg_to_rec_movie(&fh, M_handle);
		send_msg_to_live(&fh, M_handle);

	}

	return 0;
}
Esempio n. 14
0
/*==============================================================================
  函数: <pkg_placed_in_frame>
  功能: <组帧>
  参数: int8_t *frame_data,  int32_t part_frame_len,  stream_handle *M_handle
  返回值: 成功返回1,失败返回0.
  Created By liuchsh 2012.11.16 15:40:28 For EDU
  ==============================================================================*/
int32_t pkg_placed_in_frame(int8_t *frame_data,  int32_t part_frame_len,  stream_handle *M_handle)
{
	hdb_freame_head_t *fh = (hdb_freame_head_t *)frame_data;
	int32_t return_code = OPERATION_SUCC;
	uint32_t current_time = 0;
	uint32_t video_cal_time = 0, video_cal_sys_time = 0;


	if(NULL == M_handle || NULL == frame_data) {
		nslog(NS_ERROR, "M_handle = %p, frame_data = %p", M_handle, frame_data);
		return OPERATION_ERR;
	}

#if 1
	current_time = getCurrentTime();

	if(0 >= M_handle->recv_time_t.init_video_flag) {
		M_handle->recv_time_t.video_init_time = fh->m_time_tick;
		M_handle->recv_time_t.init_video_flag = 1;
		M_handle->recv_time_t.video_cal_time = 0;
		M_handle->recv_time_t.prev_video_time_tick = fh->m_time_tick;
		nslog(NS_INFO, "init video_flag  id=%d", M_handle->stream_id);
	}

	if(fh->m_time_tick > M_handle->recv_time_t.video_init_time) {
		video_cal_time = fh->m_time_tick - M_handle->recv_time_t.video_init_time;
	} else {
		video_cal_time = M_handle->recv_time_t.video_init_time - fh->m_time_tick;
	}

	if(H264_CODEC_TYPE == fh->m_data_codec) {
		if(fh->m_time_tick < M_handle->recv_time_t.prev_video_time_tick ||
		   (fh->m_time_tick > M_handle->recv_time_t.prev_video_time_tick &&
		    (fh->m_time_tick - M_handle->recv_time_t.prev_video_time_tick) > EXAMIN_TIME) &&
		   M_handle->av_connect_flag == 0) {
			M_handle->recv_time_t.time_video_tick = M_handle->recv_time_t.time_video_tick + getIntervalTime(M_handle->recv_time_t.prev_video_time, current_time);
			M_handle->recv_time_t.video_init_time = fh->m_time_tick;

			M_handle->recv_time_t.video_cal_time = M_handle->recv_time_t.time_video_tick;

			nslog(NS_WARN, "video:time_cal = %u, current_time = %u,vo_init_time = %u, tm_vo_tick = %u, vo_cal_time=%u, gap_time = %uid = %d",
			      video_cal_time,
			      current_time,
			      M_handle->recv_time_t.video_init_time,
			      M_handle->recv_time_t.time_video_tick,
			      M_handle->recv_time_t.video_cal_time,
			      M_handle->recv_time_t.prev_video_time_tick - current_time,
			      M_handle->stream_id);
		} else {
			M_handle->av_connect_flag == 0;
			M_handle->recv_time_t.time_video_tick = video_cal_time + M_handle->recv_time_t.video_cal_time;
		}
	}


	if(JPEG_CODEC_TYPE == fh->m_data_codec) {
		if(fh->m_time_tick < M_handle->recv_time_t.prev_video_time_tick) {
			M_handle->recv_time_t.time_video_tick = M_handle->recv_time_t.time_video_tick + getJpgIntervalTime(M_handle->recv_time_t.prev_video_time, current_time);

			M_handle->recv_time_t.video_init_time = fh->m_time_tick;

			M_handle->recv_time_t.video_cal_time = M_handle->recv_time_t.time_video_tick;

			nslog(NS_WARN, "JPG:time_cal = %u, prev_video_time_cal = %u, time_video_tick = %u, video_cal_time=%u, id = %d",
			      video_cal_time,
			      M_handle->recv_time_t.prev_video_time_tick,
			      M_handle->recv_time_t.time_video_tick,
			      M_handle->recv_time_t.video_cal_time,
			      M_handle->stream_id);
		} else {
			M_handle->recv_time_t.time_video_tick = video_cal_time + M_handle->recv_time_t.video_cal_time;
		}
	}

	M_handle->recv_time_t.prev_video_time_tick = fh->m_time_tick;
	M_handle->recv_time_t.prev_video_time = current_time;
#endif

	switch(fh->m_dw_segment) {
		case START_FRAME:

			if(fh->m_frame_length > MAX_FRAME_LEN) {
				nslog(NS_ERROR, "fh->m_frame_length : [%d]", fh->m_frame_length);
				return_code = OPERATION_ERR;
				break;
			}

			if(((M_handle->offset) + part_frame_len) > fh->m_frame_length) {
				M_handle->offset  = 0;
				return_code = OPERATION_ERR;
				nslog(NS_WARN, "(M_handle->offset)+ part_frame_len = %d fh->m_frame_length = %d, id = %d", (M_handle->offset) + part_frame_len, fh->m_frame_length, M_handle->stream_id);
				break;
			}

			M_handle->offset = 0;
			r_memcpy(M_handle->frame_data, frame_data + FH_LEN, part_frame_len);
			M_handle->offset += part_frame_len;;
			return_code = OPERATION_SUCC;
			break;

		case MIDDLE_FRAME:      //0表示中间包

			if(M_handle->offset + part_frame_len > fh->m_frame_length) {
				M_handle->offset  = 0;
				return_code = OPERATION_SUCC;
				nslog(NS_WARN, "(M_handle->offset)+ part_frame_len = %d fh->m_frame_length = %d, id = %d", (M_handle->offset) + part_frame_len, fh->m_frame_length, M_handle->stream_id);
				break;
			}

			r_memcpy(M_handle->frame_data + M_handle->offset, frame_data + FH_LEN, part_frame_len);
			M_handle->offset += part_frame_len;
			return_code = OPERATION_SUCC;
			break;

		case LAST_FRAME:            //表示结尾包

			if(M_handle->offset + part_frame_len > fh->m_frame_length) {
				M_handle->offset  = 0;
				return_code = OPERATION_SUCC;
				nslog(NS_WARN, "(M_handle->offset)+ part_frame_len = %d fh->m_frame_length = %d, id = %d", (M_handle->offset) + part_frame_len, fh->m_frame_length, M_handle->stream_id);
				break;
			}

			r_memcpy(M_handle->frame_data + M_handle->offset, frame_data + FH_LEN, part_frame_len);
			M_handle->offset = 0;
			return_code = OPERATION_CONTINUE;
			break;

		case  INDEPENDENT_FRAME:
			r_memcpy(M_handle->frame_data, frame_data + FH_LEN, fh->m_frame_length);
			return_code = OPERATION_CONTINUE;
			break;

		default:
			nslog(NS_WARN, "fh->m_dw_segment : [%d]", fh->m_dw_segment);
			return_code = OPERATION_SUCC;
			break;
	}

	return return_code;
}
Esempio n. 15
0
static int32_t send_msg_to_rec_audio_movie(hdb_freame_head_t *fh, stream_handle *M_handle)
{
	int32_t index = 0;
	int32_t audio_vaild_num = 0;
	stream_handle *temp_handle = NULL;
	int return_code = OPERATION_SUCC;
	int8_t *rec_frame_data = NULL;
	parse_data_t *rec_frame_head = NULL;
	m_msgque  m_rec_msgque  ;

	if(M_handle->audio_info == NULL)
	{
		nslog(NS_ERROR,"IMPORT ERROR, <AUDIO_INTO IS NULL >STREAM ID : %d\n",M_handle->stream_id);
		return RECEIVE_MALLOC_ERR;
	}

	if(M_handle->audio_info->audio_tran_movie_info.stream_num == 0)
	{

		nslog(NS_ERROR,"IMPORT ERROR, <MOVIE AUDIO NUM IS 0>STREAM ID : %d\n",M_handle->stream_id);
		return OPERATION_SUCC;
	}
	audio_vaild_num = M_handle->audio_info->audio_tran_movie_info.stream_num;

	for(index = 0 ;index < audio_vaild_num ;index++)
	{

		temp_handle = (stream_handle *)(M_handle->audio_info->audio_tran_movie_info.stream_handle_addr[index]);

		//		nslog(NS_ERROR,"FUCK_GOD_1016_MOVIE, %d   %d\n",temp_handle->stream_id ,get_usb_rec_status(temp_handle));
		if(START_USB_REC != get_usb_rec_status(temp_handle))
		{
			continue;
		}

		rec_frame_data = (int8_t *)r_malloc(fh->m_frame_length);

		if(NULL == rec_frame_data) {
			nslog(NS_ERROR, "malloc is error !!!");
			return_code = RECEIVE_MALLOC_ERR;
			return return_code;
		}

		rec_frame_head = (parse_data_t *)r_malloc(sizeof(parse_data_t));

		if(NULL == rec_frame_head) {
			if(rec_frame_data) {
				r_free(rec_frame_data);
				rec_frame_data = NULL;
			}

			return_code = RECEIVE_MALLOC_ERR;
			return return_code;
		}

		r_memcpy(rec_frame_data, M_handle->audio_data, fh->m_frame_length);
		rec_frame_head->data_type = R_AUDIO;
		rec_frame_head->code_rate = fh->m_colors;
		rec_frame_head->sample_rate = fh->m_hight;
		rec_frame_head->time_tick = M_handle->recv_time_t.time_audio_tick;

		rec_frame_head->data_len = fh->m_frame_length;
		rec_frame_head->data = rec_frame_data;
		rec_frame_data = NULL;
		rec_frame_head->flags = fh->m_dw_flags;

		// add zl
	//	rec_frame_head->sindex = M_handle->stream_id - 1;
		rec_frame_head->sindex = temp_handle->stream_id;
		rec_frame_head->index = 0;
		rec_frame_head->audio_sindex = M_handle->stream_id - 1;
		rec_frame_head->height = fh->m_hight;
		rec_frame_head->width = fh->m_width;
		rec_frame_head->blue_flag = !(fh->m_others);

		// add zl
	//	m_rec_msgque.msgtype = M_handle->stream_id;
		m_rec_msgque.msgtype = temp_handle->stream_id;
		m_rec_msgque.msgbuf = (int8_t *)rec_frame_head;
		M_handle->recv_pri.to_rec = 1;

//		nslog(NS_ERROR,"FUCK_GOD_1014_MOVIE  MSG_TYPE: %d\n",m_rec_msgque.msgtype);
		return_code = r_msg_send(temp_handle->msg_recv_to_usb_rec, &m_rec_msgque, MsgqueLen - sizeof(long), IPC_NOWAIT);

		if(0 > return_code)
		{
			if(rec_frame_head->data) {
				r_free(rec_frame_head->data);
				rec_frame_head->data = NULL;
			}

			if(rec_frame_head) {
				r_free(rec_frame_head);
				rec_frame_head = NULL;
			}

			if(FALSE == IS_FLAG_BIT_TRUE(M_handle->log_flag, RECORD_BIT)) {
				nslog(NS_WARN, "msgsnd to record failed, msgid = %d, errno = %d, stream_id = %d", M_handle->msg_recv_to_rec, errno, M_handle->stream_id);
				SET_FLAG_BIT_TRUE(M_handle->log_flag, RECORD_BIT);//置第0位为1.
			}

			M_handle->recv_pri.to_rec = 0;
			return OPERATION_SUCC;
		}

	}

	SET_FLAG_BIT_FALSE(M_handle->log_flag, RECORD_BIT);//置第0位为0.
}
Esempio n. 16
0
static int32_t send_msg_to_live_media(hdb_freame_head_t *fh, stream_handle *M_handle)
{
	int return_code = OPERATION_SUCC;
	int8_t *live_frame_data = NULL;
	parse_data_t *live_frame_head = NULL;
	m_msgque  m_live_msgque  ;

	live_frame_data = (int8_t *)r_malloc(fh->m_frame_length);

	if(NULL == live_frame_data) {
		if(live_frame_data) {
			r_free(live_frame_data);
			live_frame_data = NULL;
		}
		nslog(NS_ERROR, "malloc is error !!!");
		return_code = RECEIVE_MALLOC_ERR;
		return return_code;
	}

	live_frame_head = (parse_data_t *)r_malloc(sizeof(parse_data_t));

	if(NULL == live_frame_head) {
		if(live_frame_head) {
			r_free(live_frame_head);
			live_frame_head = NULL;
		}

		return_code = RECEIVE_MALLOC_ERR;
		return return_code;
	}

	r_memset(live_frame_head, 0, sizeof(parse_data_t));
	r_memset(live_frame_data, 0, fh->m_frame_length);

	if(H264_CODEC_TYPE == fh->m_data_codec)
	{
		r_memcpy(live_frame_data, M_handle->frame_data, fh->m_frame_length);
		live_frame_head->data_type = R_VIDEO;
		live_frame_head->sample_rate = fh->m_frame_rate;
		live_frame_head->time_tick = M_handle->recv_time_t.time_video_tick;
	}
	else if(JPEG_CODEC_TYPE == fh->m_data_codec)
	{
		r_memcpy(live_frame_data, M_handle->frame_data, fh->m_frame_length);
		live_frame_head->data_type = R_JPEG;
		live_frame_head->time_tick = M_handle->recv_time_t.time_video_tick;

	}

	live_frame_head->data_len = fh->m_frame_length;
	live_frame_head->data = live_frame_data;
	live_frame_data = NULL;
	live_frame_head->flags = fh->m_dw_flags;
	live_frame_head->sindex = M_handle->stream_id - 1;
	live_frame_head->index = 0;
	live_frame_head->audio_sindex = M_handle->stream_id - 1;
	live_frame_head->height = fh->m_hight;
	live_frame_head->width = fh->m_width;
	live_frame_head->end_flag = M_handle->live_status;
	live_frame_head->blue_flag = !(fh->m_others);

	m_live_msgque.msgtype = M_handle->stream_id;
	m_live_msgque.msgbuf = (int8_t *)live_frame_head;

	M_handle->recv_pri.to_live = 1;
	if(live_frame_head->data_type == R_JPEG)
	{
		nslog(NS_ERROR,"FUCK_GOD_1114 SEND TO A JPEG !\n");
	}
	return_code = r_msg_send(M_handle->msg_recv_to_live, &m_live_msgque, MsgqueLen - sizeof(long), IPC_NOWAIT);

	if(0 > return_code) {
		if(live_frame_head->data) {
			r_free(live_frame_head->data);
			live_frame_head->data = NULL;
		}

		if(live_frame_head) {
			r_free(live_frame_head);
			live_frame_head = NULL;
		}

		if(FALSE == IS_FLAG_BIT_TRUE(M_handle->log_flag, LIVE_BIT)) {
			nslog(NS_WARN, "msgsnd to live failed, msgid = %d, errno = %d, stream_id=%d", M_handle->msg_recv_to_live, errno, M_handle->stream_id);
			SET_FLAG_BIT_TRUE(M_handle->log_flag, LIVE_BIT);//置第1位为1.
		}

		M_handle->recv_pri.to_live = 0;
		return -1;
	}

	SET_FLAG_BIT_FALSE(M_handle->log_flag, LIVE_BIT);//置第1位为0.
	return OPERATION_SUCC;

}
Esempio n. 17
0
int32_t  __main(int32_t argc, int8_t **argv)
{
	int32_t rc, i = 0;
	recv_param r_param[MAX_STREAM];
	recv_room_handle * recv_handle= NULL;
	rc = dzlog_init(NSLOG_CONF, "Rec_server");
	if (rc) {
		printf("dzlog_init failed : <%s>\n", NSLOG_CONF);
		return -1;
	}
	r_memset(r_param, 0, sizeof(recv_param) * MAX_STREAM);

	r_memcpy(r_param[0].ipaddr, CONTROL_ADDR, sizeof(CONTROL_ADDR));
	r_param[0].port = ENCODE_PORT;
	r_param[0]. stream_id = 1;
	r_param[0].status = RUNNING;
	#if 1 
		r_memcpy(r_param[2].ipaddr, "192.168.4.239", sizeof(CONTROL_ADDR));
	r_param[2].port = ENCODE_PORT;
	r_param[2]. stream_id = 3;
	r_param[2].status = RUNNING;


		r_memcpy(r_param[1].ipaddr, "192.168.4.112", sizeof(CONTROL_ADDR));
	r_param[1].port = ENCODE_PORT;
	r_param[1]. stream_id = 2;
	r_param[1].status = RUNNING;


	r_memcpy(r_param[3].ipaddr, "192.168.4.239", sizeof(CONTROL_ADDR));
	r_param[3].port = ENCODE_PORT;
	r_param[3]. stream_id = 4;
	r_param[3].status = RUNNING;

	r_memcpy(r_param[4].ipaddr, "192.168.4.242", sizeof(CONTROL_ADDR));
	r_param[4].port = ENCODE_PORT;
	r_param[4]. stream_id = 5;
	r_param[4].status = RUNNING;

	#endif
	recv_handle = register_room_receive_module(1);
	recv_handle->set_room_info(r_param, recv_handle, 5);


    int count = 0;
	while (1)
    {
        if (60 == (count++)) 
        {
            unregister_room_receive_module(recv_handle);
        }
        if (120 == count)
        {
            recv_handle = register_room_receive_module(5);
             recv_handle->set_room_info(r_param, recv_handle, 5);
            count = 0;
        }
        sleep(1);
    }
	return 0;
}
Esempio n. 18
0
static int32_t send_msg_to_live_audio(hdb_freame_head_t *fh, stream_handle *M_handle)
{
	int32_t index = 0;
	int32_t audio_vaild_num = 0;
	stream_handle *temp_handle = NULL;
	int return_code = OPERATION_SUCC;
	int8_t *live_frame_data = NULL;
	parse_data_t *live_frame_head = NULL;
	m_msgque  m_live_msgque  ;

	if(M_handle->audio_info == NULL)
	{
		nslog(NS_ERROR,"IMPORT ERROR, < LIVE AUDIO_INTO IS NULL >STREAM ID : %d\n",M_handle->stream_id);
		return RECEIVE_MALLOC_ERR;
	}

	if(M_handle->audio_info->audio_tran_live_into.stream_num == 0)
	{

		nslog(NS_ERROR,"IMPORT ERROR, <LIVE AUDIO NUM IS 0>STREAM ID : %d\n",M_handle->stream_id);
		return OPERATION_SUCC;
	}
	audio_vaild_num = M_handle->audio_info->audio_tran_live_into.stream_num;
//	nslog(NS_ERROR,"AUDIO NUM : %d\n",audio_vaild_num);
	for(index =0 ;index < audio_vaild_num;index ++ )
	{

		// add zl
		temp_handle = (stream_handle *)(M_handle->audio_info->audio_tran_live_into.stream_handle_addr[index]);
		if(START_LIVE != get_live_status(temp_handle))
		{
			continue;
		}

//		nslog(NS_ERROR,"STREAM_ID : %d\n",temp_handle->stream_id);
		live_frame_data = (int8_t *)r_malloc(fh->m_frame_length);

		if(NULL == live_frame_data) {
			if(live_frame_data) {
				r_free(live_frame_data);
				live_frame_data = NULL;
			}
			nslog(NS_ERROR, "malloc is error !!!");
			return_code = RECEIVE_MALLOC_ERR;
			return return_code;
		}

		live_frame_head = (parse_data_t *)r_malloc(sizeof(parse_data_t));

		if(NULL == live_frame_head) {
			if(live_frame_head) {
				r_free(live_frame_head);
				live_frame_head = NULL;
			}

			return_code = RECEIVE_MALLOC_ERR;
			return return_code;
		}

		r_memset(live_frame_head, 0, sizeof(parse_data_t));
		r_memset(live_frame_data, 0, fh->m_frame_length);

		r_memcpy(live_frame_data, M_handle->audio_data, fh->m_frame_length);
		live_frame_head->data_type = R_AUDIO;
		live_frame_head->code_rate = fh->m_colors;
		live_frame_head->sample_rate = fh->m_frame_rate;
		live_frame_head->time_tick = M_handle->recv_time_t.time_audio_tick;

		live_frame_head->data_len = fh->m_frame_length;
		live_frame_head->data = live_frame_data;
		live_frame_data = NULL;
		live_frame_head->flags = fh->m_dw_flags;
		// add zl
	//	live_frame_head->sindex = M_handle->stream_id - 1;
		live_frame_head->sindex = temp_handle->stream_id;
		live_frame_head->index = 0;
		live_frame_head->audio_sindex = M_handle->stream_id - 1;
		live_frame_head->height = fh->m_hight;
		live_frame_head->width = fh->m_width;
		live_frame_head->end_flag = M_handle->live_status;
		live_frame_head->blue_flag = !(fh->m_others);

		// add zl
	//	m_live_msgque.msgtype = M_handle->stream_id;
		m_live_msgque.msgtype = temp_handle->stream_id;
		m_live_msgque.msgbuf = (int8_t *)live_frame_head;

		M_handle->recv_pri.to_live = 1;

		return_code = r_msg_send(temp_handle->msg_recv_to_live, &m_live_msgque, MsgqueLen - sizeof(long), IPC_NOWAIT);

		if(0 > return_code) {
			if(live_frame_head->data) {
				r_free(live_frame_head->data);
				live_frame_head->data = NULL;
			}

			if(live_frame_head) {
				r_free(live_frame_head);
				live_frame_head = NULL;
			}

			if(FALSE == IS_FLAG_BIT_TRUE(M_handle->log_flag, LIVE_BIT)) {
				nslog(NS_WARN, "msgsnd to live failed, msgid = %d, errno = %d, stream_id=%d", M_handle->msg_recv_to_live, errno, M_handle->stream_id);
				SET_FLAG_BIT_TRUE(M_handle->log_flag, LIVE_BIT);//置第1位为1.
			}

			M_handle->recv_pri.to_live = 0;
			return -1;
		}
	}

	SET_FLAG_BIT_FALSE(M_handle->log_flag, LIVE_BIT);//置第1位为0.
	return 0;
}