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