mirror of
				https://github.com/gnif/LookingGlass.git
				synced 2025-11-03 22:22:08 +00:00 
			
		
		
		
	[client] audio/pw: drop restarting state
Automatically restarting playback once draining has completed could result in playback starting too early (i.e., before there is enough data in the ring buffer to avoid underrunning). `audio_playbackData` will keep invoking `start` until it returns true anyway, so we can just allow draining to complete normally and wait for `start` to be called again.
This commit is contained in:
		
				
					committed by
					
						
						Geoffrey McRae
					
				
			
			
				
	
			
			
			
						parent
						
							8580978321
						
					
				
				
					commit
					68b42e1c1a
				
			@@ -33,8 +33,7 @@ typedef enum
 | 
			
		||||
{
 | 
			
		||||
  STREAM_STATE_INACTIVE,
 | 
			
		||||
  STREAM_STATE_ACTIVE,
 | 
			
		||||
  STREAM_STATE_DRAINING,
 | 
			
		||||
  STREAM_STATE_RESTARTING
 | 
			
		||||
  STREAM_STATE_DRAINING
 | 
			
		||||
}
 | 
			
		||||
StreamState;
 | 
			
		||||
 | 
			
		||||
@@ -123,20 +122,8 @@ static void pipewire_onPlaybackProcess(void * userdata)
 | 
			
		||||
static void pipewire_onPlaybackDrained(void * userdata)
 | 
			
		||||
{
 | 
			
		||||
  pw_thread_loop_lock(pw.thread);
 | 
			
		||||
 | 
			
		||||
  if (pw.playback.state == STREAM_STATE_RESTARTING)
 | 
			
		||||
  {
 | 
			
		||||
    // A play command was received while we were in the middle of stopping;
 | 
			
		||||
    // switch straight back into playing
 | 
			
		||||
    pw_stream_set_active(pw.playback.stream, true);
 | 
			
		||||
    pw.playback.state = STREAM_STATE_ACTIVE;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    pw_stream_set_active(pw.playback.stream, false);
 | 
			
		||||
    pw.playback.state = STREAM_STATE_INACTIVE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pw_stream_set_active(pw.playback.stream, false);
 | 
			
		||||
  pw.playback.state = STREAM_STATE_INACTIVE;
 | 
			
		||||
  pw_thread_loop_unlock(pw.thread);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -274,8 +261,7 @@ static bool pipewire_playbackStart(int framesBuffered)
 | 
			
		||||
 | 
			
		||||
  bool start = false;
 | 
			
		||||
 | 
			
		||||
  if (pw.playback.state != STREAM_STATE_ACTIVE &&
 | 
			
		||||
    pw.playback.state != STREAM_STATE_RESTARTING)
 | 
			
		||||
  if (pw.playback.state != STREAM_STATE_ACTIVE)
 | 
			
		||||
  {
 | 
			
		||||
    pw_thread_loop_lock(pw.thread);
 | 
			
		||||
 | 
			
		||||
@@ -291,9 +277,8 @@ static bool pipewire_playbackStart(int framesBuffered)
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case STREAM_STATE_DRAINING:
 | 
			
		||||
        // We are in the middle of draining the PipeWire buffers; we will need
 | 
			
		||||
        // to reactivate the stream once this has completed
 | 
			
		||||
        pw.playback.state = STREAM_STATE_RESTARTING;
 | 
			
		||||
        // We are in the middle of draining the PipeWire buffers; we need to
 | 
			
		||||
        // wait for this to complete before allowing the new playback to start
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
@@ -308,30 +293,12 @@ static bool pipewire_playbackStart(int framesBuffered)
 | 
			
		||||
 | 
			
		||||
static void pipewire_playbackStop(void)
 | 
			
		||||
{
 | 
			
		||||
  if (pw.playback.state != STREAM_STATE_ACTIVE &&
 | 
			
		||||
    pw.playback.state != STREAM_STATE_RESTARTING)
 | 
			
		||||
  if (pw.playback.state != STREAM_STATE_ACTIVE)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  pw_thread_loop_lock(pw.thread);
 | 
			
		||||
 | 
			
		||||
  switch (pw.playback.state)
 | 
			
		||||
  {
 | 
			
		||||
    case STREAM_STATE_ACTIVE:
 | 
			
		||||
      pw_stream_flush(pw.playback.stream, true);
 | 
			
		||||
      pw.playback.state = STREAM_STATE_DRAINING;
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case STREAM_STATE_RESTARTING:
 | 
			
		||||
      // A stop was requested, and then a start while PipeWire was draining, and
 | 
			
		||||
      // now another stop. PipeWire hasn't finished draining yet so just switch
 | 
			
		||||
      // the state back
 | 
			
		||||
      pw.playback.state = STREAM_STATE_DRAINING;
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      DEBUG_UNREACHABLE();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pw_stream_flush(pw.playback.stream, true);
 | 
			
		||||
  pw.playback.state = STREAM_STATE_DRAINING;
 | 
			
		||||
  pw_thread_loop_unlock(pw.thread);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user