Skip to content

Commit 11e4267

Browse files
committed
Fix keyframe requests for non-simulcast tracks
1 parent 7efebc9 commit 11e4267

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

assets/publisher.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ export function createPublisherHook(iceServers = []) {
238238

239239
let statsTimestamp;
240240
stats.forEach((report) => {
241-
console.log(report);
242241
if (!statsTimestamp) statsTimestamp = report.timestamp;
243242

244243
if (report.type === "outbound-rtp" && report.kind === "video") {

lib/live_ex_webrtc/publisher.ex

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ defmodule LiveExWebRTC.Publisher do
8686
defstruct id: nil,
8787
pc: nil,
8888
streaming?: false,
89-
audio_track_id: nil,
90-
video_track_id: nil,
89+
audio_track: nil,
90+
video_track: nil,
9191
on_packet: nil,
9292
on_connected: nil,
9393
pubsub: nil,
@@ -352,12 +352,20 @@ defmodule LiveExWebRTC.Publisher do
352352

353353
@impl true
354354
def handle_info({:live_ex_webrtc, :keyframe_req, layer}, socket) do
355-
# FIXME consider non-simulcast case
356355
%{publisher: publisher} = socket.assigns
357356

357+
# Non-simulcast tracks are always sent with "h" identifier
358+
# Hence, when we receive a keyframe request for "h", we must
359+
# check whether it's simulcast track or not.
360+
layer =
361+
if layer == "h" and publisher.video_track.rids == nil do
362+
nil
363+
else
364+
layer
365+
end
366+
358367
if pc = publisher.pc do
359-
Logger.warning("Sending keyframe request: #{layer}")
360-
:ok = PeerConnection.send_pli(pc, publisher.video_track_id, layer)
368+
:ok = PeerConnection.send_pli(pc, publisher.video_track.id, layer)
361369
end
362370

363371
{:noreply, socket}
@@ -368,7 +376,7 @@ defmodule LiveExWebRTC.Publisher do
368376
%{publisher: publisher} = socket.assigns
369377

370378
case publisher do
371-
%Publisher{video_track_id: ^track_id} ->
379+
%Publisher{video_track: video_track} when video_track.id == track_id ->
372380
packet =
373381
if publisher.on_packet,
374382
do: publisher.on_packet.(publisher.id, :video, packet, socket),
@@ -383,7 +391,7 @@ defmodule LiveExWebRTC.Publisher do
383391

384392
{:noreply, socket}
385393

386-
%Publisher{audio_track_id: ^track_id} ->
394+
%Publisher{audio_track: audio_track} when audio_track.id == track_id ->
387395
PubSub.broadcast(
388396
publisher.pubsub,
389397
"streams:audio:#{publisher.id}",
@@ -447,8 +455,8 @@ defmodule LiveExWebRTC.Publisher do
447455
new_publisher = %Publisher{
448456
publisher
449457
| pc: pc,
450-
audio_track_id: audio_track.id,
451-
video_track_id: video_track.id
458+
audio_track: audio_track,
459+
video_track: video_track
452460
}
453461

454462
{:noreply,

0 commit comments

Comments
 (0)