Пример #1
0
        private void DecodeTask()
        {
            H264VideoPayloadParser parser  = new H264VideoPayloadParser(new RtspClientSharp.Codecs.Video.H264CodecInfo());
            FFmpegVideoDecoder     decoder = FFmpegVideoDecoder.CreateDecoder(FFmpegVideoCodecId.H264);

            parser.FrameGenerated += (frame) =>
            {
                lock (m_decoderLock)
                {
                    IDecodedVideoFrame decodedFrame = decoder.TryDecode((RawVideoFrame)frame);
                    if (decodedFrame != null)
                    {
                        m_lastDecodedFrame = decodedFrame;
                        FrameReceived?.Invoke(this, decodedFrame);
                    }
                    else
                    {
                        Log.e(TAG, "Failed to decode frame");
                    }
                }
            };

            while (!m_CancelToken.Token.IsCancellationRequested)
            {
                try
                {
                    Payload nextFramePayload = m_payloadQueue.Receive(m_CancelToken.Token);
                    parser.Parse(new TimeSpan(1), new ArraySegment <byte>(nextFramePayload.Data.GetBuffer(), (int)nextFramePayload.Data.Position, (int)nextFramePayload.Data.Remaining()), true);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
            }
        }
Пример #2
0
        private FFmpegVideoDecoder GetDecoderForFrame(RawVideoFrame videoFrame)
        {
            FFmpegVideoCodecId codecId = DetectCodecId(videoFrame);

            if (!_videoDecodersMap.TryGetValue(codecId, out FFmpegVideoDecoder decoder))
            {
                decoder = FFmpegVideoDecoder.CreateDecoder(codecId);
                _videoDecodersMap.Add(codecId, decoder);
            }

            return(decoder);
        }