⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mddemo.c

📁 海康威视视频采集卡linux开发包4.22版
💻 C
📖 第 1 页 / 共 3 页
字号:
	full_win.h = WIN_H;
	w_full_area = gtk_drawing_area_new();
	gtk_widget_set_usize(w_full_area, full_win.w, full_win.h);
	gtk_widget_set_events(w_full_area, GDK_EXPOSURE_MASK |
				GDK_BUTTON_PRESS_MASK); 
	gtk_signal_connect(GTK_OBJECT(w_full_area), "expose_event",
				GTK_SIGNAL_FUNC(expose_ev), NULL);
	gtk_signal_connect(GTK_OBJECT(w_full_area), "button_press_event",
				GTK_SIGNAL_FUNC(click2), GINT_TO_POINTER(-1));
	gtk_container_add(GTK_CONTAINER(frame), w_full_area);
	/***************** end channel window **********************/
	
	
	/****************** opearate window *********************/
	frame = gtk_frame_new(NULL);
	gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE/*FALSE*/, TRUE/*FALSE*/, 0);
	
	vbox1 = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(frame), vbox1);
	
	//status information	
	frame = gtk_frame_new("Status Information");
	gtk_box_pack_start(GTK_BOX (vbox1), frame, TRUE, FALSE, 0);
	
	vbox2 = gtk_vbox_new(FALSE,0);
	gtk_container_add(GTK_CONTAINER(frame), vbox2);

	for(i = 0; i < 3; i++)
	{
		hbox2 = gtk_hbox_new(FALSE, 0);
		gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 5);
		label = gtk_label_new(status_str[i]);
		gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 5);

		w_status_buffer[i] = gtk_text_buffer_new(NULL);
		w_status[i] = gtk_text_view_new_with_buffer(w_status_buffer[i]);

		gtk_widget_set_usize(w_status[i], 100,25);
		if(i ==2)
			gtk_widget_set_usize(w_status[i], 60,25);
		gtk_text_view_set_editable(GTK_TEXT_VIEW(w_status[i]), FALSE);
		gtk_box_pack_start(GTK_BOX(hbox2), w_status[i], FALSE, FALSE,0);
				
	}

	/* frame information */
	frame = gtk_frame_new("Channel Info");
	gtk_box_pack_start(GTK_BOX (vbox1), frame, /*FALSE*/TRUE, FALSE, 0);
	vbox2 = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(frame), vbox2);
	
	// chan index
 	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("Channel");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);

	w_channel_buffer = gtk_text_buffer_new(NULL);
	w_channel = gtk_text_view_new_with_buffer(w_channel_buffer);

	gtk_widget_set_usize(w_channel, 95, 24);
	gtk_box_pack_start(GTK_BOX(hbox2), w_channel, FALSE, FALSE, 0);

	//set server ip
	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("Set serverip");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);
	w_set_serverip = gtk_entry_new_with_max_length(16);
	gtk_widget_set_usize(w_set_serverip, 95, 24);
	gtk_entry_set_text(GTK_ENTRY(w_set_serverip),defaultserverip);
	gtk_box_pack_start(GTK_BOX(hbox2), w_set_serverip, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_set_serverip),"activate",
			GTK_SIGNAL_FUNC(set_serverip_callback), NULL);

	//set server ip
	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("Set server chan");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);
	w_set_serverchan = gtk_entry_new_with_max_length(1);
	gtk_widget_set_usize(w_set_serverchan, 95, 24);
	gtk_entry_set_text(GTK_ENTRY(w_set_serverchan),"0");
	gtk_box_pack_start(GTK_BOX(hbox2), w_set_serverchan, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_set_serverchan),"activate",
			GTK_SIGNAL_FUNC(set_serverchan_callback), NULL);

	 //get bit rate
	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("BitRate(bps)");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);

	w_bit_rate_buffer = gtk_text_buffer_new(NULL);
	w_bit_rate = gtk_text_view_new_with_buffer(w_bit_rate_buffer);

	gtk_widget_set_usize(w_bit_rate, 95, 24);
	gtk_box_pack_start(GTK_BOX(hbox2), w_bit_rate, FALSE, FALSE, 0);
 	
	// get decode frame rate
 	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("frame rate:");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);
	
	w_decode_framerate_buffer = gtk_text_buffer_new(NULL);
	w_decode_framerate = gtk_text_view_new_with_buffer(w_decode_framerate_buffer);

	gtk_widget_set_usize(w_decode_framerate, 95, 24);
	gtk_box_pack_start(GTK_BOX(hbox2), w_decode_framerate, FALSE, FALSE, 0);
 	
	// get the info for the decode frames
 	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("Total Dec frames:");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);

	w_totalframe_buffer = gtk_text_buffer_new(NULL);
	w_totalframe = gtk_text_view_new_with_buffer(w_totalframe_buffer);

	gtk_widget_set_usize(w_totalframe, 95, 24);
	gtk_box_pack_start(GTK_BOX(hbox2), w_totalframe, FALSE, FALSE, 0);
 	
	/******************* decode file  ******************/
	frame = gtk_frame_new("Decode on MD");
	gtk_box_pack_start(GTK_BOX(vbox1), frame, TRUE, FALSE, 0);

	vbox2 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5);
	gtk_container_add(GTK_CONTAINER(frame), vbox2);

	//decode file
	hbox1 = gtk_hbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(hbox1), 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox1, TRUE, FALSE, 5);
	
	w_decodefile_flag = gtk_check_button_new_with_label("DecodeFile");
    gtk_object_set_data_full(GTK_OBJECT(md_window), "b_DecodeFile", w_decodefile_flag,
                        (GtkDestroyNotify)0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_decodefile_flag), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_decodefile_flag, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_decodefile_flag), "clicked",
			GTK_SIGNAL_FUNC(decode_file), NULL);
	//decode stream 
	hbox1 = gtk_hbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(hbox1), 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox1, TRUE, FALSE, 5);

	w_decodestream = gtk_check_button_new_with_label("DecodeStream");
    gtk_object_set_data_full(GTK_OBJECT(md_window), "b_DecodeStream", w_decodestream,
                        (GtkDestroyNotify)0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_decodestream), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_decodestream, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_decodestream), "clicked",
			GTK_SIGNAL_FUNC(decode_stream), NULL);

	//video out
	hbox1 = gtk_hbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(hbox1), 0);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox1, TRUE, FALSE, 5);

	w_videoout = gtk_check_button_new_with_label("VideoAudioOut");
	gtk_object_set_data_full(GTK_OBJECT(md_window), "b_videoaudioout", w_videoout,
                        (GtkDestroyNotify)0);
	hik_set_sensitive("b_videoaudioout", 0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_videoout), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_videoout, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_videoout), "clicked",
			GTK_SIGNAL_FUNC(video_out), NULL);

	/*******************************************************/
	// exit button
	hbox1 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(hbox1), 0);
	gtk_box_pack_start(GTK_BOX (vbox1), hbox1, FALSE, FALSE, 5);
	w_buttons[2] = gtk_button_new_with_label(button_str[2]);
	gtk_signal_connect (GTK_OBJECT (w_buttons[2]), "clicked",
			GTK_SIGNAL_FUNC (process_buttons), GINT_TO_POINTER(2));
	gtk_box_pack_start(GTK_BOX (hbox1), w_buttons[2], FALSE, /*TRUE*/FALSE, 0);
	/******************************************/
	/* setup timer*/
	count_timer = g_timer_new();
	processtimer = gtk_timeout_add(1000/5, (GtkFunction)process_time, NULL);	/* 1/5s */

	gtk_widget_show_all(md_window);

	/* init default parameters */
	for(i=0; i<TotalChannel;i++)
	{
		sprintf(serverchan[i],"0");
		sprintf(serverip[i], defaultserverip);
	}
	
	/* the sdl hack must set after the show */
    sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", GDK_WINDOW_XWINDOW(w_full_area->window));
    putenv(SDL_windowhack);
