summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/ACodec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/ACodec.cpp')
-rw-r--r--media/libstagefright/ACodec.cpp96
1 files changed, 78 insertions, 18 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 7b87676..5001c16 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -41,7 +41,7 @@
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
-
+#include <media/stagefright/PersistentSurface.h>
#include <media/hardware/HardwareAPI.h>
#include <OMX_AudioExt.h>
@@ -260,9 +260,12 @@ private:
bool onConfigureComponent(const sp<AMessage> &msg);
void onCreateInputSurface(const sp<AMessage> &msg);
+ void onUsePersistentInputSurface(const sp<AMessage> &msg);
void onStart();
void onShutdown(bool keepComponentAllocated);
+ status_t setupInputSurface();
+
DISALLOW_EVIL_CONSTRUCTORS(LoadedState);
};
@@ -480,6 +483,13 @@ void ACodec::initiateCreateInputSurface() {
(new AMessage(kWhatCreateInputSurface, this))->post();
}
+void ACodec::initiateUsePersistentInputSurface(
+ const sp<PersistentSurface> &surface) {
+ sp<AMessage> msg = new AMessage(kWhatUsePersistentInputSurface, this);
+ msg->setObject("input-surface", surface);
+ msg->post();
+}
+
void ACodec::signalEndOfInputStream() {
(new AMessage(kWhatSignalEndOfInputStream, this))->post();
}
@@ -4200,6 +4210,7 @@ bool ACodec::BaseState::onMessageReceived(const sp<AMessage> &msg) {
}
case ACodec::kWhatCreateInputSurface:
+ case ACodec::kWhatUsePersistentInputSurface:
case ACodec::kWhatSignalEndOfInputStream:
{
// This may result in an app illegal state exception.
@@ -5095,6 +5106,13 @@ bool ACodec::LoadedState::onMessageReceived(const sp<AMessage> &msg) {
break;
}
+ case ACodec::kWhatUsePersistentInputSurface:
+ {
+ onUsePersistentInputSurface(msg);
+ handled = true;
+ break;
+ }
+
case ACodec::kWhatStart:
{
onStart();
@@ -5162,20 +5180,10 @@ bool ACodec::LoadedState::onConfigureComponent(
return true;
}
-void ACodec::LoadedState::onCreateInputSurface(
- const sp<AMessage> & /* msg */) {
- ALOGV("onCreateInputSurface");
-
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatInputSurfaceCreated);
-
- sp<IGraphicBufferProducer> bufferProducer;
- status_t err;
-
- err = mCodec->mOMX->createInputSurface(mCodec->mNode, kPortIndexInput,
- &bufferProducer);
+status_t ACodec::LoadedState::setupInputSurface() {
+ status_t err = OK;
- if (err == OK && mCodec->mRepeatFrameDelayUs > 0ll) {
+ if (mCodec->mRepeatFrameDelayUs > 0ll) {
err = mCodec->mOMX->setInternalOption(
mCodec->mNode,
kPortIndexInput,
@@ -5188,10 +5196,11 @@ void ACodec::LoadedState::onCreateInputSurface(
"frames (err %d)",
mCodec->mComponentName.c_str(),
err);
+ return err;
}
}
- if (err == OK && mCodec->mMaxPtsGapUs > 0ll) {
+ if (mCodec->mMaxPtsGapUs > 0ll) {
err = mCodec->mOMX->setInternalOption(
mCodec->mNode,
kPortIndexInput,
@@ -5203,10 +5212,11 @@ void ACodec::LoadedState::onCreateInputSurface(
ALOGE("[%s] Unable to configure max timestamp gap (err %d)",
mCodec->mComponentName.c_str(),
err);
+ return err;
}
}
- if (err == OK && mCodec->mMaxFps > 0) {
+ if (mCodec->mMaxFps > 0) {
err = mCodec->mOMX->setInternalOption(
mCodec->mNode,
kPortIndexInput,
@@ -5218,10 +5228,11 @@ void ACodec::LoadedState::onCreateInputSurface(
ALOGE("[%s] Unable to configure max fps (err %d)",
mCodec->mComponentName.c_str(),
err);
+ return err;
}
}
- if (err == OK && mCodec->mTimePerCaptureUs > 0ll
+ if (mCodec->mTimePerCaptureUs > 0ll
&& mCodec->mTimePerFrameUs > 0ll) {
int64_t timeLapse[2];
timeLapse[0] = mCodec->mTimePerFrameUs;
@@ -5237,10 +5248,11 @@ void ACodec::LoadedState::onCreateInputSurface(
ALOGE("[%s] Unable to configure time lapse (err %d)",
mCodec->mComponentName.c_str(),
err);
+ return err;
}
}
- if (err == OK && mCodec->mCreateInputBuffersSuspended) {
+ if (mCodec->mCreateInputBuffersSuspended) {
bool suspend = true;
err = mCodec->mOMX->setInternalOption(
mCodec->mNode,
@@ -5253,9 +5265,28 @@ void ACodec::LoadedState::onCreateInputSurface(
ALOGE("[%s] Unable to configure option to suspend (err %d)",
mCodec->mComponentName.c_str(),
err);
+ return err;
}
}
+ return OK;
+}
+
+void ACodec::LoadedState::onCreateInputSurface(
+ const sp<AMessage> & /* msg */) {
+ ALOGV("onCreateInputSurface");
+
+ sp<AMessage> notify = mCodec->mNotify->dup();
+ notify->setInt32("what", CodecBase::kWhatInputSurfaceCreated);
+
+ sp<IGraphicBufferProducer> bufferProducer;
+ status_t err = mCodec->mOMX->createInputSurface(
+ mCodec->mNode, kPortIndexInput, &bufferProducer);
+
+ if (err == OK) {
+ err = setupInputSurface();
+ }
+
if (err == OK) {
notify->setObject("input-surface",
new BufferProducerWrapper(bufferProducer));
@@ -5270,6 +5301,35 @@ void ACodec::LoadedState::onCreateInputSurface(
notify->post();
}
+void ACodec::LoadedState::onUsePersistentInputSurface(
+ const sp<AMessage> &msg) {
+ ALOGV("onUsePersistentInputSurface");
+
+ sp<AMessage> notify = mCodec->mNotify->dup();
+ notify->setInt32("what", CodecBase::kWhatInputSurfaceAccepted);
+
+ sp<RefBase> obj;
+ CHECK(msg->findObject("input-surface", &obj));
+ sp<PersistentSurface> surface = static_cast<PersistentSurface *>(obj.get());
+
+ status_t err = mCodec->mOMX->usePersistentInputSurface(
+ mCodec->mNode, kPortIndexInput, surface->getBufferConsumer());
+
+ if (err == OK) {
+ err = setupInputSurface();
+ }
+
+ if (err != OK) {
+ // Can't use mCodec->signalError() here -- MediaCodec won't forward
+ // the error through because it's in the "configured" state. We
+ // send a kWhatInputSurfaceAccepted with an error value instead.
+ ALOGE("[%s] onUsePersistentInputSurface returning error %d",
+ mCodec->mComponentName.c_str(), err);
+ notify->setInt32("err", err);
+ }
+ notify->post();
+}
+
void ACodec::LoadedState::onStart() {
ALOGV("onStart");