stream: got rid of Encoder interface as not needed anymore considering our encoders just implement io.Writer now

This commit is contained in:
Saxon 2019-03-16 15:46:33 +10:30
parent aa888ef115
commit 1533d6a7ff
5 changed files with 7 additions and 63 deletions

View File

@ -40,7 +40,6 @@ import (
"sync" "sync"
"time" "time"
"bitbucket.org/ausocean/av/stream"
"bitbucket.org/ausocean/av/stream/flv" "bitbucket.org/ausocean/av/stream/flv"
"bitbucket.org/ausocean/av/stream/lex" "bitbucket.org/ausocean/av/stream/lex"
"bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/av/stream/mts"
@ -110,7 +109,7 @@ type Revid struct {
buffer *buffer buffer *buffer
// encoder holds the required encoders, which then write to destinations. // encoder holds the required encoders, which then write to destinations.
encoder []stream.Encoder encoder []io.Writer
// bitrate hold the last send bitrate calculation result. // bitrate hold the last send bitrate calculation result.
bitrate int bitrate int
@ -178,10 +177,10 @@ func (r *Revid) setConfig(config Config) error {
return nil return nil
} }
func (r *Revid) setupPipeline(mtsEnc func(io.Writer, int) stream.Encoder, flvEnc func(io.Writer, int) (stream.Encoder, error)) error { func (r *Revid) setupPipeline(mtsEnc func(io.Writer, int) io.Writer, flvEnc func(io.Writer, int) (io.Writer, error)) error {
r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)) r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout))
r.encoder = make([]stream.Encoder, 0) r.encoder = make([]io.Writer, 0)
// mtsSenders will hold the senders the require MPEGTS encoding, and flvSenders // mtsSenders will hold the senders the require MPEGTS encoding, and flvSenders
// will hold senders that require FLV encoding. // will hold senders that require FLV encoding.
@ -258,12 +257,12 @@ func (r *Revid) setupPipeline(mtsEnc func(io.Writer, int) stream.Encoder, flvEnc
return nil return nil
} }
func newMtsEncoder(dst io.Writer, fps int) stream.Encoder { func newMtsEncoder(dst io.Writer, fps int) io.Writer {
e := mts.NewEncoder(dst, float64(fps)) e := mts.NewEncoder(dst, float64(fps))
return e return e
} }
func newFlvEncoder(dst io.Writer, fps int) (stream.Encoder, error) { func newFlvEncoder(dst io.Writer, fps int) (io.Writer, error) {
e, err := flv.NewEncoder(dst, true, true, fps) e, err := flv.NewEncoder(dst, true, true, fps)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,11 @@ package revid
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"bitbucket.org/ausocean/av/stream"
"bitbucket.org/ausocean/av/stream/flv" "bitbucket.org/ausocean/av/stream/flv"
"bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/av/stream/mts"
"bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/iot/pi/netsender"
@ -162,7 +162,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
} }
// typeOfEncoder will return the type of encoder implementing stream.Encoder. // typeOfEncoder will return the type of encoder implementing stream.Encoder.
typeOfEncoder := func(i stream.Encoder) (string, error) { typeOfEncoder := func(i io.Writer) (string, error) {
if _, ok := i.(*mts.Encoder); ok { if _, ok := i.(*mts.Encoder); ok {
return mtsEncoderStr, nil return mtsEncoderStr, nil
} }

View File

@ -1,51 +0,0 @@
/*
NAME
encoding.go
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon@ausocean.org>
LICENSE
encoding.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
package stream
import "io"
type Encoder interface {
Write([]byte) (int, error)
GetDst() io.Writer
}
// NopEncoder returns an Encoder that performs no operation.
func NopEncoder(dst io.Writer) Encoder {
return noop{dst}
}
type noop struct {
dst io.Writer
}
// Write implements io.Writer.
func (e noop) Write(p []byte) (int, error) {
return e.dst.Write(p)
}
func (e noop) GetDst() io.Writer { return e.dst }

View File

@ -261,5 +261,3 @@ func (e *Encoder) Write(frame []byte) (int, error) {
return len(frame), nil return len(frame), nil
} }
func (e *Encoder) GetDst() io.Writer { return e.dst }

View File

@ -232,8 +232,6 @@ func (e *Encoder) Write(nalu []byte) (int, error) {
return len(nalu), nil return len(nalu), nil
} }
func (e *Encoder) GetDst() io.Writer { return e.dst }
// writePSI creates mpegts with pat and pmt tables - with pmt table having updated // writePSI creates mpegts with pat and pmt tables - with pmt table having updated
// location and time data. // location and time data.
func (e *Encoder) writePSI() error { func (e *Encoder) writePSI() error {