mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
Fix H264Writer writing 0 length payloads
Before we would call Write even if no bytes were available.
This commit is contained in:
@@ -62,7 +62,7 @@ func (h *H264Writer) WriteRTP(packet *rtp.Packet) error {
|
||||
}
|
||||
|
||||
data, err := h.cachedPacket.Unmarshal(packet.Payload)
|
||||
if err != nil {
|
||||
if err != nil || len(data) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -153,3 +153,40 @@ func TestWriteRTP(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type writerCounter struct {
|
||||
writeCount int
|
||||
}
|
||||
|
||||
func (w *writerCounter) Write([]byte) (int, error) {
|
||||
w.writeCount++
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (w *writerCounter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestNoZeroWrite(t *testing.T) {
|
||||
payloads := [][]byte{
|
||||
{0x1c, 0x80, 0x01, 0x02, 0x03},
|
||||
{0x1c, 0x00, 0x04, 0x05, 0x06},
|
||||
{0x1c, 0x00, 0x07, 0x08, 0x09},
|
||||
{0x1c, 0x00, 0x10, 0x11, 0x12},
|
||||
{0x1c, 0x40, 0x13, 0x14, 0x15},
|
||||
}
|
||||
|
||||
writer := &writerCounter{}
|
||||
h264Writer := &H264Writer{
|
||||
hasKeyFrame: true,
|
||||
writer: writer,
|
||||
}
|
||||
|
||||
for i := range payloads {
|
||||
assert.NoError(t, h264Writer.WriteRTP(&rtp.Packet{
|
||||
Payload: payloads[i],
|
||||
}))
|
||||
}
|
||||
assert.Equal(t, 1, writer.writeCount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user