/* inital the sdl */
	XInitThreads();
    putenv("SDL_VIDEO_YUV_HWACCEL=0");
                                                                                                                         
    fprintf(stderr,"Init the sdl...");
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
    {
            fprintf(stderr,"<sdk_error> init sdl failed!%s\n",SDL_GetError());
            return -1;
    }
    fprintf(stderr,"ok!\n");

    pOverlayScreen = SDL_SetVideoMode(WIN_W, WIN_H, 0, SDL_HWSURFACE);
    if(pOverlayScreen == NULL)
    {
            fprintf(stderr,"<sdk_error> create the sdl screen failed! for %s!\n", SDL_GetError());
            SDL_Quit();
            return -1;
    }
	/*SDL init finished*/
	//get coordinate of video display window
	
	gdk_window_get_deskrelative_origin(w_full_area->window,
			&full_win.x, &full_win.y);
	full_rect.x = 0;//full_win.x;
	full_rect.y = 0;//full_win.y;
	full_rect.w = full_win.w;
	full_rect.h = full_win.h;

	printf("full window at (%d, %d), w = %d, h = %d\n", full_win.x, full_win.y, full_win.w, full_win.h);
	int chan = 1;
	switch(TotalChannel)
	{
		case 1:
			chan = 1;
			break;
		case 2:
		case 3:
		case 4:
			chan = 2;
			break;
		case 5:
		case 6:
		case 7:
		case 8:
			chan = 3;
			break;
		default:
			chan = 4;
			break;
	}
	memset(bDisplayOpen, 0, sizeof(bDisplayOpen));
	memset(displaythreadrun, 0, sizeof(displaythreadrun));
	memset(bDisplayClose, 0, sizeof(bDisplayClose));

	for(i = 0; i < TotalChannel; i++)
	{
		int* threadarg;
		threadarg = (int*)malloc(sizeof(int));
		*threadarg = i;
		v_win[i].w = full_win.w/chan;
		v_win[i].h = full_win.h/chan;
		dstRect[i].x = (i%chan) * v_win[i].w;
		dstRect[i].y =  (i/chan) * v_win[i].h;		
		dstRect[i].w = v_win[i].w;
		dstRect[i].h = v_win[i].h;

		displaythreadrun[i] = 1;
		sem_init(&beginSem[i], 0, 0);
		sem_init(&displaySem[i], 0, 0); //fixed at 2005.10.8
		pthread_attr_init(&attr);
	        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
		pthread_create(&hDisplayThread[i], &attr, videodisplay, (void*)threadarg);	
	}
