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

210 lines
5.7 KiB
C
Executable File

#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;
//sprintf(buf_kill_rtsp,"./kill_rtsp.sh");
if(switch_video==5||switch_video==6){
sprintf(buf,"./start_rtsp.sh %d",1);
system(buf);
}else{
sprintf(buf,"./start_rtsp.sh %d",switch_video+1);
system(buf);
}
while(1)
{
switch_video = switch_mode[0];
if((switch_video==5 && switch_video_pre==5)||(switch_video==6 && switch_video_pre==6)){
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[4] == 0x55){
printf("+++++++++++++++++++++++++3 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",8);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",8);
system(buf);
}
if(switch_mode[5] == 0x55){
printf("+++++++++++++++++++++++++4 time out\n");
sprintf(buf_kill_rtsp,"./kill_rtsp.sh %d",9);
system(buf_kill_rtsp);
sprintf(buf,"./start_rtsp.sh %d",9);
system(buf);
}
if((switch_mode[2] == 0x55) || (switch_mode[3] == 0x55) || (switch_mode[4] == 0x55)||(switch_mode[5] == 0x55)){
printf("+++++++++++++++++++++++++time out\n");
usleep(6000000);
}
}else if(switch_video == 1 && switch_video_pre==1){
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)
{ 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[4] == 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[5] == 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);
//if((switch_video==2)|(switch_video==1)){
// sprintf(buf,"./start_rtsp.sh %d",1);
//}
//else {
if((switch_video==5)||(switch_video==6))
sprintf(buf,"./start_rtsp.sh %d",1);
else
sprintf(buf,"./start_rtsp.sh %d",switch_video+1);
//}
printf("+++++++++++++++video %s\n",buf);
system(buf);
}
//if((switch_mode[2] == 0x55) || (switch_mode[3] == 0x55) || (switch_mode[4] == 0x55)|| (switch_mode[5] == 0x55) || (switch_mode[6] == 0x55) || (switch_mode[7] == 0x55 )){
// usleep(7000000);
// usleep(6000000);
usleep(2000000);
}
}