Skip to content

Commit d12dc28

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "If an error occurs that prevents us from reallocating buffers during a format change" into ics-mr1
2 parents 351143f + d03e7d6 commit d12dc28

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/media/stagefright/ACodec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ struct ACodec : public AHierarchicalStateMachine {
166166

167167
bool allYourBuffersAreBelongToUs();
168168

169+
size_t countBuffersOwnedByComponent(OMX_U32 portIndex) const;
170+
169171
void deferMessage(const sp<AMessage> &msg);
170172
void processDeferredMessages();
171173

media/libstagefright/ACodec.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ void ACodec::initiateSetup(const sp<AMessage> &msg) {
342342
}
343343

344344
void ACodec::signalFlush() {
345+
LOGV("[%s] signalFlush", mComponentName.c_str());
345346
(new AMessage(kWhatFlush, id()))->post();
346347
}
347348

@@ -1092,6 +1093,20 @@ status_t ACodec::initNativeWindow() {
10921093
return OK;
10931094
}
10941095

1096+
size_t ACodec::countBuffersOwnedByComponent(OMX_U32 portIndex) const {
1097+
size_t n = 0;
1098+
1099+
for (size_t i = 0; i < mBuffers[portIndex].size(); ++i) {
1100+
const BufferInfo &info = mBuffers[portIndex].itemAt(i);
1101+
1102+
if (info.mStatus == BufferInfo::OWNED_BY_COMPONENT) {
1103+
++n;
1104+
}
1105+
}
1106+
1107+
return n;
1108+
}
1109+
10951110
bool ACodec::allYourBuffersAreBelongToUs(
10961111
OMX_U32 portIndex) {
10971112
for (size_t i = 0; i < mBuffers[portIndex].size(); ++i) {
@@ -2041,6 +2056,14 @@ bool ACodec::ExecutingState::onMessageReceived(const sp<AMessage> &msg) {
20412056

20422057
case kWhatFlush:
20432058
{
2059+
LOGV("[%s] ExecutingState flushing now "
2060+
"(codec owns %d/%d input, %d/%d output).",
2061+
mCodec->mComponentName.c_str(),
2062+
mCodec->countBuffersOwnedByComponent(kPortIndexInput),
2063+
mCodec->mBuffers[kPortIndexInput].size(),
2064+
mCodec->countBuffersOwnedByComponent(kPortIndexOutput),
2065+
mCodec->mBuffers[kPortIndexOutput].size());
2066+
20442067
mActive = false;
20452068

20462069
CHECK_EQ(mCodec->mOMX->sendCommand(
@@ -2180,6 +2203,12 @@ bool ACodec::OutputPortSettingsChangedState::onOMXEvent(
21802203
err);
21812204

21822205
mCodec->signalError();
2206+
2207+
// This is technically not correct, since we were unable
2208+
// to allocate output buffers and therefore the output port
2209+
// remains disabled. It is necessary however to allow us
2210+
// to shutdown the codec properly.
2211+
mCodec->changeState(mCodec->mExecutingState);
21832212
}
21842213

21852214
return true;
@@ -2408,6 +2437,9 @@ bool ACodec::FlushingState::onMessageReceived(const sp<AMessage> &msg) {
24082437

24092438
bool ACodec::FlushingState::onOMXEvent(
24102439
OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) {
2440+
LOGV("[%s] FlushingState onOMXEvent(%d,%ld)",
2441+
mCodec->mComponentName.c_str(), event, data1);
2442+
24112443
switch (event) {
24122444
case OMX_EventCmdComplete:
24132445
{

0 commit comments

Comments
 (0)