This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
515 additions
and
130 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
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,37 @@ | ||
package webrtc | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type fmtp map[string]string | ||
|
||
// parseFmtp parses fmtp string. | ||
func parseFmtp(line string) fmtp { | ||
f := fmtp{} | ||
for _, p := range strings.Split(line, ";") { | ||
pp := strings.SplitN(strings.TrimSpace(p), "=", 2) | ||
key := strings.ToLower(pp[0]) | ||
var value string | ||
if len(pp) > 1 { | ||
value = pp[1] | ||
} | ||
f[key] = value | ||
} | ||
return f | ||
} | ||
|
||
// fmtpConsist checks that two FTMP parameters are not inconsistent. | ||
func fmtpConsist(a, b fmtp) bool { | ||
for k, v := range a { | ||
if vb, ok := b[k]; ok && !strings.EqualFold(vb, v) { | ||
return false | ||
} | ||
} | ||
for k, v := range b { | ||
if va, ok := a[k]; ok && !strings.EqualFold(va, v) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
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,107 @@ | ||
package webrtc | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestParseFmtp(t *testing.T) { | ||
testCases := map[string]struct { | ||
input string | ||
expected fmtp | ||
}{ | ||
"OneParam": { | ||
input: "key-name=value", | ||
expected: fmtp{ | ||
"key-name": "value", | ||
}, | ||
}, | ||
"OneParamWithWhiteSpeces": { | ||
input: "\tkey-name=value ", | ||
expected: fmtp{ | ||
"key-name": "value", | ||
}, | ||
}, | ||
"TwoParams": { | ||
input: "key-name=value;key2=value2", | ||
expected: fmtp{ | ||
"key-name": "value", | ||
"key2": "value2", | ||
}, | ||
}, | ||
"TwoParamsWithWhiteSpeces": { | ||
input: "key-name=value; \n\tkey2=value2 ", | ||
expected: fmtp{ | ||
"key-name": "value", | ||
"key2": "value2", | ||
}, | ||
}, | ||
} | ||
for name, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(name, func(t *testing.T) { | ||
f := parseFmtp(testCase.input) | ||
if !reflect.DeepEqual(testCase.expected, f) { | ||
t.Errorf("Expected Fmtp params: %v, got: %v", testCase.expected, f) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestFmtpConsist(t *testing.T) { | ||
consistString := map[bool]string{true: "consist", false: "inconsist"} | ||
|
||
testCases := map[string]struct { | ||
a, b string | ||
consist bool | ||
}{ | ||
"Equal": { | ||
a: "key1=value1;key2=value2;key3=value3", | ||
b: "key1=value1;key2=value2;key3=value3", | ||
consist: true, | ||
}, | ||
"EqualWithWhitespaceVariants": { | ||
a: "key1=value1;key2=value2;key3=value3", | ||
b: " key1=value1; \nkey2=value2;\t\nkey3=value3", | ||
consist: true, | ||
}, | ||
"EqualWithCase": { | ||
a: "key1=value1;key2=value2;key3=value3", | ||
b: "key1=value1;key2=Value2;Key3=value3", | ||
consist: true, | ||
}, | ||
"OneHasExtraParam": { | ||
a: "key1=value1;key2=value2;key3=value3", | ||
b: "key1=value1;key2=value2;key3=value3;key4=value4", | ||
consist: true, | ||
}, | ||
"Inconsistent": { | ||
a: "key1=value1;key2=value2;key3=value3", | ||
b: "key1=value1;key2=different_value;key3=value3", | ||
consist: false, | ||
}, | ||
"Inconsistent_OneHasExtraParam": { | ||
a: "key1=value1;key2=value2;key3=value3;key4=value4", | ||
b: "key1=value1;key2=different_value;key3=value3", | ||
consist: false, | ||
}, | ||
} | ||
for name, testCase := range testCases { | ||
testCase := testCase | ||
check := func(t *testing.T, a, b string) { | ||
c := fmtpConsist(parseFmtp(a), parseFmtp(b)) | ||
if c != testCase.consist { | ||
t.Errorf( | ||
"'%s' and '%s' are expected to be %s, but treated as %s", | ||
a, b, consistString[testCase.consist], consistString[c], | ||
) | ||
} | ||
} | ||
t.Run(name, func(t *testing.T) { | ||
check(t, testCase.a, testCase.b) | ||
}) | ||
t.Run(name+"_Reversed", func(t *testing.T) { | ||
check(t, testCase.b, testCase.a) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.