#include #include #include #include #include #include #include #include #include #include #include "bitio.h" #include "h261vlc.h" #include "video_common.h" #include "frame.h" #include "encoder.h" static u_short video_port = VIDEO_PORT; void usage(char* progname) { fprintf(stderr, "Syntax: %s\n", progname); fprintf(stderr, "\t[-p port UDP PORT DEFAULT %hd]\n", video_port); fprintf(stderr, "\t[-a addr Rx address DEFAULT localhost\n"); fprintf(stderr, "\t[-o format %d for QCIF %d for CIF\n", QCIF_TYPE, CIF_TYPE); fprintf(stderr, "\t-f filename\n"); } int main(int argc, char **argv) { char *filename = NULL; int sockfd = 0; int filefd = 0; struct sockaddr_in tx_sock; char *servaddr = "127.0.0.1"; struct tmp; int format = QCIF_TYPE; char ch; frformat_t picformat; Encoder *encoder = new Encoder; while ((ch = getopt(argc, argv, "p:f:a:o:")) != -1) switch(ch) { case 'p': video_port = atoi(optarg); break; case 'a': servaddr = optarg; break; case 'f': filename = optarg; break; case 'o': format = atoi(optarg); break; default: usage(argv[0]); exit(0); break; } 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 if(format == QCIF_TYPE) picformat = QCIF_FORMAT; fprintf(stderr, "Bit-Compiling H261 VLC tables\n"); compile_h261vlc(); /* Setup socket connection */ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket (sockfd) "); exit(0); } memset(&tx_sock, 0, sizeof(tx_sock)); tx_sock.sin_family = AF_INET; if(!inet_aton(servaddr, &tx_sock.sin_addr)) { perror("invalid addr "); exit(0); } tx_sock.sin_port = htons(video_port); fprintf(stderr, "Trying to connect ...\n"); if( connect(sockfd, (sockaddr*)&tx_sock, sizeof(tx_sock)) < 0) { perror("connect "); exit(0); } encoder->init_encoder(picformat, sockfd, filefd); encoder->Start(); Thread::Join(encoder); close(sockfd); return 0; }