@@ -49,6 +49,7 @@ struct CodecState {
4949 size_t mCSDIndex ;
5050 Vector<sp<ABuffer> > mInBuffers ;
5151 Vector<sp<ABuffer> > mOutBuffers ;
52+ bool mSignalledInputEOS ;
5253 bool mSawOutputEOS ;
5354 int64_t mNumBuffersDecoded ;
5455 int64_t mNumBytesDecoded ;
@@ -127,6 +128,7 @@ static int decode(
127128 }
128129
129130 state->mCSDIndex = 0 ;
131+ state->mSignalledInputEOS = false ;
130132 state->mSawOutputEOS = false ;
131133
132134 ALOGV (" got %d pieces of codec specific data." , state->mCSD .size ());
@@ -180,33 +182,7 @@ static int decode(
180182 status_t err = extractor->getSampleTrackIndex (&trackIndex);
181183
182184 if (err != OK) {
183- ALOGV (" signalling EOS." );
184-
185- for (size_t i = 0 ; i < stateByTrack.size (); ++i) {
186- CodecState *state = &stateByTrack.editValueAt (i);
187-
188- for (;;) {
189- size_t index;
190- err = state->mCodec ->dequeueInputBuffer (&index, kTimeout );
191-
192- if (err == -EAGAIN) {
193- continue ;
194- }
195-
196- CHECK_EQ (err, (status_t )OK);
197-
198- err = state->mCodec ->queueInputBuffer (
199- index,
200- 0 /* offset */ ,
201- 0 /* size */ ,
202- 0ll /* timeUs */ ,
203- MediaCodec::BUFFER_FLAG_EOS);
204-
205- CHECK_EQ (err, (status_t )OK);
206- break ;
207- }
208- }
209-
185+ ALOGV (" saw input eos" );
210186 sawInputEOS = true ;
211187 } else {
212188 CodecState *state = &stateByTrack.editValueFor (trackIndex);
@@ -240,6 +216,33 @@ static int decode(
240216 CHECK_EQ (err, -EAGAIN);
241217 }
242218 }
219+ } else {
220+ for (size_t i = 0 ; i < stateByTrack.size (); ++i) {
221+ CodecState *state = &stateByTrack.editValueAt (i);
222+
223+ if (!state->mSignalledInputEOS ) {
224+ size_t index;
225+ status_t err =
226+ state->mCodec ->dequeueInputBuffer (&index, kTimeout );
227+
228+ if (err == OK) {
229+ ALOGV (" signalling input EOS on track %d" , i);
230+
231+ err = state->mCodec ->queueInputBuffer (
232+ index,
233+ 0 /* offset */ ,
234+ 0 /* size */ ,
235+ 0ll /* timeUs */ ,
236+ MediaCodec::BUFFER_FLAG_EOS);
237+
238+ CHECK_EQ (err, (status_t )OK);
239+
240+ state->mSignalledInputEOS = true ;
241+ } else {
242+ CHECK_EQ (err, -EAGAIN);
243+ }
244+ }
245+ }
243246 }
244247
245248 bool sawOutputEOSOnAllTracks = true ;
0 commit comments