diff --git a/mpp/CMakeLists.txt b/mpp/CMakeLists.txt index 4ee4a70d..d6eb9180 100644 --- a/mpp/CMakeLists.txt +++ b/mpp/CMakeLists.txt @@ -26,7 +26,6 @@ add_library(mpp STATIC mpp_buffer.cpp mpp_packet.cpp mpp_frame.cpp - mpp_dec.cpp mpp.cpp mpi_impl.cpp mpi.cpp @@ -36,4 +35,4 @@ add_subdirectory(legacy) add_subdirectory(test) -target_link_libraries(mpp mpp_legacy osal) +target_link_libraries(mpp mpp_hal mpp_codec mpp_legacy osal) diff --git a/mpp/codec/CMakeLists.txt b/mpp/codec/CMakeLists.txt index c19afae4..1255e2a4 100644 --- a/mpp/codec/CMakeLists.txt +++ b/mpp/codec/CMakeLists.txt @@ -1,5 +1,13 @@ # vim: syntax=cmake +# ---------------------------------------------------------------------------- +# add mpp_dec implement +# ---------------------------------------------------------------------------- +add_library(mpp_codec STATIC + mpp_enc.cpp + mpp_dec.cpp + ) + add_subdirectory(dec) add_subdirectory(enc) diff --git a/mpp/mpp_dec.h b/mpp/codec/inc/mpp_dec.h similarity index 88% rename from mpp/mpp_dec.h rename to mpp/codec/inc/mpp_dec.h index bc97b973..bff9e575 100644 --- a/mpp/mpp_dec.h +++ b/mpp/codec/inc/mpp_dec.h @@ -24,7 +24,7 @@ extern "C" { #endif /* - * main thread for all decoder. This thread will connet parser / hal / mpp + * main thread for all decoder. This thread will connect parser / hal / mpp */ void *mpp_dec_thread(void *data); diff --git a/mpp/codec/inc/mpp_enc.h b/mpp/codec/inc/mpp_enc.h new file mode 100644 index 00000000..09369d3f --- /dev/null +++ b/mpp/codec/inc/mpp_enc.h @@ -0,0 +1,35 @@ +/* + * Copyright 2010 Rockchip Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MPP_ENC_H__ +#define __MPP_ENC_H__ + +#include "rk_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * main thread for all encoder. This thread will connect encoder / hal / mpp + */ +void *mpp_enc_thread(void *data); + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_ENC_H__*/ diff --git a/mpp/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp similarity index 94% rename from mpp/mpp_dec.cpp rename to mpp/codec/mpp_dec.cpp index 505d422a..df292e3b 100644 --- a/mpp/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -17,11 +17,10 @@ #define MODULE_TAG "mpp_dec" #include "mpp_log.h" -#include "mpp_time.h" #include "mpp.h" #include "mpp_dec.h" -#include "mpp_frame_impl.h" +//#include "mpp_frame_impl.h" #include "mpp_packet.h" #include "mpp_packet_impl.h" @@ -33,7 +32,6 @@ void *mpp_dec_thread(void *data) MppThread *dec = mpp->mTheadCodec; MppThread *hal = mpp->mThreadHal; mpp_list *packets = mpp->mPackets; - mpp_list *frames = mpp->mFrames; MppPacketImpl packet; while (MPP_THREAD_RUNNING == dec->get_status()) { diff --git a/mpp/codec/mpp_enc.cpp b/mpp/codec/mpp_enc.cpp new file mode 100644 index 00000000..688d35c6 --- /dev/null +++ b/mpp/codec/mpp_enc.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2010 Rockchip Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODULE_TAG "mpp_enc" + +#include "mpp_log.h" +#include "mpp_mem.h" + +#include "mpp.h" +#include "mpp_enc.h" +#include "mpp_frame_impl.h" +#include "mpp_packet.h" +#include "mpp_packet_impl.h" + +void *mpp_enc_thread(void *data) +{ + Mpp *mpp = (Mpp*)data; + MppThread *thd_enc = mpp->mTheadCodec; + mpp_list *packets = mpp->mPackets; + mpp_list *frames = mpp->mFrames; + MppFrameImpl frame; + MppPacket packet; + size_t size = SZ_1M; + char *buf = mpp_malloc(char, size); + + while (MPP_THREAD_RUNNING == thd_enc->get_status()) { + if (frames->list_size()) { + frames->del_at_head(&frame, sizeof(frame)); + + mpp_packet_init(&packet, buf, size); + packets->add_at_tail(&packet, sizeof(packet)); + } + } + mpp_free(buf); + return NULL; +} + diff --git a/mpp/hal/CMakeLists.txt b/mpp/hal/CMakeLists.txt index 3b2b7855..9ec0bd91 100644 --- a/mpp/hal/CMakeLists.txt +++ b/mpp/hal/CMakeLists.txt @@ -1,4 +1,11 @@ # vim: syntax=cmake +# ---------------------------------------------------------------------------- +# add mpp_hal implement +# ---------------------------------------------------------------------------- +add_library(mpp_hal STATIC + mpp_hal.cpp + ) + add_subdirectory(rkdec/h264d) add_subdirectory(rkdec/h265d) diff --git a/mpp/hal/inc/mpp_hal.h b/mpp/hal/inc/mpp_hal.h index eb0ada6e..31a4a5d3 100644 --- a/mpp/hal/inc/mpp_hal.h +++ b/mpp/hal/inc/mpp_hal.h @@ -66,9 +66,19 @@ typedef struct { void *pointers[1]; } MppHalDecTask; +#ifdef __cplusplus +extern "C" { +#endif + void HalTaskSetDstBuffer(); void HalTaskSetDpb(); void HalTaskSetDXVA(); +void *mpp_hal_thread(void *data); + +#ifdef __cplusplus +} +#endif + #endif /*__HAL_TASK__*/ diff --git a/mpp/hal/mpp_hal.cpp b/mpp/hal/mpp_hal.cpp new file mode 100644 index 00000000..301d7f7c --- /dev/null +++ b/mpp/hal/mpp_hal.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2010 Rockchip Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODULE_TAG "mpp_hal" + +#include "mpp_log.h" + +#include "mpp.h" +#include "mpp_hal.h" +#include "mpp_frame_impl.h" + +#define MPP_TEST_FRAME_SIZE SZ_1M + +void *mpp_hal_thread(void *data) +{ + Mpp *mpp = (Mpp*)data; + MppThread *hal = mpp->mThreadHal; + mpp_list *frames = mpp->mFrames; + mpp_list *tasks = mpp->mTasks; + + while (MPP_THREAD_RUNNING == hal->get_status()) { + /* + * hal thread wait for dxva interface intput firt + */ + hal->lock(); + if (0 == tasks->list_size()) + hal->wait(); + hal->unlock(); + + // get_config + // register genertation + if (tasks->list_size()) { + MppHalDecTask *task; + mpp->mTasks->del_at_head(&task, sizeof(task)); + mpp->mTaskGetCount++; + + /* + * wait previous register set done + */ + // hal->get_regs; + + /* + * send current register set to hardware + */ + // hal->put_regs; + + /* + * mark previous buffer is complete + */ + // signal() + // mark frame in output queue + // wait up output thread to get a output frame + + // for test + MppBuffer buffer; + mpp_buffer_get(mpp->mFrameGroup, &buffer, MPP_TEST_FRAME_SIZE); + + MppFrame frame; + mpp_frame_init(&frame); + mpp_frame_set_buffer(frame, buffer); + frames->add_at_tail(&frame, sizeof(frame)); + mpp->mFramePutCount++; + } + } + + return NULL; +} + diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 3a287678..82100bc4 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -22,92 +22,14 @@ #include "mpp.h" #include "mpp_dec.h" +#include "mpp_enc.h" +#include "mpp_hal.h" #include "mpp_frame_impl.h" #include "mpp_packet.h" #include "mpp_packet_impl.h" #define MPP_TEST_FRAME_SIZE SZ_1M -void *thread_hal(void *data) -{ - Mpp *mpp = (Mpp*)data; - MppThread *codec = mpp->mTheadCodec; - MppThread *hal = mpp->mThreadHal; - mpp_list *frames = mpp->mFrames; - mpp_list *tasks = mpp->mTasks; - - while (MPP_THREAD_RUNNING == hal->get_status()) { - /* - * hal thread wait for dxva interface intput firt - */ - hal->lock(); - if (0 == tasks->list_size()) - hal->wait(); - hal->unlock(); - - // get_config - // register genertation - if (tasks->list_size()) { - MppHalDecTask *task; - mpp->mTasks->del_at_head(&task, sizeof(task)); - mpp->mTaskGetCount++; - - /* - * wait previous register set done - */ - // hal->get_regs; - - /* - * send current register set to hardware - */ - // hal->put_regs; - - /* - * mark previous buffer is complete - */ - // signal() - // mark frame in output queue - // wait up output thread to get a output frame - - // for test - MppBuffer buffer; - mpp_buffer_get(mpp->mFrameGroup, &buffer, MPP_TEST_FRAME_SIZE); - - MppFrame frame; - mpp_frame_init(&frame); - mpp_frame_set_buffer(frame, buffer); - frames->add_at_tail(&frame, sizeof(frame)); - mpp->mFramePutCount++; - } - } - - return NULL; -} - -static void *thread_enc(void *data) -{ - Mpp *mpp = (Mpp*)data; - MppThread *thd_enc = mpp->mTheadCodec; - MppThread *thd_hal = mpp->mThreadHal; - mpp_list *packets = mpp->mPackets; - mpp_list *frames = mpp->mFrames; - MppFrameImpl frame; - MppPacket packet; - size_t size = SZ_1M; - char *buf = mpp_malloc(char, size); - - while (MPP_THREAD_RUNNING == thd_enc->get_status()) { - if (frames->list_size()) { - frames->del_at_head(&frame, sizeof(frame)); - - mpp_packet_init(&packet, buf, size); - packets->add_at_tail(&packet, sizeof(packet)); - } - } - mpp_free(buf); - return NULL; -} - Mpp::Mpp(MppCtxType type, MppCodingType coding) : mPackets(NULL), mFrames(NULL), @@ -134,7 +56,7 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding) mFrames = new mpp_list((node_destructor)mpp_frame_deinit); mTasks = new mpp_list((node_destructor)NULL); mTheadCodec = new MppThread(mpp_dec_thread, this); - mThreadHal = new MppThread(thread_hal, this); + mThreadHal = new MppThread(mpp_hal_thread, this); mTask = mpp_malloc(MppHalDecTask*, mTaskNum); mpp_buffer_group_normal_get(&mPacketGroup, MPP_BUFFER_TYPE_NORMAL); mpp_buffer_group_limited_get(&mFrameGroup, MPP_BUFFER_TYPE_ION); @@ -144,8 +66,8 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding) mFrames = new mpp_list((node_destructor)NULL); mPackets = new mpp_list((node_destructor)mpp_packet_deinit); mTasks = new mpp_list((node_destructor)NULL); - mTheadCodec = new MppThread(thread_enc, this); - mThreadHal = new MppThread(thread_hal, this); + mTheadCodec = new MppThread(mpp_enc_thread, this); + mThreadHal = new MppThread(mpp_hal_thread, this); mTask = mpp_malloc(MppHalDecTask*, mTaskNum); mpp_buffer_group_normal_get(&mPacketGroup, MPP_BUFFER_TYPE_NORMAL); mpp_buffer_group_limited_get(&mFrameGroup, MPP_BUFFER_TYPE_ION);