diff --git a/inc/mpp_packet.h b/inc/mpp_packet.h index 4c814415..9f918502 100644 --- a/inc/mpp_packet.h +++ b/inc/mpp_packet.h @@ -29,7 +29,10 @@ extern "C" { /* * MppPacket interface */ -MPP_RET mpp_packet_init(MppPacket *packet, void *data, RK_U32 size); +MPP_RET mpp_packet_init(MppPacket *packet, void *data, size_t size); +MPP_RET mpp_packet_set_pts(MppPacket packet, RK_S64 pts); +MPP_RET mpp_packet_set_dts(MppPacket packet, RK_S64 dts); +MPP_RET mpp_packet_set_eos(MppPacket packet); MPP_RET mpp_packet_deinit(MppPacket *packet); #ifdef __cplusplus diff --git a/mpp/CMakeLists.txt b/mpp/CMakeLists.txt index be66bf73..ccbd6ecc 100644 --- a/mpp/CMakeLists.txt +++ b/mpp/CMakeLists.txt @@ -21,6 +21,7 @@ add_subdirectory(hal) # ---------------------------------------------------------------------------- add_library(mpp STATIC mpp_info.cpp + mpp_packet.cpp mpi_impl.cpp mpi.cpp ) diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp index 35e1b8cb..9ee20c39 100644 --- a/mpp/mpi.cpp +++ b/mpp/mpi.cpp @@ -186,7 +186,7 @@ MPP_RET mpp_deinit(MppCtx* ctx) mpp_free(p->api); if (p) mpp_free(p); - p = NULL; + *ctx = NULL; MPI_FUNCTION_LEAVE(); return MPP_OK; diff --git a/mpp/mpp_packet.cpp b/mpp/mpp_packet.cpp new file mode 100644 index 00000000..b69c79f5 --- /dev/null +++ b/mpp/mpp_packet.cpp @@ -0,0 +1,94 @@ +/* + * 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_packet" + +#include "mpp_log.h" +#include "mpp_mem.h" +#include "mpp_packet.h" +#include "mpp_packet_impl.h" + +MPP_RET mpp_packet_init(MppPacket *packet, void *data, size_t size) +{ + if (NULL == packet || NULL == data || 0 == size) { + mpp_err("mpp_packet_init invalid input packet %p data %p size %d\n", + packet, data, size); + return MPP_ERR_NULL_PTR; + } + + mpp_packet_impl *p = mpp_calloc(mpp_packet_impl, 1); + if (NULL == p) { + mpp_err("mpp_packet_init malloc failed\n"); + return MPP_ERR_NULL_PTR; + } + + p->data = data; + p->size = size; + + *packet = p; + + return MPP_OK; +} + +MPP_RET mpp_packet_set_pts(MppPacket packet, RK_S64 pts) +{ + if (NULL == packet) { + mpp_err("mpp_packet_set_pts invalid input %p\n", packet); + return MPP_ERR_NULL_PTR; + } + + mpp_packet_impl *p = (mpp_packet_impl *)packet; + p->pts = pts; + return MPP_OK; +} + +MPP_RET mpp_packet_set_dts(MppPacket packet, RK_S64 dts) +{ + if (NULL == packet) { + mpp_err("mpp_packet_set_pts invalid input %p\n", packet); + return MPP_ERR_NULL_PTR; + } + + mpp_packet_impl *p = (mpp_packet_impl *)packet; + p->dts = dts; + return MPP_OK; +} + +MPP_RET mpp_packet_set_eos(MppPacket packet) +{ + if (NULL == packet) { + mpp_err("mpp_packet_set_pts invalid input %p\n", packet); + return MPP_ERR_NULL_PTR; + } + + mpp_packet_impl *p = (mpp_packet_impl *)packet; + p->flag |= MPP_PACKET_FLAG_EOS; + return MPP_OK; +} + +MPP_RET mpp_packet_deinit(MppPacket *packet) +{ + if (NULL == packet) { + mpp_err("mpp_packet_deinit invalid input packet %p\n", packet); + return MPP_ERR_NULL_PTR; + } + + mpp_packet_impl *p = (mpp_packet_impl *)*packet; + mpp_free(p); + *packet = NULL; + return MPP_OK; +} + diff --git a/mpp/mpp_packet_impl.h b/mpp/mpp_packet_impl.h new file mode 100644 index 00000000..ade6575d --- /dev/null +++ b/mpp/mpp_packet_impl.h @@ -0,0 +1,46 @@ +/* + * 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_IMPL_H__ +#define __MPP_IMPL_H__ + +#include "rk_type.h" + +#define MPP_PACKET_FLAG_EOS (0x00000001) + +/* + * mpp_packet_imp structure + * + * data : pointer + * size : total buffer size + * offset : valid data start offset + * length : valid data length + * pts : packet pts + * dts : packet dts + */ +typedef struct { + void *data; + size_t size; + size_t offset; + size_t length; + + RK_S64 pts; + RK_S64 dts; + + RK_U32 flag; +} mpp_packet_impl; + +#endif /*__MPP_IMPL_H__*/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2efcaf6d..75e5d1b8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,5 +21,8 @@ endmacro() # legacy vpu_api unit test add_mpp_test(vpu_api) +# mpp_packet unit test +add_mpp_test(mpp_packet) + # mpi unit test add_mpp_test(mpi) diff --git a/test/mpp_packet_test.c b/test/mpp_packet_test.c new file mode 100644 index 00000000..0ac6002b --- /dev/null +++ b/test/mpp_packet_test.c @@ -0,0 +1,67 @@ +/* + * 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_packet_test" + +#include + +#include "mpp_log.h" +#include "mpp_packet.h" + +#define MPP_PACKET_TEST_SIZE 1024 + +int main() +{ + MPP_RET ret; + MppPacket packet = NULL; + void *data = NULL; + size_t size = MPP_PACKET_TEST_SIZE; + + mpp_log("mpp_packet_test start\n"); + + data = malloc(size); + if (NULL == data) { + mpp_err("mpp_packet_test malloc failed\n"); + goto MPP_PACKET_failed; + } + + ret = mpp_packet_init(&packet, data, size); + if (MPP_OK != ret) { + mpp_err("mpp_packet_test mpp_packet_init failed\n"); + goto MPP_PACKET_failed; + } + mpp_packet_set_eos(packet); + if (MPP_OK != ret) { + mpp_err("mpp_packet_test mpp_packet_set_eos failed\n"); + goto MPP_PACKET_failed; + } + mpp_packet_deinit(&packet); + + free(data); + mpp_log("mpp_packet_test success\n"); + return ret; + +MPP_PACKET_failed: + if (packet) + mpp_packet_deinit(&packet); + + if (data) + free(data); + + mpp_log("mpp_packet_test failed\n"); + return ret; +} +