int main(int argc, char ** argv) { bgav_t * b; bgav_options_t * opt; if(argc < 2) { fprintf(stderr, "Usage: %s <file>\n", argv[0]); return -1; } b = bgav_create(); opt = bgav_get_options(b); bgav_options_set_sample_accurate(opt, 1); bgav_options_set_index_callback(opt, index_callback, NULL); if(!bgav_open(b, argv[1])) return -1; fprintf(stderr, "\n"); if(b->demuxer->si) bgav_superindex_dump(b->demuxer->si); bgav_file_index_dump(b); bgav_close(b); return 0; }
static void sfsamples_bang(t_sfsamples *x) { DEBUG(post("sfsamples_bang")); const gavl_audio_format_t* open_audio_format; gavl_time_t gavl_time; if(x->filename == &s_) { pd_error(x,"no file set"); return; } if(!bgav_open(x->decoder, x->filename->s_name)) { pd_error(x, "Could not open file %s", x->filename->s_name); } // only concerned with the first audio stream open_audio_format = bgav_get_audio_format(x->decoder, 0); // we can get audio formats that are unkown if (open_audio_format->sample_format == GAVL_SAMPLE_NONE) { pd_error(x, "sorry, this file has unsupported audio."); } gavl_time = bgav_get_duration(x->decoder, 0); outlet_float(x->x_obj.ob_outlet, (float)(gavl_time_to_samples(open_audio_format->samplerate, gavl_time) / (float)open_audio_format->samplerate)); }
static int open_avdec(void * priv, const char * location) { bgav_options_t * opt; avdec_priv * avdec = priv; avdec->dec = bgav_create(); opt = bgav_get_options(avdec->dec); bgav_options_copy(opt, avdec->opt); if(!bgav_open(avdec->dec, location)) return 0; return open_common(avdec); }
void *the_thread_opener(void *xp) { ReadMedia *rm = NULL; int num_urls=0, num_tracks=0, audio_stream_count=0, video_stream_count =0; rm = (ReadMedia *)xp; rm->setState(STATE_OPENING); // AFTER WE KILL THE THREADS, THERE IS NO NEED TO LOCK AV mutex // ALL functions that want to get info on the file, seek, // or decode a frame, MUST first check the state. If the // state is STATE_READY, then it can perform it's function, // locking on the necessary variables that might conflict with // the AV. // clearFile deletes old file and creates new File rm->clearFile(); if(!bgav_open(rm->getFile(), rm->getFilename())) { printf( "Could not open file %s\n", rm->getFilename()); rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL); //return NULL; } else { printf("opened %s\n", rm->getFilename()); } // check to see if it is a redirector if(bgav_is_redirector( rm->getFile() )) { num_urls = bgav_redirector_get_num_urls( rm->getFile() ); printf( "Found redirector with %d urls inside, we will try to use the first one.\n", num_urls); printf( "Name %d: %s\n", 1, bgav_redirector_get_name(rm->getFile() , 0)); printf("URL %d: %s\n", 1, bgav_redirector_get_url(rm->getFile(), 0)); sprintf(rm->getFilename(), "%s", bgav_redirector_get_url(rm->getFile(), 0) ); rm->clearFile(); if (!bgav_open( rm->getFile(), rm->getFilename() )) { printf("Could not open redirector\n"); rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL); //return NULL; } else { printf("opened redirector %s\n", rm->getFilename()); } } num_tracks = bgav_num_tracks(rm->getFile()); if ( num_tracks ) { bgav_select_track(rm->getFile(), 0); } else { printf("No tracks associated with file:%s\n", rm->getFilename() ); rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL); } audio_stream_count = bgav_num_audio_streams(rm->getFile(), 0); if( audio_stream_count ) bgav_set_audio_stream(rm->getFile(), 0, BGAV_STREAM_DECODE); video_stream_count = bgav_num_video_streams(rm->getFile(), 0); if( video_stream_count ) bgav_set_video_stream(rm->getFile(), 0, BGAV_STREAM_DECODE); rm->setVideoStreamCount(video_stream_count); rm->setAudioStreamCount(audio_stream_count); //printf("astream_count = %d, vstream_count=%d\n", audio_stream_count, video_stream_count); if(!bgav_start(rm->getFile())) { printf( "failed to start file\n"); rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL) ; //return NULL; } if( !rm->initFormat() ){ rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL) ; } if( !rm->startAVThreads() ){ rm->setState( STATE_EMPTY ); rm->closeFile(); rm->callOpenCallback(); pthread_exit(NULL) ; } // AV threads are now running, blocking will be necessary // STATE_READY and callOpenCallback is set/called in the // fifo fill callbacks rm->signalAV(); rm->signalAV(); //extra signal for second thread pthread_exit(NULL); //return NULL; }