summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2009-08-20 11:16:40 -0700
committerAndreas Huber <andih@google.com>2009-08-20 11:16:40 -0700
commit7530e9c708275c273c134c36c68179f511c1940e (patch)
treef9b20729ecf6a6f3acdd27ebade2bbae94f50aef
parentbde3caae211e215e4bbfef1a267f8d680efa4764 (diff)
downloadframeworks_av-7530e9c708275c273c134c36c68179f511c1940e.zip
frameworks_av-7530e9c708275c273c134c36c68179f511c1940e.tar.gz
frameworks_av-7530e9c708275c273c134c36c68179f511c1940e.tar.bz2
Dynamically allocate a pair of MemoryHeaps according buffer count/sizes required by the OMX component, respect JPEG compressed size.
-rw-r--r--cmds/stagefright/JPEGSource.cpp6
-rw-r--r--include/media/stagefright/MetaData.h1
-rw-r--r--include/media/stagefright/OMXCodec.h5
-rw-r--r--media/libstagefright/OMXCodec.cpp39
4 files changed, 36 insertions, 15 deletions
diff --git a/cmds/stagefright/JPEGSource.cpp b/cmds/stagefright/JPEGSource.cpp
index 338a3d5..a7994ed 100644
--- a/cmds/stagefright/JPEGSource.cpp
+++ b/cmds/stagefright/JPEGSource.cpp
@@ -60,6 +60,7 @@ JPEGSource::JPEGSource(const sp<DataSource> &source)
mHeight(0),
mOffset(0) {
CHECK_EQ(parseJPEG(), OK);
+ CHECK(mSource->getSize(&mSize) == OK);
}
JPEGSource::~JPEGSource() {
@@ -73,10 +74,6 @@ status_t JPEGSource::start(MetaData *) {
return UNKNOWN_ERROR;
}
- if (mSource->getSize(&mSize) != OK) {
- return UNKNOWN_ERROR;
- }
-
mGroup = new MediaBufferGroup;
mGroup->add_buffer(new MediaBuffer(mSize));
@@ -105,6 +102,7 @@ sp<MetaData> JPEGSource::getFormat() {
meta->setCString(kKeyMIMEType, "image/jpeg");
meta->setInt32(kKeyWidth, mWidth);
meta->setInt32(kKeyHeight, mHeight);
+ meta->setInt32(kKeyCompressedSize, mSize);
return meta;
}
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 6ce2581..be60565 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -45,6 +45,7 @@ enum {
kKeyPlatformPrivate = 'priv',
kKeyDecoderComponent = 'decC',
kKeyBufferID = 'bfID',
+ kKeyCompressedSize = 'cmpS',
};
enum {
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index c8ee255..0b94118 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -108,7 +108,7 @@ private:
Vector<CodecSpecificData *> mCodecSpecificData;
size_t mCodecSpecificDataIndex;
- sp<MemoryDealer> mDealer;
+ sp<MemoryDealer> mDealer[2];
State mState;
Vector<BufferInfo> mPortBuffers[2];
@@ -148,6 +148,9 @@ private:
void setImageOutputFormat(
OMX_COLOR_FORMATTYPE format, OMX_U32 width, OMX_U32 height);
+ void setJPEGInputFormat(
+ OMX_U32 width, OMX_U32 height, OMX_U32 compressedSize);
+
status_t allocateBuffers();
status_t allocateBuffersOnPort(OMX_U32 portIndex);
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 1774eaf..ec9f6d3 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -302,7 +302,7 @@ sp<OMXCodec> OMXCodec::Create(
int32_t width, height;
bool success = meta->findInt32(kKeyWidth, &width);
success = success && meta->findInt32(kKeyHeight, &height);
- assert(success);
+ CHECK(success);
if (createEncoder) {
codec->setVideoInputFormat(mime, width, height);
@@ -321,9 +321,16 @@ sp<OMXCodec> OMXCodec::Create(
int32_t width, height;
bool success = meta->findInt32(kKeyWidth, &width);
success = success && meta->findInt32(kKeyHeight, &height);
- assert(success);
+
+ int32_t compressedSize;
+ success = success && meta->findInt32(
+ kKeyCompressedSize, &compressedSize);
+
+ CHECK(success);
+ CHECK(compressedSize > 0);
codec->setImageOutputFormat(format, width, height);
+ codec->setJPEGInputFormat(width, height, (OMX_U32)compressedSize);
}
codec->initOutputFormat(meta);
@@ -355,7 +362,7 @@ status_t OMXCodec::setVideoPortFormatType(
}
// The following assertion is violated by TI's video decoder.
- // assert(format.nIndex == index);
+ // CHECK_EQ(format.nIndex, index);
#if 1
LOGI("portIndex: %ld, index: %ld, eCompressionFormat=%d eColorFormat=%d",
@@ -618,7 +625,6 @@ OMXCodec::OMXCodec(
mComponentName(strdup(componentName)),
mSource(source),
mCodecSpecificDataIndex(0),
- mDealer(new MemoryDealer(5 * 1024 * 1024)),
mState(LOADED),
mSignalledEOS(false),
mNoMoreOutputData(false),
@@ -716,8 +722,11 @@ status_t OMXCodec::allocateBuffersOnPort(OMX_U32 portIndex) {
return err;
}
+ size_t totalSize = def.nBufferCountActual * def.nBufferSize;
+ mDealer[portIndex] = new MemoryDealer(totalSize);
+
for (OMX_U32 i = 0; i < def.nBufferCountActual; ++i) {
- sp<IMemory> mem = mDealer->allocate(def.nBufferSize);
+ sp<IMemory> mem = mDealer[portIndex]->allocate(def.nBufferSize);
CHECK(mem.get() != NULL);
IOMX::buffer_id buffer;
@@ -1491,23 +1500,33 @@ void OMXCodec::setImageOutputFormat(
break;
}
+ def.nBufferCountActual = def.nBufferCountMin;
+
err = mOMX->set_parameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
CHECK_EQ(err, OK);
+}
- ////
-
+void OMXCodec::setJPEGInputFormat(
+ OMX_U32 width, OMX_U32 height, OMX_U32 compressedSize) {
+ OMX_PARAM_PORTDEFINITIONTYPE def;
+ def.nSize = sizeof(def);
+ def.nVersion.s.nVersionMajor = 1;
+ def.nVersion.s.nVersionMinor = 1;
def.nPortIndex = kPortIndexInput;
- err = mOMX->get_parameter(
+ status_t err = mOMX->get_parameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
CHECK_EQ(err, OK);
+ CHECK_EQ(def.eDomain, OMX_PortDomainImage);
+ OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
+
CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingJPEG);
imageDef->nFrameWidth = width;
imageDef->nFrameHeight = height;
- def.nBufferSize = 128 * 1024;
+ def.nBufferSize = compressedSize;
def.nBufferCountActual = def.nBufferCountMin;
err = mOMX->set_parameter(
@@ -1558,7 +1577,7 @@ status_t OMXCodec::start(MetaData *) {
}
status_t OMXCodec::stop() {
- LOGI("stop");
+ LOGV("stop");
Mutex::Autolock autoLock(mLock);