Skip to content

Commit

Permalink
examples: add 14a-local-render-remote-participant
Browse files Browse the repository at this point in the history
  • Loading branch information
aconchillo committed Apr 10, 2024
1 parent 0bf15fd commit 9fcbb36
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/foundational/03a-image-local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import tkinter as tk

from dailyai.pipeline.frames import TextFrame, EndFrame
from dailyai.pipeline.frames import TextFrame
from dailyai.pipeline.pipeline import Pipeline
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.transports.local_transport import LocalTransport
Expand Down
7 changes: 2 additions & 5 deletions examples/foundational/14-render-remote-participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from typing import AsyncGenerator

from PIL import Image

from dailyai.pipeline.aggregators import FrameProcessor

from dailyai.pipeline.frames import ImageFrame, Frame, UserImageFrame
Expand All @@ -25,14 +23,13 @@
class UserImageProcessor(FrameProcessor):

async def process_frame(self, frame: Frame) -> AsyncGenerator[Frame, None]:
print(frame)
if isinstance(frame, UserImageFrame):
yield ImageFrame(frame.image, frame.size)
else:
yield frame


async def main(room_url):
async def main(room_url: str, token):
transport = DailyTransport(
room_url,
token,
Expand All @@ -53,4 +50,4 @@ async def on_first_other_participant_joined(transport, participant):

if __name__ == "__main__":
(url, token) = configure()
asyncio.run(main(url))
asyncio.run(main(url, token))
72 changes: 72 additions & 0 deletions examples/foundational/14a-local-render-remote-participant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import asyncio
import io
import logging
import tkinter as tk

from typing import AsyncGenerator

from dailyai.pipeline.aggregators import FrameProcessor

from dailyai.pipeline.frames import ImageFrame, Frame, UserImageFrame
from dailyai.pipeline.pipeline import Pipeline
from dailyai.transports.daily_transport import DailyTransport

from dailyai.transports.local_transport import LocalTransport
from runner import configure

from dotenv import load_dotenv
load_dotenv(override=True)

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)


class UserImageProcessor(FrameProcessor):

async def process_frame(self, frame: Frame) -> AsyncGenerator[Frame, None]:
if isinstance(frame, UserImageFrame):
yield ImageFrame(frame.image, frame.size)
else:
yield frame


async def main(room_url: str, token):
tk_root = tk.Tk()
tk_root.title("dailyai")

local_transport = LocalTransport(
tk_root=tk_root,
camera_enabled=True,
camera_width=1280,
camera_height=720
)

transport = DailyTransport(
room_url,
token,
"Render participant video",
video_rendering_enabled=True
)

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport, participant):
transport.render_participant_video(participant["id"])

async def run_tk():
while not transport._stop_threads.is_set():
tk_root.update()
tk_root.update_idletasks()
await asyncio.sleep(0.1)

local_pipeline = Pipeline([UserImageProcessor()], source=transport.receive_queue)

await asyncio.gather(
transport.run(),
local_transport.run(local_pipeline, override_pipeline_source_queue=False),
run_tk()
)

if __name__ == "__main__":
(url, token) = configure()
asyncio.run(main(url, token))

0 comments on commit 9fcbb36

Please sign in to comment.