/* Handle STREAM_CLOSE */ static int stream_on_close(void) { int status = STREAM_STOPPED; stream_mgr_lock(); /* Any open file that was accepted for playback? */ if (stream_mgr.filename != NULL) { /* Yes - hide video */ stream_show_vo(false); /* Stop any playback */ status = stream_mgr.status; stream_on_stop(false); /* Tell parser file is finished */ parser_close_stream(); /* Reinitialize manager */ stream_mgr_init_state(); } /* Let disk buffer reset itself - file might be open even if no good */ disk_buf_close(); stream_mgr_unlock(); return status; }
/* Handle STREAM_CLOSE */ static int stream_on_close(void) { int status = STREAM_STOPPED; stream_mgr_lock(); /* Any open file? */ if (stream_mgr.filename != NULL) { /* Yes - hide video */ stream_show_vo(false); /* Stop any playback */ status = stream_mgr.status; stream_on_stop(false); /* Tell parser file is finished */ parser_close_stream(); /* Close file */ disk_buf_close(); /* Reinitialize manager */ stream_mgr_init_state(); } stream_mgr_unlock(); return status; }
/* Initializes the playback engine */ int stream_init(void) { void *mem; size_t memsize; stream_mgr.status = STREAM_STOPPED; stream_mgr_init_state(); /* Initialize our window to the outside world first */ rb->mutex_init(&stream_mgr.str_mtx); rb->mutex_init(&stream_mgr.actl_mtx); stream_mgr.q = &stream_mgr_queue; rb->queue_init(stream_mgr.q, false); /* sets audiosize and returns buffer pointer */ mem = rb->plugin_get_audio_buffer(&memsize); /* Initialize non-allocator blocks first */ #ifndef HAVE_LCD_COLOR long greysize; /* Greylib init handles all necessary cache alignment */ if (!grey_init(mem, memsize, GREY_BUFFERED|GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, &greysize)) { rb->splash(HZ, "greylib init failed!"); return STREAM_ERROR; } mem += greysize; memsize -= greysize; grey_clear_display(); #endif /* !HAVE_LCD_COLOR */ stream_mgr.thread = rb->create_thread(stream_mgr_thread, stream_mgr_thread_stack, sizeof(stream_mgr_thread_stack), 0, "mpgstream_mgr" IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); rb->queue_enable_queue_send(stream_mgr.q, &stream_mgr_queue_send, stream_mgr.thread); if (stream_mgr.thread == 0) { rb->splash(HZ, "Could not create stream manager thread!"); return STREAM_ERROR; } /* Wait for thread to initialize */ stream_mgr_send_msg(STREAM_NULL, 0); /* Initialise our malloc buffer */ if (!mpeg_alloc_init(mem, memsize)) { rb->splash(HZ, "Out of memory in stream_init"); } /* These inits use the allocator */ else if (!pcm_output_init()) { rb->splash(HZ, "Could not initialize PCM!"); } else if (!audio_thread_init()) { rb->splash(HZ, "Cannot create audio thread!"); } else if (!video_thread_init()) { rb->splash(HZ, "Cannot create video thread!"); } /* Disk buffer takes max allotment of what's left so it must be last */ else if (!disk_buf_init()) { rb->splash(HZ, "Cannot create buffering thread!"); } else if (!parser_init()) { rb->splash(HZ, "Parser init failed!"); } else { return STREAM_OK; } return STREAM_ERROR; }