Files
hisi_SS524V100_SDK/mpp/sample/rtsp_switch/rtsp_switch_2.c
T

148 lines
4.6 KiB
C

#include <linux/input.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <arpa/inet.h>
#include <netdb.h>
int switch_video;
unsigned char key_value;
int *switch_memory_open(void) {
char buf[128];
int fd;
sprintf(buf, "/video_switch");
fd = shm_open(buf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if(fd < 0) { perror("shm_open"); exit(1); }
if (ftruncate(fd, 4096) == -1) { perror("ftruncate"); exit(1); }
int *retval = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return retval;
}
int main(int argc, char **argv)
{
int ret;
int *switch_mode;
int switch_video=0;
int switch_video_pre=0;
unsigned char buf[1024];
unsigned char buf_kill_rtsp[1024];
switch_mode = switch_memory_open();
switch_video = switch_mode[0];
switch_video_pre = switch_video;
/* 0->1 双全屏, 1->2 左全屏, 2->3 右全屏, 3->4 左放大, 4->5 右放大 */
sprintf(buf,"./start_rtsp.sh %d",switch_video+1);
system(buf);
while(1)
{
switch_video = switch_mode[0];
/* 双全屏:任一路无信号切该路备路(6=通道0备路, 7=通道1备路) */
if(switch_video==0 && switch_video_pre==0){
if(switch_mode[2] == 0x55){
printf("+++++++++++++++++++++++++1 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",6);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",6);
system(buf);
}
if(switch_mode[3] == 0x55){
printf("+++++++++++++++++++++++++2 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",7);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",7);
system(buf);
}
if((switch_mode[2] == 0x55) || (switch_mode[3] == 0x55)){
printf("+++++++++++++++++++++++++time out\n");
usleep(6000000);
}
}else if(switch_video == 1 && switch_video_pre==1){ /* 左屏通道0全屏 */
if(switch_mode[2] == 0x55){
printf("+++++++++++++++++++++++++11 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",2);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",2);
system(buf);
}
}
else if(switch_video == 2 && switch_video_pre==2) /* 右屏通道1全屏 */
{ if(switch_mode[3] == 0x55){
printf("+++++++++++++++++++++++++22 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",2);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",3);
system(buf);
}
}
else if(switch_video == 3 && switch_video_pre==3) /* 左放大右隐藏 */
{ if(switch_mode[2] == 0x55){
printf("+++++++++++++++++++++++++33 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",2);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",4);
system(buf);
}
}
else if(switch_video == 4 && switch_video_pre==4) /* 右放大左隐藏 */
{ if(switch_mode[3] == 0x55){
printf("+++++++++++++++++++++++++44 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",2);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",5);
system(buf);
}
}
if((switch_video != switch_video_pre )){
switch_video_pre = switch_video;
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",1);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",switch_video+1);
printf("+++++++++++++++video %s\n",buf);
system(buf);
}
usleep(3000000);
}
}