Beispiel #1
0
        private void OnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawAudioFrame rawAudioFrame))
            {
                return;
            }

            FFmpegAudioDecoder decoder = GetDecoderForFrame(rawAudioFrame);

            if (!decoder.TryDecode(rawAudioFrame, out int decodedFrameSize))
            {
                return;
            }

            if (_decodedFrameBuffer.Length < decodedFrameSize)
            {
                _decodedFrameBuffer = new byte[decodedFrameSize];
            }

            var bufferSegment = new ArraySegment <byte>(_decodedFrameBuffer, 0, decodedFrameSize);

            IDecodedAudioFrame decodedFrame = decoder.GetDecodedFrame(bufferSegment);

            FrameReceived?.Invoke(this, decodedFrame);
        }
        private FFmpegAudioDecoder GetDecoderForFrame(RawAudioFrame audioFrame)
        {
            FFmpegAudioCodecId codecId = DetectCodecId(audioFrame);

            if (!_audioDecodersMap.TryGetValue(codecId, out FFmpegAudioDecoder decoder))
            {
                int bitsPerCodedSample = 0;

                if (audioFrame is RawG726Frame g726Frame)
                {
                    bitsPerCodedSample = g726Frame.BitsPerCodedSample;
                }

                decoder = FFmpegAudioDecoder.CreateDecoder(codecId, bitsPerCodedSample);
                _audioDecodersMap.Add(codecId, decoder);
            }

            return(decoder);
        }
        //convert the raw frame to decoded frame
        private void RtspClientOnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawAudioFrame rawAudioFrame))
            {
                return;
            }

            FFmpegAudioDecoder decoder = GetDecoderForFrame(rawAudioFrame);

            if (!decoder.TryDecode(rawAudioFrame))
            {
                return;
            }

            //OutBitsPerSample may need to be set by user or the program?
            IDecodedAudioFrame decodedFrame = decoder.GetDecodedFrame(new AudioConversionParameters()
            {
                OutBitsPerSample = 16
            });

            System.Windows.Application.Current.Dispatcher.Invoke(_invalidateAction, DispatcherPriority.Send, decodedFrame);
        }
Beispiel #4
0
        private void OnFrameReceived(object sender, RawFrame rawFrame)
        {
            if (!(rawFrame is RawAudioFrame rawAudioFrame))
            {
                return;
            }

            FFmpegAudioDecoder decoder = GetDecoderForFrame(rawAudioFrame);

            if (!decoder.TryDecode(rawAudioFrame))
            {
                return;
            }

            IDecodedAudioFrame decodedFrame = decoder.GetDecodedFrame(new AudioConversionParameters()
            {
                OutBitsPerSample = 16
            });



            FrameReceived?.Invoke(this, decodedFrame);
        }