MCPcopy Create free account
hub / github.com/Monibuca/engine / PlayBlock

Method PlayBlock

subscriber.go:222–428  ·  view source on GitHub ↗

PlayBlock 阻塞式读取数据

(subType byte)

Source from the content-addressed store, hash-verified

220
221// PlayBlock 阻塞式读取数据
222func (s *Subscriber) PlayBlock(subType byte) {
223 spesic := s.Spesific
224 if spesic == nil {
225 s.Error("play before subscribe")
226 return
227 }
228 if s.IO.Err() != nil {
229 s.Error("play", zap.Error(s.IO.Err()))
230 return
231 }
232 s.Info("playblock", zap.Uint8("subType", subType))
233 s.TrackPlayer.Context, s.TrackPlayer.CancelFunc = context.WithCancel(s.IO)
234 ctx := s.TrackPlayer.Context
235 conf := s.Config
236 hasVideo, hasAudio := s.Video != nil && conf.SubVideo, s.Audio != nil && conf.SubAudio
237 stopReason := zap.String("reason", "stop")
238 defer s.onStop(&stopReason)
239 if !hasAudio && !hasVideo {
240 stopReason = zap.String("reason", "play neither video nor audio")
241 return
242 }
243 sendVideoDecConf := func() {
244 // s.Debug("sendVideoDecConf")
245 spesic.OnEvent(s.Video.ParamaterSets)
246 spesic.OnEvent(VideoDeConf(s.VideoReader.Track.SequenceHead))
247 }
248 sendAudioDecConf := func() {
249 // s.Debug("sendAudioDecConf")
250 spesic.OnEvent(AudioDeConf(s.AudioReader.Track.SequenceHead))
251 }
252 var sendAudioFrame, sendVideoFrame func(*AVFrame)
253 switch subType {
254 case SUBTYPE_RAW:
255 sendVideoFrame = func(frame *AVFrame) {
256 if frame.AUList.ByteLength == 0 {
257 return
258 }
259 spesic.OnEvent(VideoFrame{frame, s.Video, s.VideoReader.AbsTime, s.VideoReader.GetPTS32(), s.VideoReader.GetDTS32()})
260 }
261 sendAudioFrame = func(frame *AVFrame) {
262 if frame.AUList.ByteLength == 0 {
263 return
264 }
265 // fmt.Println("a", s.AudioReader.Delay)
266 // fmt.Println("a", frame.Sequence, s.AudioReader.AbsTime)
267 spesic.OnEvent(AudioFrame{frame, s.Audio, s.AudioReader.AbsTime, s.AudioReader.GetPTS32(), s.AudioReader.GetDTS32()})
268 }
269 case SUBTYPE_RTP:
270 var videoSeq, audioSeq uint16
271 sendVideoFrame = func(frame *AVFrame) {
272 // fmt.Println("v", frame.Sequence, frame.AbsTime, s.VideoReader.AbsTime, frame.IFrame)
273 delta := uint32(s.VideoReader.SkipTs * 90 / time.Millisecond)
274 frame.RTP.Range(func(vp RTPFrame) bool {
275 videoSeq++
276 copy := *vp.Packet
277 vp.Packet = &copy
278 vp.Header.Timestamp = vp.Header.Timestamp - delta
279 vp.Header.SequenceNumber = videoSeq

Callers 3

PlayRawMethod · 0.95
PlayFLVMethod · 0.95
PlayRTPMethod · 0.95

Calls 15

onStopMethod · 0.95
SizeOfBuffersFunction · 0.92
PutBEFunction · 0.92
ConditoinalFunction · 0.92
VideoDeConfTypeAlias · 0.85
AudioDeConfTypeAlias · 0.85
GetPTS32Method · 0.80
GetDTS32Method · 0.80
ReadFrameMethod · 0.80
DecConfChangedMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected