Skip to content

Commit 8d1cfb8

Browse files
committed
daily-python: simplify Qt/Gtk demos
1 parent a3458a7 commit 8d1cfb8

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

demos/gtk/gtk_app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
gi.require_version("Gtk", "4.0")
2222
from gi.repository import GLib, Gtk
2323

24-
import numpy as np
25-
2624
from daily import *
2725

2826
class DailyGtkApp(Gtk.Application):
@@ -45,7 +43,7 @@ def __init__(self, meeting_url, participant_id, save_audio, screen_share):
4543
self.__frame_width = self.__width
4644
self.__frame_height = self.__height
4745

48-
self.__black_frame = np.zeros(self.__width * self.__height * 4)
46+
self.__black_frame = bytearray(self.__width * self.__height * 4)
4947

5048
self.__joined = False
5149
self.__meeting_url = meeting_url
@@ -145,7 +143,7 @@ def leave(self):
145143

146144
def drawing_area_draw(self, area, context, w, h, data):
147145
if self.__joined and not self.__frame is None:
148-
image = self.__frame
146+
image = bytearray(self.__frame.buffer)
149147
else:
150148
image = self.__black_frame
151149

@@ -170,7 +168,7 @@ def on_audio_data(self, participant_id, audio_data):
170168
def on_video_frame(self, participant_id, video_frame):
171169
self.__frame_width = video_frame.width
172170
self.__frame_height = video_frame.height
173-
self.__frame = np.frombuffer(video_frame.buffer, dtype=np.uint8).copy()
171+
self.__frame = video_frame
174172
self.__drawing_area.queue_draw()
175173

176174

demos/qt/qt_app.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,12 @@
1515
import sys
1616
import wave
1717

18-
from dataclasses import dataclass
19-
2018
from PySide6 import QtCore, QtGui, QtWidgets
2119

22-
import numpy as np
23-
2420
from daily import *
2521

2622
class DailyQtWidget(QtWidgets.QWidget):
27-
@dataclass
28-
class VideoFrameData:
29-
buffer: np.ndarray
30-
width: int
31-
height: int
32-
33-
frame_signal = QtCore.Signal(VideoFrameData)
23+
frame_signal = QtCore.Signal(VideoFrame)
3424

3525
def __init__(self, meeting_url, participant_id, save_audio, screen_share):
3626
super().__init__()
@@ -138,9 +128,9 @@ def join(self, meeting_url, participant_id):
138128
def leave(self):
139129
self.__client.leave(completion = self.on_left)
140130

141-
def draw_image(self, frame_data):
142-
image = QtGui.QImage(frame_data.buffer, frame_data.width, frame_data.height,
143-
frame_data.width * 4, QtGui.QImage.Format.Format_ARGB32)
131+
def draw_image(self, video_frame):
132+
image = QtGui.QImage(video_frame.buffer, video_frame.width, video_frame.height,
133+
video_frame.width * 4, QtGui.QImage.Format.Format_ARGB32)
144134
scaled = image.scaled(self.__frame_width, self.__frame_height, QtCore.Qt.AspectRatioMode.KeepAspectRatio)
145135
pixmap = QtGui.QPixmap.fromImage(scaled)
146136
self.__image_label.setPixmap(pixmap)
@@ -149,9 +139,7 @@ def on_audio_data(self, participant_id, audio_data):
149139
self.__wave.writeframes(audio_data.audio_frames)
150140

151141
def on_video_frame(self, participant_id, video_frame):
152-
data = np.frombuffer(video_frame.buffer, dtype=np.uint8).copy()
153-
frame_data = self.VideoFrameData(data, video_frame.width, video_frame.height)
154-
self.frame_signal.emit(frame_data)
142+
self.frame_signal.emit(video_frame)
155143

156144
def main():
157145
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)