#ifdef  RAWSTREAM
        {
                char    filename[64];
                RegisterDisplayVideoCaptureCallback((IMAGE_STREAM_CALLBACK)ImageStreamCallback, NULL);
                sprintf(filename, "displayimagefile.yuv");
                imagefile_fd = open(filename, O_WRONLY | O_CREAT, 0777);
        }
#endif

	
	//get time
	now = time(NULL);
	tm = localtime(&now);
	strftime(timebuf, sizeof(timebuf), "%Y-%m-%d", tm);
	sprintf(starttime,"%s  ",timebuf);

	gtk_text_buffer_set_text(w_status_buffer[0], timebuf, strlen(timebuf)); 
	gtk_text_view_set_buffer(GTK_TEXT_VIEW(w_status[0]), w_status_buffer[0]);
//	gtk_text_insert(GTK_TEXT_VIEW(w_status[0]), NULL, NULL, NULL, timebuf, -1);

	strftime(timebuf, sizeof(timebuf), "%T", tm);
	strcat(starttime, timebuf);
	gtk_text_buffer_set_text(w_status_buffer[1], timebuf, strlen(timebuf)); 
	gtk_text_view_set_buffer(GTK_TEXT_VIEW(w_status[1]), w_status_buffer[1]);
//	gtk_text_insert(GTK_TEXT_VIEW(w_status[1]), NULL, NULL, NULL, timebuf, -1);

	gtk_main();

	return 0;
}


void*	PlayOver(void* arg)
{
	UINT	chan = *(UINT*)arg;
//	fprintf(stderr,"<demo_info> .............. in play over for chan %d!\n", chan);
	sem_wait(&FileEndSem[chan]);
	bDisplayOpen[chan] = 0;		//to stop the display
	sem_post(&displaySem[chan]);   /* fixed at 2005.10.8 */
	fprintf(stderr,"<demo_info> ......................... have get the play over sem for chan%d!flag :%d\n", chan, bDisplayOpen[chan]);

	HW_Stop(ChannelHandle[chan]);
	HW_CloseFile(ChannelHandle[chan]);
	sem_destroy(&FileEndSem[chan]);
	if(bfileopenok)
		bfileopenok--;
//	fprintf(stderr,"<demo_info> in play over thread, the file open count is %d!\n", bfileopenok);
	
	if(bfileopenok==0)
	{
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_decodefile_flag), FALSE);	
		gdk_window_clear(w_full_area->window);
	}
	
	if(arg)
		free(arg);
	pthread_exit(NULL);
}

