Ergebniss meiner Test mit verschieden großen Buffer hat ergeben, dass es momentan keinen Sinn mach den buffur zu erhöhen. Wenn der buffer größer ist, brauch die sende routing länger zum verschicken, also füllt sich gleichzeitig der speicher mehr mit daten aus dem TS an, also kommt es eher zu abbrüchen. Daher hab ich den Puffer auf 32*7*188 belassen.
Ich habe noch ein paar andere Kleinigkeiten eingebaut, vor allem fürs debugging und hab die wiederhoversuche beim SENDEN per #ifdef abgeschaltet, weil es sonst anscheinen zu Problemen mit YWebLive kommen konnte. Die aktuelle Version läuft bei mir absolut stabil - konnte keine ungeünschte abbrüche beobachten.
Habe noch ein bischen Code für das handel eines kill-signals eingebaut, damit der demuxer immer sauber geschlossen wird. Ist einfach sauberer, auch wenn es anscheinend auch ohne das ging.
Bitte neu downloaden und testen.
Hier das diff von udpstreamts zum aktuellen CVS:
Code: Alles auswählen
49a50
> #include <sys/signal.h>
50a52
> #include <errno.h>
72a75,81
> #define MAX_RETRIES 10
>
> #undef UDPSTREAMTS_DEBUG
> #undef USE_SEND_RETRY
>
>
> char exiting = 0;
119a129,132
> #ifdef USE_SEND_RETRY
> unsigned int retries=0;
> #endif
>
162a176,189
> #ifdef USE_SEND_RETRY
> /*
> * retry to send
> */
> retries = 0;
> while((written == -1) && (retries < MAX_RETRIES)){
> retries++;
> fprintf(stderr,"Error writing to socket, still trying..(%i/%i);",retries,MAX_RETRIES);
> perror(" Reason");
> written = write(fd, bp, UDP_PACKET_SIZE);
> }
> #endif
>
>
167,168c194,197
< perror("write");
< return -1;
---
>
> perror("Error writing to socket, giving up");
> return -1;
>
226a256,267
> void
> sig_handler(int sig) /* signal handler */
> {
> switch(sig)
> {
> case SIGTERM:
> /* do the cleanup */
> printf("Got kill signal. Cleaning and bailing out...\n");
> exiting = 1;
> break;
> }
> }
237c278,284
< int i;
---
> int i,j;
>
> int argp = 1, retries=0;
>
> #ifdef UDPSTREAMTS_DEBUG
> int min_read = READ_BUFFER_SIZE+1, max_read = -1;
> #endif
244c291,299
<
---
> #ifdef UDPSTREAMTS_DEBUG
> printf("udpstreamts (compiled in debug mode) starting... \n");
> printf("Size of readbuffer: %d bytes\n", READ_BUFFER_SIZE);
> printf("Size of writebuffer: %d bytes\n", UDP_PACKET_SIZE);
> printf("\n");
> #else
> printf("udpstreamts starting... \n");
> printf("\n");
> #endif
250c305
< fprintf(stderr, "usage: %s <ip> <port> <pid> [<pid> ...]\n", argv[0]);
---
> fprintf(stderr, "usage: %s [-b <logfile>] <ip> <port> <pid> [<pid> ...]\n", argv[0]);
253a309,351
> /* inserted A.Wacker 19.07.2007 for starting udpstreamts in background */
> if (!strncmp(argv[1],"-b",2)) {
> printf("Daemonizing %s and logging to %s...\n", argv[0], argv[2]);
> fflush(stdout);
>
> /* daemonize */
> j=fork();
> if (j<0) exit(1); /* fork error */
> if (j>0) exit(0); /* parent exits */
> /* child daemon continous */
>
> setsid(); /* obtain a new process group */
>
> for (j=getdtablesize();j>=0;--j) close(j); /* close all descriptors */
>
> j = open(argv[2], O_RDWR|O_CREAT|O_TRUNC); /*open stdin */
> dup(j); /* stdout */
> dup(j); /* stderr */
>
> if (j == -1)
> {
> perror("Cannot open logfile for writing");
> }
>
> chdir ("/");
>
> signal(SIGCHLD,SIG_IGN); /* ignore child terminate signal */
> signal(SIGTERM,sig_handler); /* termination signal from kill */
>
>
> /* check again if there are enough arguments */
> if (argc < 6) {
> fprintf(stderr, "usage: %s [-b <logfile>] <ip> <port> <pid> [<pid> ...]\n", argv[0]);
> return EXIT_FAILURE;
> }
>
> /* finally shift the remaining arguments, so that the rest of the code remains untouched */
> argp = 3;
> }
> printf("Preparing to send the transport stream to %s:%s ...\n",argv[argp],argv[argp+1]);
> /* end changes 19.07.2007 */
>
>
263,264c361,362
< sin.sin_addr.s_addr = inet_addr(argv[1]);
< sin.sin_port = htons(strtoul(argv[2], NULL, 0));
---
> sin.sin_addr.s_addr = inet_addr(argv[argp]);
> sin.sin_port = htons(strtoul(argv[argp+1], NULL, 0));
282,283c380,385
< for (i = 0; i < argc - 3; i++)
< dmx[i] = dmx_pid_filter_start(strtoul(argv[i + 3], NULL, 0));
---
> for (i = 0; i < (argc - (argp+2)); i++)
> {
> printf("Preparing demuxer for streaming PID %i: %s ...\n",i ,argv[i + (argp + 2)]);
> dmx[i] = dmx_pid_filter_start(strtoul(argv[i + (argp + 2)], NULL, 0));
> }
> fflush(stdout);
291c393
< perror("read");
---
> perror("Error reading from dvr");
311a414,428
>
> /*
> * retry to read
> */
> retries = 0;
> while((rsize == -1) && (retries < MAX_RETRIES) && (errno==EOVERFLOW)){
> retries++;
> #ifdef UDPSTREAMTS_DEBUG
> fprintf(stderr,"Error reading from dvr, still trying..(%i/%i)",retries,MAX_RETRIES);
> perror("; Reason");
> #endif
> rsize = read(dvr, readbuf + read_offset, sizeof(readbuf) - read_offset - size_offset);
> }
>
>
313c430
< perror("read");
---
> perror("Error reading from dvr. Giving up");
330a448,467
>
> #ifdef UDPSTREAMTS_DEBUG
> /* just for debugging*/
> if(rsize>max_read)
> {
> max_read = rsize;
> printf("New max read size: %d\n",max_read);
> }
> if(rsize<min_read)
> {
> min_read = rsize;
> printf("New min read size: %d\n",min_read);
> }
> if ((rsize!=max_read) && (rsize!=min_read))
> {
> printf("Current read size: %d\n",rsize);
> }
> #endif
>
>
336a474
>
367c505
< } while (wsize >= 0);
---
> } while (wsize >= 0 && !exiting);
370c508,512
< for (i = 0; i < argc - 3; i++)
---
> printf("Prepare for shutdown ");
>
> for (i = 0; i < (argc - (argp+2)); i++)
> {
> fprintf(stdout,".");
371a514
> }
374a518,522
> /* just to be sure, that everything is closed */
> for (j=getdtablesize();j>=3;--j) close(j); /* close all descriptors, except std dscr. */
>
> printf(" done. Goodby!\n");
>