void fb_exit(void) { audio_stop = 1; audio_clear(); pthread_kill(audio_thread, SIGURG); if (current) { free(current); current = NULL; } mvpw_hide(fb_progress); video_clear(); av_stop(); if (!mvpw_visible(playlist_widget)) playlist_clear(); }
bool audio_init(audio_t *a, size_t sample_rate, size_t n_channels, size_t samples_per_chunk) { //***Initialize PA internal data structures****** if(Pa_Initialize() != paNoError) return false; size_t frames_per_buffer = samples_per_chunk / n_channels; //******Initialize input device******* PaStreamParameters inparams; PaDeviceIndex dev; PaTime lat; dev = Pa_GetDefaultInputDevice(); if(dev == paNoDevice) return false; lat = Pa_GetDeviceInfo(dev)->defaultLowInputLatency; inparams = (PaStreamParameters) { .device = dev, .channelCount = n_channels, .sampleFormat = paInt16, .suggestedLatency = lat, .hostApiSpecificStreamInfo = NULL }; //******Initialize output device******* PaStreamParameters outparams; //************** dev = Pa_GetDefaultOutputDevice(); if(dev == paNoDevice) return false; lat = Pa_GetDeviceInfo(dev)->defaultLowInputLatency; outparams = (PaStreamParameters) { .device = dev, .channelCount = n_channels, .sampleFormat = paInt16, .suggestedLatency = lat, .hostApiSpecificStreamInfo = NULL }; //********Open play stream******* PaStream *pstream=NULL; if(Pa_OpenStream( &pstream, NULL, &outparams, sample_rate, frames_per_buffer, paClipOff, playCallback, a) != paNoError) return false; //************** //********Open record and listen stream******* PaStream *rstream=NULL; if(Pa_OpenStream( &rstream, &inparams, NULL, sample_rate, frames_per_buffer, paClipOff, recordCallback, a) != paNoError) return false; //*****Initialize communication ring buffers******************** PaUtilRingBuffer rb; void *rb_data; size_t rb_size; rb_size = 1 << (sizeof(samples_per_chunk) * CHAR_BIT - __builtin_clz(samples_per_chunk * RB_MULTIPLIER)); rb_data = malloc(sizeof(audio_sample_t) * rb_size); PaUtil_InitializeRingBuffer(&rb, sizeof(audio_sample_t), rb_size, rb_data); *a = (audio_t) { .sample_rate = sample_rate, .n_channels = n_channels, .samples_per_chunk = samples_per_chunk, .pstream = pstream, .rstream = rstream, .wakeup = false, .wakeup_sig = PTHREAD_COND_INITIALIZER, .wakeup_mutex = PTHREAD_MUTEX_INITIALIZER, .flags = DEFAULT, .prbuf = NULL, .prbuf_size = 0, .prbuf_offset = 0, .rb = rb, .rb_data = rb_data }; return true; } void audio_destroy(audio_t *a) { Pa_CloseStream(a->pstream); Pa_CloseStream(a->rstream); Pa_Terminate(); pthread_cond_destroy(&a->wakeup_sig); pthread_mutex_destroy(&a->wakeup_mutex); audio_clear(a); free(a->rb_data); }
static void select_callback(mvp_widget_t *widget, char *item, void *key) { char path[1024], *ptr; struct stat64 sb; sprintf(path, "%s/%s", cwd, item); if (stat64(path, &sb)!=0) { printf("Could not stat %s error %d\n",item,errno); if (strcmp(item,"../")==0 ) { // probably lost network put you back in root strcpy(cwd,"/"); strcpy(path,"/"); stat64(path, &sb); } } if (current_pl && !is_playlist(item)) { free(current_pl); current_pl = NULL; } if (current_pl && (playlist == NULL)) { free(current_pl); current_pl = NULL; } printf("%s(): path '%s'\n", __FUNCTION__, path); if (current && (strcmp(path, current) == 0)) { printf("selected current item\n"); if (is_video(item) || (is_streaming(item) > 100)) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); screensaver_disable(); return; } } if (current_pl && (strcmp(path, current_pl) == 0)) { if (is_playlist(item)) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); return; } } if (S_ISDIR(sb.st_mode)) { if (strcmp(item, "../") == 0) { strcpy(path, cwd); if (path[strlen(path)-1] == '/') path[strlen(path)-1] = '\0'; if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; if (path[0] == '\0') sprintf(path, "/"); } else { if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; } if (strstr(path,"/uPnP")!=NULL && strstr(cwd,"/uPnP")==NULL ){ mount_djmount(path); } else if (strstr(path,"/uPnP")==NULL && strstr(cwd,"/uPnP")!=NULL ) { unmount_djmount(); } strncpy(cwd, path, sizeof(cwd)); while ((cwd[0] == '/') && (cwd[1] == '/')) memmove(cwd, cwd+1, strlen(cwd)); mvpw_clear_menu(widget); mvpw_set_menu_title(widget, cwd); busy_start(); add_dirs(widget); add_files(widget); busy_end(); mvpw_expose(widget); } else { switch_hw_state(MVPMC_STATE_FILEBROWSER); if (current) free(current); current = NULL; audio_stop = 1; pthread_kill(audio_thread, SIGURG); while (audio_playing) usleep(1000); current = strdup(path); if (is_streaming(item) > 100) { // Use VLC callbacks for streaming items video_functions = &vlc_functions; // Allow broadcast messages to be sent so // we can tell VLC to start the stream vlc_broadcast_enabled = 1; } else { video_functions = &file_functions; } add_osd_widget(fb_program_widget, OSD_PROGRAM, osd_settings.program, NULL); mvpw_set_text_str(fb_name, item); /* * This code sends the currently playing file name to the display. */ snprintf(display_message, sizeof(display_message), "File:%s\n", item); display_send(display_message); audio_clear(); video_clear(); playlist_clear(); if (is_video(item)) { if (key != NULL) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); } else { mvpw_show(fb_progress); } mvpw_set_timer(fb_progress, fb_osd_update, 500); video_play(NULL); mvpw_show(root); mvpw_expose(root); mvpw_focus(root); } else if (is_audio(item) || is_streaming(item)>=0 ) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); audio_play(NULL); } else if (is_image(item)) { mvpw_hide(widget); printf("Displaying image '%s'\n", path); if (mvpw_load_image_jpeg(iw, path) == 0) { mvpw_show_image_jpeg(iw); av_wss_update_aspect(WSS_ASPECT_UNKNOWN); } else { mvpw_set_image(iw, path); } mvpw_show(iw); mvpw_focus(iw); loaded_offset = 0; loaded_status = 0; fb_next_image(1); } else if (is_playlist(item)) { if (current_pl) free(current_pl); current_pl = strdup(path); mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); playlist_clear(); playlist_play(NULL); } } }
int file_open(void) { seeking = 1; audio_selected = 0; audio_checks = 0; if ( http_playing == HTTP_FILE_CLOSED ) { if (video_reopen == 1) audio_clear(); close(fd); fd = -1; } if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } if ( http_playing == HTTP_FILE_CLOSED ) { if (gui_state != MVPMC_STATE_EMULATE) { fd=open(current, O_RDONLY|O_LARGEFILE); } else { fd = open("/tmp/FIFO", O_RDONLY); } if (fd < 0) { printf("Open failed errno %d file %s\n", errno, current); video_reopen = 0; return -1; } printf("opened %s\n", current); } else { printf("http opened %s\n", current); } if (video_reopen == 1) { av_set_audio_output(AV_AUDIO_MPEG); fd_audio = av_get_audio_fd(); av_play(); demux_reset(handle); ts_demux_reset(tshandle); demux_attr_reset(handle); demux_seek(handle); vid_event_discontinuity_possible(); if (gui_state == MVPMC_STATE_EMULATE || http_playing == HTTP_VIDEO_FILE_MPG) { video_thumbnail(AV_THUMBNAIL_OFF, 0); } else { video_thumbnail(AV_THUMBNAIL_EIGTH, 0); } av_play(); } zoomed = 0; display_on = 0; seeking = 0; jumping = 0; audio_type = 0; pcm_decoded = 0; ac3len = 0; video_reopen = 0; pthread_cond_broadcast(&video_cond); printf("write threads released\n"); return 0; }