uint8_t ffmpegEncoderCQ::init (uint32_t val, uint32_t fps1000, uint8_t vbr) { printf ("[LAVCODEC] Using Q=%u\n",val); mplayer_init (); _qual = val; _vbr = vbr; _context->flags |= CODEC_FLAG_QSCALE; if (_vbr) { _context->flags |= CODEC_FLAG_PASS1; _statfile = NULL; } _context->time_base = (AVRational) { 1000, fps1000}; /* _context->frame_rate_base = 1000; _context->frame_rate = fps1000; */ _context->bit_rate = 0; _context->bit_rate_tolerance = 1024 * 8 * 1000; return initContext (); }
/*--- */ uint8_t ffmpegEncoderFFMjpeg::init (uint32_t val, uint32_t fps1000, uint8_t vbr) { UNUSED_ARG (val); UNUSED_ARG (vbr); mplayer_init (); float f; f = val; f = 31. - (29. * f / 100.); _qual = (uint32_t) floor (f); // _context->frame_rate_base = 1000; // _context->frame_rate = fps1000; _context->time_base = (AVRational) { 1000, fps1000}; _context->flags = CODEC_FLAG_QSCALE; _context->bit_rate = 0; _context->bit_rate_tolerance = 1024 * 8 * 1000; _context->gop_size = 250; printf ("[LAVCODEC]FF Mjpeg codec initializing %d %% -> q =%d...\n", val, _qual); return initContext (); }
/*--- */ uint8_t ffmpegEncoderFFY800::init (uint32_t fps1000, uint8_t vbr) { UNUSED_ARG (vbr); mplayer_init (); _context->time_base = (AVRational) { 1000, fps1000}; _context->flags = 0; _context->bit_rate = 0; _context->bit_rate_tolerance = 1024 * 8 * 1000; _context->gop_size = 250; printf ("[LAVCODEC]FF Mjpeg codec initializing...\n"); return initContext (); }
//------------------------------ uint8_t ffmpegEncoderFFHuff::init (uint32_t val, uint32_t fps1000, uint8_t vbr) { UNUSED_ARG (val); UNUSED_ARG (vbr); mplayer_init (); /* _context->frame_rate_base = 1000; _context->frame_rate = fps1000;*/ _context->time_base = (AVRational) { 1000, fps1000}; _context->bit_rate = 0; _context->bit_rate_tolerance = 1024 * 8 * 1000; _context->gop_size = 250; return initContext (); }
int main(int argc, char ** argv){ int r; char c; printf("Type [s,n,p,e]: "); fflush(stdout); if(!isatty(ttyfd)) fatal("not on a tty"); if(tcgetattr(ttyfd, &orig_termios) < 0) fatal("can't get tty settings"); if(atexit(tty_reset) != 0) fatal("atexit: can't register tty reset"); tty_raw(); if(argc < 2) fatal("Missing fifo file path"); mplayer_init(argv[1]); while(1){ r = read(0, &c, 1); switch(c){ case 's': mplayer_send(MPLAYER_START); break; case 'p': mplayer_send(MPLAYER_PREV); break; case 'n': mplayer_send(MPLAYER_NEXT); break; case 'e': exit(0); default: printf("Unknown command"); break; } } return 0; }
/* val is the average bitrate wanted, else it is useless */ uint8_t ffmpegEncoderVBR::init (uint32_t val, uint32_t fps1000) { uint32_t statSize; FILE *_statfile; printf ("[lavc] initializing in VBR mode\n"); _qual = val; mplayer_init (); // _context->frame_rate_base = 1000; // _context->frame_rate = fps1000; _context->time_base = (AVRational) { 1000, fps1000}; /* If internal 2 passes mode is selected ... */ _context->flags |= CODEC_FLAG_PASS2; _statfile = fopen (LogName, "rb"); if (!_statfile) { printf ("internal file does not exists ?\n"); return 0; } fseek (_statfile, 0, SEEK_END); statSize = ftello (_statfile); fseek (_statfile, 0, SEEK_SET); _context->stats_in = (char *) ADM_alloc (statSize + 1); _context->stats_in[statSize] = 0; fread (_context->stats_in, statSize, 1, _statfile); fclose(_statfile); _context->bit_rate = val; // bitrate return initContext (); }
/** This is used only for Mpeg1, so it is a bit tuned for it */ uint8_t ffmpegEncoderVBRExternal::init (uint32_t val, uint32_t fps1000) { printf ("[lavc] initializing in VBRExternal mode\n"); _qual = val; mplayer_init (); /* _context->frame_rate_base = 1000; _context->frame_rate = fps1000;*/ _context->time_base = (AVRational) { 1000, fps1000}; _context->flags |= CODEC_FLAG_QSCALE;; _context->bit_rate = 0; _context->bit_rate_tolerance = 1024 * 8 * 1000; _context->max_qdiff = 10; // since this is used only for mpeg1 ... // PAL ? _context->bit_rate = 2500 * 1000 * 8; _context->sample_aspect_ratio.num = 4; _context->sample_aspect_ratio.den = 3; return initContext ();; }
uint8_t ffmpegEncoderCBR::init (uint32_t val, uint32_t fps1000) { // mpeg4_encoder // // now init our stuff // _br = val; mplayer_init (); /* _context->frame_rate_base = 1000; _context->frame_rate = fps1000;*/ _context->time_base = (AVRational) { 1000, fps1000}; if(_id==FF_MPEG2 || _id==FF_MPEG1) _context->bit_rate = _br; else _context->bit_rate = _br*1000; printf ("[LAVCODEC] Using bitrate in context :%lu kbps",_context->bit_rate/1000); return initContext (); }
int main(int argc, char *argv[]) { int ffi, sfd_on, thr_create_err; socklen_t l; pthread_t *ptid; struct sockaddr_in myaddr; struct sockaddr *client_addr; st.mid = pthread_self(); signal(SIGQUIT, &s_safe_exit); signal(SIGINT, &s_safe_exit); signal(SIGPIPE, SIG_IGN); pthread_mutex_init(&mx, NULL); st.port = SERV_DEF_PORT; if(argc > 1) { st.port = atoi(argv[1]); } if((st.sfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("Failed to open socket"); return 1; } sfd_on = 1; /* SO_REUSEADDR to enable quick rebooting server on the same port */ if(( setsockopt(st.sfd, SOL_SOCKET, SO_REUSEADDR, (char*)&sfd_on, sizeof(sfd_on))) < 0) { perror("Failed to set socket options"); return 1; } myaddr.sin_family = PF_INET; myaddr.sin_port = htons(st.port); myaddr.sin_addr.s_addr = INADDR_ANY; if(bind(st.sfd, (struct sockaddr*)&myaddr, sizeof(myaddr)) != 0) { perror("Problem with binding socket"); return 1; } #ifdef DEBUG puts("DEBUG mode is on!"); st.verbose = 1; #else st.verbose = 0; #endif /* display info on startup */ if(st.verbose) { printf("[%s] now on IP %s Port %d \n[%s] Ready, PID=%d, [%ld]\n", (argv[0] + 2), get_ip(st.ip_buffer), st.port, timestamp(st.tmr_buf), getpid(), sizeof(client_t) ); } l = sizeof(st.last_client->caddr); listen(st.sfd, 5); /* launch music player thread */ mplayer_init(); /* main loop */ while(!st.exit) { /* get place for client on client table */ ffi = getffi(st, clbuf); st.last_client = malloc(sizeof(client_t)); if(st.last_client == NULL){ perror("Problems with memory"); s_safe_exit(EXIT_FAILURE); } st.last_client->cid = ffi; ptid = &st.last_client->tid; client_addr = (struct sockaddr*)&st.last_client->caddr; /* listen on socket to accept client */ if((st.last_client->cfd = accept(st.sfd, client_addr, &l)) < 0) { if(!st.exit) { perror("Problem with accepting client"); } else { s_safe_exit(0); } } else { /* safely create thread to serve client */ pthread_mutex_lock(&mx); clbuf[ffi] = st.last_client; thr_create_err = pthread_create(ptid, NULL, client_thread, st.last_client); if(thr_create_err) { perror("Can't create thread"); pthread_mutex_unlock(&mx); s_safe_exit(0); } #ifdef DETACHED pthread_detach(*ptid); #endif pthread_mutex_unlock(&mx); } st.last_client = NULL; } s_safe_exit(-1); return 0; }