void*	videodisplay(void* arg)
{
	UINT	chan = *(UINT*)arg;
	UINT	useSyncSem = 1;
    ULONG   fnum;

	while(1)
	{
		sem_wait(&beginSem[chan]);
		if(displaythreadrun[chan] == 0)
			break;
		memset(&displayconf[chan], 0, sizeof(displayconf[chan]));
		displayconf[chan].w = dstRect[chan].w;
		displayconf[chan].h = dstRect[chan].h;
//		sem_init(&displaySem[chan], 0, 0);
		displayconf[chan].SyncSem = &displaySem[chan];
		fprintf(stderr,"<demo_info> to start the display for chan%d!\n", chan);
		if(HW_StartDecVgaDisplay(ChannelHandle[chan], &displayconf[chan], useSyncSem) < 0)
		{
			fprintf(stderr,"<demo_info>start video display (port %d) failed, for 0x%x\n",chan, GetLastErrorNum());
			goto DISPLAYEXIT;
		}
		fprintf(stderr,"<demo_info> Chan %d Start video display ok, the sync sem is 0x%x, addr is 0x%x!\n", chan, displayconf[chan].SyncSem, displayconf[chan].dataAddr);
		pOverlaySurface[chan] = SDL_CreateYUVOverlay(displayconf[chan].w, displayconf[chan].h, SDL_YV12_OVERLAY, pOverlayScreen);
		if(pOverlaySurface[chan] == NULL)
		{
			fprintf(stderr,"chan %d the SDL overlay surface create failed!\n", chan);
			goto DISPLAYEXIT;
		}
		fprintf(stderr,"<demo_info> Chan %d Create the yuv overlay ok!\n", chan);
		bDisplayOpen[chan] = 1;		
		bDisplayClose[chan] = 0;
		while(bDisplayOpen[chan])
		{
			usleep(100);
			
			if(sem_wait(&displaySem[chan]) == 0)
			{
                                HW_GetCurrentFrameNum(chan,&fnum);
/*
                                if(chan==0)
                                        fprintf(stderr,"<dem_info> chan%d, frame number is %d!\n", chan, fnum);
*/

				SDL_LockYUVOverlay(pOverlaySurface[chan]);
				memcpy(*(pOverlaySurface[chan]->pixels), displayconf[chan].dataAddr, displayconf[chan].imageSize);
				SDL_UnlockYUVOverlay(pOverlaySurface[chan]);
				SDL_DisplayYUVOverlay(pOverlaySurface[chan], &dstRect[chan]);
			}
		}
		if(HW_StopDecChanVgaDisplay(ChannelHandle[chan])<0)
		{
			fprintf(stderr,"<demo_info>   stop the video display failed!error: 0x%x!\n", GetLastErrorNum());
			goto DISPLAYEXIT;
		}
		SDL_LockYUVOverlay(pOverlaySurface[chan]);
		memset(*(pOverlaySurface[chan]->pixels), 0, displayconf[chan].imageSize);
		SDL_UnlockYUVOverlay(pOverlaySurface[chan]);
		
		SDL_FreeYUVOverlay(pOverlaySurface[chan]);
		bDisplayClose[chan] = 1;
		fprintf(stderr,"<demo_info>........................... stop display for chan%d!\n", chan);
	}
DISPLAYEXIT:
	fprintf(stderr,"<demo_info> exit the video display thread for chan%d!\n", chan);
	sem_destroy(&displaySem[chan]);
	if(arg)
		free(arg);
	pthread_exit(NULL);
}

void ReadDataCallBack(int StockHandle,char * pPacketBuffer,int nPacketSize)
{
	int	 i;
	int	 chan;
//	fprintf(stderr,"!");
	chan = StockHandle;
	datasum[chan]+=nPacketSize;
	if(HW_InputData(ChannelHandle[chan], pPacketBuffer, nPacketSize)<0)
	{
	//	fprintf(stderr,"<demo_info> input data error:0x%x\n", GetLastErrorNum());
	}
                                                                                                                             
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -