BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
722 stars 286 forks source link

AAC decoding #22

Closed roman-miniailov closed 5 years ago

roman-miniailov commented 5 years ago

I'm trying to add AAC audio decoding to your player sample app.

I'm using 86018 as audio codec ID (AAC), avcodec_find_decoder gave me ff_aac_decoder.

I'm using code like in your sample but for audio buffer:

context->AvRawPacket.data = static_cast<uint8_t *>(rawBuffer);
context->AvRawPacket.size = rawBufferLength;

int got_frame;

const int len = avcodec_decode_audio4(context->AvCodecContext, context->Frame, &got_frame, &context->AvRawPacket);

len is AVERROR_INVALIDDATA after method call.

I'm using classic AVERROR_INVALIDDATA stream.

Used data is

byte* rawBufferPtr = &rawAudioFrame.FrameSegment.Array[rawAudioFrame.FrameSegment.Offset]

Am I doing something wrong here (maybe FFMPEG wrong usage)?

BogdanovKirill commented 5 years ago

Did you try to set extradata field for AVCodecContext ? Your RawAACFrame has ConfigSegment property, you need to use it.

roman-miniailov commented 5 years ago

Doesn't worked...

Using same code as for video codec.

if (rawAudioFrame is RawAACFrame rawAacFrame)
                {
                    if (rawAacFrame.ConfigSegment.Array != null &&
                        !_extraData.SequenceEqual(rawAacFrame.ConfigSegment))
                    {
                        if (_extraData.Length != rawAacFrame.ConfigSegment.Count)
                            _extraData = new byte[rawAacFrame.ConfigSegment.Count];

                        Buffer.BlockCopy(rawAacFrame.ConfigSegment.Array, rawAacFrame.ConfigSegment.Offset,
                            _extraData, 0, rawAacFrame.ConfigSegment.Count);

                        fixed (byte* initDataPtr = &_extraData[0])
                        {
                            resultCode = FFmpegPInvoke.SetDecoderExtraData(_decoderHandle,
                                (IntPtr)initDataPtr, _extraData.Length);

                            if (resultCode != 0)
                                throw new DecoderException(
                                    $"An error is occurred while setting audio extra data, {_audioCodecId} codec, code: {resultCode}");
                        }
                    }
                }
BBUBBA commented 5 years ago

Mr BogdanovKirill.

My friend ~!~! Cheer up!

i wating for your reply^^

and Thanks anything ~!

roman-miniailov commented 5 years ago

i wating for your reply^^

Do you have the same issue?

BogdanovKirill commented 5 years ago

I need RTSP server with AAC audio. I could make some research on nearest saturday or sunday

roman-miniailov commented 5 years ago

I'm using the following URL for tests - rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov

Thank you!

BBUBBA commented 5 years ago

@roman-minyaylov

Yep !! +.+

roman-miniailov commented 5 years ago

Any news? May I help?

roman-miniailov commented 5 years ago

Can I pay you something to resolve this issue?

(Have same problem with AMCREST IP camera)

BogdanovKirill commented 5 years ago

@roman-minyaylov

Sorry, I don't have free time now. I will try to make it at this weekend. You could support me through paypal or could make your offer directly to bogdanov.kv@bk.ru

BogdanovKirill commented 5 years ago

Hi guys,

Thank you for your work. Today I've fixed bug in AAC parser (new version of nuget package is available): https://github.com/BogdanovKirill/RtspClientSharp/commit/8069d3c87d682c078c1612f92846032092284306 That should resolve all decoding problems with AAC frames. Also I've written audio decoder for SimpleRtspPlayer in master branch. You could get all this code to use it in your projects: https://github.com/BogdanovKirill/RtspClientSharp/commit/0eec11dd5bfafde68c0444a77f7149eec8a22059 Please start from "RealtimeAudioSource" class. It will give you PCM frames which could be played by NAudio or something else. Later I will write playback logic by myself.

BBUBBA commented 5 years ago

안녕 얘들 아,

당신의 일에 감사드립니다. 오늘 AAC 파서에서 버그를 수정했습니다 (새로운 버전의 Nuget 패키지를 사용할 수 있습니다) : 8069d3c AAC 프레임의 모든 디코딩 문제를 해결해야합니다. 또한 master 브랜치에 SimpleRtspPlayer 용 오디오 디코더를 작성했습니다. 이 코드를 모두 프로젝트에서 사용할 수 있습니다 : 0eec11d "RealtimeAudioSource"클래스부터 시작하십시오. NAudio 또는 다른 어떤 것으로 재생할 수있는 PCM 프레임을 제공합니다. 나중에 나는 스스로 재생 논리를 쓸 것이다.

Thanks !!!!!!!!!!!!!!!!!!!! Mr. !!

i hope your life is Happy !!

BogdanovKirill commented 5 years ago

It seems that we could close that issue