(slice []byte)
| 32 | } |
| 33 | |
| 34 | func (vt *H264) WriteSliceBytes(slice []byte) { |
| 35 | if len(slice) > 4 && bytes.Equal(slice[:4], codec.NALU_Delimiter2) { |
| 36 | slice = slice[4:] // 有些设备厂商不规范,所以需要移除前导的 00 00 00 01 |
| 37 | } |
| 38 | if len(slice) == 0 { |
| 39 | vt.Error("H264 WriteSliceBytes got empty slice") |
| 40 | return |
| 41 | } |
| 42 | naluType := codec.ParseH264NALUType(slice[0]) |
| 43 | if log.Trace { |
| 44 | vt.Trace("naluType", zap.Uint8("naluType", naluType.Byte())) |
| 45 | } |
| 46 | switch naluType { |
| 47 | case codec.NALU_SPS: |
| 48 | spsInfo, _ := codec.ParseSPS(slice) |
| 49 | if spsInfo.Width != vt.SPSInfo.Width || spsInfo.Height != vt.SPSInfo.Height { |
| 50 | vt.Debug("SPS", zap.Any("SPSInfo", spsInfo)) |
| 51 | } |
| 52 | vt.SPSInfo = spsInfo |
| 53 | vt.Video.SPS = slice |
| 54 | vt.ParamaterSets[0] = slice |
| 55 | case codec.NALU_PPS: |
| 56 | vt.Video.PPS = slice |
| 57 | vt.ParamaterSets[1] = slice |
| 58 | lenSPS := len(vt.Video.SPS) |
| 59 | lenPPS := len(vt.Video.PPS) |
| 60 | var b util.Buffer |
| 61 | if lenSPS > 3 { |
| 62 | b.Write(codec.RTMP_AVC_HEAD[:6]) |
| 63 | b.Write(vt.Video.SPS[1:4]) |
| 64 | b.Write(codec.RTMP_AVC_HEAD[9:10]) |
| 65 | } else { |
| 66 | b.Write(codec.RTMP_AVC_HEAD) |
| 67 | } |
| 68 | b.WriteByte(0xE1) |
| 69 | b.WriteUint16(uint16(lenSPS)) |
| 70 | b.Write(vt.Video.SPS) |
| 71 | b.WriteByte(0x01) |
| 72 | b.WriteUint16(uint16(lenPPS)) |
| 73 | b.Write(vt.Video.PPS) |
| 74 | vt.WriteSequenceHead(b) |
| 75 | case codec.NALU_IDR_Picture: |
| 76 | vt.Value.IFrame = true |
| 77 | vt.AppendAuBytes(slice) |
| 78 | case codec.NALU_Non_IDR_Picture, |
| 79 | codec.NALU_Data_Partition_A, |
| 80 | codec.NALU_Data_Partition_B, |
| 81 | codec.NALU_Data_Partition_C: |
| 82 | vt.Value.IFrame = false |
| 83 | vt.AppendAuBytes(slice) |
| 84 | case codec.NALU_SEI: |
| 85 | vt.AppendAuBytes(slice) |
| 86 | case codec.NALU_Access_Unit_Delimiter: |
| 87 | case codec.NALU_Filler_Data: |
| 88 | default: |
| 89 | if vt.Value.IFrame { |
| 90 | vt.AppendAuBytes(slice) |
| 91 | return |
no test coverage detected