summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2009-12-01 15:26:54 -0800
committerAndreas Huber <andih@google.com>2009-12-01 15:26:54 -0800
commitc297fccffc4ab1cb3b9f5c6a5b0802be057f3e0f (patch)
tree7f7bd7bfa58df757385ab01ffcd3fd7e27351cfb /cmds
parenta7c816c4bdb72cf4f9fe853a96cd7efdb394006d (diff)
downloadframeworks_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')
-rw-r--r--cmds/stagefright/Android.mk22
-rw-r--r--cmds/stagefright/SineSource.cpp1
-rw-r--r--cmds/stagefright/audioloop.cpp81
3 files changed, 104 insertions, 0 deletions
diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk
index 5b55252..100af89 100644
--- a/cmds/stagefright/Android.mk
+++ b/cmds/stagefright/Android.mk
@@ -43,4 +43,26 @@ LOCAL_MODULE:= record
include $(BUILD_EXECUTABLE)
+################################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ SineSource.cpp \
+ audioloop.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libstagefright
+
+LOCAL_C_INCLUDES:= \
+ $(JNI_H_INCLUDE) \
+ frameworks/base/media/libstagefright \
+ $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include
+
+LOCAL_CFLAGS += -Wno-multichar
+
+LOCAL_MODULE:= audioloop
+
+include $(BUILD_EXECUTABLE)
+
endif
diff --git a/cmds/stagefright/SineSource.cpp b/cmds/stagefright/SineSource.cpp
index e272a65..021f636 100644
--- a/cmds/stagefright/SineSource.cpp
+++ b/cmds/stagefright/SineSource.cpp
@@ -52,6 +52,7 @@ sp<MetaData> SineSource::getFormat() {
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
meta->setInt32(kKeyChannelCount, mNumChannels);
meta->setInt32(kKeySampleRate, mSampleRate);
+ meta->setInt32(kKeyMaxInputSize, kBufferSize);
return meta;
}
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;
+}