コード例 #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
        public void Parse_DifferentAggregationUnits_ReturnsValidIFrame(byte[] testBytes)
        {
            H264CodecInfo testCodecInfo = CreateTestH264CodecInfo();

            RawH264Frame frame  = null;
            var          parser = new H264VideoPayloadParser(testCodecInfo);

            parser.FrameGenerated = rawFrame => frame = (RawH264Frame)rawFrame;
            parser.Parse(TimeSpan.Zero, new ArraySegment <byte>(testBytes), true);

            Assert.IsNotNull(frame);
            Assert.IsInstanceOfType(frame, typeof(RawH264IFrame));
        }