parallel_pipeline: don't queue system frames

This commit is contained in:
Aleix Conchillo Flaqué
2024-12-09 09:35:18 -08:00
parent c6b401b5d1
commit e0a6c6871c
2 changed files with 15 additions and 3 deletions

View File

@@ -70,6 +70,8 @@ async def on_audio_data(processor, audio, sample_rate, num_channels):
### Fixed ### Fixed
- Fixed a `ParallelPipeline` issue that would cause system frames to be queued.
- Fixed `FastAPIWebsocketTransport` so it can work with binary data (e.g. using - Fixed `FastAPIWebsocketTransport` so it can work with binary data (e.g. using
the protobuf serializer). the protobuf serializer).

View File

@@ -12,7 +12,7 @@ from typing import List
from pipecat.pipeline.base_pipeline import BasePipeline from pipecat.pipeline.base_pipeline import BasePipeline
from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.pipeline import Pipeline
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.frames.frames import CancelFrame, EndFrame, Frame, StartFrame from pipecat.frames.frames import CancelFrame, EndFrame, Frame, StartFrame, SystemFrame
from loguru import logger from loguru import logger
@@ -27,6 +27,11 @@ class Source(FrameProcessor):
match direction: match direction:
case FrameDirection.UPSTREAM: case FrameDirection.UPSTREAM:
# We don't want to queue system frames as they would be
# processed by a separate task.
if isinstance(frame, SystemFrame):
await self.push_frame(frame, direction)
else:
await self._up_queue.put(frame) await self._up_queue.put(frame)
case FrameDirection.DOWNSTREAM: case FrameDirection.DOWNSTREAM:
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
@@ -44,6 +49,11 @@ class Sink(FrameProcessor):
case FrameDirection.UPSTREAM: case FrameDirection.UPSTREAM:
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
case FrameDirection.DOWNSTREAM: case FrameDirection.DOWNSTREAM:
# We don't want to queue system frames as they would be
# processed by a separate task.
if isinstance(frame, SystemFrame):
await self.push_frame(frame, direction)
else:
await self._down_queue.put(frame) await self._down_queue.put(frame)