Example #1
0
void
ags_devout_thread_stop(AgsThread *thread)
{
  AgsDevout *devout;
  AgsAudioLoop *audio_loop;
  AgsDevoutThread *devout_thread;

  devout_thread = AGS_DEVOUT_THREAD(thread);

  devout = AGS_DEVOUT(thread->devout);
  audio_loop = AGS_AUDIO_LOOP(thread->parent);

  if((AGS_DEVOUT_START_PLAY & (devout->flags)) != 0){
#ifdef AGS_DEBUG
    g_message("ags_devout_thread_stop:  just starting\n\0");
#endif
    return;
  }

  AGS_THREAD_CLASS(ags_devout_thread_parent_class)->stop(thread);

  devout->flags &= ~(AGS_DEVOUT_PLAY);
  
  if((AGS_DEVOUT_ALSA & (devout->flags)) != 0){
    ags_devout_alsa_free(devout);
  }else{  
  }
}
Example #2
0
void
ags_gui_task_thread_run(AgsThread *thread)
{
  AgsGuiThread *gui_thread;
  GMainContext *main_context;

  gui_thread = AGS_AUDIO_LOOP(AGS_MAIN(AGS_DEVOUT(thread->devout)->ags_main)->main_loop)->gui_thread;
  main_context = g_main_context_default();

  if(!g_main_context_acquire(main_context)){
    gboolean got_ownership = FALSE;

    while(!got_ownership){
      got_ownership = g_main_context_wait(main_context,
					  &(gui_thread->cond),
					  &(gui_thread->mutex));
    }
  }

  gdk_threads_enter();
  gdk_threads_leave();

  g_main_context_iteration(main_context, FALSE);

  AGS_THREAD_CLASS(ags_gui_task_thread_parent_class)->run(thread);

  g_main_context_release(main_context);
}
void
ags_polling_thread_start(AgsThread *thread)
{
  /*  */
  if((AGS_THREAD_SINGLE_LOOP & (g_atomic_int_get(&(thread->flags)))) == 0){
    AGS_THREAD_CLASS(ags_polling_thread_parent_class)->start(thread);
  }
}
Example #4
0
void
ags_gui_task_thread_start(AgsThread *thread)
{
  AgsGuiTaskThread *gui_task_thread;

  gui_task_thread = AGS_GUI_TASK_THREAD(thread);

  if((AGS_THREAD_SINGLE_LOOP & (g_atomic_int_get(&(thread->flags)))) == 0){
    AGS_THREAD_CLASS(ags_gui_task_thread_parent_class)->start(thread);
  }
}
void
ags_soundcard_thread_start(AgsThread *thread)
{
  AgsSoundcardThread *soundcard_thread;

  AgsThread *main_loop;
  AgsPollingThread *polling_thread;
  
  GObject *soundcard;

  GList *poll_fd;
  
  GError *error;

  soundcard_thread = AGS_SOUNDCARD_THREAD(thread);
  main_loop = ags_thread_get_toplevel(thread);
  
  soundcard = soundcard_thread->soundcard;

  /* disable timing */
  g_atomic_int_and(&(thread->flags),
		   (~AGS_THREAD_TIMING));
  
  /* find polling thread */
  polling_thread = (AgsPollingThread *) ags_thread_find_type(main_loop,
							     AGS_TYPE_POLLING_THREAD);
    
  /* add poll fd and connect dispatch */
  poll_fd = ags_soundcard_get_poll_fd(AGS_SOUNDCARD(soundcard));
    
  while(poll_fd != NULL){
    if(polling_thread != NULL){
      gint position;
      
      ags_polling_thread_add_poll_fd(polling_thread,
				     poll_fd->data);
      g_signal_connect(G_OBJECT(poll_fd->data), "dispatch",
		       G_CALLBACK(ags_soundcard_thread_dispatch_callback), soundcard_thread);

      position = ags_polling_thread_fd_position(polling_thread,
						AGS_POLL_FD(poll_fd->data)->fd);
      
      if(position != -1){
	polling_thread->fds[position].events = POLLOUT;
      }
    }
    
    poll_fd = poll_fd->next;
  }

  if((AGS_THREAD_SINGLE_LOOP & (g_atomic_int_get(&(thread->flags)))) == 0){
    AGS_THREAD_CLASS(ags_soundcard_thread_parent_class)->start(thread);
  }
}
void
ags_soundcard_thread_stop(AgsThread *thread)
{
  AgsSoundcardThread *soundcard_thread;

  AgsThread *main_loop;
  AgsPollingThread *polling_thread;
  
  GObject *soundcard;

  GList *poll_fd;
    
  soundcard_thread = AGS_SOUNDCARD_THREAD(thread);
  main_loop = ags_thread_get_toplevel(thread);

  soundcard = soundcard_thread->soundcard;

  /* stop thread and soundcard */
  AGS_THREAD_CLASS(ags_soundcard_thread_parent_class)->stop(thread);

  //FIXME:JK: is this safe?
  ags_soundcard_stop(AGS_SOUNDCARD(soundcard));

  g_atomic_int_or(&(thread->flags),
		  AGS_THREAD_TIMING);

  /* find polling thread */
  polling_thread = (AgsPollingThread *) ags_thread_find_type(main_loop,
							     AGS_TYPE_POLLING_THREAD);
    
  /* remove poll fd */
  poll_fd = ags_soundcard_get_poll_fd(AGS_SOUNDCARD(soundcard));
    
  while(poll_fd != NULL){
    if(polling_thread != NULL){
      gint position;
      
      g_object_disconnect(G_OBJECT(poll_fd->data),
			  "any_signal::dispatch",
			  G_CALLBACK(ags_soundcard_thread_dispatch_callback),
			  soundcard_thread,
			  NULL);
      
      ags_polling_thread_remove_poll_fd(polling_thread,
					poll_fd->data);
    }
    
    poll_fd = poll_fd->next;
  }
}
Example #7
0
void
ags_devout_thread_start(AgsThread *thread)
{
  AgsDevout *devout;
  AgsDevoutThread *devout_thread;
  static gboolean initialized = FALSE;
  GError *error;

  devout_thread = AGS_DEVOUT_THREAD(thread);

  devout = AGS_DEVOUT(thread->devout);

  /*  */
  if((AGS_THREAD_INITIAL_RUN & (g_atomic_int_get(&(thread->flags)))) != 0){
    pthread_mutex_lock(&(thread->start_mutex));

    g_atomic_int_and(&(thread->flags),
		     (~AGS_THREAD_INITIAL_RUN));
    pthread_cond_broadcast(&(thread->start_cond));

    pthread_mutex_unlock(&(thread->start_mutex));
  }

  /*  */
  devout->flags |= (AGS_DEVOUT_BUFFER3 |
		    AGS_DEVOUT_PLAY);

  /*  */
  devout_thread->error = NULL;

  if((AGS_DEVOUT_ALSA & (devout->flags)) != 0){
    if(devout->out.alsa.handle == NULL){
      ags_devout_alsa_init(devout,
      			   devout_thread->error);
      
      devout->flags &= (~AGS_DEVOUT_START_PLAY);
#ifdef AGS_DEBUG
      g_message("ags_devout_alsa_play\0");
#endif
    }
  }


  if(devout_thread->error != NULL){
    AgsAudioLoop *audio_loop;

    /* preserve AgsAudioLoop from playing */
    //TODO:JK: implement me

    return;
  }

  memset(devout->buffer[0], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short));
  memset(devout->buffer[1], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short));
  memset(devout->buffer[2], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short));
  memset(devout->buffer[3], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short));

  if((AGS_THREAD_SINGLE_LOOP & (g_atomic_int_get(&(thread->flags)))) == 0){
    AGS_THREAD_CLASS(ags_devout_thread_parent_class)->start(thread);
  }
}
void
ags_polling_thread_stop(AgsThread *thread)
{
  /*  */
  AGS_THREAD_CLASS(ags_polling_thread_parent_class)->stop(thread);  
}