Skip to content

PubSub Problem #2

@hasnhasan

Description

@hasnhasan

Hello,
Records after Pubsub first read are coming in as problematic. Any chance of checking?
Out Of Range

...
sess.Pubsub.SetPub(c)
sess.Pubsub.AddSub(stopCloser, Recorder)
...

func (w *MediaRecorder) WritePacket(pkt av.Packet) (err error) {

	defer func() {
		if dErr := recover(); dErr != nil { //catch
			fmt.Fprintf(os.Stderr, "WritePacket Exception: %v\n", dErr)
		}
	}()

	pts := pkt.CTime.Milliseconds() + pkt.Time.Milliseconds()
	dts := pkt.Time.Milliseconds()
	if w.Muxer == nil {
		return
	}
	switch pkt.Type {
	case av.H264DecoderConfig:
		if !w.hasVideo {
			w.vtid = w.Muxer.AddVideoTrack(mp4.MP4_CODEC_H264)
			w.hasVideo = true
		}
		tmpspss, tmpppss := codec.CovertExtradata(pkt.Data)
		frame := make([]byte, 0, len(tmpspss[0])+len(tmpppss[0]))
		frame = append(frame, tmpspss[0]...)
		frame = append(frame, tmpppss[0]...)
		//codec.ShowPacketHexdump(tmpspss[0])
		codec.GetSPSIdWithStartCode(tmpspss[0])
		w.Muxer.Write(w.vtid, frame, uint64(pkt.CTime+pkt.Time), uint64(dts))
	case av.H264:
		for len(pkt.Data) > 0 {
			naluSize := binary.BigEndian.Uint32(pkt.Data[:4])
			//codec.ShowPacketHexdump(pkt.Data[:6])
			nSize := 4 + naluSize
			codec.CovertAVCCToAnnexB(pkt.Data)
			if nSize <= uint32(len(pkt.Data)) {
				w.Muxer.Write(w.vtid, pkt.Data[:4+naluSize], uint64(pts), uint64(dts))
				pkt.Data = pkt.Data[4+naluSize:]
			} else {
				break
			}
		}
		//fmt.Println("h264 frame pts ", pts, "dts ", dts)
	case av.AACDecoderConfig:
		if !w.hasAudio {
			w.atid = w.Muxer.AddAudioTrack(mp4.MP4_CODEC_AAC)
			w.hasAudio = true
		}

		w.asc = make([]byte, len(pkt.Data))
		copy(w.asc, pkt.Data)
	case av.AAC:
		adts, err := codec.ConvertASCToADTS(w.asc, len(pkt.Data)+7)
		if err == nil {
			adtsFrame := append(adts.Encode(), pkt.Data...)
			w.Muxer.Write(w.atid, adtsFrame, uint64(pts), uint64(dts))
		}
	}
	return
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions