📄 dsdemo.c
字号:
#else
#ifdef RAWSTREAM
port = 1;
/* yxq test the get image stream at 4.19 */
if(GTK_TOGGLE_BUTTON(widget)->active)
{
//start
if(SetImageStream(ChannelHandle[port], 1, 5, 704, 576, imageBuf)<0)
fprintf(stderr,"<demo_info> set the image stream failed!\n");
fprintf(stderr,"<demo_info> start image raw stream ok!\n");
}else
if(SetImageStream(ChannelHandle[port], 0, 5, 704, 576, imageBuf)<0)
fprintf(stderr,"<demo_info> set the image stream failed!\n");
#endif
#endif
}
void set_bit_rate_callback(GtkWidget *widget)
{
const char *str;
long max_bps;
str = gtk_entry_get_text(GTK_ENTRY(w_set_bit_rate));
strcpy(set_bit_rate_str[selectport], str);
max_bps = atol(str);
printf("selectport = %d, bps = %ld\n", selectport, max_bps);
SetupBitrateControl(ChannelHandle[selectport], max_bps);
}
/* add at 2002.5.14 for audio preview */
void audio_preview_callback(GtkWidget *widget, gpointer data)
{
int ret;
ret = SetAudioPreview(ChannelHandle[audiopreviewport], GTK_TOGGLE_BUTTON(widget)->active);
if(ret < 0)
printf("Audio preview error.\n");
}
/* record operation*/
void record_callback(GtkWidget *widget, gpointer data)
{
int port, retval;
#if 1
if(GTK_TOGGLE_BUTTON(w_record_flag)->active){ // start capture
for(port = 0; port < totalport; port++)
{
#ifdef WRITE_FILE
sprintf(filename[port], "%s/test%02d%d.mp4", savepath, port, count[port]);
if((record_fd[port] = open(filename[port], O_WRONLY | O_CREAT, 0777)) < 0)
perror(">>>open");
else
{
ftruncate(record_fd[port], 0);
}
sprintf(filename[port], "%s/test%02d%d.dat", savepath, port, count[port]);
if((index_fd[port] = open(filename[port], O_WRONLY | O_CREAT, 0777)) < 0)
perror(">>>open");
else
{
ftruncate(index_fd[port], 0);
}
if(cifqcif_flag[port])
{
sprintf(filename[port], "%s/test%02d%d_1.mp4", savepath, port, count[port]);
if((cifqcif_fd[port] = open(filename[port], O_WRONLY | O_CREAT, 0777)) < 0)
perror(">>>open the subchannel");
else
{
ftruncate(cifqcif_fd[port], 0);
}
}
zero_count[port] = 0;
if(net_flag){
write(record_fd[port], file_head[port], 40);
if(cifqcif_flag[port])
write(cifqcif_fd[port], cifqciffile_head[port], 40);
record_flag[port] = 1;
}
else{
g_timer_start(count_timer);
retval = StartVideoCapture(ChannelHandle[port]);
if(retval < 0)
{
record_flag[port] = 0;
printf("StartVideoCapture failed. \n");
}
record_flag[port] = 1;
if(cifqcif_flag[port])
{
retval = StartSubVideoCapture(ChannelHandle[port]);
fprintf(stderr,"<demo_info> start sub channel capture for chan%d!ret is %x\n", port,retval);
}
}
}
#endif
}
else //stop capture
{
for(port = 0; port < totalport; port++){
end_record(port);
record_flag[port] = 0;
if(!net_flag){
g_timer_stop(count_timer);
if(StopVideoCapture(ChannelHandle[port]) < 0)
printf("record_callbacl: StopvideoCapture(port %d) failed\n", port);
}
current_frames[port] = 0;
old_frames[port] = 0;
}
memset(count, 0, sizeof(count));
}
#endif
}
void stringtoclient_callback(GtkWidget *widget, gpointer data)
{
int port;
char messagebuf[256];
/* test the string to client */
for(port = 0; port < 20; port++)
{
sprintf(messagebuf, "server message to client, no.%d!\n", port);
MP4_ServerStringToClient("192.0.0.128", messagebuf, strlen(messagebuf));
fprintf(stderr,"<demo_info> have send the len %d message to client!\n", strlen(messagebuf));
}
}
void motion_detect_callback(GtkWidget *widget, gpointer data)
{
int port;
if(GTK_TOGGLE_BUTTON(w_motion_detect_flag)->active){ // start motion_detect
for(port = 0; port < totalport; port++)
{
fprintf(stderr,"<demo_info> start chan%d 's motion detection!\n", port);
StartMotionDetection(ChannelHandle[port]);
}
}
else{//stop motion detect
for(port = 0; port < totalport; port++){
StopMotionDetection(ChannelHandle[port]);
}
memset(motion_data, 0, sizeof(motion_data));
}
}
/* for motion detect */
void motion_detect(int channel)
{
int x, y;
float ratioX, ratioY;
unsigned int *pBuf = (unsigned int *)motion_data[channel];
int maxy = video_height[channel]/32; //add at 2005.3.1
if(full_win_flag){
//fixed at 2005.3.1
if( channel == clickport){
//printf("full_win_flag = %d, channel = %d,clickport = %d, maxy = %d\n", full_win_flag, channel, clickport, maxy);
ratioX = (float)full_win.w / (float)704;
ratioY = (float)full_win.h /(float)video_height[channel];
pBuf = (unsigned int *)motion_data[channel];
#ifdef MOTION_DEBUG
printf("full_win(port %d): ratioX = %f, ratioY = %f,video_height = %d\n",channel, ratioX, ratioY,video_height[channel]);
#endif
for(y = 0; y < maxy; y ++){
unsigned int val = pBuf[y];
for(x = 0; x < 22; x++){
if(val & (1 << x)){
gdk_draw_rectangle(w_full_area->window, gc2, TRUE,
full_win.x + x * ratioX * 32,
full_win.y + y * ratioY * 32,
ratioX * 32,
ratioY * 32);
}
}
}
}
return;
}
else{
ratioX = (float)v_win[channel].w /(float)704;
ratioY = (float)v_win[channel].h /(float)video_height[channel];
#ifdef MOTION_DEBUG
if(channel == 2)
printf("port %02d: ratioX= %08f, ratioY = %08f, RectLeft = %03d, RectTop = %03d\n",channel, ratioX,ratioY,motion_list[channel].RectLeft, motion_list[channel].RectTop );
#endif
for(y = 0; y < maxy; y++){
unsigned int val = pBuf[y];
for(x = 0; x< 22; x ++){
if(val & (1 << x)){
gdk_draw_rectangle(w_full_area->window, gc2, TRUE,
motion_list[channel].RectLeft + x * ratioX * 32 ,
motion_list[channel].RectTop + y * ratioY * 32,
ratioX * 32,
ratioY * 32);
}
}
}
}//else
}
void StreamRead_callback(int channel, char *databuf, int frametype, int framelength)
{
int subType;
#if 1
#if 0
if((channel == 0) && (frametype != PktAudioFrames))
printf("channel=%d, frametype=0x%x, framelength=%6d\n", channel,frametype,framelength);
#endif
subType = GetSubChannelStreamType(databuf, frametype);
// fprintf(stderr,"<demo_info> have get the data for type %d! for chan%d\n", subType, channel);
switch(frametype)
{
case PktSubIFrames:
case PktSubPFrames:
case PktSubBBPFrames:
case PktSubSysHeader:
if(frametype == PktSubSysHeader){
fprintf(stderr,"<demo_info> have get the sub channel sys header for chan%d!\n", channel);
memcpy(cifqciffile_head[channel], databuf, framelength);
head_size = framelength;
}
if(record_flag[channel] && cifqcif_fd[channel] && ((subType == 2)||(subType == 4)||(subType == 5))){
write(cifqcif_fd[channel], databuf, framelength);
}
case PktSysHeader:
case PktIFrames:
case PktPFrames:
case PktBBPFrames:
case PktAudioFrames:
case PktSFrames:
{
#if 0
if((frametype == PktIFrames)||(channel==1))
fprintf(stderr,"<yxq_info> now the I frame len is %d!\n", framelength);
#endif
if(cifqcif_flag[channel] == 0)
{
if(frametype == PktSysHeader){
memcpy(file_head[channel], databuf, framelength);
head_size = framelength;
}
if(record_flag[channel] && record_fd[channel]){
write(record_fd[channel], databuf, framelength);
//add at 2005.6.2 to create the index file
nodeinfo[channel].FilePos += framelength;
if(frametype == PktSysHeader)
nodeinfo[channel].FrameNum=0;
if(frametype == PktIFrames)
{
write(index_fd[channel], &nodeinfo[channel], sizeof(nodeinfo[channel]));
// fprintf(stderr,"<demo_info> write to index file!\n");
nodeinfo[channel].FrameNum++;
}
if(frametype == PktBBPFrames)
nodeinfo[channel].FrameNum+=3;
}
bit_rate_size[channel] += framelength;
if(net_flag){
//fprintf(stderr,"StreamRead_callback(): net_flag is 1, net_head_flag[%d] = %d, frametype = %d\n",channel, net_head_flag[channel], frametype);
if(net_head_flag[channel] == 0){
if(frametype != PktSysHeader){
//fprintf(stderr,"frametype != PktSyaHeader\n");
MP4_ServerWriteDataEx(channel,file_head[channel], head_size, PktSysHeader, 0,0);
}
else
MP4_ServerWriteDataEx(channel,(char*)databuf,framelength,frametype, 0,0);
net_head_flag[channel] = 1;
}
else
{
MP4_ServerWriteDataEx(channel,
(char*)databuf,
framelength,
frametype,
0,
0);
//fprintf(stderr,"<yxq_info> the data len is %d!\n", framelength);
}
}
}
else
{
if(frametype == PktSubSysHeader){
fprintf(stderr,"<demo_info> have get the sub channel sys header for chan%d!\n", channel);
memcpy(cifqciffile_head[channel], databuf, framelength);
head_size = framelength;
}
if(subType == 1){
memcpy(file_head[channel], databuf, framelength);
head_size = framelength;
}
if(record_flag[channel] && record_fd[channel]&&((subType == 1)||(subType == 3)||(subType == 5))){
write(record_fd[channel], databuf, framelength);
}
bit_rate_size[channel] += framelength;
if(net_flag){
switch(subType){
case 1:
case 3:
/* for cif data to put to subchan0 */
if(net_head_flag[channel] == 0){
if(frametype != PktSysHeader){
MP4_ServerWriteDataEx(channel,file_head[channel], head_size, PktSysHeader, 0,0);
}
else
MP4_ServerWriteDataEx(channel,(char*)databuf,framelength,frametype, 0,0);
net_head_flag[channel] = 1;
}
else
MP4_ServerWriteDataEx(channel,
(char*)databuf,
framelength,
frametype,
0,
0);
break;
case 2:
case 4:
/* for qcif/qqcif data to put to subchan1 */
if(subchan_net_head_flag[channel] == 0){
if(frametype != PktSysHeader){
MP4_ServerWriteDataEx(channel,cifqciffile_head[channel], head_size, PktSysHeader, 0, 1);
}
else
MP4_ServerWriteDataEx(channel,(char*)databuf,framelength,frametype, 0,1);
subchan_net_head_flag[channel] = 1;
}
else
MP4_ServerWriteDataEx(channel,
(char*)databuf,
framelength,
frametype,
0,
1);
break;
case 5: /*audio data*/
MP4_ServerWriteDataEx(channel,
(char*)databuf,
framelength,
frametype,
0,
0);
MP4_ServerWriteDataEx(channel,
(char*)databuf,
framelength,
frametype,
0,
1);
break;
default:
printf("have get other data!\n");
}
}
}
break;
}
case PktMotionDetection:
{
int length;
length = framelength;
fprintf(stderr,"motion pkt!\n");
memcpy(motion_data[channel], databuf, length); //fixed at 2005.3.1
if(GTK_TOGGLE_BUTTON(w_motion_detect_flag)->active) // motion_detect started
motion_detect(channel);
break;
}
default:
break;
}
#endif
}
void my_exit()
{
int port;
printf("End ......");
MP4_ServerStop();
if(processtimer){
gtk_timeout_remove(processtimer);
processtimer = 0;
}
if(looptimer){
gtk_timeout_remove(looptimer);
looptimer = 0;
}
if(count_timer){
g_timer_destroy(count_timer);
count_timer = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -