container/mts/mpegts.go: FindPSI now returns a map[uint16]uint8 containing program PIDs and their types instead of []psi.PmtElementaryStream

This commit is contained in:
Saxon 2019-08-06 15:38:34 +09:30
parent 0cb9a50af8
commit ed11fac655
2 changed files with 17 additions and 7 deletions

View File

@ -225,9 +225,8 @@ var (
) )
// FindPSI finds the index of a PAT in an a slice of MPEG-TS and returns, along // FindPSI finds the index of a PAT in an a slice of MPEG-TS and returns, along
// with a map of meta from the PMT and the PmtElementaryStreams, which contain // with a map of meta from the PMT and the stream PIDs and their types.
// the media PIDs and their types. func FindPSI(d []byte) (int, map[uint16]uint8, map[string]string, error) {
func FindPSI(d []byte) (int, []gotspsi.PmtElementaryStream, map[string]string, error) {
if len(d) < PacketSize { if len(d) < PacketSize {
return -1, nil, nil, ErrInvalidLen return -1, nil, nil, ErrInvalidLen
} }
@ -278,7 +277,12 @@ func FindPSI(d []byte) (int, []gotspsi.PmtElementaryStream, map[string]string, e
return i, nil, meta, errors.Wrap(err, "could not get streams from PMT") return i, nil, meta, errors.Wrap(err, "could not get streams from PMT")
} }
return i, streams, meta, nil var streamMap map[uint16]uint8
for _, s := range streams {
streamMap[s.ElementaryPid()] = s.StreamType()
}
return i, streamMap, meta, nil
} }
// FillPayload takes a channel and fills the packets Payload field until the // FillPayload takes a channel and fills the packets Payload field until the

View File

@ -734,9 +734,15 @@ func TestFindPSI(t *testing.T) {
t.Fatalf("gotStreams should not be 0 length") t.Fatalf("gotStreams should not be 0 length")
} }
s := gotStreams[0] var (
gotStreamType := s.StreamType() gotStreamPID uint16
gotStreamPID := s.ElementaryPid() gotStreamType uint8
)
for k, v := range gotStreams {
gotStreamPID = k
gotStreamType = v
}
if gotStreamType != test.want.streamType { if gotStreamType != test.want.streamType {
t.Errorf("did not get expected stream type for test %d\nGot: %v\nWant: %v\n", i, gotStreamType, test.want.streamType) t.Errorf("did not get expected stream type for test %d\nGot: %v\nWant: %v\n", i, gotStreamType, test.want.streamType)