mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	stream: add a method to check if driving or not
When the node is driving, we need to call trigger_process() otherwise we don't and we simply need to wait for the process() to be called, triggered by the driver node. See #1484
This commit is contained in:
		
							parent
							
								
									3c97090ba0
								
							
						
					
					
						commit
						b030a4e7da
					
				
					 5 changed files with 32 additions and 14 deletions
				
			
		| 
						 | 
					@ -208,8 +208,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
 | 
				
			||||||
		interval.tv_sec = 0;
 | 
							interval.tv_sec = 0;
 | 
				
			||||||
		interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
							interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
 | 
							if (pw_stream_is_driving(data->stream))
 | 
				
			||||||
				data->timer, &timeout, &interval, false);
 | 
								pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
 | 
				
			||||||
 | 
										data->timer, &timeout, &interval, false);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -214,8 +214,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
 | 
				
			||||||
		interval.tv_sec = 0;
 | 
							interval.tv_sec = 0;
 | 
				
			||||||
		interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
							interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
 | 
							if (pw_stream_is_driving(data->stream))
 | 
				
			||||||
				data->timer, &timeout, &interval, false);
 | 
								pw_loop_update_timer(pw_thread_loop_get_loop(data->loop),
 | 
				
			||||||
 | 
										data->timer, &timeout, &interval, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		timeout.tv_sec = 1;
 | 
							timeout.tv_sec = 1;
 | 
				
			||||||
		timeout.tv_nsec = 0;
 | 
							timeout.tv_nsec = 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -208,8 +208,9 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
 | 
				
			||||||
		interval.tv_sec = 0;
 | 
							interval.tv_sec = 0;
 | 
				
			||||||
		interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
							interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
 | 
							if (pw_stream_is_driving(data->stream))
 | 
				
			||||||
				data->timer, &timeout, &interval, false);
 | 
								pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
 | 
				
			||||||
 | 
										data->timer, &timeout, &interval, false);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2106,6 +2106,13 @@ int pw_stream_flush(struct pw_stream *stream, bool drain)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SPA_EXPORT
 | 
				
			||||||
 | 
					bool pw_stream_is_driving(struct pw_stream *stream)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
 | 
				
			||||||
 | 
						return impl->driving;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
do_trigger_process(struct spa_loop *loop,
 | 
					do_trigger_process(struct spa_loop *loop,
 | 
				
			||||||
                 bool async, uint32_t seq, const void *data, size_t size, void *user_data)
 | 
					                 bool async, uint32_t seq, const void *data, size_t size, void *user_data)
 | 
				
			||||||
| 
						 | 
					@ -2133,14 +2140,16 @@ int pw_stream_trigger_process(struct pw_stream *stream)
 | 
				
			||||||
	/* flag to check for old or new behaviour */
 | 
						/* flag to check for old or new behaviour */
 | 
				
			||||||
	impl->using_drive = true;
 | 
						impl->using_drive = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (impl->driving) {
 | 
						if (!impl->driving)
 | 
				
			||||||
		if (impl->direction == SPA_DIRECTION_OUTPUT &&
 | 
							return -EINVAL;
 | 
				
			||||||
		    !impl->process_rt) {
 | 
					
 | 
				
			||||||
			pw_loop_invoke(impl->context->main_loop,
 | 
						if (impl->direction == SPA_DIRECTION_OUTPUT &&
 | 
				
			||||||
				do_call_process, 1, NULL, 0, false, impl);
 | 
						    !impl->process_rt) {
 | 
				
			||||||
		}
 | 
							pw_loop_invoke(impl->context->main_loop,
 | 
				
			||||||
		res = pw_loop_invoke(impl->context->data_loop,
 | 
								do_call_process, 1, NULL, 0, false, impl);
 | 
				
			||||||
			do_trigger_process, 1, NULL, 0, false, impl);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						res = pw_loop_invoke(impl->context->data_loop,
 | 
				
			||||||
 | 
							do_trigger_process, 1, NULL, 0, false, impl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -362,6 +362,12 @@ int pw_stream_set_active(struct pw_stream *stream, bool active);
 | 
				
			||||||
 * be called when all data is played or recorded */
 | 
					 * be called when all data is played or recorded */
 | 
				
			||||||
int pw_stream_flush(struct pw_stream *stream, bool drain);
 | 
					int pw_stream_flush(struct pw_stream *stream, bool drain);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Check if the stream is driving. The stream needs to have the
 | 
				
			||||||
 | 
					 * PW_STREAM_FLAG_DRIVER set. When the stream is driving,
 | 
				
			||||||
 | 
					 * pw_stream_trigger_process() needs to be called when data is
 | 
				
			||||||
 | 
					 * available (output) or needed (input). Since 0.3.34 */
 | 
				
			||||||
 | 
					bool pw_stream_is_driving(struct pw_stream *stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Trigger a push/pull on the stream. One iteration of the graph will
 | 
					/** Trigger a push/pull on the stream. One iteration of the graph will
 | 
				
			||||||
 * scheduled and process() will be called. Since 0.3.34 */
 | 
					 * scheduled and process() will be called. Since 0.3.34 */
 | 
				
			||||||
int pw_stream_trigger_process(struct pw_stream *stream);
 | 
					int pw_stream_trigger_process(struct pw_stream *stream);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue