From 3f1100ca08a48f3f3ba7ba319cf2afc8ecec7ba9 Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Wed, 9 Sep 2015 16:04:33 +0000 Subject: [PATCH] [mpp]: add frame signal chain to mpp parser/hal thread and get_frame interface git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@254 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/codec/mpp_dec.cpp | 1 + mpp/codec/mpp_enc.cpp | 1 + mpp/mpp.cpp | 9 ++++++++- test/mpi_test.c | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) 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);