示例#1
0
文件: oss.c 项目: amitkr/deadbeef
static int
oss_init (void) {
    trace ("oss_init\n");
    state = OUTPUT_STATE_STOPPED;
    oss_terminate = 0;
    mutex = 0;

    // prepare oss for playback
    fd = open (oss_device, O_WRONLY);
    if (fd == -1) {
        fprintf (stderr, "oss: failed to open file %s\n", oss_device);
        perror (oss_device);
        plugin.free ();
        return -1;
    }

    oss_set_hwparams (&plugin.fmt);

    mutex = deadbeef->mutex_create ();

    oss_tid = deadbeef->thread_start (oss_thread, NULL);
    return 0;
}
示例#2
0
文件: main.c 项目: Gardenya/deadbeef
void
player_mainloop (void) {
    for (;;) {
        uint32_t msg;
        uintptr_t ctx;
        uint32_t p1;
        uint32_t p2;
        int term = 0;
        while (messagepump_pop(&msg, &ctx, &p1, &p2) != -1) {
            // broadcast to all plugins
            DB_plugin_t **plugs = plug_get_list ();
            for (int n = 0; plugs[n]; n++) {
                if (plugs[n]->message) {
                    plugs[n]->message (msg, ctx, p1, p2);
                }
            }
            if (!term) {
                DB_output_t *output = plug_get_output ();
                switch (msg) {
                case DB_EV_REINIT_SOUND:
                    plug_reinit_sound ();
                    streamer_reset (1);
                    conf_save ();
                    break;
                case DB_EV_TERMINATE:
                    {
                        save_resume_state ();

                        pl_playqueue_clear ();

                        // stop streaming and playback before unloading plugins
                        DB_output_t *output = plug_get_output ();
                        output->stop ();
                        streamer_free ();
                        output->free ();
                        term = 1;
                    }
                    break;
                case DB_EV_PLAY_CURRENT:
                    streamer_play_current_track ();
                    break;
                case DB_EV_PLAY_NUM:
                    pl_playqueue_clear ();
                    streamer_set_nextsong (p1, 4);
                    break;
                case DB_EV_STOP:
                    streamer_set_nextsong (-2, 0);
                    break;
                case DB_EV_NEXT:
                    streamer_move_to_nextsong (1);
                    break;
                case DB_EV_PREV:
                    streamer_move_to_prevsong (1);
                    break;
                case DB_EV_PAUSE:
                    if (output->state () != OUTPUT_STATE_PAUSED) {
                        output->pause ();
                        messagepump_push (DB_EV_PAUSED, 0, 1, 0);
                    }
                    break;
                case DB_EV_TOGGLE_PAUSE:
                    if (output->state () == OUTPUT_STATE_PAUSED) {
                        streamer_play_current_track ();
                    }
                    else {
                        output->pause ();
                        messagepump_push (DB_EV_PAUSED, 0, 1, 0);
                    }
                    break;
                case DB_EV_PLAY_RANDOM:
                    streamer_move_to_randomsong (1);
                    break;
                case DB_EV_PLAYLIST_REFRESH:
                    pl_save_current ();
                    messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
                    break;
                case DB_EV_CONFIGCHANGED:
                    conf_save ();
                    streamer_configchanged ();
                    junk_configchanged ();
                    break;
                case DB_EV_SEEK:
                    streamer_set_seek (p1 / 1000.f);
                    break;
                }
            }
            if (msg >= DB_EV_FIRST && ctx) {
                messagepump_event_free ((ddb_event_t *)ctx);
            }
        }
        if (term) {
            return;
        }
        messagepump_wait ();
    }
}