fastrtc icon indicating copy to clipboard operation
fastrtc copied to clipboard

Crash in gemini demo 'video/rtx' MIMEType retransmission incorrectly handled as a codec needing a decoder

Open ahundt opened this issue 1 week ago • 3 comments

I'm running this demo: https://huggingface.co/spaces/freddyaboulton/gemini-audio-video-chat

I've reported this upstream in aiortc too: https://github.com/aiortc/aiortc/issues/1258

Expected behavior: When parts of a video stream are retransmitted, that info should be re-incorporated into the main stream.

Behavior encountered: Retransmitted data is interpreted as an additional separate stream, so decoding fails with the error below.

Exception in thread video-decoder:
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1041, in _bootstrap_inner
    self.run()
    ~~~~~~~~^^
  File "/usr/local/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 992, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages/aiortc/rtcrtpreceiver.py", line 65, in decoder_worker
    decoder = get_decoder(codec)
  File "/Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages/aiortc/codecs/__init__.py", line 155, in get_decoder
    raise ValueError(f"No decoder found for MIME type `{mimeType}`")
ValueError: No decoder found for MIME type `video/rtx`
2025-02-21 17:41:27,130 - INFO - Video emit cancelled.
2025-02-21 17:41:27,133 - WARNING - RTCRtpsender(video) Traceback (most recent call last):
  File "/Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages/aiortc/rtcrtpsender.py", line 359, in _run_rtp
    enc_frame = await self._next_encoded_frame(codec)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages/aiortc/rtcrtpsender.py", line 311, in _next_encoded_frame
    payloads, timestamp = self.__encoder.pack(data)
                          ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages/aiortc/codecs/vpx.py", line 358, in pack
    payloads = self._packetize(bytes(packet), self.picture_id)
                               ~~~~~^^^^^^^^
TypeError: cannot convert 'NoneType' object to bytes

version info:

± uv pip show aiortc
Name: aiortc
Version: 1.10.1
Location: /Users/athundt/source/gemini-audio-video-chat/.venv/lib/python3.13/site-packages
Requires: aioice, av, cffi, cryptography, google-crc32c, pyee, pylibsrtp, pyopenssl
Required-by: gradio-webrtc

Here is code to run to reproduce, run this app (a free gemini key and twilio account is required, unfortuately), hit the record button, then hit the stop button: https://huggingface.co/spaces/freddyaboulton/gemini-audio-video-chat/tree/main

Relevant code: get_encoder() will check the various MIMEType strings, see there is no 'video/rtx' encoder, and raise an exception, but really I believe this is retransmitted data that should have been used to repair the main video stream e.g. if a packet was dropped. https://github.com/aiortc/aiortc/blob/main/src/aiortc/codecs/init.py#L158

decoder_worker() fails to catch the exception thrown by get_encoder(): https://github.com/aiortc/aiortc/blob/main/src/aiortc/rtcrtpreceiver.py#L65

ahundt avatar Feb 21 '25 23:02 ahundt