mirror of https://bitbucket.org/ausocean/av.git
stream: got rid of Encoder interface as not needed anymore considering our encoders just implement io.Writer now
This commit is contained in:
parent
aa888ef115
commit
1533d6a7ff
|
@ -40,7 +40,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/av/stream"
|
||||
"bitbucket.org/ausocean/av/stream/flv"
|
||||
"bitbucket.org/ausocean/av/stream/lex"
|
||||
"bitbucket.org/ausocean/av/stream/mts"
|
||||
|
@ -110,7 +109,7 @@ type Revid struct {
|
|||
buffer *buffer
|
||||
|
||||
// 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 int
|
||||
|
@ -178,10 +177,10 @@ func (r *Revid) setConfig(config Config) error {
|
|||
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.encoder = make([]stream.Encoder, 0)
|
||||
r.encoder = make([]io.Writer, 0)
|
||||
|
||||
// mtsSenders will hold the senders the require MPEGTS encoding, and flvSenders
|
||||
// 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
|
||||
}
|
||||
|
||||
func newMtsEncoder(dst io.Writer, fps int) stream.Encoder {
|
||||
func newMtsEncoder(dst io.Writer, fps int) io.Writer {
|
||||
e := mts.NewEncoder(dst, float64(fps))
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -3,11 +3,11 @@ package revid
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"bitbucket.org/ausocean/av/stream"
|
||||
"bitbucket.org/ausocean/av/stream/flv"
|
||||
"bitbucket.org/ausocean/av/stream/mts"
|
||||
"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 := func(i stream.Encoder) (string, error) {
|
||||
typeOfEncoder := func(i io.Writer) (string, error) {
|
||||
if _, ok := i.(*mts.Encoder); ok {
|
||||
return mtsEncoderStr, nil
|
||||
}
|
||||
|
|
|
@ -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 }
|
|
@ -261,5 +261,3 @@ func (e *Encoder) Write(frame []byte) (int, error) {
|
|||
|
||||
return len(frame), nil
|
||||
}
|
||||
|
||||
func (e *Encoder) GetDst() io.Writer { return e.dst }
|
||||
|
|
|
@ -232,8 +232,6 @@ func (e *Encoder) Write(nalu []byte) (int, error) {
|
|||
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
|
||||
// location and time data.
|
||||
func (e *Encoder) writePSI() error {
|
||||
|
|
Loading…
Reference in New Issue