[mpp_packet]: add mpp_packet functions

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@117 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-17 11:27:18 +00:00
parent c2544d0f9c
commit 01153f0f93
7 changed files with 216 additions and 2 deletions

View File

@@ -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

View File

@@ -21,6 +21,7 @@ add_subdirectory(hal)
# ----------------------------------------------------------------------------
add_library(mpp STATIC
mpp_info.cpp
mpp_packet.cpp
mpi_impl.cpp
mpi.cpp
)

View File

@@ -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;

94
mpp/mpp_packet.cpp Normal file
View File

@@ -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;
}

46
mpp/mpp_packet_impl.h Normal file
View File

@@ -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__*/

View File

@@ -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)

67
test/mpp_packet_test.c Normal file
View File

@@ -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 <stdlib.h>
#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;
}