-
Notifications
You must be signed in to change notification settings - Fork 0
Add codec information to manifest #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,63 @@ defmodule ExWebRTC.Recorder.Manifest do | |
| kind: :video | :audio, | ||
| streams: [MediaStreamTrack.stream_id()], | ||
| rid_map: %{MediaStreamTrack.rid() => integer()}, | ||
| codec: ExWebRTC.RTPCodecParameters.t() | nil, | ||
| location: location() | ||
| } | ||
|
|
||
| @type t :: %{MediaStreamTrack.id() => track_manifest()} | ||
|
|
||
| @doc false | ||
| @spec to_map(t()) :: map() | ||
| def to_map(manifest) do | ||
Gawor270 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Map.new(manifest, fn {id, entry} -> | ||
| { | ||
| id, | ||
| %{ | ||
| "start_time" => DateTime.to_iso8601(entry.start_time), | ||
| "kind" => Atom.to_string(entry.kind), | ||
| "streams" => entry.streams, | ||
| "rid_map" => encode_rid_map(entry.rid_map), | ||
| "codec" => encode_codec(entry.codec), | ||
| "location" => entry.location | ||
| } | ||
| } | ||
| end) | ||
| end | ||
|
|
||
| defp encode_rid_map(rid_map) do | ||
| Map.new(rid_map, fn | ||
| {nil, v} -> {"nil", v} | ||
| {layer, v} -> {layer, v} | ||
| end) | ||
| end | ||
|
|
||
| defp encode_codec(nil), do: nil | ||
|
|
||
| defp encode_codec(%ExWebRTC.RTPCodecParameters{} = codec) do | ||
| %{ | ||
| "payload_type" => codec.payload_type, | ||
| "mime_type" => codec.mime_type, | ||
| "clock_rate" => codec.clock_rate, | ||
| "channels" => codec.channels, | ||
| "sdp_fmtp_line" => fmtp_to_string(codec.sdp_fmtp_line), | ||
| "rtcp_fbs" => rtcp_fbs_to_strings(codec.rtcp_fbs) | ||
| } | ||
| end | ||
|
|
||
| defp fmtp_to_string([]), do: nil | ||
| defp fmtp_to_string(nil), do: nil | ||
| defp fmtp_to_string(fmtp), do: fmtp |> to_string() |> String.replace_prefix("fmtp:", "") | ||
|
|
||
| defp rtcp_fbs_to_strings(nil), do: nil | ||
| defp rtcp_fbs_to_strings([]), do: nil | ||
|
|
||
| defp rtcp_fbs_to_strings(list) when is_list(list) do | ||
| list | ||
| |> Enum.map(&to_string/1) | ||
| |> Enum.map(&String.replace_prefix(&1, "rtcp-fb:", "")) | ||
| end | ||
|
|
||
| @doc false | ||
| @spec from_json!(map()) :: t() | ||
| def from_json!(json_manifest) do | ||
|
|
@@ -38,14 +90,16 @@ defmodule ExWebRTC.Recorder.Manifest do | |
| "kind" => kind, | ||
| "streams" => streams, | ||
| "rid_map" => rid_map, | ||
| "codec" => codec, | ||
| "location" => location | ||
| }) do | ||
| %{ | ||
| streams: streams, | ||
| location: location, | ||
| start_time: parse_start_time(start_time), | ||
| rid_map: parse_rid_map(rid_map), | ||
| kind: parse_kind(kind) | ||
| kind: parse_kind(kind), | ||
| codec: parse_codec(codec) | ||
| } | ||
| end | ||
|
|
||
|
|
@@ -63,4 +117,40 @@ defmodule ExWebRTC.Recorder.Manifest do | |
|
|
||
| defp parse_kind("video"), do: :video | ||
| defp parse_kind("audio"), do: :audio | ||
|
|
||
| defp parse_codec(%{ | ||
| "payload_type" => payload_type, | ||
| "mime_type" => mime_type, | ||
| "clock_rate" => clock_rate, | ||
| "channels" => channels, | ||
| "sdp_fmtp_line" => sdp_fmtp_line, | ||
| "rtcp_fbs" => rtcp_fbs | ||
| }) do | ||
| %ExWebRTC.RTPCodecParameters{ | ||
| payload_type: payload_type, | ||
| mime_type: mime_type, | ||
| clock_rate: clock_rate, | ||
| channels: channels, | ||
| sdp_fmtp_line: parse_sdp_fmtp_line(sdp_fmtp_line), | ||
| rtcp_fbs: parse_rtcp_fbs(rtcp_fbs) | ||
| } | ||
| end | ||
|
|
||
| defp parse_codec(nil), do: nil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this will be If you have the time, you could consider writing unit tests for this module -- since it looks like we'll continue extending the Recorder, adding tests will help ensure basic functionality like this keeps working with further changes
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the value returned by Jason.decode!(json_string) is passed to from_json!() (see converter.ex:134); Jason.decode/1 converts JSON null to Elixir nil, and I added tests to confirm this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, my bad. I assumed it behaved the same way as our |
||
|
|
||
| defp parse_sdp_fmtp_line(sdp_fmtp_line) when is_binary(sdp_fmtp_line) do | ||
| {:ok, fmtp} = ExSDP.Attribute.FMTP.parse(sdp_fmtp_line) | ||
| fmtp | ||
| end | ||
|
|
||
| defp parse_sdp_fmtp_line(nil), do: [] | ||
sgfn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| defp parse_rtcp_fbs(rtcp_fbs) when is_list(rtcp_fbs) do | ||
| Enum.map(rtcp_fbs, fn fb -> | ||
| {:ok, rtcp_fb} = ExSDP.Attribute.RTCPFeedback.parse(fb) | ||
| rtcp_fb | ||
| end) | ||
| end | ||
|
|
||
| defp parse_rtcp_fbs(nil), do: [] | ||
sgfn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.