Esempio n. 1
0
int bg_avdec_init(avdec_priv * avdec)
  {
  int i;
  const bgav_metadata_t * m;
  const gavl_chapter_list_t * cl;
  gavl_time_t duration;
  
  avdec->num_tracks = bgav_num_tracks(avdec->dec);
  avdec->track_info = calloc(avdec->num_tracks, sizeof(*(avdec->track_info)));
  
  for(i = 0; i < avdec->num_tracks; i++)
    {
    avdec->track_info[i].num_audio_streams = bgav_num_audio_streams(avdec->dec, i);
    avdec->track_info[i].num_video_streams = bgav_num_video_streams(avdec->dec, i);
    avdec->track_info[i].num_text_streams = bgav_num_text_streams(avdec->dec, i);
    avdec->track_info[i].num_overlay_streams = bgav_num_overlay_streams(avdec->dec, i);

    if(bgav_can_seek(avdec->dec))
      avdec->track_info[i].flags |= BG_TRACK_SEEKABLE;
    if(bgav_can_pause(avdec->dec))
      avdec->track_info[i].flags |= BG_TRACK_PAUSABLE;
    
    if(avdec->track_info[i].num_audio_streams)
      {
      avdec->track_info[i].audio_streams =
        calloc(avdec->track_info[i].num_audio_streams,
               sizeof(*avdec->track_info[i].audio_streams));
      }
    
    if(avdec->track_info[i].num_video_streams)
      {
      avdec->track_info[i].video_streams =
        calloc(avdec->track_info[i].num_video_streams,
               sizeof(*avdec->track_info[i].video_streams));
      }
    if(avdec->track_info[i].num_text_streams)
      {
      avdec->track_info[i].text_streams =
        calloc(avdec->track_info[i].num_text_streams,
               sizeof(*avdec->track_info[i].text_streams));
      }
    if(avdec->track_info[i].num_overlay_streams)
      {
      avdec->track_info[i].overlay_streams =
        calloc(avdec->track_info[i].num_overlay_streams,
               sizeof(*avdec->track_info[i].overlay_streams));
      }

    duration = bgav_get_duration(avdec->dec, i);

    if(duration != GAVL_TIME_UNDEFINED)
      gavl_metadata_set_long(&avdec->track_info[i].metadata,
                             GAVL_META_APPROX_DURATION, duration);
        
    /* Get metadata */
    
    m = bgav_get_metadata(avdec->dec, i);
    
    gavl_metadata_copy(&avdec->track_info[i].metadata, m);

    /* Get chapters */

    cl = bgav_get_chapter_list(avdec->dec, i);
    if(cl)
      {
      avdec->track_info[i].chapter_list =
        gavl_chapter_list_copy(cl);
      bg_chapter_list_set_default_names(avdec->track_info[i].chapter_list);
      }
    }
  return 1;
  }
Esempio n. 2
0
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;
}