From 4edb015d2d785e3b293e5a6da74c91b81afffa12 Mon Sep 17 00:00:00 2001 From: DoubleX69 Date: Mon, 28 Jun 2021 17:34:07 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=A2=9E=E5=8A=A0AudioPlayer=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_player.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_player.cpp b/tests/test_player.cpp index 5a5005e5..883755d0 100644 --- a/tests/test_player.cpp +++ b/tests/test_player.cpp @@ -18,6 +18,8 @@ #include "FFMpegDecoder.h" #include "YuvDisplayer.h" #include "Extension/H265.h" +#include "Extension/AAC.h" +#include "Audio/AudioPlayer.h" using namespace std; using namespace toolkit; @@ -80,6 +82,11 @@ int main(int argc, char *argv[]) { return; } + auto audioTrack = strongPlayer->getTrack(TrackAudio,false); + if( !audioTrack){ + WarnL << "没有音频!"; + } + AnyStorage::Ptr storage(new AnyStorage); viedoTrack->addDelegate(std::make_shared([storage](const Frame::Ptr &frame_in) { auto frame = Frame::getCacheAbleFrame(frame_in); @@ -106,6 +113,30 @@ int main(int argc, char *argv[]) { return true; }); })); + + auto audio_delagate = std::make_shared([storage, audioTrack](const Frame::Ptr& frame_in) { + auto frame = Frame::getCacheAbleFrame(frame_in); + AACTrack::Ptr aacTrack = dynamic_pointer_cast(audioTrack); + + std::string codename = frame->getCodecName(); + int out_sample_fmt = aacTrack->getAudioSampleBit(); + int channelnum = aacTrack->getAudioChannel(); + int sample_rate = aacTrack->getAudioSampleRate(); + + auto &audioplayer = (*storage)["audioplayer"]; + + if(!audioplayer){ + audioplayer.set(sample_rate,channelnum,out_sample_fmt); + } + + audioplayer.get().inputFrame( frame ); + + }); + + if( audioTrack ) { + audioTrack->addDelegate(audio_delagate); + } + });