Merge change I8768f2cc into eclair-mr2
* changes: 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).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
81
cmds/stagefright/audioloop.cpp
Normal file
81
cmds/stagefright/audioloop.cpp
Normal file
@@ -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;
|
||||
}
|
||||
@@ -146,8 +146,7 @@ private:
|
||||
|
||||
void setComponentRole();
|
||||
|
||||
void setAMRFormat();
|
||||
void setAMRWBFormat();
|
||||
void setAMRFormat(bool isWAMR);
|
||||
void setAACFormat(int32_t numChannels, int32_t sampleRate);
|
||||
|
||||
status_t setVideoPortFormatType(
|
||||
|
||||
@@ -416,10 +416,10 @@ sp<OMXCodec> OMXCodec::Create(
|
||||
}
|
||||
|
||||
if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mime)) {
|
||||
codec->setAMRFormat();
|
||||
codec->setAMRFormat(false /* isWAMR */);
|
||||
}
|
||||
if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mime)) {
|
||||
codec->setAMRWBFormat();
|
||||
codec->setAMRFormat(true /* isWAMR */);
|
||||
}
|
||||
if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime)) {
|
||||
int32_t numChannels, sampleRate;
|
||||
@@ -1900,54 +1900,24 @@ void OMXCodec::setRawAudioFormat(
|
||||
CHECK_EQ(err, OK);
|
||||
}
|
||||
|
||||
void OMXCodec::setAMRFormat() {
|
||||
if (!mIsEncoder) {
|
||||
OMX_AUDIO_PARAM_AMRTYPE def;
|
||||
InitOMXParams(&def);
|
||||
def.nPortIndex = kPortIndexInput;
|
||||
void OMXCodec::setAMRFormat(bool isWAMR) {
|
||||
OMX_U32 portIndex = mIsEncoder ? kPortIndexOutput : kPortIndexInput;
|
||||
|
||||
status_t err =
|
||||
mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
OMX_AUDIO_PARAM_AMRTYPE def;
|
||||
InitOMXParams(&def);
|
||||
def.nPortIndex = portIndex;
|
||||
|
||||
CHECK_EQ(err, OK);
|
||||
status_t err =
|
||||
mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
|
||||
def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
|
||||
def.eAMRBandMode = OMX_AUDIO_AMRBandModeNB0;
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
CHECK_EQ(err, OK);
|
||||
}
|
||||
def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
|
||||
def.eAMRBandMode =
|
||||
isWAMR ? OMX_AUDIO_AMRBandModeWB0 : OMX_AUDIO_AMRBandModeNB0;
|
||||
|
||||
////////////////////////
|
||||
|
||||
if (mIsEncoder) {
|
||||
sp<MetaData> format = mSource->getFormat();
|
||||
int32_t sampleRate;
|
||||
int32_t numChannels;
|
||||
CHECK(format->findInt32(kKeySampleRate, &sampleRate));
|
||||
CHECK(format->findInt32(kKeyChannelCount, &numChannels));
|
||||
|
||||
setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
|
||||
}
|
||||
}
|
||||
|
||||
void OMXCodec::setAMRWBFormat() {
|
||||
if (!mIsEncoder) {
|
||||
OMX_AUDIO_PARAM_AMRTYPE def;
|
||||
InitOMXParams(&def);
|
||||
def.nPortIndex = kPortIndexInput;
|
||||
|
||||
status_t err =
|
||||
mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
|
||||
def.eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
|
||||
|
||||
err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
CHECK_EQ(err, OK);
|
||||
}
|
||||
err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user