webrtc_sendrecv.py: Add AV1 support when creating the offer

Requires svtav1enc at present for simplicity.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4644>
This commit is contained in:
Nirbheek Chauhan 2023-05-09 18:23:04 +05:30 committed by GStreamer Marge Bot
parent 61e536b546
commit aa1fa50129

View file

@ -34,7 +34,7 @@ except ImportError:
# These properties all mirror the ones in webrtc-sendrecv.c, see there for explanations
PIPELINE_DESC_VP8 = '''
webrtcbin name=sendrecv latency=0 stun-server=stun://stun.l.google.com:19302
videotestsrc is-live=true pattern=ball ! videoconvert ! queue ! \
videotestsrc is-live=true pattern=ball ! videoconvert ! queue !
vp8enc deadline=1 keyframe-max-dist=2000 ! rtpvp8pay picture-id-mode=15-bit !
queue ! application/x-rtp,media=video,encoding-name=VP8,payload={video_pt} ! sendrecv.
audiotestsrc is-live=true ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay !
@ -42,14 +42,25 @@ webrtcbin name=sendrecv latency=0 stun-server=stun://stun.l.google.com:19302
'''
PIPELINE_DESC_H264 = '''
webrtcbin name=sendrecv latency=0 stun-server=stun://stun.l.google.com:19302
videotestsrc is-live=true pattern=ball ! videoconvert ! queue ! \
x264enc tune=zerolatency speed-preset=ultrafast key-int-max=30 intra-refresh=true ! rtph264pay aggregate-mode=zero-latency config-interval=-1 !
videotestsrc is-live=true pattern=ball ! videoconvert ! queue !
x264enc tune=zerolatency speed-preset=ultrafast key-int-max=30 intra-refresh=true !
rtph264pay aggregate-mode=zero-latency config-interval=-1 !
queue ! application/x-rtp,media=video,encoding-name=H264,payload={video_pt} ! sendrecv.
audiotestsrc is-live=true ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay !
queue ! application/x-rtp,media=audio,encoding-name=OPUS,payload={audio_pt} ! sendrecv.
'''
# Force I420 because dav1d bundled with Chrome doesn't support 10-bit choma/luma (I420_10LE)
PIPELINE_DESC_AV1 = '''
webrtcbin name=sendrecv latency=0 stun-server=stun://stun.l.google.com:19302
videotestsrc is-live=true pattern=ball ! videoconvert ! queue !
video/x-raw,format=I420 ! svtav1enc preset=13 ! av1parse ! rtpav1pay !
queue ! application/x-rtp,media=video,encoding-name=AV1,payload={video_pt} ! sendrecv.
audiotestsrc is-live=true ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay !
queue ! application/x-rtp,media=audio,encoding-name=OPUS,payload={audio_pt} ! sendrecv.
'''
PIPELINE_DESC = {
'AV1': PIPELINE_DESC_AV1,
'H264': PIPELINE_DESC_H264,
'VP8': PIPELINE_DESC_VP8,
}
@ -334,22 +345,26 @@ class WebRTCClient:
self.conn = None
def check_plugins():
needed = ["opus", "vpx", "nice", "webrtc", "dtls", "srtp", "rtp",
def check_plugins(video_encoding):
needed = ["opus", "nice", "webrtc", "dtls", "srtp", "rtp",
"rtpmanager", "videotestsrc", "audiotestsrc"]
if video_encoding == 'vp8':
needed.append('vpx')
elif video_encoding == 'h264':
needed += ['x264', 'videoparsersbad']
elif video_encoding == 'av1':
needed += ['svtav1', 'videoparsersbad']
missing = list(filter(lambda p: Gst.Registry.get().find_plugin(p) is None, needed))
if len(missing):
print_error('Missing gstreamer plugins:', missing)
print_error(f'Missing gstreamer plugins: {missing}')
return False
return True
if __name__ == '__main__':
Gst.init(None)
if not check_plugins():
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('--video-encoding', default='vp8', nargs='?', choices=['vp8', 'h264'],
parser.add_argument('--video-encoding', default='vp8', nargs='?', choices=['vp8', 'h264', 'av1'],
help='Video encoding to negotiate')
parser.add_argument('--peer-id', help='String ID of the peer to connect to')
parser.add_argument('--our-id', help='String ID that the peer can use to connect to us')
@ -359,6 +374,8 @@ if __name__ == '__main__':
dest='remote_is_offerer',
help='Request that the peer generate the offer and we\'ll answer')
args = parser.parse_args()
if not check_plugins(args.video_encoding):
sys.exit(1)
if not args.peer_id and not args.our_id:
print('You must pass either --peer-id or --our-id')
sys.exit(1)