void stride_cleanup(void) { #ifdef APE #else decoder_cleanup(); #endif }
static void decoder_chain_cleanup(Decoder *self) { DecoderPrivate *priv = DECODER_GET_PRIVATE (self); if (priv->chain != NULL) { decoder_chain_cleanup(priv->chain); } decoder_cleanup(self); return; }
/* Run client and the server if needed. */ static void start_moc (const struct parameters *params, lists_t_strs *args) { int server_sock; if (params->foreground) { set_me_server (); server_init (params->debug, params->foreground); server_loop (); return; } server_sock = server_connect (); if (server_sock != -1 && params->only_server) fatal ("Server is already running!"); if (server_sock == -1) { int i = 0; int notify_pipe[2]; ssize_t rc; printf ("Running the server...\n"); /* To notify the client that the server socket is ready */ if (pipe(notify_pipe)) fatal ("pipe() failed: %s", xstrerror (errno)); switch (fork()) { case 0: /* child - start server */ set_me_server (); server_init (params->debug, params->foreground); rc = write (notify_pipe[1], &i, sizeof(i)); if (rc < 0) fatal ("write() to notify pipe failed: %s", xstrerror (errno)); close (notify_pipe[0]); close (notify_pipe[1]); server_loop (); options_free (); decoder_cleanup (); io_cleanup (); files_cleanup (); rcc_cleanup (); common_cleanup (); exit (EXIT_SUCCESS); case -1: fatal ("fork() failed: %s", xstrerror (errno)); default: close (notify_pipe[1]); if (read(notify_pipe[0], &i, sizeof(i)) != sizeof(i)) fatal ("Server exited!"); close (notify_pipe[0]); server_sock = server_connect (); if (server_sock == -1) { perror ("server_connect()"); fatal ("Can't connect to the server!"); } } } if (params->only_server) send_int (server_sock, CMD_DISCONNECT); else { xsignal (SIGPIPE, SIG_IGN); if (!ping_server (server_sock)) fatal ("Can't connect to the server!"); init_interface (server_sock, params->debug, args); interface_loop (); interface_end (); } close (server_sock); }
void stream_video(void) { char stream_buf[VIDEO_INBUF_SZ + 16]; // padded so libavcodec detects the end SOCKET videoSocket = INVALID_SOCKET; int keep_waiting = 0; if (g_ip != NULL) { videoSocket = connectDroidCam(g_ip, g_port); if (videoSocket == INVALID_SOCKET) { return; } } v_running =1; _wait: // We are the server if (videoSocket == INVALID_SOCKET) { videoSocket = accept_inet_connection(g_port); if (videoSocket == INVALID_SOCKET) { goto _out; } keep_waiting = 1; } { int L = sprintf(stream_buf, VIDEO_REQ, g_webcam_w, g_webcam_h); if ( SendRecv(1, stream_buf, L, videoSocket) <= 0 ){ MSG_ERROR("Connection lost!"); goto _out; } dbgprint("Sent request, "); } memset(stream_buf, 0, sizeof(stream_buf)); if ( SendRecv(0, stream_buf, 5, videoSocket) <= 0 ){ MSG_ERROR("Connection reset!\nDroidCam is probably busy with another client"); goto _out; } if (decoder_prepare_video(stream_buf) == FALSE) { goto _out; } while (1){ int frameLen; char *p = stream_buf; if (SendRecv(0, p, 4, videoSocket) == FALSE) goto _out; make_int4(frameLen, p[0], p[1], p[2], p[3]); SetImageFrameSize(frameLen); p = GetImageFrameBuf(); while (frameLen > 4096) { if (SendRecv(0, p, 4096, videoSocket) == FALSE) goto _out; frameLen -= 4096; p += 4096; } if (SendRecv(0, p, frameLen, videoSocket) == FALSE) goto _out; if (DecodeFrame() == FALSE) break; } _out: dbgprint("disconnect\n"); disconnect(videoSocket); decoder_cleanup(); if (keep_waiting){ videoSocket = INVALID_SOCKET; goto _wait; } v_running = 0; connection_cleanup(); }
int main (int argc, char *argv[]) { struct parameters params; lists_t_strs *deferred_overrides; lists_t_strs *args; #ifdef HAVE_UNAME_SYSCALL int rc; struct utsname uts; #endif #ifdef PACKAGE_REVISION logit ("This is Music On Console (revision %s)", PACKAGE_REVISION); #else logit ("This is Music On Console (version %s)", PACKAGE_VERSION); #endif #ifdef CONFIGURATION logit ("Configured:%s", CONFIGURATION); #endif #ifdef HAVE_UNAME_SYSCALL rc = uname (&uts); if (rc == 0) logit ("Running on: %s %s %s", uts.sysname, uts.release, uts.machine); #endif log_command_line (argc, argv); files_init (); if (get_home () == NULL) fatal ("Could not determine user's home directory!"); memset (¶ms, 0, sizeof(params)); options_init (); deferred_overrides = lists_strs_new (4); /* set locale according to the environment variables */ if (!setlocale(LC_ALL, "")) logit ("Could not set locale!"); args = process_command_line (argc, argv, ¶ms, deferred_overrides); if (params.dont_run_iface && params.only_server) fatal ("-c, -a and -p options can't be used with --server!"); if (!params.config_file) params.config_file = xstrdup (create_file_name ("config")); options_parse (params.config_file); if (params.config_file) free (params.config_file); params.config_file = NULL; process_deferred_overrides (deferred_overrides); lists_strs_free (deferred_overrides); deferred_overrides = NULL; check_moc_dir (); io_init (); rcc_init (); decoder_init (params.debug); srand (time(NULL)); if (!params.only_server && params.dont_run_iface) server_command (¶ms, args); else start_moc (¶ms, args); lists_strs_free (args); options_free (); decoder_cleanup (); io_cleanup (); rcc_cleanup (); files_cleanup (); compat_cleanup (); exit (EXIT_SUCCESS); }