@@ -342,6 +342,7 @@ void ACodec::initiateSetup(const sp<AMessage> &msg) {
342342}
343343
344344void 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+
10951110bool 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
24092438bool 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