udp_send_module_handle *UdpSend_init(stream_send_cond_t *src)
{
	if(NULL  == src->ip || strlen(src->ip) > RUdpS_IP_LEN) {
		ERR_PRINTF("ip = [%p]", __TIME__,  __func__, __LINE__, src->ip);
		return NULL;
	}

	udp_send_module_handle *p_udp_send_module_hand = NULL;
	p_udp_send_module_hand = (udp_send_module_handle *)r_malloc(sizeof(udp_send_module_handle));

	if(NULL == p_udp_send_module_hand) {
		ERR_PRINTF("malloc error");
		return NULL;
	}

	memset(p_udp_send_module_hand, 0, sizeof(udp_send_module_handle));
	p_udp_send_module_hand->rtp_hand = (US_RTP_BUILD_HANDLE)UdpSend_rtp_build_init(0, 0);
	p_udp_send_module_hand->udp_hand.prev_video_time = 0;
	p_udp_send_module_hand->udp_hand.snd_video_port = src->video_port;
	p_udp_send_module_hand->udp_hand.snd_audio_port = src->audio_port;
	p_udp_send_module_hand->udp_hand.src_data = (uint8_t *)r_malloc(UdpSend_Max_Frame_Length);

	if(NULL == p_udp_send_module_hand->udp_hand.src_data) {
		ERR_PRINTF("malloc error p_udp_send_module_hand->udp_hand.src_data = [%p]", p_udp_send_module_hand->udp_hand.src_data);
		return NULL;
	}

	sprintf(p_udp_send_module_hand->udp_hand.snd_ip, "%s", src->ip);

	p_udp_send_module_hand->udp_hand.snd_fd = UdpSend_create_sock(&p_udp_send_module_hand->udp_hand);
	return p_udp_send_module_hand;
}
int32_t UdpSend_rtp_data(udp_send_module_handle *p_udp_hand, frame_info_t *frame_info)
{
	int32_t 		ret								= -1;
	US_FRAMEHEAD		frame_head;
	int32_t 		mtu								= MAX_VOD_MTU - 20;
	int32_t 		index							= 0;
	int32_t			video_time 				= 0;
	send_udp_handle *udp_hand = &p_udp_hand->udp_hand;
	US_RTP_BUILD_HANDLE rtp_hand   = p_udp_hand->rtp_hand;


	//ERR_PRINTF("len = %d, time = %d, fd  = %d", freame_info->data_len, freame_info->video_time, p_udp_hand->udp_hand.snd_fd);
	video_time = UdpSend_get_time_tick(udp_hand, frame_info->time_tick);
	UdpSend_set_hdb_freame_head(&frame_head, frame_info);

	if(RUdpS_H264_CODEC_TYPE == frame_info->m_data_codec) {
#if 1
		ret = UdpSend_rtp_build_video_data(rtp_hand, frame_info->m_frame_length, udp_hand->src_data, mtu , video_time, udp_hand, &frame_head);

		if(ret < 0) {
			ERR_PRINTF("rtp_build_video_data is error!\n");
		}

#endif

	} else if(RUdpS_JPEG_CODEC_TYPE == frame_info->m_data_codec) {
#if 1
		printf("UdpSend_rtp_build_jpeg_data rtp_handle=%p,len=%d,src_date=%p,mtu=%d,udp_hand=%p\n", rtp_hand, frame_info->m_frame_length, udp_hand->src_data, mtu, udp_hand);
		ret = UdpSend_rtp_build_jpeg_data(rtp_hand, frame_info->m_frame_length, udp_hand->src_data, mtu , video_time, udp_hand, &frame_head);

		if(ret < 0) {
			ERR_PRINTF("rtp_build_jpeg_data is error!\n");
		}

#endif
	} else {
#if 1
		ret = UdpSend_rtp_build_audio_data(rtp_hand, frame_info->m_frame_length, udp_hand->src_data, frame_info->m_hight, mtu , video_time, udp_hand, &frame_head);

		if(ret < 0) {
			ERR_PRINTF("rtp_build_audio_data is error!\n");
		}

#endif
	}

	return OPERATION_SUCC;
}
Beispiel #3
0
static int videoin_mmap (struct file *file, struct vm_area_struct *vma)
{	
	struct video_device *dev = video_devdata(file);
	videoin_priv_t *priv = (videoin_priv_t *)dev->priv;
	unsigned long start = vma->vm_start;
	unsigned long size  = vma->vm_end-vma->vm_start;
	unsigned long page, pos;
	DBG_PRINTF("%s\n",__FUNCTION__);	
	DBG_PRINTF("start = 0x%x\n",start);
	DBG_PRINTF("size = 0x%x\n",size);
	
	if(bDumpframeBuffer==0)	
		pos = videoIn_buf[0].u32VirtAddr;	
	else
		pos = videoIn_buf[3].u32VirtAddr;
	priv->mmap_bufsize = size;
	while (size > 0) 
	{
		page = vmalloc_to_pfn((void *)pos);
		if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
		{
			ERR_PRINTF("remap error\n");
			return -EAGAIN;
		}
		start += PAGE_SIZE;
		pos += PAGE_SIZE;
		if (size > PAGE_SIZE)
			size -= PAGE_SIZE;
		else
			size = 0;
	}
	return 0;
	
}
Beispiel #4
0
/*
* read data after encode/decode finished
*/
static ssize_t videoin_read(struct file *file, char __user *buf,
		      size_t count, loff_t *ppos)
{
	struct video_device *dev = video_devdata(file);
	videoin_priv_t *priv = (videoin_priv_t *)dev->priv;

	int nonblock = file->f_flags & O_NONBLOCK;
	int ret;
	int size, index;
	videoin_info_t videoininfo;

	DBG_PRINTF("%s\n",__FUNCTION__);	
 
	if(bDumpframeBuffer==0)
	{//Preview pipe
		size = priv->preview_height * priv->preview_width * LCDBPP/8;
		DBG_PRINTF("Packet W*H = %d * %d \n", priv->preview_width , priv->preview_height);
		priv->vaddr = videoIn_buf[0].u32VirtAddr;	
	}
	else
	{//Encode pipe	
		priv->vaddr = videoIn_buf[3].u32VirtAddr;
		if(tEncode.u32Format & 1)
			size = tEncode.u32Width * tEncode.u32Height  * 3/2;
		else
			size = tEncode.u32Width * tEncode.u32Height * 2;		
		DBG_PRINTF("Planar format %s,  W*H = %d * %d \n", (tEncode.u32Format&1) ? "YUV420":"YUV422",  
					tEncode.u32Width , tEncode.u32Height);
	}

	down(&priv->lock);
	if (size >= count)
		size = count;
		
	if (priv->videoin_bufferend == 0)
		index = CONFIG_VIDEOIN_BUFFER_COUNT - 1;
	else
		index = priv->videoin_bufferend - 1;

	DBG_PRINTF("index = 0x%x\n", index);
	DBG_PRINTF("Dst buf addr = 0x%x\n", (UINT32)buf);
	DBG_PRINTF("Dst buf addr = 0x%x\n", (UINT32)(priv->vaddr + index * CONFIG_VIDEOIN_PREVIEW_BUFFER_SIZE));
	if (copy_to_user(buf, priv->vaddr + index * CONFIG_VIDEOIN_PREVIEW_BUFFER_SIZE, size)) 
	{
		ERR_PRINTF("videoin_read copy_to_user error\n");
		ret = -EFAULT;
		goto out;
	}
	*ppos += size;
	
	DBG_PRINTF("*ppos = %d\n", *ppos);

	up(&priv->lock);
	
	ret = size;
out:
	return ret;
}
Beispiel #5
0
int log_init(const char *logfile)
{
    log_pf = fopen(logfile, "w+");
    if (log_pf == NULL) {
        ERR_PRINTF("open log file %s failed.\n", logfile);
        return -1;
    }

    return 0;
}
Beispiel #6
0
int main(int argc, char *argv[])
{
	//1. 配置解析
	if (up_conf_init(argc, argv) <0){
		ERR_PRINTF("up_conf_init failed.\n");
		return -1;
	}
	
	
	//2.
    if (server_init() < 0) {
		ERR_PRINTF("server_init failed.\n");
		return -1;
	}

	server_run();
		

	return 0;
}
void qup_manager_qmi_client_thread(void *unused)
{
  qmi_client_type clnt;
  qmi_txn_handle txn;
  qmi_client_type notifier;
  unsigned int num_services, num_entries=10, i=0, num_services_old=0;
  int rc;
  qmi_cci_os_signal_type os_params;
  qmi_service_info info[10];

  qup_manager_registration(unused);

  os_params.ext_signal = NULL;
  os_params.sig = QMI_CLNT_WAIT_SIG;
  os_params.timer_sig = QMI_CLNT_TIMER_SIG;

  qmi_idl_service_object_type qupm_service_object = qupm_get_service_object_v01();
  if (!qupm_service_object)
  {
    ERR_PRINTF("%s: Unable to get QUP Manager Service Object\n", __func__, 0);
  }

  rc = qmi_client_notifier_init(qupm_service_object, &os_params, &notifier);
  DEBUG_PRINTF("%s: qmi_client_notifier_init, rc=%d \n", __func__, rc);

  /* Check if the service is up, if not wait on a signal */
  while(1)
  {
    QMI_CCI_OS_SIGNAL_WAIT(&os_params, 0);
    QMI_CCI_OS_SIGNAL_CLEAR(&os_params);
    /* The server has come up, store the information in info variable */
    num_entries=10;
    rc = qmi_client_get_service_list( qupm_service_object, info, &num_entries, &num_services);

    if(rc != QMI_NO_ERR || num_services == num_services_old)
      continue;

    num_services_old = num_services;

    for(i = 0; i < num_services; i++)
    {
      rc = qmi_client_init(&info[i], qupm_service_object, qup_manager_ping_ind_cb, NULL, &os_params, &clnt);

      DEBUG_PRINTF("Registered test client with QUP MANAGER service: %d, rc=%d \n", i, rc);
      rc = qup_manager_ping_msg_test(&clnt, &txn);
	  if (rc)
        qmi_client_release(clnt);
    }
  }
}
static void UdpSend_set_hdb_freame_head(US_FRAMEHEAD *fh, frame_info_t *frame_info)
{

	if(RUdpS_H264_CODEC_TYPE == frame_info->m_data_codec) {
		fh->codec 	= 0;
		fh->framerate 	= frame_info->m_frame_rate;
		fh->height 		= frame_info->m_hight;
		fh->width 		= frame_info->m_width;
		fh->samplerate	= frame_info->is_blue;		//是否蓝屏;samplerate  为1时蓝屏.
		fh->framelength	= frame_info->m_frame_length;
		fh->reserve		= 0;
		fh->Iframe		= 0;

		if(frame_info->m_dw_flags != 0) {
			fh->Iframe = 1;
		}

	} else if(RUdpS_JPEG_CODEC_TYPE == frame_info->m_data_codec) {
		fh->codec 	= 2;

		//fh->framerate 	= pd->sample_rate;  	old
		fh->framerate 	= frame_info->m_frame_rate;
		fh->height 		= frame_info->m_hight;
		fh->width 		= frame_info->m_width;
		fh->samplerate	= 0;
		fh->framelength	= frame_info->m_frame_length;
		fh->reserve		= 0;
		fh->Iframe		= 0;

		if(frame_info->m_dw_flags != 0) {
			fh->Iframe = 1;
		}
	} else if(RUdpS_AAC_CODEC_TYPE == frame_info->m_data_codec) {
		fh->codec 		= 1;
		fh->framerate 	= 0;
		fh->height 		= 0;
		fh->width 		= 0;
		fh->framelength	= frame_info->m_frame_length;
		fh->samplerate	= UdpSend_switch_audio_sample_rate(frame_info->m_hight);
		fh->reserve		= 0;
		fh->Iframe 		= 0;

		if(frame_info->m_dw_flags != 0) {
			fh->Iframe = 1;
		}
	} else {
		ERR_PRINTF("pd->data_type is error!\n");
	}
}
int32_t UdpSend_create_sock(send_udp_handle *p_handle)
{
	int 				udp_fd = 0;
	int 				optval 						= 1;
	socklen_t 	size 							= sizeof(struct sockaddr);
	int 				optlen							= 0;
	int 				upd_max_buf			= RUdpS_BUF_MAX_SIZE;
	int  				ret 								= 0;
	struct sockaddr_in 	addr;

	memset((void *)&addr, 0, sizeof(struct sockaddr_in));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(p_handle->snd_video_port);
	addr.sin_addr.s_addr = inet_addr(p_handle->snd_ip);
	udp_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	setsockopt(udp_fd, SOL_SOCKET, SO_REUSEADDR, &optval, size);
	ret = setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &upd_max_buf, sizeof(int32_t));

	if(ret < 0) {
		ERR_PRINTF("SET_SOCKET RECV_BUF IS ERROR! <SOCKET : %d> <SEND_BUF : %d > <ERROR_MESSAGE : %s >", udp_fd, upd_max_buf, strerror(errno));
		return OPERATION_ERR;
	}

	optlen = sizeof(int);
	upd_max_buf = 0 ;
	ret = getsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &upd_max_buf , &optlen);

	if(ret < 0) {
		ERR_PRINTF("GET_SOCKET RECV_BUF IS ERROR! <SOCKET : %d> <SEND_BUF : %d > <ERROR_MESSAGE : %s >", udp_fd, upd_max_buf, strerror(errno));
	}

	//	SUC_PRINTF("udp_fd = %d, upd_max_snd_buf = %d, video_port = %d, audio_port  = %d, snd_ip = %s\n", udp_fd, upd_max_buf, p_handle->snd_video_port,
	//	           p_handle->snd_audio_port, p_handle->snd_ip);
	return udp_fd;

}
Beispiel #10
0
int server_init()
{
	//1. 服务器初始化
	if (sock_listen() < 0){
		ERR_PRINTF("sock_listen\n");
		return -1;
	}

	//2.信号处理
	signal(SIGINT, sig_handler);
	signal(SIGPIPE, SIG_IGN);

	//3.日志

	return 0;
}
Beispiel #11
0
void UdpSend_deinit(udp_send_module_handle *p_udp_send)
{
	if(NULL == p_udp_send) {
		ERR_PRINTF("p_udp_send = [%p]", p_udp_send);
	}

	if(NULL != p_udp_send->udp_hand.src_data) {
		r_free(p_udp_send->udp_hand.src_data);
		p_udp_send->udp_hand.src_data = NULL;
	}

	if(0 < p_udp_send->udp_hand.snd_fd) {
		close_socket(p_udp_send->udp_hand.snd_fd);
		p_udp_send->udp_hand.snd_fd = -1;
	}

	UdpSend_rtp_build_uninit(&p_udp_send->rtp_hand);
	r_free(p_udp_send);
	p_udp_send = NULL;
}
Beispiel #12
0
int main()
{
	int sock_fd = sock_init();
	
	signal(SIGINT, sig_handler);
	signal(SIGPIPE, sig_handler); // SIG_IGN

	struct sockaddr_in cli_addr;
	socklen_t addr_len = sizeof(cli_addr);

	fd_set rdfds;
	int max_fd = 0;
	int i;
	for (i = 0; i <sizeof cli_fd / sizeof cli_fd[0]; ++i) {
		cli_fd[i] = -1;
	}	

	struct timeval tv = {0, 0};

	while (!srv_shutdown) {
		FD_ZERO(&rdfds);
		FD_SET(sock_fd, &rdfds);
		max_fd = sock_fd;
		for (i = 0; i < sizeof cli_fd/ sizeof(cli_fd[0]); ++i) {
			if (cli_fd[i] != -1) {
				FD_SET(cli_fd[i], &rdfds);
				max_fd = MAX(max_fd, cli_fd[i]);
			}
		}
		tv.tv_sec = 2;
		tv.tv_usec = 0;
		i = select(max_fd + 1, &rdfds, NULL, NULL, &tv);
		if (i == -1) {
			perror("select");
			return -1;
		}else if (i == 0) {
			continue;
		}else{
			for (i = 0; i < BACKLOG; ++i) {
				if (cli_fd[i] == -1) {
					continue;
				}
				if (FD_ISSET(cli_fd[i], &rdfds)) {
					int conn_fd = cli_fd[i];
					char buf[BUF_SIZE] = {0};

					int n = read(conn_fd, buf, BUF_SIZE);
					//int n = recv(conn_fd, buf, BUF_SIZE, MSG_DONTWAIT);
					if (n == -1) {
						perror("recv");
					}
					if (n == 0) {
						DBG_PRINTF("connect closed by peer\n");
						FD_CLR(conn_fd, &rdfds);
						cli_fd[i] = -1;
					}else {
						DBG_PRINTF("recv:%s\n", buf);
						write(conn_fd, buf, n);
					}
				}
			}
			if (FD_ISSET(sock_fd, &rdfds)) {
				//new connect coming
				int conn_fd = accept(sock_fd, (struct sockaddr *)&cli_addr, &addr_len);
				DBG_PRINTF("new connection %s:%hu\n", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
				for (i = 0; i < BACKLOG; ++i) {
					if (cli_fd[i] == -1) {
						cli_fd[i] = conn_fd;
						FD_SET(conn_fd, &rdfds);
						break;
					}		 
				}
				if (i == BACKLOG) {
					ERR_PRINTF("client has reach the MAX limit\n");
					char buf[BUF_SIZE] = {0};
					i = snprintf(buf, BUF_SIZE,"[Error] client has reach the max limit of %d\n", BACKLOG);
					write(conn_fd, buf, i);
					close(conn_fd);
				}
			}
		}
	}

	for (i = 0; i < BACKLOG; ++i) {
		if (cli_fd[i] != -1) {
			close(cli_fd[i]);
		}
	}


	return 0;
}
Beispiel #13
0
int server_run()
{
	struct sockaddr_in cli_addr;
	socklen_t addr_len = sizeof(cli_addr);

	fd_set rdfds;
	int max_fd = 0;
	int i;
	for (i = 0; i <sizeof cli_fd / sizeof cli_fd[0]; ++i) {
		cli_fd[i] = -1;
	}	

	struct timeval tv = {0, 0};

	while (!srv_shutdown) {
		FD_ZERO(&rdfds);
		FD_SET(sock_fd, &rdfds);
		max_fd = sock_fd;
		for (i = 0; i < sizeof cli_fd/ sizeof(cli_fd[0]); ++i) {
			if (cli_fd[i] != -1) {
				FD_SET(cli_fd[i], &rdfds);
				max_fd = MAX(max_fd, cli_fd[i]);
			}
		}
		tv.tv_sec = 2;
		tv.tv_usec = 0;
		i = select(max_fd + 1, &rdfds, NULL, NULL, &tv);
		if (i == -1) {
			perror("select");
			return -1;
		}else if (i == 0) {
			continue;
		}else{
			for (i = 0; i < BACKLOG; ++i) {
				if (cli_fd[i] == -1) {
					continue;
				}
				if (FD_ISSET(cli_fd[i], &rdfds)) {

					client_handler(i);
				}
			}
			if (FD_ISSET(sock_fd, &rdfds)) {
				//new connect coming
				int conn_fd = accept(sock_fd, (struct sockaddr *)&cli_addr, &addr_len);
				if (up_conf.verbose){
				DBG_PRINTF("new connection %s:%hu\n", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
				}
				for (i = 0; i < BACKLOG; ++i) {
					if (cli_fd[i] == -1) {
						cli_fd[i] = conn_fd;
						FD_SET(conn_fd, &rdfds);
						break;
					}		 
				}
				if (i == BACKLOG) {
					ERR_PRINTF("client has reach the MAX limit\n");
					char buf[BUF_SIZE] = {0};
					i = snprintf(buf, BUF_SIZE,"[Error] client has reach the max limit of %d\n", BACKLOG);
					write(conn_fd, buf, i);
					close(conn_fd);
				}
			}
		}
	}

	for (i = 0; i < BACKLOG; ++i) {
		if (cli_fd[i] != -1) {
			close(cli_fd[i]);
		}
	}

	return 0;
}