Browse Source

rtmp: normalize API

pull/1039/head
aler9 3 years ago
parent
commit
45c1370145
  1. 2
      internal/rtmp/chunk/chunk.go
  2. 4
      internal/rtmp/chunk/chunk0.go
  3. 4
      internal/rtmp/chunk/chunk0_test.go
  4. 4
      internal/rtmp/chunk/chunk1.go
  5. 4
      internal/rtmp/chunk/chunk1_test.go
  6. 4
      internal/rtmp/chunk/chunk2.go
  7. 4
      internal/rtmp/chunk/chunk2_test.go
  8. 4
      internal/rtmp/chunk/chunk3.go
  9. 4
      internal/rtmp/chunk/chunk3_test.go
  10. 14
      internal/rtmp/rawmessage/reader_test.go
  11. 2
      internal/rtmp/rawmessage/writer.go

2
internal/rtmp/chunk/chunk.go

@ -7,5 +7,5 @@ import ( @@ -7,5 +7,5 @@ import (
// Chunk is a chunk.
type Chunk interface {
Read(io.Reader, uint32) error
Write() ([]byte, error)
Marshal() ([]byte, error)
}

4
internal/rtmp/chunk/chunk0.go

@ -41,8 +41,8 @@ func (c *Chunk0) Read(r io.Reader, chunkMaxBodyLen uint32) error { @@ -41,8 +41,8 @@ func (c *Chunk0) Read(r io.Reader, chunkMaxBodyLen uint32) error {
return err
}
// Write writes the chunk.
func (c Chunk0) Write() ([]byte, error) {
// Marshal writes the chunk.
func (c Chunk0) Marshal() ([]byte, error) {
buf := make([]byte, 12+len(c.Body))
buf[0] = c.ChunkStreamID
buf[1] = byte(c.Timestamp >> 16)

4
internal/rtmp/chunk/chunk0_test.go

@ -28,8 +28,8 @@ func TestChunk0Read(t *testing.T) { @@ -28,8 +28,8 @@ func TestChunk0Read(t *testing.T) {
require.Equal(t, chunk0dec, chunk0)
}
func TestChunk0Write(t *testing.T) {
buf, err := chunk0dec.Write()
func TestChunk0Marshal(t *testing.T) {
buf, err := chunk0dec.Marshal()
require.NoError(t, err)
require.Equal(t, chunk0enc, buf)
}

4
internal/rtmp/chunk/chunk1.go

@ -41,8 +41,8 @@ func (c *Chunk1) Read(r io.Reader, chunkMaxBodyLen uint32) error { @@ -41,8 +41,8 @@ func (c *Chunk1) Read(r io.Reader, chunkMaxBodyLen uint32) error {
return err
}
// Write writes the chunk.
func (c Chunk1) Write() ([]byte, error) {
// Marshal writes the chunk.
func (c Chunk1) Marshal() ([]byte, error) {
buf := make([]byte, 8+len(c.Body))
buf[0] = 1<<6 | c.ChunkStreamID
buf[1] = byte(c.TimestampDelta >> 16)

4
internal/rtmp/chunk/chunk1_test.go

@ -27,8 +27,8 @@ func TestChunk1Read(t *testing.T) { @@ -27,8 +27,8 @@ func TestChunk1Read(t *testing.T) {
require.Equal(t, chunk1dec, chunk1)
}
func TestChunk1Write(t *testing.T) {
buf, err := chunk1dec.Write()
func TestChunk1Marshal(t *testing.T) {
buf, err := chunk1dec.Marshal()
require.NoError(t, err)
require.Equal(t, chunk1enc, buf)
}

4
internal/rtmp/chunk/chunk2.go

@ -30,8 +30,8 @@ func (c *Chunk2) Read(r io.Reader, chunkBodyLen uint32) error { @@ -30,8 +30,8 @@ func (c *Chunk2) Read(r io.Reader, chunkBodyLen uint32) error {
return err
}
// Write writes the chunk.
func (c Chunk2) Write() ([]byte, error) {
// Marshal writes the chunk.
func (c Chunk2) Marshal() ([]byte, error) {
buf := make([]byte, 4+len(c.Body))
buf[0] = 2<<6 | c.ChunkStreamID
buf[1] = byte(c.TimestampDelta >> 16)

4
internal/rtmp/chunk/chunk2_test.go

@ -24,8 +24,8 @@ func TestChunk2Read(t *testing.T) { @@ -24,8 +24,8 @@ func TestChunk2Read(t *testing.T) {
require.Equal(t, chunk2dec, chunk2)
}
func TestChunk2Write(t *testing.T) {
buf, err := chunk2dec.Write()
func TestChunk2Marshal(t *testing.T) {
buf, err := chunk2dec.Marshal()
require.NoError(t, err)
require.Equal(t, chunk2enc, buf)
}

4
internal/rtmp/chunk/chunk3.go

@ -30,8 +30,8 @@ func (c *Chunk3) Read(r io.Reader, chunkBodyLen uint32) error { @@ -30,8 +30,8 @@ func (c *Chunk3) Read(r io.Reader, chunkBodyLen uint32) error {
return err
}
// Write writes the chunk.
func (c Chunk3) Write() ([]byte, error) {
// Marshal writes the chunk.
func (c Chunk3) Marshal() ([]byte, error) {
buf := make([]byte, 1+len(c.Body))
buf[0] = 3<<6 | c.ChunkStreamID
copy(buf[1:], c.Body)

4
internal/rtmp/chunk/chunk3_test.go

@ -23,8 +23,8 @@ func TestChunk3Read(t *testing.T) { @@ -23,8 +23,8 @@ func TestChunk3Read(t *testing.T) {
require.Equal(t, chunk3dec, chunk3)
}
func TestChunk3Write(t *testing.T) {
buf, err := chunk3dec.Write()
func TestChunk3Marshal(t *testing.T) {
buf, err := chunk3dec.Marshal()
require.NoError(t, err)
require.Equal(t, chunk3enc, buf)
}

14
internal/rtmp/rawmessage/reader_test.go

@ -10,12 +10,8 @@ import ( @@ -10,12 +10,8 @@ import (
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
)
type writableChunk interface {
Write() ([]byte, error)
}
type sequenceEntry struct {
chunk writableChunk
chunk chunk.Chunk
msg *Message
}
@ -28,7 +24,7 @@ func TestReader(t *testing.T) { @@ -28,7 +24,7 @@ func TestReader(t *testing.T) {
})
for _, entry := range seq {
buf2, err := entry.chunk.Write()
buf2, err := entry.chunk.Marshal()
require.NoError(t, err)
buf.Write(buf2)
msg, err := r.Read()
@ -138,14 +134,14 @@ func TestReader(t *testing.T) { @@ -138,14 +134,14 @@ func TestReader(t *testing.T) {
MessageStreamID: 3123,
BodyLen: 192,
Body: bytes.Repeat([]byte{0x03}, 128),
}.Write()
}.Marshal()
require.NoError(t, err)
buf.Write(buf2)
buf2, err = chunk.Chunk3{
ChunkStreamID: 27,
Body: bytes.Repeat([]byte{0x03}, 64),
}.Write()
}.Marshal()
require.NoError(t, err)
buf.Write(buf2)
@ -181,7 +177,7 @@ func TestReaderAcknowledge(t *testing.T) { @@ -181,7 +177,7 @@ func TestReaderAcknowledge(t *testing.T) {
MessageStreamID: 3123,
BodyLen: 64,
Body: bytes.Repeat([]byte{0x03}, 64),
}.Write()
}.Marshal()
require.NoError(t, err)
buf.Write(buf2)
}

2
internal/rtmp/rawmessage/writer.go

@ -17,7 +17,7 @@ type writerChunkStream struct { @@ -17,7 +17,7 @@ type writerChunkStream struct {
}
func (wc *writerChunkStream) writeChunk(c chunk.Chunk) error {
buf, err := c.Write()
buf, err := c.Marshal()
if err != nil {
return err
}

Loading…
Cancel
Save