From a7c2a65ebcc1fa5923843cc7c784c90f60e0ebb2 Mon Sep 17 00:00:00 2001 From: sirius Date: Wed, 30 Oct 2019 00:01:25 +0800 Subject: [PATCH] audio seems correct, but need more elegant way, and still bad interleaving --- src/engine/client/video.cpp | 18 +++++++++++++----- src/engine/client/video.h | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/engine/client/video.cpp b/src/engine/client/video.cpp index 597df9edd..51f4897f6 100644 --- a/src/engine/client/video.cpp +++ b/src/engine/client/video.cpp @@ -238,6 +238,11 @@ void CVideo::nextAudioFrame(short* pData) { if (m_Recording && m_HasAudio) { + m_aseq += 1; + for(int i=0; i < 1024; i++) + m_aBuffer[i+(m_aseq%2)*1024] = pData[i]; + if(m_aseq % 2) + { m_ProcessingAudioFrame = true; m_AudioStream.frame->pts = m_AudioStream.enc->frame_number; dbg_msg("video_recorder", "aframe: %d", m_AudioStream.enc->frame_number); @@ -262,14 +267,14 @@ void CVideo::nextAudioFrame(short* pData) // ); // dbg_msg("video_recorder", "dst_nb_samples: %d", dst_nb_samples); - fwrite(pData, sizeof(short), 1024, m_dbgfile); + //fwrite(pData, sizeof(short), 1024, m_dbgfile); av_samples_fill_arrays( (uint8_t**)m_AudioStream.tmp_frame->data, 0, // pointer to linesize (int*) - (const uint8_t*)pData, + (const uint8_t*)m_aBuffer, 2, // channels - m_AudioStream.tmp_frame->nb_samples, + m_AudioStream.tmp_frame->nb_samples * 2, AV_SAMPLE_FMT_S16, 0 // align ); @@ -283,9 +288,9 @@ void CVideo::nextAudioFrame(short* pData) ret = swr_convert( m_AudioStream.swr_ctx, m_AudioStream.frame->data, - m_AudioStream.frame->nb_samples, + m_AudioStream.frame->nb_samples * 2, (const uint8_t **)m_AudioStream.tmp_frame->data, - m_AudioStream.tmp_frame->nb_samples + m_AudioStream.tmp_frame->nb_samples * 2 ); if (ret < 0) @@ -303,6 +308,7 @@ void CVideo::nextAudioFrame(short* pData) write_frame(&m_AudioStream); m_ProcessingAudioFrame = false; + } } } @@ -510,6 +516,8 @@ void CVideo::open_audio() dbg_msg("video_recorder", "Failed to initialize the resampling context"); exit(1); } + + m_aseq = 0; } diff --git a/src/engine/client/video.h b/src/engine/client/video.h index f778085e2..91cca475e 100644 --- a/src/engine/client/video.h +++ b/src/engine/client/video.h @@ -94,6 +94,8 @@ private: int m_Height; char m_Name[256]; FILE *m_dbgfile; + int m_aseq; + short m_aBuffer[2048]; int m_FPS;