mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
[mpg4d]: commit empty mpeg4 parser/hal with correct split function
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@940 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -20,7 +20,8 @@ target_link_libraries(mpp_codec
|
|||||||
codec_vp9d
|
codec_vp9d
|
||||||
codec_h265d
|
codec_h265d
|
||||||
codec_avsd
|
codec_avsd
|
||||||
codec_m2vd
|
codec_m2vd
|
||||||
|
codec_mpg4d
|
||||||
codec_dummy_enc
|
codec_dummy_enc
|
||||||
codec_dummy_dec
|
codec_dummy_dec
|
||||||
mpp_base)
|
mpp_base)
|
||||||
|
@@ -12,3 +12,4 @@ add_subdirectory(avs)
|
|||||||
|
|
||||||
add_subdirectory(m2v)
|
add_subdirectory(m2v)
|
||||||
|
|
||||||
|
add_subdirectory(mpg4)
|
||||||
|
16
mpp/codec/dec/mpg4/CMakeLists.txt
Normal file
16
mpp/codec/dec/mpg4/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# vim: syntax=cmake
|
||||||
|
set(MPG4D_PARSER_HDR
|
||||||
|
mpg4d_parser.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(MPG4D_PARSER_SRC
|
||||||
|
mpg4d_api.c
|
||||||
|
mpg4d_parser.c
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(codec_mpg4d STATIC
|
||||||
|
${MPG4D_PARSER_SRC} ${MPG4D_PARSER_HDR}
|
||||||
|
)
|
||||||
|
set_target_properties(codec_mpg4d PROPERTIES FOLDER "mpp/codec")
|
||||||
|
|
||||||
|
target_link_libraries(codec_mpg4d mpp_base)
|
308
mpp/codec/dec/mpg4/mpg4d_api.c
Normal file
308
mpp/codec/dec/mpg4/mpg4d_api.c
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015 Rockchip Electronics 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 "mpg4d_api"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_mem.h"
|
||||||
|
#include "mpp_common.h"
|
||||||
|
#include "mpp_packet.h"
|
||||||
|
|
||||||
|
#include "mpg4d_api.h"
|
||||||
|
#include "mpg4d_parser.h"
|
||||||
|
|
||||||
|
#define MPG4D_INIT_STREAM_SIZE SZ_64K
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// parameter interact with mpp_dec
|
||||||
|
MppBufSlots frame_slots;
|
||||||
|
MppBufSlots packet_slots;
|
||||||
|
RK_S32 task_count;
|
||||||
|
RK_U8 *stream;
|
||||||
|
size_t stream_size;
|
||||||
|
MppPacket task_pkt;
|
||||||
|
RK_S64 task_pts;
|
||||||
|
RK_U32 task_eos;
|
||||||
|
|
||||||
|
// runtime parameter
|
||||||
|
RK_U32 need_split;
|
||||||
|
RK_U32 frame_count;
|
||||||
|
IOInterruptCB notify_cb;
|
||||||
|
|
||||||
|
// parser context
|
||||||
|
Mpg4dParser parser;
|
||||||
|
} Mpg4dCtx;
|
||||||
|
|
||||||
|
MPP_RET mpg4d_init(void *dec, ParserCfg *cfg)
|
||||||
|
{
|
||||||
|
Mpg4dParser parser = NULL;
|
||||||
|
MppPacket task_pkt = NULL;
|
||||||
|
Mpg4dCtx *p;
|
||||||
|
MPP_RET ret;
|
||||||
|
RK_U8 *stream;
|
||||||
|
size_t stream_size = MPG4D_INIT_STREAM_SIZE;
|
||||||
|
|
||||||
|
if (NULL == dec) {
|
||||||
|
mpp_err_f("found NULL intput dec %p cfg %p\n", dec, cfg);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream = mpp_malloc_size(RK_U8, stream_size);
|
||||||
|
if (NULL == stream) {
|
||||||
|
mpp_err_f("failed to malloc stream buffer size %d\n", stream_size);
|
||||||
|
return MPP_ERR_MALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mpp_packet_init(&task_pkt, stream, stream_size);
|
||||||
|
if (ret) {
|
||||||
|
mpp_err_f("failed to create mpp_packet for task\n");
|
||||||
|
goto ERR_RET;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset task packet length to zero
|
||||||
|
// NOTE: set length must after set pos
|
||||||
|
mpp_packet_set_pos(task_pkt, stream);
|
||||||
|
mpp_packet_set_length(task_pkt, 0);
|
||||||
|
|
||||||
|
ret = mpp_mpg4_parser_init(&parser, cfg->frame_slots);
|
||||||
|
if (ret) {
|
||||||
|
mpp_err_f("failed to init parser\n");
|
||||||
|
goto ERR_RET;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = (Mpg4dCtx *)dec;
|
||||||
|
p->frame_slots = cfg->frame_slots;
|
||||||
|
p->packet_slots = cfg->packet_slots;
|
||||||
|
p->need_split = cfg->need_split;
|
||||||
|
p->task_count = cfg->task_count = 2;
|
||||||
|
p->notify_cb = cfg->notify_cb;
|
||||||
|
p->stream = stream;
|
||||||
|
p->stream_size = stream_size;
|
||||||
|
p->task_pkt = task_pkt;
|
||||||
|
p->parser = parser;
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
ERR_RET:
|
||||||
|
if (task_pkt) {
|
||||||
|
mpp_packet_deinit(&task_pkt);
|
||||||
|
}
|
||||||
|
if (stream) {
|
||||||
|
mpp_free(stream);
|
||||||
|
stream = NULL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpg4d_deinit(void *dec)
|
||||||
|
{
|
||||||
|
Mpg4dCtx *p;
|
||||||
|
if (NULL == dec) {
|
||||||
|
mpp_err_f("found NULL intput\n");
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = (Mpg4dCtx *)dec;
|
||||||
|
if (p->parser) {
|
||||||
|
mpp_mpg4_parser_deinit(p->parser);
|
||||||
|
p->parser = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->task_pkt) {
|
||||||
|
mpp_packet_deinit(&p->task_pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->stream) {
|
||||||
|
mpp_free(p->stream);
|
||||||
|
p->stream = NULL;
|
||||||
|
}
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpg4d_reset(void *dec)
|
||||||
|
{
|
||||||
|
if (NULL == dec) {
|
||||||
|
mpp_err_f("found NULL intput\n");
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MPP_RET mpg4d_flush(void *dec)
|
||||||
|
{
|
||||||
|
if (NULL == dec) {
|
||||||
|
mpp_err_f("found NULL intput\n");
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MPP_RET mpg4d_control(void *dec, RK_S32 cmd_type, void *param)
|
||||||
|
{
|
||||||
|
if (NULL == dec) {
|
||||||
|
mpp_err_f("found NULL intput\n");
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
(void)cmd_type;
|
||||||
|
(void)param;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpg4d_prepare(void *dec, MppPacket pkt, HalDecTask *task)
|
||||||
|
{
|
||||||
|
Mpg4dCtx *p;
|
||||||
|
RK_U8 *pos;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
if (NULL == dec || NULL == pkt || NULL == task) {
|
||||||
|
mpp_err_f("found NULL intput dec %p pkt %p task %p\n", dec, pkt, task);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = (Mpg4dCtx *)dec;
|
||||||
|
pos = mpp_packet_get_pos(pkt);
|
||||||
|
length = mpp_packet_get_length(pkt);
|
||||||
|
|
||||||
|
if (NULL == p->stream) {
|
||||||
|
mpp_err("failed to malloc task buffer for hardware with size %d\n", length);
|
||||||
|
return MPP_ERR_UNKNOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p->need_split) {
|
||||||
|
/*
|
||||||
|
* Copy packet mode:
|
||||||
|
* Decoder's user will insure each packet is one frame for process
|
||||||
|
* Parser will just copy packet to the beginning of stream buffer
|
||||||
|
*/
|
||||||
|
if (length > p->stream_size) {
|
||||||
|
// NOTE: here we double the buffer length to reduce frequency of realloc
|
||||||
|
do {
|
||||||
|
p->stream_size <<= 1;
|
||||||
|
} while (length > p->stream_size);
|
||||||
|
|
||||||
|
mpp_free(p->stream);
|
||||||
|
p->stream = mpp_malloc_size(RK_U8, p->stream_size);
|
||||||
|
mpp_assert(p->stream);
|
||||||
|
mpp_packet_set_data(p->task_pkt, p->stream);
|
||||||
|
mpp_packet_set_size(p->task_pkt, p->stream_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(p->stream, pos, length);
|
||||||
|
mpp_packet_set_pos(p->task_pkt, p->stream);
|
||||||
|
mpp_packet_set_length(p->task_pkt, length);
|
||||||
|
// set input packet length to 0 here
|
||||||
|
// indicate that the input packet has been all consumed
|
||||||
|
mpp_packet_set_pos(pkt, pos + length);
|
||||||
|
// always use latest pts for current packet
|
||||||
|
p->task_pts = mpp_packet_get_pts(pkt);
|
||||||
|
p->task_eos = mpp_packet_get_eos(pkt);
|
||||||
|
/* this step will enable the task and goto parse stage */
|
||||||
|
task->valid = 1;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Split packet mode:
|
||||||
|
* Input packet can be any length and no need to be bound of on frame
|
||||||
|
* Parser will do split frame operation to find the beginning and end of one frame
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* NOTE: on split mode total length is the left size plus the new incoming
|
||||||
|
* packet length.
|
||||||
|
*/
|
||||||
|
size_t remain_length = mpp_packet_get_length(p->task_pkt);
|
||||||
|
size_t total_length = remain_length + length;
|
||||||
|
if (total_length > p->stream_size) {
|
||||||
|
RK_U8 *dst;
|
||||||
|
do {
|
||||||
|
p->stream_size <<= 1;
|
||||||
|
} while (length > p->stream_size);
|
||||||
|
|
||||||
|
// NOTE; split mode need to copy remaining stream to new buffer
|
||||||
|
dst = mpp_malloc_size(RK_U8, p->stream_size);
|
||||||
|
mpp_assert(dst);
|
||||||
|
|
||||||
|
memcpy(dst, p->stream, remain_length);
|
||||||
|
mpp_free(p->stream);
|
||||||
|
p->stream = dst;
|
||||||
|
mpp_packet_set_data(p->task_pkt, p->stream);
|
||||||
|
mpp_packet_set_size(p->task_pkt, p->stream_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// start parser split
|
||||||
|
if (MPP_OK == mpp_mpg4_parser_split(p->parser, p->task_pkt, pkt)) {
|
||||||
|
task->valid = 1;
|
||||||
|
}
|
||||||
|
p->task_pts = mpp_packet_get_pts(p->task_pkt);
|
||||||
|
p->task_eos = mpp_packet_get_eos(p->task_pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
task->input_packet = p->task_pkt;
|
||||||
|
task->flags.eos = p->task_eos;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpg4d_parse(void *dec, HalDecTask *task)
|
||||||
|
{
|
||||||
|
MPP_RET ret;
|
||||||
|
Mpg4dCtx *p;
|
||||||
|
|
||||||
|
if (NULL == dec || NULL == task) {
|
||||||
|
mpp_err_f("found NULL intput dec %p task %p\n", dec, task);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
|
}
|
||||||
|
p = (Mpg4dCtx *)dec;
|
||||||
|
ret = mpp_mpg4_parser_decode(p->parser, task->input_packet);
|
||||||
|
if (ret) {
|
||||||
|
// found error on decoding drop this task and clear remaining length
|
||||||
|
task->output = -1;
|
||||||
|
mpp_packet_set_length(&task->input_packet, 0);
|
||||||
|
return MPP_NOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpp_mpg4_parser_setup_syntax(p->parser, task->syntax);
|
||||||
|
mpp_mpg4_parser_setup_output(p->parser, &task->output);
|
||||||
|
mpp_mpg4_parser_setup_refer(p->parser, task->refer, MAX_DEC_REF_NUM);
|
||||||
|
mpp_mpg4_parser_setup_display(p->parser);
|
||||||
|
|
||||||
|
p->frame_count++;
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpg4d_callback(void *dec, void *err_info)
|
||||||
|
{
|
||||||
|
(void)dec;
|
||||||
|
(void)err_info;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
const ParserApi api_mpg4d_parser = {
|
||||||
|
"api_mpg4d_parser",
|
||||||
|
MPP_VIDEO_CodingMPEG4,
|
||||||
|
sizeof(Mpg4dCtx),
|
||||||
|
0,
|
||||||
|
mpg4d_init,
|
||||||
|
mpg4d_deinit,
|
||||||
|
mpg4d_prepare,
|
||||||
|
mpg4d_parse,
|
||||||
|
mpg4d_reset,
|
||||||
|
mpg4d_flush,
|
||||||
|
mpg4d_control,
|
||||||
|
mpg4d_callback,
|
||||||
|
};
|
||||||
|
|
231
mpp/codec/dec/mpg4/mpg4d_parser.c
Normal file
231
mpp/codec/dec/mpg4/mpg4d_parser.c
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2010 Rockchip Electronics 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @file api_mpg4d_parser.c
|
||||||
|
* @brief
|
||||||
|
* @author gzl(lance.gao@rock-chips.com)
|
||||||
|
* @version 1.0.0
|
||||||
|
* @history
|
||||||
|
* 2015.7.15 : Create
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_mem.h"
|
||||||
|
#include "mpp_common.h"
|
||||||
|
#include "mpp_packet.h"
|
||||||
|
|
||||||
|
#include "mpg4d_parser.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MppBufSlots frame_slots;
|
||||||
|
RK_S32 output;
|
||||||
|
RK_U32 width;
|
||||||
|
RK_U32 height;
|
||||||
|
RK_S64 pts;
|
||||||
|
RK_U32 eos;
|
||||||
|
|
||||||
|
// spliter parameter
|
||||||
|
RK_S32 pos_frm_start; // negtive - not found; non-negtive - position of frame start
|
||||||
|
RK_S32 pos_frm_end; // negtive - not found; non-negtive - position of frame end
|
||||||
|
} Mpg4dParserImpl;
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_init(Mpg4dParser *ctx, MppBufSlots frame_slots)
|
||||||
|
{
|
||||||
|
Mpg4dParserImpl *p = mpp_calloc(Mpg4dParserImpl, 1);
|
||||||
|
if (NULL == p) {
|
||||||
|
mpp_err_f("malloc context failed\n");
|
||||||
|
return MPP_NOK;
|
||||||
|
}
|
||||||
|
mpp_buf_slot_setup(frame_slots, 8);
|
||||||
|
p->frame_slots = frame_slots;
|
||||||
|
p->pos_frm_start = -1;
|
||||||
|
p->pos_frm_end = -1;
|
||||||
|
*ctx = p;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_deinit(Mpg4dParser ctx)
|
||||||
|
{
|
||||||
|
Mpg4dParserImpl *p = (Mpg4dParserImpl *)ctx;
|
||||||
|
mpp_free(p);
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_flush(Mpg4dParser ctx)
|
||||||
|
{
|
||||||
|
(void)ctx;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_reset(Mpg4dParser ctx)
|
||||||
|
{
|
||||||
|
(void)ctx;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_split(Mpg4dParser ctx, MppPacket dst, MppPacket src)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_NOK;
|
||||||
|
Mpg4dParserImpl *p = (Mpg4dParserImpl *)ctx;
|
||||||
|
RK_U8 *dst_buf = mpp_packet_get_data(dst);
|
||||||
|
size_t dst_len = mpp_packet_get_length(dst);
|
||||||
|
RK_U8 *src_buf = mpp_packet_get_pos(src);
|
||||||
|
size_t src_len = mpp_packet_get_length(src);
|
||||||
|
RK_S32 pos_frm_start = p->pos_frm_start;
|
||||||
|
RK_S32 pos_frm_end = p->pos_frm_end;
|
||||||
|
size_t src_pos = 0;
|
||||||
|
RK_U32 state = 0;
|
||||||
|
|
||||||
|
mpp_assert(src_len);
|
||||||
|
|
||||||
|
if (pos_frm_start < 0) {
|
||||||
|
// scan for frame start
|
||||||
|
for (src_pos = 0; src_pos < src_len; src_pos++) {
|
||||||
|
state = (state << 8) | src_buf[src_pos];
|
||||||
|
if (state == 0x1B6) {
|
||||||
|
src_pos++;
|
||||||
|
pos_frm_start = src_pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos_frm_start) {
|
||||||
|
// scan for frame end
|
||||||
|
for (; src_pos < src_len; src_pos++) {
|
||||||
|
state = (state << 8) | src_buf[src_pos];
|
||||||
|
if ((state & 0xFFFFFF00) == 0x100) {
|
||||||
|
pos_frm_end = src_pos - 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos_frm_start < 0 || pos_frm_end < 0) {
|
||||||
|
// do not found frame start or do not found frame end, just copy the hold buffer to dst
|
||||||
|
memcpy(dst_buf + dst_len, src_buf, src_len);
|
||||||
|
// update dst buffer length
|
||||||
|
mpp_packet_set_length(dst, dst_len + src_len);
|
||||||
|
// set src buffer pos to end to src buffer
|
||||||
|
mpp_packet_set_pos(src, src_buf + src_len);
|
||||||
|
} else {
|
||||||
|
// found both frame start and frame end - only copy frame
|
||||||
|
memcpy(dst_buf + dst_len, src_buf, pos_frm_end);
|
||||||
|
mpp_packet_set_length(dst, dst_len + pos_frm_end);
|
||||||
|
// set src buffer pos to end to src buffer
|
||||||
|
mpp_packet_set_pos(src, src_buf + pos_frm_end);
|
||||||
|
// return ok indicate the frame is ready and reset frame start/end position
|
||||||
|
ret = MPP_OK;
|
||||||
|
pos_frm_start = -1;
|
||||||
|
pos_frm_end = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->pos_frm_start = pos_frm_start;
|
||||||
|
p->pos_frm_end = pos_frm_end;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_decode(Mpg4dParser ctx, MppPacket pkt)
|
||||||
|
{
|
||||||
|
Mpg4dParserImpl *p = (Mpg4dParserImpl *)ctx;
|
||||||
|
RK_U8 *buf = mpp_packet_get_data(pkt);
|
||||||
|
|
||||||
|
p->width = 1920;
|
||||||
|
p->height = 1080;
|
||||||
|
|
||||||
|
mpp_packet_set_pos(pkt, buf);
|
||||||
|
mpp_packet_set_length(pkt, 0);
|
||||||
|
|
||||||
|
p->pts = mpp_packet_get_pts(pkt);
|
||||||
|
p->eos = mpp_packet_get_eos(pkt);
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_syntax(Mpg4dParser ctx, MppSyntax syntax)
|
||||||
|
{
|
||||||
|
(void) ctx;
|
||||||
|
(void) syntax;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_output(Mpg4dParser ctx, RK_S32 *output)
|
||||||
|
{
|
||||||
|
Mpg4dParserImpl *p = (Mpg4dParserImpl *)ctx;
|
||||||
|
MppBufSlots slots = p->frame_slots;
|
||||||
|
MppFrame frame = NULL;
|
||||||
|
RK_S32 index = -1;
|
||||||
|
|
||||||
|
mpp_frame_init(&frame);
|
||||||
|
mpp_frame_set_width(frame, p->width);
|
||||||
|
mpp_frame_set_height(frame, p->height);
|
||||||
|
mpp_frame_set_hor_stride(frame, MPP_ALIGN(p->width, 16));
|
||||||
|
mpp_frame_set_ver_stride(frame, MPP_ALIGN(p->height, 16));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set slots information
|
||||||
|
* 1. output index MUST be set
|
||||||
|
* 2. get unused index for output if needed
|
||||||
|
* 3. set output index as hal_input
|
||||||
|
* 4. set frame information to output index
|
||||||
|
* 5. if one frame can be display, it SHOULD be enqueued to display queue
|
||||||
|
*/
|
||||||
|
mpp_buf_slot_get_unused(slots, &index);
|
||||||
|
mpp_buf_slot_set_flag(slots, index, SLOT_HAL_OUTPUT);
|
||||||
|
mpp_frame_set_pts(frame, p->pts);
|
||||||
|
mpp_frame_set_eos(frame, p->eos);
|
||||||
|
mpp_buf_slot_set_prop(slots, index, SLOT_FRAME, frame);
|
||||||
|
mpp_frame_deinit(&frame);
|
||||||
|
mpp_assert(NULL == frame);
|
||||||
|
p->output = index;
|
||||||
|
*output = index;
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_refer(Mpg4dParser ctx, RK_S32 *refer, RK_S32 max_ref)
|
||||||
|
{
|
||||||
|
(void) ctx;
|
||||||
|
/*
|
||||||
|
* setup output task
|
||||||
|
* 1. valid flag MUST be set if need hardware to run once
|
||||||
|
* 2. set output slot index
|
||||||
|
* 3. set reference slot index
|
||||||
|
*/
|
||||||
|
memset(refer, -1, sizeof(max_ref * sizeof(*refer)));
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_display(Mpg4dParser ctx)
|
||||||
|
{
|
||||||
|
Mpg4dParserImpl *p = (Mpg4dParserImpl *)ctx;
|
||||||
|
MppBufSlots slots = p->frame_slots;
|
||||||
|
RK_S32 output = p->output;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update dpb status assuming that hw has decoded the frame
|
||||||
|
*/
|
||||||
|
mpp_buf_slot_set_flag(slots, output, SLOT_QUEUE_USE);
|
||||||
|
mpp_buf_slot_enqueue(slots, output, QUEUE_DISPLAY);
|
||||||
|
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
57
mpp/codec/dec/mpg4/mpg4d_parser.h
Normal file
57
mpp/codec/dec/mpg4/mpg4d_parser.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2010 Rockchip Electronics 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 __MPG4D_PARSER_H__
|
||||||
|
#define __MPG4D_PARSER_H__
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_packet.h"
|
||||||
|
#include "mpp_buf_slot.h"
|
||||||
|
#include "hal_task.h"
|
||||||
|
|
||||||
|
extern RK_U32 mpg4d_debug;
|
||||||
|
#define MPG4D_DBG_FUNCTION (0x00000001)
|
||||||
|
#define MPG4D_DBG_PPS (0x00000008)
|
||||||
|
#define MPG4D_DBG_SLICE_HDR (0x00000010)
|
||||||
|
#define MPG4D_DBG_REF (0x00000080)
|
||||||
|
#define MPG4D_DBG_TIME (0x00000100)
|
||||||
|
|
||||||
|
#define mpg4d_dbg(flag, fmt, ...) _mpp_dbg(mpg4d_debug, flag, fmt, ## __VA_ARGS__)
|
||||||
|
|
||||||
|
typedef void* Mpg4dParser;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_init(Mpg4dParser *ctx, MppBufSlots frame_slots);
|
||||||
|
MPP_RET mpp_mpg4_parser_deinit(Mpg4dParser ctx);
|
||||||
|
MPP_RET mpp_mpg4_parser_flush(Mpg4dParser ctx);
|
||||||
|
MPP_RET mpp_mpg4_parser_reset(Mpg4dParser ctx);
|
||||||
|
|
||||||
|
MPP_RET mpp_mpg4_parser_split(Mpg4dParser ctx, MppPacket dst, MppPacket src);
|
||||||
|
MPP_RET mpp_mpg4_parser_decode(Mpg4dParser ctx, MppPacket pkt);
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_syntax(Mpg4dParser ctx, MppSyntax syntax);
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_output(Mpg4dParser ctx, RK_S32 *output);
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_refer(Mpg4dParser ctx, RK_S32 *refer, RK_S32 max_ref);
|
||||||
|
MPP_RET mpp_mpg4_parser_setup_display(Mpg4dParser ctx);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif/* __MPG4D_PAESER_H__ */
|
@@ -29,6 +29,7 @@
|
|||||||
#include "vp9d_api.h"
|
#include "vp9d_api.h"
|
||||||
#include "avsd_api.h"
|
#include "avsd_api.h"
|
||||||
#include "m2vd_api.h"
|
#include "m2vd_api.h"
|
||||||
|
#include "mpg4d_api.h"
|
||||||
|
|
||||||
// for test and demo
|
// for test and demo
|
||||||
#include "dummy_dec_api.h"
|
#include "dummy_dec_api.h"
|
||||||
@@ -42,6 +43,7 @@ static const ParserApi *parsers[] = {
|
|||||||
&api_h265d_parser,
|
&api_h265d_parser,
|
||||||
&api_avsd_parser,
|
&api_avsd_parser,
|
||||||
&api_m2vd_parser,
|
&api_m2vd_parser,
|
||||||
|
&api_mpg4d_parser,
|
||||||
&dummy_dec_parser,
|
&dummy_dec_parser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -23,6 +23,9 @@ add_subdirectory(rkdec/vp9d)
|
|||||||
add_subdirectory(rkdec/avsd)
|
add_subdirectory(rkdec/avsd)
|
||||||
|
|
||||||
add_subdirectory(vpu/m2vd)
|
add_subdirectory(vpu/m2vd)
|
||||||
|
|
||||||
|
add_subdirectory(vpu/mpg4d)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# add hardware worker implement
|
# add hardware worker implement
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
@@ -30,7 +33,17 @@ add_subdirectory(worker/libvpu)
|
|||||||
add_subdirectory(worker/libv4l2)
|
add_subdirectory(worker/libv4l2)
|
||||||
|
|
||||||
if(RKPLATFORM)
|
if(RKPLATFORM)
|
||||||
target_link_libraries(mpp_hal hal_h264d hal_h265d hal_vp9d vpu hal_avsd hal_m2vd hal_dummy)
|
set(RKPLAT_VPU vpu)
|
||||||
else()
|
endif(RKPLATFORM)
|
||||||
target_link_libraries(mpp_hal hal_h264d hal_h265d hal_vp9d hal_avsd hal_m2vd hal_dummy)
|
|
||||||
endif()
|
|
||||||
|
target_link_libraries(mpp_hal
|
||||||
|
hal_h264d
|
||||||
|
hal_h265d
|
||||||
|
hal_vp9d
|
||||||
|
hal_avsd
|
||||||
|
hal_m2vd
|
||||||
|
hal_mpg4d
|
||||||
|
hal_dummy
|
||||||
|
${RKPLAT_VPU}
|
||||||
|
)
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "hal_vp9d_api.h"
|
#include "hal_vp9d_api.h"
|
||||||
#include "hal_avsd_api.h"
|
#include "hal_avsd_api.h"
|
||||||
#include "hal_m2vd_api.h"
|
#include "hal_m2vd_api.h"
|
||||||
|
#include "hal_mpg4d_api.h"
|
||||||
|
|
||||||
// for test and demo
|
// for test and demo
|
||||||
#include "hal_dummy_dec_api.h"
|
#include "hal_dummy_dec_api.h"
|
||||||
@@ -44,6 +45,7 @@ static const MppHalApi *hw_apis[] = {
|
|||||||
&hal_api_vp9d,
|
&hal_api_vp9d,
|
||||||
&hal_api_avsd,
|
&hal_api_avsd,
|
||||||
&hal_api_m2vd,
|
&hal_api_m2vd,
|
||||||
|
&hal_api_mpg4d,
|
||||||
&hal_api_dummy_dec,
|
&hal_api_dummy_dec,
|
||||||
&hal_api_dummy_enc,
|
&hal_api_dummy_enc,
|
||||||
};
|
};
|
||||||
|
22
mpp/hal/vpu/mpg4d/CMakeLists.txt
Normal file
22
mpp/hal/vpu/mpg4d/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# vim: syntax=cmake
|
||||||
|
# hal mpeg4 reg
|
||||||
|
|
||||||
|
set(HAL_MPEG4D_HDR
|
||||||
|
)
|
||||||
|
|
||||||
|
set(HAL_MPEG4D_SRC
|
||||||
|
hal_mpg4d_reg.c
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(hal_mpg4d STATIC
|
||||||
|
${HAL_MPEG4D_SRC} ${HAL_MPEG4D_HDR}
|
||||||
|
)
|
||||||
|
set_target_properties(hal_mpg4d PROPERTIES FOLDER "mpp/hal")
|
||||||
|
|
||||||
|
if(ANDROID)
|
||||||
|
target_link_libraries(hal_mpg4d vpu mpp_base)
|
||||||
|
else()
|
||||||
|
target_link_libraries(hal_mpg4d mpp_base)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#add_subdirectory(test)
|
143
mpp/hal/vpu/mpg4d/hal_mpg4d_reg.c
Normal file
143
mpp/hal/vpu/mpg4d/hal_mpg4d_reg.c
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* *
|
||||||
|
* * Copyright 2016 Rockchip Electronics 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.
|
||||||
|
* */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @file hal_vpu_mpg4d_reg.c
|
||||||
|
* @brief
|
||||||
|
* @author gzl(lance.gao@rock-chips.com)
|
||||||
|
|
||||||
|
* @version 1.0.0
|
||||||
|
* @history
|
||||||
|
* 2016.04.11 : Create
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MODULE_TAG "hal_vpu_mpg4d"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
#include "mpp_err.h"
|
||||||
|
#include "mpp_mem.h"
|
||||||
|
#include "mpp_env.h"
|
||||||
|
#include "mpp_buffer.h"
|
||||||
|
|
||||||
|
#include "mpp_dec.h"
|
||||||
|
#include "mpg4d_syntax.h"
|
||||||
|
#include "vpu.h"
|
||||||
|
|
||||||
|
typedef struct mpeg4d_reg_context {
|
||||||
|
RK_S32 vpu_fd;
|
||||||
|
MppBufSlots slots;
|
||||||
|
MppBufSlots packet_slots;
|
||||||
|
MppBufferGroup group;
|
||||||
|
MppBuffer directMV_Addr;
|
||||||
|
int addr_init_flag;
|
||||||
|
void* hw_regs;
|
||||||
|
IOInterruptCB int_cb;
|
||||||
|
} hal_mpg4_ctx;
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_init(void *hal, MppHalCfg *cfg)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
hal_mpg4_ctx *reg_ctx = (hal_mpg4_ctx *)hal;
|
||||||
|
|
||||||
|
if (NULL == reg_ctx) {
|
||||||
|
mpp_err("hal instan no alloc");
|
||||||
|
return MPP_ERR_UNKNOW;
|
||||||
|
}
|
||||||
|
reg_ctx->slots = cfg->frame_slots;
|
||||||
|
reg_ctx->int_cb = cfg->hal_int_cb;
|
||||||
|
|
||||||
|
reg_ctx->packet_slots = cfg->packet_slots;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_deinit(void *hal)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
(void) hal;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_gen_regs(void *hal, HalTaskInfo *syn)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
(void) hal;
|
||||||
|
(void) syn;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_start(void *hal, HalTaskInfo *task)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
(void)hal;
|
||||||
|
(void)task;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_wait(void *hal, HalTaskInfo *task)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
(void)task;
|
||||||
|
(void) hal;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_reset(void *hal)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
(void)hal;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_flush(void *hal)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
|
||||||
|
(void)hal;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPP_RET hal_vpu_mpg4d_control(void *hal, RK_S32 cmd_type, void *param)
|
||||||
|
{
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
|
||||||
|
(void)hal;
|
||||||
|
(void)cmd_type;
|
||||||
|
(void)param;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MppHalApi hal_api_mpg4d = {
|
||||||
|
"mpg4d_vpu",
|
||||||
|
MPP_CTX_DEC,
|
||||||
|
MPP_VIDEO_CodingMPEG4,
|
||||||
|
sizeof(hal_mpg4_ctx),
|
||||||
|
0,
|
||||||
|
hal_vpu_mpg4d_init,
|
||||||
|
hal_vpu_mpg4d_deinit,
|
||||||
|
hal_vpu_mpg4d_gen_regs,
|
||||||
|
hal_vpu_mpg4d_start,
|
||||||
|
hal_vpu_mpg4d_wait,
|
||||||
|
hal_vpu_mpg4d_reset,
|
||||||
|
hal_vpu_mpg4d_flush,
|
||||||
|
hal_vpu_mpg4d_control,
|
||||||
|
};
|
||||||
|
|
35
mpp/hal/vpu/mpg4d/hal_mpg4d_reg.h
Normal file
35
mpp/hal/vpu/mpg4d/hal_mpg4d_reg.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* *
|
||||||
|
* * Copyright 2016 Rockchip Electronics 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.
|
||||||
|
* */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @file hal_mpeg4d_reg.h
|
||||||
|
* @brief
|
||||||
|
* @author gzl(lance.gao@rock-chips.com)
|
||||||
|
|
||||||
|
* @version 1.0.0
|
||||||
|
* @history
|
||||||
|
* 2016.04.11 : Create
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __HAL_MPG4D_REG_H__
|
||||||
|
#define __HAL_MPG4D_REG_H__
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Reference in New Issue
Block a user