#include #include #include #include #include #include #include #include #include #include #include #include #include "global.h" #include "video_common.h" #include "decoder.h" #include "encoder.h" #include "xthread.h" #include "h261ctrl.h" static u_short recv_port = VIDEO_PORT; static u_short send_port = VIDEO_PORT; void usage(char* progname) { fprintf(stderr, "Syntax: %s\n", progname); fprintf(stderr, "\t[-o format %d for QCIF %d for CIF\n", QCIF_TYPE, CIF_TYPE); fprintf(stderr, "\t[-r recv_port DEFAULT %hd]\n", recv_port); fprintf(stderr, "\t[-r send_port DEFAULT %hd]\n", send_port); } H261CtrlConn connector; int main(int argc, char** argv) { char ch; int read_fd = 0; int sockfd = 0; int format = CIF_TYPE; frformat_t picformat; struct sockaddr_in peeraddr; char *servaddr = "127.0.0.1"; int filefd = 0; char *filename = NULL; XPicThread xth; Decoder *decoder = new Decoder; Encoder *encoder = new Encoder; int is_first = 0; while ((ch = getopt(argc, argv, "s:r:o:a:f:")) != -1) switch(ch) { case 'r': recv_port = atoi(optarg); break; case 's': send_port = atoi(optarg); break; case 'o': format = atoi(optarg); break; case 'a': servaddr = optarg; break; case 'f': filename = optarg; break; default: usage(argv[0]); goto quit; } if(format != QCIF_TYPE && format != CIF_TYPE) { usage(argv[0]); exit(0); } if(!filename) { usage(argv[0]); exit(0); } if( (filefd=open(filename, O_RDONLY)) < 0) { perror("open "); exit(0); } if(format == CIF_TYPE) picformat = CIF_FORMAT; else picformat = QCIF_FORMAT; compile_h261vlc(); xth.init_Xdpy(&argc, argv); read_fd = wait_for_connect(recv_port); if(read_fd < 0) goto quit; if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket (sockfd) "); exit(0); } fprintf(stderr, "readfd = %d sockfd = %d\n", read_fd, sockfd); memset(&peeraddr, 0, sizeof(peeraddr)); peeraddr.sin_family = AF_INET; if(!inet_aton(servaddr, &peeraddr.sin_addr)) { perror("invalid addr "); exit(0); } peeraddr.sin_port = htons(send_port); fprintf(stderr, "Trying to connect ...\n"); if( connect(sockfd, (sockaddr*)&peeraddr, sizeof(peeraddr)) < 0) { perror("connect "); exit(0); } /* Bind TCL stuff to file descriptior for read */ decoder->init_decoder(picformat, read_fd, xth.Gettop(), xth.GetpicW()); encoder->init_encoder(picformat, sockfd, filefd); Et_Init(&argc, argv); ET_INSTALL_COMMANDS; ET_INCLUDE(playergui.tk); xth.Start(); decoder->Start(); encoder->Start(); Et_MainLoop(); Thread::Join(&xth); Thread::Join(decoder); Thread::Join(encoder); delete decoder; quit: return 0; }