Skip to content

Commit abcc8c7

Browse files
committed
raise err if av frame format is unsupported
1 parent eabaf4f commit abcc8c7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

getstream/video/rtc/track_util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,10 @@ def from_av_frame(cls, frame: "av.AudioFrame") -> "PcmData":
436436
pcm_format = AudioFormat.F32
437437
dtype = np.float32
438438
else:
439-
pcm_format = AudioFormat.S16
440-
dtype = np.int16
439+
raise ValueError(
440+
f"Unsupported audio frame format: '{frame_format}'. "
441+
f"Supported formats are: s16, s16p (int16), flt, fltp (float32)"
442+
)
441443

442444
# Handle empty frames
443445
if frame.samples == 0:

tests/rtc/test_pcm_data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,3 +1541,22 @@ def test_from_audioframe_48khz_standard():
15411541
assert pcm.format == "s16"
15421542
assert len(pcm.samples) == 960
15431543
assert pcm.duration_ms == pytest.approx(20.0, rel=1e-3)
1544+
1545+
1546+
def test_from_audioframe_unsupported_format():
1547+
"""Test that unsupported audio formats raise a clear exception."""
1548+
# Create audio frame with unsupported s32 format
1549+
samples = np.array([100, 200, 300], dtype=np.int32)
1550+
frame = av.AudioFrame.from_ndarray(
1551+
samples.reshape(1, -1), format="s32p", layout="mono"
1552+
)
1553+
frame.sample_rate = 16000
1554+
1555+
# Should raise ValueError with a clear error message
1556+
with pytest.raises(ValueError) as exc_info:
1557+
PcmData.from_av_frame(frame)
1558+
1559+
error_msg = str(exc_info.value)
1560+
assert "Unsupported audio frame format" in error_msg
1561+
assert "s32p" in error_msg
1562+
assert "s16" in error_msg or "flt" in error_msg # Should mention supported formats

0 commit comments

Comments
 (0)