-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from membraneframework/support-for-byterange-tag
Add support for byterange tag and nested segment tags
- Loading branch information
Showing
6 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule ExM3U8.Tags.ByteRange do | ||
@moduledoc """ | ||
Structure representing byte range of the following media segment/chunk. | ||
""" | ||
use TypedStruct | ||
|
||
typedstruct enforce: true do | ||
field :length, non_neg_integer() | ||
field :offset, non_neg_integer() | nil, default: nil | ||
end | ||
|
||
defimpl ExM3U8.Serializer do | ||
use ExM3U8.DSL | ||
|
||
require ExM3U8.Helpers | ||
|
||
@impl true | ||
def serialize(%@for{length: length, offset: offset}) do | ||
offset = | ||
if offset do | ||
"@#{offset}" | ||
else | ||
"" | ||
end | ||
|
||
[ExM3U8.Helpers.tag_prefix(), "BYTERANGE:", "#{length}#{offset}"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule ExM3U8.Tags.ByteRangeTest do | ||
use ExUnit.Case | ||
|
||
import ExM3U8.TestUtils, only: [serialize: 1] | ||
|
||
test "serialize byte range" do | ||
byte_range = %ExM3U8.Tags.ByteRange{ | ||
length: 5, | ||
offset: nil | ||
} | ||
|
||
assert """ | ||
#EXT-X-BYTERANGE:5 | ||
""" | ||
|> String.trim_trailing() == serialize(byte_range) | ||
|
||
byte_range = %ExM3U8.Tags.ByteRange{ | ||
length: 5, | ||
offset: 111 | ||
} | ||
|
||
assert """ | ||
#EXT-X-BYTERANGE:5@111 | ||
""" | ||
|> String.trim_trailing() == serialize(byte_range) | ||
end | ||
end |