From c297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 1 Dec 2009 15:26:54 -0800 Subject: A small sample tool to encode pcm audio data to amr, decode it again and play it. Some changes to OMXCodec to properly configure the AMR decoder(s). --- cmds/stagefright/audioloop.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 cmds/stagefright/audioloop.cpp (limited to 'cmds/stagefright/audioloop.cpp') diff --git a/cmds/stagefright/audioloop.cpp b/cmds/stagefright/audioloop.cpp new file mode 100644 index 0000000..70ab559 --- /dev/null +++ b/cmds/stagefright/audioloop.cpp @@ -0,0 +1,81 @@ +#include "SineSource.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace android; + +int main() { + // We only have an AMR-WB encoder on sholes... + static bool outputWBAMR = false; + static const int32_t kSampleRate = outputWBAMR ? 16000 : 8000; + static const int32_t kNumChannels = 1; + + android::ProcessState::self()->startThreadPool(); + + OMXClient client; + CHECK_EQ(client.connect(), OK); + + sp source = new SineSource(kSampleRate, kNumChannels); + + sp meta = new MetaData; + + meta->setCString( + kKeyMIMEType, + outputWBAMR ? MEDIA_MIMETYPE_AUDIO_AMR_WB + : MEDIA_MIMETYPE_AUDIO_AMR_NB); + + meta->setInt32(kKeyChannelCount, kNumChannels); + meta->setInt32(kKeySampleRate, kSampleRate); + + int32_t maxInputSize; + if (source->getFormat()->findInt32(kKeyMaxInputSize, &maxInputSize)) { + meta->setInt32(kKeyMaxInputSize, maxInputSize); + } + + sp encoder = OMXCodec::Create( + client.interface(), + meta, true /* createEncoder */, + source); + + sp decoder = OMXCodec::Create( + client.interface(), + meta, false /* createEncoder */, + encoder); + +#if 1 + AudioPlayer *player = new AudioPlayer(NULL); + player->setSource(decoder); + + player->start(); + + sleep(10); + + player->stop(); + + delete player; + player = NULL; +#else + CHECK_EQ(decoder->start(), OK); + + MediaBuffer *buffer; + while (decoder->read(&buffer) == OK) { + // do something with buffer + + putchar('.'); + fflush(stdout); + + buffer->release(); + buffer = NULL; + } + + CHECK_EQ(decoder->stop(), OK); +#endif + + return 0; +} -- cgit v1.1