Skip to content

Commit

Permalink
Add AV1 to the list of default video codecs (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 authored Dec 8, 2023
1 parent d310708 commit 8693629
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
35 changes: 22 additions & 13 deletions lib/ex_webrtc/peer_connection/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@ defmodule ExWebRTC.PeerConnection.Configuration do
mime_type: "audio/opus",
clock_rate: 48_000,
channels: 2,
sdp_fmtp_line: %FMTP{pt: 111, minptime: 10, useinbandfec: true},
rtcp_fbs: []
sdp_fmtp_line: %FMTP{pt: 111, minptime: 10, useinbandfec: true}
}
]

@default_video_codecs [
%RTPCodecParameters{
payload_type: 96,
mime_type: "video/VP8",
clock_rate: 90_000
},
%RTPCodecParameters{
payload_type: 45,
mime_type: "video/AV1",
clock_rate: 90_000
},
%RTPCodecParameters{
payload_type: 98,
mime_type: "video/H264",
clock_rate: 90_000,
channels: nil,
sdp_fmtp_line: %FMTP{
pt: 98,
level_asymmetry_allowed: true,
packetization_mode: 1,
profile_level_id: 0x42001F
},
rtcp_fbs: []
},
%RTPCodecParameters{
payload_type: 96,
mime_type: "video/VP8",
clock_rate: 90_000,
channels: nil,
sdp_fmtp_line: nil,
rtcp_fbs: []
}
}
]

Expand Down Expand Up @@ -74,6 +73,16 @@ defmodule ExWebRTC.PeerConnection.Configuration do
If you wish to add codecs to default ones do
`audio_codecs: Configuration.default_audio_codecs() ++ my_codecs`
* `video_codecs` - the same as `audio_codecs` but for video.
If you wish to e.g. only use AV1, pass as video_codecs:
```
video_codecs: [
%ExWebRTC.RTPCodecParameters{
payload_type: 45,
mime_type: "video/AV1",
clock_rate: 90_000
}
]
```
* `rtp_hdr_extensions` - list of RTP header extensions to use.
MID extension is enabled by default and cannot be turned off.
If an extension can be used both for audio and video media, it
Expand Down
3 changes: 2 additions & 1 deletion lib/ex_webrtc/rtp_codec_parameters.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule ExWebRTC.RTPCodecParameters do
rtcp_fbs: [ExSDP.Attribute.RTCPFeedback.t()]
}

defstruct [:payload_type, :mime_type, :clock_rate, :channels, :sdp_fmtp_line, :rtcp_fbs]
@enforce_keys [:payload_type, :mime_type, :clock_rate]
defstruct @enforce_keys ++ [:channels, :sdp_fmtp_line, rtcp_fbs: []]

def new(type, rtp_mapping, fmtp, rtcp_fbs) do
%__MODULE__{
Expand Down
18 changes: 7 additions & 11 deletions test/ex_webrtc/peer_connection/configuration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
pt: 111,
minptime: 10,
useinbandfec: true
},
rtcp_fbs: []
}
}

h264_codec = %RTPCodecParameters{
Expand All @@ -38,26 +37,23 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
profile_level_id: 0x42001F,
level_asymmetry_allowed: true,
packetization_mode: 1
},
rtcp_fbs: []
}
}

vp8_codec = %RTPCodecParameters{
payload_type: 96,
mime_type: "video/VP8",
clock_rate: 90_000,
rtcp_fbs: []
clock_rate: 90_000
}

av1_codec = %RTPCodecParameters{
payload_type: 45,
mime_type: "video/AV1",
clock_rate: 90_000,
rtcp_fbs: []
clock_rate: 90_000
}

# default audio and video codecs
# assert there are only them - no av1, g711 or others
# assert there are only them - no g711 or others
{:ok, pc} = PeerConnection.start_link()

offer = %SessionDescription{
Expand All @@ -81,13 +77,13 @@ defmodule ExWebRTC.PeerConnection.ConfigurationTest do
direction: :recvonly,
kind: :video,
rtp_hdr_exts: [^mid_rtp_hdr_ext],
codecs: [^vp8_codec, ^h264_codec]
codecs: [^vp8_codec, ^h264_codec, ^av1_codec]
}
] = transceivers

assert :ok = PeerConnection.close(pc)

# audio level rtp hdr ext, no audio codecs and one non-default av1 codec
# audio level rtp hdr ext, no audio codecs and one video codec
# assert there are no audio, h264 and vp8 codecs, and there is audio level
# rtp hdr extension
{:ok, pc} =
Expand Down

0 comments on commit 8693629

Please sign in to comment.