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

📄 dsdemo.c

📁 海康威视视频采集卡linux开发包4.22版
💻 C
📖 第 1 页 / 共 5 页
字号:
	gtk_box_pack_start(GTK_BOX(vbox2), hbox2, TRUE, FALSE, 0);
	label = gtk_label_new("SetBitRate(bps)");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 0);
	w_set_bit_rate = gtk_entry_new_with_max_length(10);
	gtk_widget_set_usize(w_set_bit_rate, 95, 24);
	gtk_entry_set_text(GTK_ENTRY(w_set_bit_rate),"0");
	gtk_box_pack_start(GTK_BOX(hbox2), w_set_bit_rate, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_set_bit_rate),"activate",
			GTK_SIGNAL_FUNC(set_bit_rate_callback), NULL);

	hbox2 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox1), hbox2, TRUE, FALSE, 2);
	label = gtk_label_new("Net User Count");
	gtk_box_pack_start(GTK_BOX(hbox2), label, TRUE, FALSE, 2);

	w_netusercount_buffer = gtk_text_buffer_new(NULL);
	w_netusercount = gtk_text_view_new_with_buffer(w_netusercount_buffer);

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

	/******* set video info ******/
	frame = gtk_frame_new("Video Info");
	gtk_box_pack_start(GTK_BOX (vbox1), frame, /*FALSE*/TRUE, FALSE, 0);

	vbox2 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5);
	gtk_container_add(GTK_CONTAINER(frame), vbox2);
		
	for(i = 0; i < 4; i++){
		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*/, /*TRUE*/FALSE, 0);
		
		label = gtk_label_new(info_str[i]);
		//gtk_widget_set_usize(GTK_WIDGET(label), 60, 20);
		gtk_box_pack_start(GTK_BOX (hbox1), label, TRUE/*FALSE*/, /*TRUE*/FALSE, 0);
		if(i ==0)
			w_adj[i] = gtk_adjustment_new(v_info[0].Brightness, 1, 256, 1, 1, 0);
		if(i ==1)
			w_adj[i] = gtk_adjustment_new(v_info[0].Contrast, 1, 128, 1, 1, 0);
		if(i ==2)
			w_adj[i] = gtk_adjustment_new(v_info[0].Saturation, 1, 128, 1, 1, 0);
		if(i ==3)
			w_adj[i] = gtk_adjustment_new(v_info[0].Hue, 1, 256, 1, 1, 0);
		
		gtk_signal_connect(GTK_OBJECT(w_adj[i]), "value_changed", GTK_SIGNAL_FUNC(ch_bscale), GINT_TO_POINTER(i));
		//range
		w_info_scale[i] = gtk_hscale_new(GTK_ADJUSTMENT(w_adj[i]));
		gtk_widget_set_usize(GTK_WIDGET(w_info_scale[i]), 90, 30);
		gtk_range_set_update_policy(GTK_RANGE(w_info_scale[i]), GTK_UPDATE_CONTINUOUS);
		gtk_scale_set_draw_value(GTK_SCALE(w_info_scale[i]), FALSE);

		gtk_box_pack_start(GTK_BOX (hbox1), w_info_scale[i], TRUE/*FALSE*/, /*TRUE*/FALSE, 0);
	}
	/********* end video info ***********/
	
	
	//capture	
	//frame = gtk_frame_new("录像");
	frame = gtk_frame_new(NULL);
	gtk_box_pack_start(GTK_BOX(vbox1), frame, TRUE/*FALSE*/, /*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);
	
	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*/, /*TRUE*/FALSE, 5);

	w_record_flag = gtk_check_button_new_with_label("Record");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_record_flag), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_record_flag, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_record_flag), "clicked",
			GTK_SIGNAL_FUNC(record_callback), NULL);
	//motion detect
	w_motion_detect_flag = gtk_check_button_new_with_label("MotionDetect");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_motion_detect_flag), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_motion_detect_flag, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_motion_detect_flag), "clicked",
			GTK_SIGNAL_FUNC(motion_detect_callback), NULL);
	
	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*/, /*TRUE*/FALSE, 5);

	//audio preview
	w_audio_preview = gtk_check_button_new_with_label("AudioPreview");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_audio_preview), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_audio_preview, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_audio_preview), "clicked",
			GTK_SIGNAL_FUNC(audio_preview_callback), NULL);
	//net transfer
	w_net_transfer = gtk_check_button_new_with_label("NetTransfer");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_net_transfer), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_net_transfer, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_net_transfer), "clicked",
			GTK_SIGNAL_FUNC(net_transfer_callback), NULL);

	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*/, /*TRUE*/FALSE, 5);

	//preview	
	w_preview = gtk_check_button_new_with_label("Preview");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_preview), TRUE);	//active preview 
	//gtk_box_pack_start(GTK_BOX(vbox2), w_preview, TRUE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox1), w_preview, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_preview), "clicked",
			GTK_SIGNAL_FUNC(preview_callback), NULL);
	//string to client : test add at 2004.8
	w_stringtoclient = gtk_check_button_new_with_label("StringToClient");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_stringtoclient), FALSE);
	gtk_box_pack_start(GTK_BOX(hbox1), w_stringtoclient, TRUE, FALSE, 0);
	gtk_signal_connect(GTK_OBJECT(w_stringtoclient), "clicked",
			GTK_SIGNAL_FUNC(stringtoclient_callback), NULL); 
	

	/* get original image */
	vbox2 = gtk_vbox_new(FALSE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
	gtk_box_pack_start(GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
	w_image = gtk_button_new_with_label("Get Image");
	gtk_widget_set_usize(w_image, 120, 25);
	gtk_signal_connect (GTK_OBJECT (w_image), "clicked",
			GTK_SIGNAL_FUNC (process_buttons), GINT_TO_POINTER(3));
	gtk_box_pack_start(GTK_BOX (vbox2), w_image, TRUE,FALSE, 10);
	/* Capture a I frame */
	w_I_frame = gtk_button_new_with_label("Capture I Frame");
	gtk_signal_connect (GTK_OBJECT (w_image), "clicked",
			GTK_SIGNAL_FUNC (process_buttons), GINT_TO_POINTER(4));
	gtk_widget_set_usize(w_I_frame, 120, 25);
	gtk_box_pack_start(GTK_BOX (vbox2), w_I_frame, FALSE,FALSE, 0);
			
	/***********  exit ****************/
	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);

	//initial datas
	memset(old_frames, 0, sizeof(old_frames));
	memset(current_frames, 0, sizeof(current_frames));
	memset(bit_rate_time, 0, sizeof(bit_rate_time));
	memset(bit_rate_size, 0, sizeof(bit_rate_size));
	memset(net_head_flag, 0, sizeof(net_head_flag));
        memset(subchan_net_head_flag, 0, sizeof(subchan_net_head_flag));

	//setup timer 
	count_timer = g_timer_new();
	
	processtimer = gtk_timeout_add(1000/5, (GtkFunction)process_time, NULL);	/* 1/5s */
	looptimer = gtk_timeout_add(1000 * timeconst, (GtkFunction)process_time_loop, NULL); /* timeconst/60 minutes */
#ifdef 	USE_PREVIEW_TIMER
        /* set the preview flush timer*/
        previewtimer = gtk_timeout_add(40, (GtkFunction)preview_loop, NULL); /* 40 millisecond*/
#endif
#ifdef TEST_GETORIIMAGE
	/* set the get original image timer*/
	imagetimer = gtk_timeout_add(4 * 1000, (GtkFunction)getimage_loop, NULL); /* 4 second */
#endif


	gtk_widget_show_all(window);
	
	/* 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*/


	for(i = 0; i < MAX_PORT; i++)
		count[i] = 0;

	if(InitDSPs() == 0)	//fixed at 2004.12.3
	{
		printf("Initial DSP failed.error code is 0x%x\n", GetLastErrorNum());
		exit(1);
	}

	//get total cards and ports
	totalcard = GetTotalDSPs();
	totalport = GetTotalChannels();

//	totalport = 1;	//debug 	/* yxq test at 2005.9.29 for high quality d1 */

	printf("total cards = %d, total ports = %d\n", totalcard, totalport);
	
	limitsize =  timeconst * (totalport * fixsize) /1024; /* KB */
	printf("limit free space : %luKB\n", limitsize);
	
#ifdef LOGO
	/* set logo */
	//logoptr = (unsigned char *)malloc(128 * 32 * 2);
	logoptr = (unsigned char *)malloc(128 * 128 * 2);
	memset(logoptr, 0, sizeof(logoptr));
	if(LoadYUVFromBmpFile("logo.bmp", logoptr, 128 * 128 * 2, &logo_w, &logo_h)<0)
		fprintf(stderr,"<demo_info> load bmp file error! error code is 0x%x!\n", GetLastErrorNum());
#endif
	/* open channel */
	for(i = 0; i < totalport; i++)
	{
		if((ChannelHandle[i] = ChannelOpen(i, pStreamRead)) < 0)
		{
			fprintf(stderr, "open port %d failed\n", i);
			for(j = 0; j< i; j++)
				ChannelClose(ChannelHandle[j]);
			exit(1);
		}
		fprintf(stderr,"the Chan%d open ok!\n", i);
/*
		//test the mask setup 
		RECT r={8,327,16,335};
		SetupMask(ChannelHandle[i],&r,1);
*/

		//SetStreamType(ChannelHandle[i], STREAM_TYPE_VIDEO);
		//SetDefaultQuant(ChannelHandle[i],12,12,17);
	
		GetVideoPara(ChannelHandle[i],
		       &videostandard[i],	
			&v_info[i].Brightness, &v_info[i].Contrast, &v_info[i].Saturation, &v_info[i].Hue);
#ifdef OSDDEMO
		//SetOsdDisplayMode(ChannelHandle[i], 0xff, 1, 0x0000, format1, format2);
		{
			unsigned short* p[2];	
			p[0] = format1;
			p[1] = format2;
			fprintf(stderr,"<demo_info> to set osd display mode ex!\n");
			SetOsdDisplayModeEx(ChannelHandle[i], 0xff, 1, 0x2020000, 2, p);
		}
	
		/* yxq test at 2004.4.28*/
		SetOsd(ChannelHandle[i], 1);
#endif
		
#ifdef LOGO
 		if(videostandard[i] == StandardNTSC)	
			SetLogo(ChannelHandle[i], 576, 448, logo_w, logo_h, logoptr);
	        else
			if(SetLogo(ChannelHandle[i], 576, 544, logo_w, logo_h, logoptr)==0)
				fprintf(stderr,"<demo_info> set the logo ok! chan%d\n", i);
			else
				fprintf(stderr,"<demo_info> set the logo failed!chan%d,w*h: %d*%d,error:0x%x\n",i, logo_w, logo_h, GetLastErrorNum());
		//SetLogoDisplayMode(ChannelHandle[i], 0x0, 0x0, 0x0, 1, 0x0201);
		SetLogoDisplayMode(ChannelHandle[i], 0xff, 0x0, 0x0, 0, 0);
#endif		
		
		      
		AdjustMotionDetectPrecision(ChannelHandle[i], 2, 2, 0);	/* disable slow motion detect */
		//There is constant bit rate now! 
		SetBitrateControlMode(ChannelHandle[i], brc);

		SetStreamType(ChannelHandle[i], stream_type);
		
		if(videostandard[i] == StandardNTSC)
			video_height[i] = 480;
		else
			video_height[i] = 576;
	
	}
#ifdef	RAWSTREAM
	{
		char	filename[64];
		RegisterImageStreamCallback((IMAGE_STREAM_CALLBACK)ImageStreamCallback, NULL);
		sprintf(filename, "imagefile.yuv");
		imagefile_fd = open(filename, O_WRONLY | O_CREAT, 0777);
	}
#endif
//set QCIF and 2CIF or CIFQCIF
	memset(qcif_flag, 0, sizeof(qcif_flag));
	memset(hcif_flag, 0, sizeof(hcif_flag));
//	memset(cifqcif_flag, 1, sizeof(cifqcif_flag));
	memset(D1_flag, 0, sizeof(D1_flag));
	memset(dcif_flag, 0, sizeof(dcif_flag));

//	qcif_flag[0] = 1;
//	dcif_flag[1] = 1;
//	hcif_flag[2] = 1;
//	D1_flag[0] = 1;
//	D1_flag[1] = 1;
//	dcif_flag[0] = 1;
//	qcif_flag[1] = 1;
//	cifqcif_flag[0] = 1;
	for(i = 0; i<totalport; i++){
		SetupBitrateControl(ChannelHandle[i],768000 );
	//	SetupBitrateControl(ChannelHandle[i],1500000 );
		if(qcif_flag[i])
		{
			SetEncoderPictureFormat(ChannelHandle[i], ENC_QCIF_FORMAT);
		}
		else if(hcif_flag[i])
		{
			SetEncoderPictureFormat(ChannelHandle[i], ENC_2CIF_FORMAT);
		}
		else if(cifqcif_flag[i])
			{
//				SetEncoderPictureFormat(ChannelHandle[i], ENC_CIFQCIF_FORMAT);
				SetEncoderPictureFormat(ChannelHandle[i], ENC_4CIF_FORMAT);
				SetSubEncoderPictureFormat(ChannelHandle[i], ENC_QCIF_FORMAT);
				SetupSubChannel(ChannelHandle[i], 1);
				SetIBPMode(ChannelHandle[i], 25, 0, 0, 15);
				SetupSubChannel(ChannelHandle[i], 0);
			}
		else if(D1_flag[i])
		{
			SetEncoderPictureFormat(ChannelHandle[i], ENC_4CIF_FORMAT);
		}
		else if(dcif_flag[i])
		{
			SetEncoderPictureFormat(ChannelHandle[i], ENC_DCIF_FORMAT);
		}
		else{
			SetEncoderPictureFormat(ChannelHandle[i], ENC_CIF_FORMAT);
			SetIBPMode(ChannelHandle[i],25,2,0,25);
			SetDefaultQuant(ChannelHandle[i], 15, 15, 20);
		}
	}
	
	

	/* get cardno */
	{
		unsigned int boardtype;
		char serialno[20], serialno_str[20];
		
		for(i = 0; i < totalport; i++)
		{
			GetBoardInfo(ChannelHandle[i], &boardtype, serialno);
			for(j = 0; j < 12; j++){
				serialno_str[j] = serialno[j] + 0x30;
			}
			serialno_str[j] = '\0';
			printf("card[%d]'s serialno = %s\n", i, serialno_str);
			
		}
	}
#if 1
	//get coordinate of video output window
	//and start preview
	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;
        if(totalport <= 4)
             chan = 2;
        else{
                if(totalport <= 9)
                     chan = 3;
                else{
                     if (totalport <= 16)
                                chan = 4;
                     else{
                          if(totalport <= 25)
                                chan = 5;
                          else
                                chan = 6;
                        }
                }
        }

	memset(bPreviewOpen, 0, sizeof(bPreviewOpen));
	memset(previewconf, 0, sizeof(previewconf));
	memset(bPreviewThreadRun, 0, sizeof(bPreviewThreadRun));
	/* yxq test the preivew */
	for(i = 0; i < totalport; i++)
	{
#if 1
		v_win[i].w = full_win.w/chan;
		v_

⌨️ 快捷键说明

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