revid: simplified determination of sender types

This commit is contained in:
Saxon 2019-03-29 16:17:11 +10:30
parent 648b43c50a
commit 7c724c9fc3
1 changed files with 7 additions and 39 deletions

View File

@ -1,7 +1,6 @@
package revid
import (
"errors"
"fmt"
"io"
"os"
@ -100,11 +99,11 @@ func (e *tstFlvEncoder) Write(d []byte) (int, error) { return 0, nil }
func TestResetEncoderSenderSetup(t *testing.T) {
// We will use these to indicate types after assertion.
const (
mtsSenderStr = "revid.mtsSender"
rtpSenderStr = "revid.rtpSender"
rtmpSenderStr = "revid.RtmpSender"
mtsEncoderStr = "mts.Encoder"
flvEncoderStr = "flv.Encoder"
mtsSenderStr = "*revid.mtsSender"
rtpSenderStr = "*revid.rtpSender"
rtmpSenderStr = "*revid.rtmpSender"
mtsEncoderStr = "*revid.tstMtsEncoder"
flvEncoderStr = "*revid.tstFlvEncoder"
)
// Struct that will be used to format test cases nicely below.
@ -185,31 +184,6 @@ func TestResetEncoderSenderSetup(t *testing.T) {
},
}
// typeOfEncoder will return the type of encoder implementing stream.Encoder.
typeOfEncoder := func(i io.Writer) (string, error) {
if _, ok := i.(*tstMtsEncoder); ok {
return mtsEncoderStr, nil
}
if _, ok := i.(*tstFlvEncoder); ok {
return flvEncoderStr, nil
}
return "", errors.New("unknown Encoder type")
}
// typeOfSender will return the type of sender implementing loadSender.
typeOfSender := func(s loadSender) (string, error) {
if _, ok := s.(*mtsSender); ok {
return mtsSenderStr, nil
}
if _, ok := s.(*rtpSender); ok {
return rtpSenderStr, nil
}
if _, ok := s.(*rtmpSender); ok {
return rtmpSenderStr, nil
}
return "", errors.New("unknown loadSender type")
}
rv, err := New(Config{Logger: &testLogger{}}, nil)
if err != nil {
t.Fatalf("unexpected err: %v", err)
@ -241,10 +215,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
// Now check the correctness of encoders and their destinations.
for _, e := range rv.encoder {
// Get e's type.
encoderType, err := typeOfEncoder(e)
if err != nil {
t.Fatalf("could not get encoders type for test %v, failed with err: %v", testNum, err)
}
encoderType := fmt.Sprintf("%T", e)
// Check that we expect this encoder to be here.
idx := -1
@ -278,10 +249,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
ok := false
for _, dst := range senders {
// Get type of sender.
senderType, err := typeOfSender(dst.(loadSender))
if err != nil {
t.Fatalf("could not get encoders type for test %v, failed with err: %v", testNum, err)
}
senderType := fmt.Sprintf("%T", dst.(loadSender))
// If it's one we want, indicate.
if senderType == expectDst {