Skip to content

Commit

Permalink
テスト追加
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Oct 12, 2024
1 parent a3ef7d9 commit 9a62b76
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tests/test_encoded_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def __init__(

self._connection.on_track = self._on_track

self._is_called_on_audio_transform = False
self._is_called_on_video_transform = False

def connect(self):
self._connection.connect()

Expand All @@ -241,6 +244,14 @@ def get_stats(self):
stats = json.loads(raw_stats)
return stats

@property
def is_called_on_audio_transform(self):
return self._is_called_on_audio_transform

@property
def is_called_on_video_transform(self):
return self._is_called_on_video_transform

def _on_set_offer(self, raw_offer):
offer = json.loads(raw_offer)
if offer["type"] == "offer":
Expand Down Expand Up @@ -287,9 +298,11 @@ def _on_audio_transform(self, frame: SoraTransformableAudioFrame):

# ここで new_data の末尾にデータをつける new_data を暗号化するなど任意の処理を実装する

self._is_called_on_audio_transform = True

# 加工したフレームデータで frame の フレームデータを入れ替える
frame.set_data(new_data)
self._video_transformer.enqueue(frame)
self._audio_transformer.enqueue(frame)

def _on_video_transform(self, frame: SoraTransformableVideoFrame):
# この実装が Encoded Transform を利用する上での基本形となる
Expand All @@ -300,6 +313,8 @@ def _on_video_transform(self, frame: SoraTransformableVideoFrame):

# ここで new_data の末尾にデータをつける new_data を暗号化するなど任意の処理を実装する

self._is_called_on_video_transform = True

# 加工したフレームデータで frame の フレームデータを入れ替える
frame.set_data(new_data)
self._video_transformer.enqueue(frame)
Expand All @@ -319,11 +334,20 @@ def test_encoded_transform(setup):
)
sendonly.connect()

recvonly = RecvonlyEncodedTransform(
signaling_urls,
channel_id,
metadata,
)
recvonly.connect()

time.sleep(5)

sendonly_stats = sendonly.get_stats()
recvonly_stats = recvonly.get_stats()

sendonly.disconnect()
recvonly.disconnect()

# codec が無かったら StopIteration 例外が上がる
sendonly_codec_stats = next(
Expand Down Expand Up @@ -352,6 +376,38 @@ def test_encoded_transform(setup):
assert outbound_rtp_stats["bytesSent"] > 0
assert outbound_rtp_stats["packetsSent"] > 0

print(recvonly_stats)

# codec が無かったら StopIteration 例外が上がる
recvonly_codec_stats = next(
s for s in recvonly_stats if s.get("type") == "codec" and s.get("mimeType") == "audio/opus"
)
assert recvonly_codec_stats["mimeType"] == "audio/opus"

recvonly_codec_stats = next(
s for s in recvonly_stats if s.get("type") == "codec" and s.get("mimeType") == "video/VP9"
)
assert recvonly_codec_stats["mimeType"] == "video/VP9"

# inbound-rtp が無かったら StopIteration 例外が上がる
inbound_rtp_stats = next(
s for s in recvonly_stats if s.get("type") == "inbound-rtp" and s.get("kind") == "audio"
)
# audio には encoderImplementation が無い
assert inbound_rtp_stats["bytesReceived"] > 0
assert inbound_rtp_stats["packetsReceived"] > 0

# inbound-rtp が無かったら StopIteration 例外が上がる
inbound_rtp_stats = next(
s for s in recvonly_stats if s.get("type") == "inbound-rtp" and s.get("kind") == "video"
)
# video には encoderImplementation が無い
assert inbound_rtp_stats["bytesReceived"] > 0
assert inbound_rtp_stats["packetsReceived"] > 0

# on_transform が呼ばれていることを確認
assert sendonly.is_called_on_audio_transform is True
assert sendonly.is_called_on_video_transform is True

assert recvonly.is_called_on_audio_transform is True
assert recvonly.is_called_on_video_transform is True

0 comments on commit 9a62b76

Please sign in to comment.