mirror of
https://github.com/facefusion/facefusion.git
synced 2026-05-30 09:29:33 +02:00
Move RTC init helpers to bindings layer and clean up structs (#1086)
* converted from type() factory to proper ctypes.Structure subclasses * change class to method * bring back rtcSetLocalDescription * rename rtc_bindings.py to datachannel.py * rename rtc_library to datachannel_library and rearrange methods * cleanup
This commit is contained in:
@@ -10,26 +10,26 @@ from facefusion.types import SdpOffer
|
||||
|
||||
|
||||
def create_sdp_offer() -> Optional[SdpOffer]:
|
||||
rtc_library = rtc.create_static_rtc_library()
|
||||
datachannel_library = rtc.create_static_datachannel_library()
|
||||
peer_connection = rtc.create_peer_connection(disable_auto_negotiation = True)
|
||||
|
||||
rtc_library.rtcAddTrack(peer_connection, rtc.build_media_description('video', 96, 'VP8/90000', 'recvonly', 0))
|
||||
rtc_library.rtcAddTrack(peer_connection, rtc.build_media_description('audio', 111, 'opus/48000/2', 'recvonly', 1))
|
||||
rtc_library.rtcSetLocalDescription(peer_connection, b'offer')
|
||||
datachannel_library.rtcAddTrack(peer_connection, rtc.build_media_description('video', 96, 'VP8/90000', 'recvonly', 0))
|
||||
datachannel_library.rtcAddTrack(peer_connection, rtc.build_media_description('audio', 111, 'opus/48000/2', 'recvonly', 1))
|
||||
datachannel_library.rtcSetLocalDescription(peer_connection, b'offer')
|
||||
|
||||
buffer_size = 16384
|
||||
buffer_string = ctypes.create_string_buffer(buffer_size)
|
||||
wait_limit = time.monotonic() + 5
|
||||
|
||||
while time.monotonic() < wait_limit:
|
||||
if rtc_library.rtcGetLocalDescription(peer_connection, buffer_string, buffer_size) > 0:
|
||||
if datachannel_library.rtcGetLocalDescription(peer_connection, buffer_string, buffer_size) > 0:
|
||||
sdp = buffer_string.value.decode()
|
||||
rtc_library.rtcDeletePeerConnection(peer_connection)
|
||||
datachannel_library.rtcDeletePeerConnection(peer_connection)
|
||||
return sdp
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
rtc_library.rtcDeletePeerConnection(peer_connection)
|
||||
datachannel_library.rtcDeletePeerConnection(peer_connection)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
+8
-8
@@ -15,14 +15,14 @@ def test_build_media_description() -> None:
|
||||
|
||||
def test_create_peer_connection() -> None:
|
||||
peer_connection = rtc.create_peer_connection()
|
||||
rtc_library = rtc.create_static_rtc_library()
|
||||
datachannel_library = rtc.create_static_datachannel_library()
|
||||
|
||||
assert peer_connection > 0
|
||||
assert rtc_library.rtcDeletePeerConnection(peer_connection) == 0
|
||||
assert datachannel_library.rtcDeletePeerConnection(peer_connection) == 0
|
||||
|
||||
|
||||
def test_add_audio_track() -> None:
|
||||
rtc_library = rtc.create_static_rtc_library()
|
||||
datachannel_library = rtc.create_static_datachannel_library()
|
||||
|
||||
sender_connection = rtc.create_peer_connection()
|
||||
sender_audio_track = rtc.add_audio_track(sender_connection, 'sendonly')
|
||||
@@ -40,12 +40,12 @@ def test_add_audio_track() -> None:
|
||||
assert 'opus/48000/2' in sdp_offer
|
||||
assert 'opus/48000/2' in sdp_answer
|
||||
|
||||
assert rtc_library.rtcDeletePeerConnection(sender_connection) == 0
|
||||
assert rtc_library.rtcDeletePeerConnection(receiver_connection) == 0
|
||||
assert datachannel_library.rtcDeletePeerConnection(sender_connection) == 0
|
||||
assert datachannel_library.rtcDeletePeerConnection(receiver_connection) == 0
|
||||
|
||||
|
||||
def test_add_video_track() -> None:
|
||||
rtc_library = rtc.create_static_rtc_library()
|
||||
datachannel_library = rtc.create_static_datachannel_library()
|
||||
|
||||
sender_connection = rtc.create_peer_connection()
|
||||
sender_video_track = rtc.add_video_track(sender_connection, 'sendonly')
|
||||
@@ -63,5 +63,5 @@ def test_add_video_track() -> None:
|
||||
assert 'VP8/90000' in sdp_offer
|
||||
assert 'VP8/90000' in sdp_answer
|
||||
|
||||
assert rtc_library.rtcDeletePeerConnection(sender_connection) == 0
|
||||
assert rtc_library.rtcDeletePeerConnection(receiver_connection) == 0
|
||||
assert datachannel_library.rtcDeletePeerConnection(sender_connection) == 0
|
||||
assert datachannel_library.rtcDeletePeerConnection(receiver_connection) == 0
|
||||
|
||||
Reference in New Issue
Block a user