diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index cab8ed01..127e476a 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -260,6 +260,7 @@ void *mpp_dec_hal_thread(void *data) frames->lock(); frames->add_at_tail(&frame, sizeof(frame)); mpp->mFramePutCount++; + frames->signal(); frames->unlock(); } diff --git a/mpp/codec/mpp_enc.cpp b/mpp/codec/mpp_enc.cpp index 5104ffb9..66ab68c8 100644 --- a/mpp/codec/mpp_enc.cpp +++ b/mpp/codec/mpp_enc.cpp @@ -108,6 +108,7 @@ void *mpp_enc_hal_thread(void *data) frames->lock(); frames->add_at_tail(&frame, sizeof(frame)); mpp->mFramePutCount++; + frames->signal(); frames->unlock(); } } diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 2d5cd7ef..a5cb0e98 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -168,20 +168,27 @@ MPP_RET Mpp::get_frame(MppFrame *frame) { Mutex::Autolock autoLock(mFrames->mutex()); MppFrame first = NULL; + + if (0 == mFrames->list_size()) { + mThreadCodec->signal(); + mFrames->wait(); + } + if (mFrames->list_size()) { mFrames->del_at_tail(&first, sizeof(frame)); mFrameGetCount++; + mThreadHal->signal(); MppFrame prev = first; MppFrame next = NULL; while (mFrames->list_size()) { mFrames->del_at_tail(&next, sizeof(frame)); mFrameGetCount++; + mThreadHal->signal(); mpp_frame_set_next(prev, next); prev = next; } } - mThreadHal->signal(); *frame = first; return MPP_OK; } diff --git a/test/mpi_test.c b/test/mpi_test.c index 0be3598b..d9201af6 100644 --- a/test/mpi_test.c +++ b/test/mpi_test.c @@ -82,6 +82,10 @@ int main() for (i = 0; i < MPI_DEC_LOOP_COUNT; i++) { mpp_packet_init(&dec_in, buf, size); + // IMPORTANT: eos flag will flush all decoded frame + if (i == MPI_DEC_LOOP_COUNT - 1) + mpp_packet_set_eos(dec_in); + // TODO: read stream data to buf ret = mpi->decode(ctx, dec_in, &dec_out); @@ -108,6 +112,10 @@ int main() for (i = 0; i < MPI_DEC_LOOP_COUNT; i++) { mpp_packet_init(&dec_in, buf, size); + // IMPORTANT: eos flag will flush all decoded frame + if (i == MPI_DEC_LOOP_COUNT - 1) + mpp_packet_set_eos(dec_in); + // TODO: read stream data to buf ret = mpi->decode_put_packet(ctx, dec_in);