mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	plugins: small cleanups
This commit is contained in:
		
							parent
							
								
									b05d82d514
								
							
						
					
					
						commit
						032cc69f2f
					
				
					 5 changed files with 62 additions and 41 deletions
				
			
		| 
						 | 
				
			
			@ -248,20 +248,33 @@ send_have_output (SpaAudioTestSrc *this)
 | 
			
		|||
static void
 | 
			
		||||
set_timer (SpaAudioTestSrc *this, bool enabled)
 | 
			
		||||
{
 | 
			
		||||
  if (enabled) {
 | 
			
		||||
    if (this->props.live) {
 | 
			
		||||
      uint64_t next_time = this->start_time + this->elapsed_time;
 | 
			
		||||
      this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
 | 
			
		||||
      this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
 | 
			
		||||
  if (this->async || this->props.live) {
 | 
			
		||||
    if (enabled) {
 | 
			
		||||
      if (this->props.live) {
 | 
			
		||||
        uint64_t next_time = this->start_time + this->elapsed_time;
 | 
			
		||||
        this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
 | 
			
		||||
        this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
 | 
			
		||||
      } else {
 | 
			
		||||
        this->timerspec.it_value.tv_sec = 0;
 | 
			
		||||
        this->timerspec.it_value.tv_nsec = 1;
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      this->timerspec.it_value.tv_sec = 0;
 | 
			
		||||
      this->timerspec.it_value.tv_nsec = 1;
 | 
			
		||||
      this->timerspec.it_value.tv_nsec = 0;
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    this->timerspec.it_value.tv_sec = 0;
 | 
			
		||||
    this->timerspec.it_value.tv_nsec = 0;
 | 
			
		||||
    timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
read_timer (SpaAudioTestSrc *this)
 | 
			
		||||
{
 | 
			
		||||
  uint64_t expirations;
 | 
			
		||||
 | 
			
		||||
  if (this->async || this->props.live) {
 | 
			
		||||
    if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
 | 
			
		||||
      perror ("read timerfd");
 | 
			
		||||
  }
 | 
			
		||||
  timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static SpaResult
 | 
			
		||||
| 
						 | 
				
			
			@ -269,11 +282,9 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
 | 
			
		|||
{
 | 
			
		||||
  ATSBuffer *b;
 | 
			
		||||
  SpaPortIO *io = this->io;
 | 
			
		||||
  uint64_t expirations;
 | 
			
		||||
  int n_bytes, n_samples;
 | 
			
		||||
 | 
			
		||||
  if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
 | 
			
		||||
    perror ("read timerfd");
 | 
			
		||||
  read_timer (this);
 | 
			
		||||
 | 
			
		||||
  if (spa_list_is_empty (&this->empty)) {
 | 
			
		||||
    set_timer (this, false);
 | 
			
		||||
| 
						 | 
				
			
			@ -942,7 +953,8 @@ audiotestsrc_clear (SpaHandle *handle)
 | 
			
		|||
 | 
			
		||||
  this = (SpaAudioTestSrc *) handle;
 | 
			
		||||
 | 
			
		||||
  spa_loop_remove_source (this->data_loop, &this->timer_source);
 | 
			
		||||
  if (this->data_loop)
 | 
			
		||||
    spa_loop_remove_source (this->data_loop, &this->timer_source);
 | 
			
		||||
  close (this->timer_source.fd);
 | 
			
		||||
 | 
			
		||||
  return SPA_RESULT_OK;
 | 
			
		||||
| 
						 | 
				
			
			@ -1006,7 +1018,7 @@ audiotestsrc_init (const SpaHandleFactory  *factory,
 | 
			
		|||
  this->timerspec.it_interval.tv_sec = 0;
 | 
			
		||||
  this->timerspec.it_interval.tv_nsec = 0;
 | 
			
		||||
 | 
			
		||||
  if (this->data_loop && this->async)
 | 
			
		||||
  if (this->data_loop)
 | 
			
		||||
    spa_loop_add_source (this->data_loop, &this->timer_source);
 | 
			
		||||
 | 
			
		||||
  this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue