diff options
author | Andreas Huber <andih@google.com> | 2009-12-01 15:26:54 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2009-12-01 15:26:54 -0800 |
commit | c297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f (patch) | |
tree | 7f7bd7bfa58df757385ab01ffcd3fd7e27351cfb /cmds/stagefright/audioloop.cpp | |
parent | a7c816c4bdb72cf4f9fe853a96cd7efdb394006d (diff) | |
download | frameworks_av-c297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f.zip frameworks_av-c297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f.tar.gz frameworks_av-c297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f.tar.bz2 |
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).
Diffstat (limited to 'cmds/stagefright/audioloop.cpp')
-rw-r--r-- | cmds/stagefright/audioloop.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
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 <binder/ProcessState.h> +#include <media/stagefright/AudioPlayer.h> +#include <media/stagefright/MediaDebug.h> +#include <media/stagefright/MediaDefs.h> +#include <media/stagefright/MetaData.h> +#include <media/stagefright/OMXClient.h> +#include <media/stagefright/OMXCodec.h> + +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<MediaSource> source = new SineSource(kSampleRate, kNumChannels); + + sp<MetaData> 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<OMXCodec> encoder = OMXCodec::Create( + client.interface(), + meta, true /* createEncoder */, + source); + + sp<OMXCodec> 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; +} |