annotate codecctrl.c @ 947:76fd9463b9d3

FAST_OSD option to disable font outline antialiasing
author arpi_esp
date Sat, 02 Jun 2001 16:02:38 +0000
parents f6f8f53b75ad
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 //#define DEBUG_SIGNALS
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #define DEBUG_SIGNALS_SLEEP ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 //#define DEBUG_SIGNALS_SLEEP sleep(2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #ifdef DEBUG_SIGNALS
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 #define DEBUG_SIG if(1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #define DEBUG_SIG if(0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 //======= Interprocess Comminication (IPC) between player & codec =========
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 static int child_pid=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 static int codec_pid=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 // player:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 static int data_fifo=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 static int control_fifo=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 // codec:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 static int data_fifo2=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 static int control_fifo2=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 // SIGTERM handler of codec controller (2nd process):
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 static void codec_ctrl_sighandler(int x){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 DEBUG_SIG printf("\nCTRL: received signal %d, terminating child first:\n",x);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 // first terminate the codec:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 //kill(child_pid,SIGTERM);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 kill(child_pid,x);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 usleep(50000); // 50ms must be enough
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 DEBUG_SIG printf("CTRL: Sending KILL signal to child:\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 kill(child_pid,SIGKILL); // worst case
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 usleep(10000);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 // and exit
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 if(x!=SIGHUP){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 DEBUG_SIG printf("CTRL: Exiting...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 exit(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 static vo_functions_t *codec_video_out_ptr=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 // SIGTERM handler of the codec (3nd process):
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 static void codec_sighandler(int x){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 DEBUG_SIG printf("\nCHILD: received signal %d, exiting...\n",x);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 if(x==SIGTERM){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 //mpeg2_close(codec_video_out_ptr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 codec_video_out_ptr->uninit(); // closing video_out
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 exit(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 void mpeg_codec_controller(vo_functions_t *video_out){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 //================== CODEC Controller: ==========================
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 signal(SIGTERM,codec_ctrl_sighandler); // set our SIGTERM handler
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 signal(SIGHUP,codec_ctrl_sighandler); // set our SIGHUP handler
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 printf("starting video codec...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 int status;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 if((child_pid=fork())==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 // child:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 unsigned int t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 codec_video_out_ptr=video_out;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 signal(SIGTERM,codec_sighandler); // set our SIGTERM handler
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 signal(SIGHUP,codec_sighandler); // set our SIGHUP handler
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 // terminate requests:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 signal(SIGTERM,codec_sighandler); // kill
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 signal(SIGHUP,codec_sighandler); // kill -HUP / xterm closed
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 signal(SIGINT,codec_sighandler); // Interrupt from keyboard
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 signal(SIGQUIT,codec_sighandler); // Quit from keyboard
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 // fatal errors:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 signal(SIGBUS,codec_sighandler); // bus error
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 signal(SIGSEGV,codec_sighandler); // segfault
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 signal(SIGILL,codec_sighandler); // illegal instruction
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 signal(SIGFPE,codec_sighandler); // floating point exc.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 signal(SIGABRT,codec_sighandler); // abort()
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 send_cmd(control_fifo2,0x22222222); // Send WE_ARE_READY command
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 send_cmd(control_fifo2,getpid()); // Send out PID
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 unsigned int syncword=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 read(data_fifo2,&syncword,4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 if(syncword==0x22222222) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 printf("codec: drop bad frame (%X)\n",syncword);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 //printf("codec: connection synced\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 int len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 int len2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 send_cmd(control_fifo2,0x3030303);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 len2=my_read(data_fifo2,(unsigned char*) &len,4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 if(len2!=4){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 printf("FATAL: cannot read packet len from data fifo (ret=%d, errno=%d)\n",len2,errno);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 if(len==0){ printf("mpeg2dec: EOF, exiting...\n");break; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 // printf("mpeg2dec: frame (%d bytes) read\n",len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 t-=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 mpeg2_decode_data(video_out, videobuffer, videobuffer+len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 t+=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 send_cmd(control_fifo2,0); // FRAME_COMPLETED command
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
107 send_cmd(control_fifo2,frameratecode2framerate[picture->frame_rate_code]); // fps
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 send_cmd(control_fifo2,100+picture->repeat_count);picture->repeat_count=0;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
109 // send_cmd(control_fifo2,100); // FIXME!
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 send_cmd(control_fifo2,t);t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 video_out->uninit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 exit(0); // leave process
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 wait(&status); // Waiting for the child!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 // printf("restarting video codec...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 exit(0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120