File: h264.go

package info (click to toggle)
golang-github-pion-webrtc.v3 3.1.56-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,392 kB
  • sloc: javascript: 595; sh: 28; makefile: 5
file content (80 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package fmtp

import (
	"encoding/hex"
)

func profileLevelIDMatches(a, b string) bool {
	aa, err := hex.DecodeString(a)
	if err != nil || len(aa) < 2 {
		return false
	}
	bb, err := hex.DecodeString(b)
	if err != nil || len(bb) < 2 {
		return false
	}
	return aa[0] == bb[0] && aa[1] == bb[1]
}

type h264FMTP struct {
	parameters map[string]string
}

func (h *h264FMTP) MimeType() string {
	return "video/h264"
}

// Match returns true if h and b are compatible fmtp descriptions
// Based on RFC6184 Section 8.2.2:
//   The parameters identifying a media format configuration for H.264
//   are profile-level-id and packetization-mode.  These media format
//   configuration parameters (except for the level part of profile-
//   level-id) MUST be used symmetrically; that is, the answerer MUST
//   either maintain all configuration parameters or remove the media
//   format (payload type) completely if one or more of the parameter
//   values are not supported.
//     Informative note: The requirement for symmetric use does not
//     apply for the level part of profile-level-id and does not apply
//     for the other stream properties and capability parameters.
func (h *h264FMTP) Match(b FMTP) bool {
	c, ok := b.(*h264FMTP)
	if !ok {
		return false
	}

	// test packetization-mode
	hpmode, hok := h.parameters["packetization-mode"]
	if !hok {
		return false
	}
	cpmode, cok := c.parameters["packetization-mode"]
	if !cok {
		return false
	}

	if hpmode != cpmode {
		return false
	}

	// test profile-level-id
	hplid, hok := h.parameters["profile-level-id"]
	if !hok {
		return false
	}

	cplid, cok := c.parameters["profile-level-id"]
	if !cok {
		return false
	}

	if !profileLevelIDMatches(hplid, cplid) {
		return false
	}

	return true
}

func (h *h264FMTP) Parameter(key string) (string, bool) {
	v, ok := h.parameters[key]
	return v, ok
}