int mpd_init_from_httplive(MPD_CREATE_CTXT_T *pCtxt, const HTTPLIVE_DATA_T *pHttplive, const char *outdir) { int rc = 0; DASH_INIT_CTXT_T dashInit; if(!pCtxt || !pHttplive || !pCtxt->pAvCtxt || !outdir) { return -1; } memset(&dashInit, 0, sizeof(dashInit)); dashInit.enableDash = 1; dashInit.indexcount = pHttplive->indexCount; strncpy((char *) dashInit.outdir, outdir, sizeof(dashInit.outdir) - 1); dashInit.outdir_ts = pHttplive->dir; dashInit.outfileprefix = pHttplive->fileprefix; dashInit.uriprefix = pHttplive->uriprefix; dashInit.nodelete_expired = 1; if((rc = mpd_init(pCtxt, &dashInit, pCtxt->pAvCtxt)) >= 0) { pCtxt->init.outfilesuffix = HTTPLIVE_TS_NAME_EXT; pCtxt->cbFormatPathPrefix = httplive_format_path_prefix; pCtxt->mpdOutputTypes[0].type = DASH_MPD_TYPE_TS_SEGMENT_TEMPLATE_NUMBER; pCtxt->mpdOutputTypes[1].type = DASH_MPD_TYPE_INVALID; } //fprintf(stderr, "MPD OUTFILEPREFIX:'%s' '%s', suffix:'%s', outidx:%d, outdir:'%s', outdir_ts:'%s'\n", pHttplive->fileprefix, pCtxt->init.outfileprefix, pCtxt->init.outfilesuffix, pHttplive->outidx, pCtxt->init.outdir, pCtxt->init.outdir_ts); return rc; }
int main(int argc, const char **argv){ /* if(argc!=2){ g_printerr("Usage: %s [status messgae]\n", argv[0]); return 0; } */ g_type_init(); struct tp_presence *p; tp_presence_init(&p); mpd_init(); mpd_main_loop(update_status, p); return 0; }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *a, *b; mpd_t *q, *r; char *qs, *rs; char status_str[MPD_MAX_FLAG_STRING]; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "divmod: usage: ./divmod x y\n"); exit(1); } mpd_init(&ctx, 38); ctx.traps = 0; q = mpd_new(&ctx); r = mpd_new(&ctx); a = mpd_new(&ctx); b = mpd_new(&ctx); mpd_set_string(a, argv[1], &ctx); mpd_set_string(b, argv[2], &ctx); start_clock = clock(); mpd_divmod(q, r, a, b, &ctx); end_clock = clock(); fprintf(stderr, "time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); qs = mpd_to_sci(q, 1); rs = mpd_to_sci(r, 1); mpd_snprint_flags(status_str, MPD_MAX_FLAG_STRING, ctx.status); printf("%s %s %s\n", qs, rs, status_str); mpd_del(q); mpd_del(r); mpd_del(a); mpd_del(b); mpd_free(qs); mpd_free(rs); return 0; }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *a, *b; mpd_t *result; char *rstring; char status_str[MPD_MAX_FLAG_STRING]; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "shift: usage: ./shift x y\n"); exit(1); } mpd_init(&ctx, 38); ctx.traps = 0; result = mpd_new(&ctx); a = mpd_new(&ctx); b = mpd_new(&ctx); mpd_set_string(a, argv[1], &ctx); mpd_set_string(b, argv[2], &ctx); start_clock = clock(); mpd_shift(result, a, b, &ctx); end_clock = clock(); fprintf(stderr, "time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); rstring = mpd_to_sci(result, 1); mpd_snprint_flags(status_str, MPD_MAX_FLAG_STRING, ctx.status); printf("%s %s\n", rstring, status_str); mpd_del(a); mpd_del(b); mpd_del(result); mpd_free(rstring); return 0; }
int main(int argc, char **argv) { int option; char *configfile; int background; int mdns_no_rsp; int mdns_no_daap; int loglevel; char *logdomains; char *logfile; char *ffid; char *pidfile; const char *gcry_version; sigset_t sigs; int sigfd; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) struct kevent ke_sigs[4]; #endif int ret; struct option option_map[] = { { "ffid", 1, NULL, 'b' }, { "debug", 1, NULL, 'd' }, { "logdomains", 1, NULL, 'D' }, { "foreground", 0, NULL, 'f' }, { "config", 1, NULL, 'c' }, { "pidfile", 1, NULL, 'P' }, { "version", 0, NULL, 'v' }, { "mdns-no-rsp", 0, NULL, 512 }, { "mdns-no-daap", 0, NULL, 513 }, { NULL, 0, NULL, 0 } }; configfile = CONFFILE; pidfile = PIDFILE; loglevel = -1; logdomains = NULL; logfile = NULL; background = 1; ffid = NULL; mdns_no_rsp = 0; mdns_no_daap = 0; while ((option = getopt_long(argc, argv, "D:d:c:P:fb:v", option_map, NULL)) != -1) { switch (option) { case 512: mdns_no_rsp = 1; break; case 513: mdns_no_daap = 1; break; case 'b': ffid = optarg; break; case 'd': ret = safe_atoi32(optarg, &option); if (ret < 0) fprintf(stderr, "Error: loglevel must be an integer in '-d %s'\n", optarg); else loglevel = option; break; case 'D': logdomains = optarg; break; case 'f': background = 0; break; case 'c': configfile = optarg; break; case 'P': pidfile = optarg; break; case 'v': version(); return EXIT_SUCCESS; break; default: usage(argv[0]); return EXIT_FAILURE; break; } } ret = logger_init(NULL, NULL, (loglevel < 0) ? E_LOG : loglevel); if (ret != 0) { fprintf(stderr, "Could not initialize log facility\n"); return EXIT_FAILURE; } ret = conffile_load(configfile); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "Config file errors; please fix your config\n"); logger_deinit(); return EXIT_FAILURE; } logger_deinit(); /* Reinit log facility with configfile values */ if (loglevel < 0) loglevel = cfg_getint(cfg_getsec(cfg, "general"), "loglevel"); logfile = cfg_getstr(cfg_getsec(cfg, "general"), "logfile"); ret = logger_init(logfile, logdomains, loglevel); if (ret != 0) { fprintf(stderr, "Could not reinitialize log facility with config file settings\n"); conffile_unload(); return EXIT_FAILURE; } /* Set up libevent logging callback */ event_set_log_callback(logger_libevent); DPRINTF(E_LOG, L_MAIN, "Forked Media Server Version %s taking off\n", VERSION); ret = av_lockmgr_register(ffmpeg_lockmgr); if (ret < 0) { DPRINTF(E_FATAL, L_MAIN, "Could not register ffmpeg lock manager callback\n"); ret = EXIT_FAILURE; goto ffmpeg_init_fail; } av_register_all(); #if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 13) avformat_network_init(); #endif av_log_set_callback(logger_ffmpeg); #ifdef LASTFM /* Initialize libcurl */ curl_global_init(CURL_GLOBAL_DEFAULT); #endif /* Initialize libgcrypt */ gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); gcry_version = gcry_check_version(GCRYPT_VERSION); if (!gcry_version) { DPRINTF(E_FATAL, L_MAIN, "libgcrypt version mismatch\n"); ret = EXIT_FAILURE; goto gcrypt_init_fail; } /* We aren't handling anything sensitive, so give up on secure * memory, which is a scarce system resource. */ gcry_control(GCRYCTL_DISABLE_SECMEM, 0); gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); DPRINTF(E_DBG, L_MAIN, "Initialized with gcrypt %s\n", gcry_version); /* Block signals for all threads except the main one */ sigemptyset(&sigs); sigaddset(&sigs, SIGINT); sigaddset(&sigs, SIGHUP); sigaddset(&sigs, SIGCHLD); sigaddset(&sigs, SIGTERM); sigaddset(&sigs, SIGPIPE); ret = pthread_sigmask(SIG_BLOCK, &sigs, NULL); if (ret != 0) { DPRINTF(E_LOG, L_MAIN, "Error setting signal set\n"); ret = EXIT_FAILURE; goto signal_block_fail; } /* Daemonize and drop privileges */ ret = daemonize(background, pidfile); if (ret < 0) { DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n"); ret = EXIT_FAILURE; goto daemon_fail; } /* Initialize libevent (after forking) */ evbase_main = event_init(); DPRINTF(E_LOG, L_MAIN, "mDNS init\n"); ret = mdns_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "mDNS init failed\n"); ret = EXIT_FAILURE; goto mdns_fail; } /* Initialize the database before starting */ DPRINTF(E_INFO, L_MAIN, "Initializing database\n"); ret = db_init(); if (ret < 0) { DPRINTF(E_FATAL, L_MAIN, "Database init failed\n"); ret = EXIT_FAILURE; goto db_fail; } /* Open a DB connection for the main thread */ ret = db_perthread_init(); if (ret < 0) { DPRINTF(E_FATAL, L_MAIN, "Could not perform perthread DB init for main\n"); ret = EXIT_FAILURE; goto db_fail; } /* Spawn worker thread */ ret = worker_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "Worker thread failed to start\n"); ret = EXIT_FAILURE; goto worker_fail; } /* Spawn cache thread */ ret = cache_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "Cache thread failed to start\n"); ret = EXIT_FAILURE; goto cache_fail; } /* Spawn file scanner thread */ ret = filescanner_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "File scanner thread failed to start\n"); ret = EXIT_FAILURE; goto filescanner_fail; } #ifdef HAVE_SPOTIFY_H /* Spawn Spotify thread */ ret = spotify_init(); if (ret < 0) { DPRINTF(E_INFO, L_MAIN, "Spotify thread not started\n");; } #endif /* Spawn player thread */ ret = player_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "Player thread failed to start\n"); ret = EXIT_FAILURE; goto player_fail; } /* Spawn HTTPd thread */ ret = httpd_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "HTTPd thread failed to start\n"); ret = EXIT_FAILURE; goto httpd_fail; } #ifdef MPD /* Spawn MPD thread */ ret = mpd_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "MPD thread failed to start\n"); ret = EXIT_FAILURE; goto mpd_fail; } #endif /* Start Remote pairing service */ ret = remote_pairing_init(); if (ret != 0) { DPRINTF(E_FATAL, L_MAIN, "Remote pairing service failed to start\n"); ret = EXIT_FAILURE; goto remote_fail; } /* Register mDNS services */ ret = register_services(ffid, mdns_no_rsp, mdns_no_daap); if (ret < 0) { ret = EXIT_FAILURE; goto mdns_reg_fail; } #if defined(__linux__) /* Set up signal fd */ sigfd = signalfd(-1, &sigs, SFD_NONBLOCK | SFD_CLOEXEC); if (sigfd < 0) { DPRINTF(E_FATAL, L_MAIN, "Could not setup signalfd: %s\n", strerror(errno)); ret = EXIT_FAILURE; goto signalfd_fail; } event_set(&sig_event, sigfd, EV_READ, signal_signalfd_cb, NULL); #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) sigfd = kqueue(); if (sigfd < 0) { DPRINTF(E_FATAL, L_MAIN, "Could not setup kqueue: %s\n", strerror(errno)); ret = EXIT_FAILURE; goto signalfd_fail; } EV_SET(&ke_sigs[0], SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); EV_SET(&ke_sigs[1], SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); EV_SET(&ke_sigs[2], SIGHUP, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); EV_SET(&ke_sigs[3], SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); ret = kevent(sigfd, ke_sigs, 4, NULL, 0, NULL); if (ret < 0) { DPRINTF(E_FATAL, L_MAIN, "Could not register signal events: %s\n", strerror(errno)); ret = EXIT_FAILURE; goto signalfd_fail; } event_set(&sig_event, sigfd, EV_READ, signal_kqueue_cb, NULL); #endif event_base_set(evbase_main, &sig_event); event_add(&sig_event, NULL); /* Run the loop */ event_base_dispatch(evbase_main); DPRINTF(E_LOG, L_MAIN, "Stopping gracefully\n"); ret = EXIT_SUCCESS; /* * On a clean shutdown, bring mDNS down first to give a chance * to the clients to perform a clean shutdown on their end */ DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n"); mdns_deinit(); signalfd_fail: mdns_reg_fail: DPRINTF(E_LOG, L_MAIN, "Remote pairing deinit\n"); remote_pairing_deinit(); remote_fail: DPRINTF(E_LOG, L_MAIN, "HTTPd deinit\n"); httpd_deinit(); httpd_fail: DPRINTF(E_LOG, L_MAIN, "TCPd deinit\n"); #ifdef MPD DPRINTF(E_LOG, L_MAIN, "MPD deinit\n"); mpd_deinit(); mpd_fail: #endif DPRINTF(E_LOG, L_MAIN, "Player deinit\n"); player_deinit(); player_fail: #ifdef HAVE_SPOTIFY_H DPRINTF(E_LOG, L_MAIN, "Spotify deinit\n"); spotify_deinit(); #endif DPRINTF(E_LOG, L_MAIN, "File scanner deinit\n"); filescanner_deinit(); filescanner_fail: DPRINTF(E_LOG, L_MAIN, "Cache deinit\n"); cache_deinit(); cache_fail: DPRINTF(E_LOG, L_MAIN, "Worker deinit\n"); worker_deinit(); worker_fail: DPRINTF(E_LOG, L_MAIN, "Database deinit\n"); db_perthread_deinit(); db_deinit(); db_fail: if (ret == EXIT_FAILURE) { DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n"); mdns_deinit(); } mdns_fail: daemon_fail: if (background) { ret = seteuid(0); if (ret < 0) DPRINTF(E_LOG, L_MAIN, "seteuid() failed: %s\n", strerror(errno)); else { ret = unlink(pidfile); if (ret < 0) DPRINTF(E_LOG, L_MAIN, "Could not unlink PID file %s: %s\n", pidfile, strerror(errno)); } } signal_block_fail: gcrypt_init_fail: #ifdef LASTFM curl_global_cleanup(); #endif #if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 13) avformat_network_deinit(); #endif av_lockmgr_register(NULL); ffmpeg_init_fail: DPRINTF(E_LOG, L_MAIN, "Exiting.\n"); conffile_unload(); logger_deinit(); return ret; }
/* -------------------------------------------------------------------------- */ void *mpd_run(void *cookie) { time_t next_update, current; gboolean result; int retry_count = RETRY_INTERVAL; struct lcd_stuff_mpd mpd; /* default values */ mpd.lcd = (struct lcd_stuff *)cookie; mpd.mpd = NULL; mpd.error = 0; mpd.current_state = 0; mpd.song_displayed = false; mpd.current_song = NULL; mpd.stop_time = UINT_MAX; mpd.current_list = NULL; mpd.connection = NULL; mpd.timeout = 0; result = key_file_has_group(MODULE_NAME); if (!result) { report(RPT_INFO, "mpd disabled"); conf_dec_count(); return NULL; } if (!mpd_init(&mpd)) goto out; if (!mpd_init_connection(&mpd)) goto out_screen; if (!mpd_start_connection(&mpd)) goto out_screen; /* do first update instantly */ next_update = time(NULL); conf_dec_count(); /* dispatcher */ while (!g_exit) { /* if we are in error state, try to retrieve a connection first */ if (mpd.error) { if (retry_count-- <= 0) { /* each minute */ if (mpd_start_connection(&mpd)) { mpd.error = false; } else { retry_count = RETRY_INTERVAL; } } if (mpd.error) { g_usleep(1000000); continue; } } current = time(NULL); g_usleep(1000000); mpd_status_queue_update(mpd.mpd); mpd_status_check(mpd.mpd); mpd_update_status_time(&mpd); /* check playlists ? */ if (current > next_update) { mpd_update_playlist_menu(&mpd); next_update = time(NULL) + 60; } if (current > mpd.stop_time) { mpd_player_stop(mpd.mpd); mpd.stop_time = UINT_MAX; service_thread_command(mpd.lcd->service_thread, "menu_set_item \"\" mpd_standby -value 0\n"); } } out_screen: mpd_deinit(&mpd); out: if (mpd.mpd) mpd_free(mpd.mpd); if (mpd.current_list) mpd_free_playlist(mpd.current_list); service_thread_unregister_client(mpd.lcd->service_thread, MODULE_NAME); mpd_song_delete(mpd.current_song); connection_delete(mpd.connection); return NULL; }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *x0, *y0; mpd_t *sqrt_2, *xstep, *ystep; uint32_t prec = 19; int iter = 1000; int points[40][80]; int i, j; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "usage: ./bench prec iter\n"); exit(1); } prec = strtoul(argv[1], NULL, 10); iter = strtol(argv[2], NULL, 10); mpd_init(&ctx, prec); /* no more MPD_MINALLOC changes after here */ sqrt_2 = mpd_new(&ctx); xstep = mpd_new(&ctx); ystep = mpd_new(&ctx); x0 = mpd_new(&ctx); y0 = mpd_new(&ctx); mpd_set_u32(sqrt_2, 2, &ctx); mpd_sqrt(sqrt_2, sqrt_2, &ctx); mpd_div_u32(xstep, sqrt_2, 40, &ctx); mpd_div_u32(ystep, sqrt_2, 20, &ctx); start_clock = clock(); mpd_copy(y0, sqrt_2, &ctx); for (i = 0; i < 40; i++) { mpd_copy(x0, sqrt_2, &ctx); mpd_set_negative(x0); for (j = 0; j < 80; j++) { points[i][j] = color_point(x0, y0, iter, &ctx); mpd_add(x0, x0, xstep, &ctx); } mpd_sub(y0, y0, ystep, &ctx); } end_clock = clock(); #ifdef BENCH_VERBOSE for (i = 0; i < 40; i++) { for (j = 0; j < 80; j++) { if (points[i][j] == iter) { putchar('*'); } else if (points[i][j] >= 10) { putchar('+'); } else if (points[i][j] >= 5) { putchar('.'); } else { putchar(' '); } } putchar('\n'); } putchar('\n'); #endif printf("time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); mpd_del(x0); mpd_del(y0); mpd_del(sqrt_2); mpd_del(xstep); mpd_del(ystep); return 0; }