@@ -65,7 +65,7 @@ defmodule ExWebRTC.Recorder.Converter do
6565 }
6666
6767 @ typedoc """
68- Options that can be passed to `convert_manifest!/2` and `convert_path !/2`.
68+ Options that can be passed to `convert !/2`.
6969
7070 * `:output_path` - Directory where Converter will save its artifacts. `#{ @ default_output_path } ` by default.
7171 * `:s3_upload_config` - If passed, processed recordings will be uploaded to S3-compatible storage.
@@ -75,13 +75,19 @@ defmodule ExWebRTC.Recorder.Converter do
7575 See `t:ExWebRTC.Recorder.S3.override_config/0` for more info.
7676 * `:thumbnails_ctx` - If passed, Converter will generate thumbnails for the output files.
7777 See `t:thumbnails_ctx/0` for more info.
78+ * `:only_rids` - By default, when processing a video track with multiple layers (i.e. simulcast),
79+ Converter generates multiple output files, one per layer. If passed, Converter will only process
80+ the layers with RIDs present in this list. E.g. if you want to receive a single video file
81+ from the layer `"h"`, pass `["h"]`. For single-layer tracks RID is set to `nil`,
82+ so if you want to handle both simulcast and regular tracks, pass `["h", nil]`.
7883 """
7984 @ type option ::
8085 { :output_path , Path . t ( ) }
8186 | { :s3_upload_config , keyword ( ) }
8287 | { :download_path , Path . t ( ) }
8388 | { :s3_download_config , keyword ( ) }
8489 | { :thumbnails_ctx , thumbnails_ctx ( ) }
90+ | { :only_rids , [ ExWebRTC.MediaStreamTrack . rid ( ) | nil ] }
8591
8692 @ type options :: [ option ( ) ]
8793
@@ -116,7 +122,7 @@ defmodule ExWebRTC.Recorder.Converter do
116122
117123 def convert! ( recorder_manifest , options ) when map_size ( recorder_manifest ) > 0 do
118124 thumbnails_ctx =
119- case Keyword . get ( options , :thumbnails_ctx , nil ) do
125+ case Keyword . get ( options , :thumbnails_ctx ) do
120126 nil ->
121127 nil
122128
@@ -127,6 +133,15 @@ defmodule ExWebRTC.Recorder.Converter do
127133 }
128134 end
129135
136+ rid_allowed? =
137+ case Keyword . get ( options , :only_rids ) do
138+ nil ->
139+ fn _rid -> true end
140+
141+ allowed_rids ->
142+ fn rid -> Enum . member? ( allowed_rids , rid ) end
143+ end
144+
130145 output_path = Keyword . get ( options , :output_path , @ default_output_path ) |> Path . expand ( )
131146 download_path = Keyword . get ( options , :download_path , @ default_download_path ) |> Path . expand ( )
132147 File . mkdir_p! ( output_path )
@@ -143,7 +158,7 @@ defmodule ExWebRTC.Recorder.Converter do
143158 output_manifest =
144159 recorder_manifest
145160 |> fetch_remote_files! ( download_path , download_config )
146- |> do_convert_manifest! ( output_path , thumbnails_ctx )
161+ |> do_convert_manifest! ( output_path , thumbnails_ctx , rid_allowed? )
147162
148163 result_manifest =
149164 if upload_handler != nil do
@@ -159,6 +174,12 @@ defmodule ExWebRTC.Recorder.Converter do
159174 S3.UploadHandler . process_result ( upload_handler , task_result )
160175 end
161176
177+ # UploadHandler spawns a task that gets auto-monitored
178+ # We don't want to propagate this message
179+ receive do
180+ { :DOWN , ^ ref , :process , _pid , _reason } -> :ok
181+ end
182+
162183 upload_handler_result_manifest
163184 |> __MODULE__ . Manifest . from_upload_handler_manifest ( output_manifest )
164185 else
@@ -197,7 +218,7 @@ defmodule ExWebRTC.Recorder.Converter do
197218 end
198219 end
199220
200- defp do_convert_manifest! ( manifest , output_path , thumbnails_ctx ) do
221+ defp do_convert_manifest! ( manifest , output_path , thumbnails_ctx , rid_allowed? ) do
201222 stream_map =
202223 Enum . reduce ( manifest , % { } , fn { id , track } , stream_map ->
203224 % {
@@ -218,6 +239,8 @@ defmodule ExWebRTC.Recorder.Converter do
218239 output_metadata =
219240 case kind do
220241 :video ->
242+ rid_map = filter_rids ( rid_map , rid_allowed? )
243+
221244 convert_video_track ( id , rid_map , output_path , packets )
222245
223246 :audio ->
@@ -405,4 +428,8 @@ defmodule ExWebRTC.Recorder.Converter do
405428 store
406429 end
407430 end
431+
432+ defp filter_rids ( rid_map , rid_allowed? ) do
433+ Map . filter ( rid_map , fn { rid , _rid_idx } -> rid_allowed? . ( rid ) end )
434+ end
408435end
0 commit comments