Changeset 2816

Show
Ignore:
Timestamp:
2007-05-31 03:56:34 (2 years ago)
Author:
shans
Message:

Audio loads-on-demand; audio-free tracks are now supported

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • liboggplay/trunk/plugin/plugin_gui_linux.c

    r2814 r2816  
    7676#endif 
    7777  gboolean              audio_opened; 
     78  gboolean              tried_audio; 
    7879  int64_t           playback_target; 
    7980 } PluginWindowInfo; 
     
    9293  _time += (tv.tv_usec / 1000); 
    9394  return _time; 
     95} 
     96 
     97void 
     98open_audio(PluginWindowInfo *info) { 
     99  int err; 
     100 
     101  info->audio_opened = TRUE; 
     102  info->playback_target = 0; 
     103 
     104  err = sa_device_create_pcm(&(info->audio_handle), "Mozilla Plugin",  
     105                  SA_PCM_WRONLY, SA_PCM_S16_LE, AUDIO_RATE, AUDIO_CHANNELS); 
     106   
     107  if (err) { 
     108        printf("Error creating audio device\n"); 
     109        info->audio_opened = FALSE; 
     110    return; 
     111  }  
     112 
     113  err = sa_device_open(info->audio_handle); 
     114  if (err) { 
     115        printf("Error opening audio device\n"); 
     116        info->audio_opened = FALSE; 
     117    return; 
     118  }  
     119  return; 
    94120} 
    95121 
     
    128154    imlib_free_image_and_decache(); 
    129155  } else { 
    130     printf("I got no frame\n"); 
    131156    return TRUE; 
    132157  } 
    133158 
     159#ifdef USE_AUDIO 
     160  if (info->tried_audio == FALSE && frame_data.samples != NULL) { 
     161    info->tried_audio = TRUE; 
     162    open_audio(info); 
     163  } 
     164 
     165  if (info->audio_opened == FALSE)  
     166#endif 
     167  { 
     168    info->playback_target = get_curr_time();  
     169  } 
     170  
    134171calc_offset: 
    135172   
     
    178215  if (info->new_oggplay_handle != NULL) { 
    179216    void * old_ogg_handle; 
    180     int err; 
    181217     
    182218    SEM_WAIT(info->oggplay_replace_sem); 
     
    187223    shut_oggplay(old_ogg_handle); 
    188224#ifdef USE_AUDIO   
    189     sa_device_close(info->audio_handle); 
    190     err = sa_device_create_pcm(&(info->audio_handle), "Mozilla Plugin",  
    191                   SA_PCM_WRONLY, SA_PCM_S16_LE, AUDIO_RATE, AUDIO_CHANNELS); 
    192     if (err) { 
    193         printf("Error creating audio device\n"); 
    194           info->audio_opened = FALSE; 
    195     }  
    196     err = sa_device_open(info->audio_handle); 
    197     if (err) { 
    198           printf("Error opening audio device\n"); 
    199         info->audio_opened = FALSE; 
    200     }  
    201  
    202     if (info->audio_opened == TRUE)  
    203     { 
    204       info->playback_target = 0; 
    205     }  
    206     else 
    207 #endif 
    208     { 
    209       info->playback_target = get_curr_time();  
    210     } 
     225    if (info->audio_opened == TRUE) 
     226      sa_device_close(info->audio_handle); 
     227    info->audio_opened = FALSE; 
     228    info->tried_audio = FALSE; 
     229#endif 
     230    offset = 40; 
    211231  } 
    212232   
     
    236256void * 
    237257display_thread(void *_info) { 
    238 #ifdef USE_AUDIO 
    239   int err; 
    240 #endif 
    241258 
    242259  PluginWindowInfo  * info = (PluginWindowInfo *)_info; 
    243260 
    244   /* open audio device for playback */ 
    245   info->playback_target = 0; 
    246 #ifdef USE_AUDIO 
    247   info->audio_opened = TRUE; 
    248   err = sa_device_create_pcm(&(info->audio_handle), "Mozilla Plugin",  
    249                   SA_PCM_WRONLY, SA_PCM_S16_LE, AUDIO_RATE, AUDIO_CHANNELS); 
    250    
    251   if (err) { 
    252         printf("Error creating audio device\n"); 
    253         info->audio_opened = FALSE; 
    254   }  
    255  
    256   err = sa_device_open(info->audio_handle); 
    257   if (err) { 
    258         printf("Error opening audio device\n"); 
    259         info->audio_opened = FALSE; 
    260   }  
    261  
    262   if (info->audio_opened == FALSE)  
    263 #endif 
    264   { 
    265     info->playback_target = get_curr_time();  
    266   } 
    267    
    268261  /* 
    269262   * construct a new toplevel window to draw into.  Make sure window is 
     
    290283  gtk_main(); 
    291284#ifdef USE_AUDIO   
    292   sa_device_close(info->audio_handle); 
     285  if (info->audio_opened == TRUE) 
     286    sa_device_close(info->audio_handle); 
    293287  info->audio_handle = NULL; 
    294288  info->audio_opened = FALSE; 
     
    317311  info->window = (GtkWidget*)plug; 
    318312  info->new_oggplay_handle = NULL; 
     313  info->tried_audio = FALSE; 
     314  info->audio_opened = FALSE; 
    319315  // set depending on the plugin startup settings 
    320316  info->playback_state = PLAYING;