[dec]: fix mpp_packet error usage in test

1. mpp_packet length is the valid data size, fix this in copy_init function
2. in mpp_dec_test setup pos and length only do not touch data and size

Change-Id: Ic1bb15126fa09e7da0869ea79ec85ad2869c3955
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2016-11-29 10:07:52 +08:00
parent 3ddd67009e
commit 5e5f667d68
2 changed files with 27 additions and 15 deletions

View File

@@ -117,29 +117,32 @@ MPP_RET mpp_packet_copy_init(MppPacket *packet, const MppPacket src)
return MPP_OK;
}
size_t size = mpp_packet_get_size(src);
/*
* NOTE: only copy valid data
*/
size_t length = mpp_packet_get_length(src);
/*
* due to parser may be read 32 bit interface so we must alloc more size then real size
* to avoid read carsh
*/
void *data = mpp_malloc_size(void, size + 256);
if (NULL == data) {
mpp_err_f("malloc failed, size %d\n", size);
void *pos = mpp_malloc_size(void, length + 256);
if (NULL == pos) {
mpp_err_f("malloc failed, size %d\n", length);
mpp_packet_deinit(&pkt);
return MPP_ERR_MALLOC;
}
MppPacketImpl *p = (MppPacketImpl *)pkt;
memcpy(p, src_impl, sizeof(*src_impl));
p->data = p->pos = data;
p->size = p->length = size;
p->data = p->pos = pos;
p->size = p->length = length;
p->flag |= MPP_PACKET_FLAG_INTERNAL;
if (size) {
memcpy(data, src_impl->data, size);
if (length) {
memcpy(pos, src_impl->pos, length);
/*
* clean more alloc byte to zero
*/
memset((RK_U8*)data + size, 0, 256);
memset((RK_U8*)pos + length, 0, 256);
}
*packet = pkt;
return MPP_OK;
@@ -173,8 +176,8 @@ void mpp_packet_set_pos(MppPacket packet, void *pos)
return ;
MppPacketImpl *p = (MppPacketImpl *)packet;
p->pos = pos;
p->length = p->size - ((char *)pos - (char *)p->data);
p->length -= (RK_U8 *)pos - (RK_U8 *)p->pos;
p->pos = pos;
mpp_assert(p->data <= p->pos);
mpp_assert(p->size >= p->length);
}

View File

@@ -31,7 +31,7 @@
#include "utils.h"
#define MPI_DEC_LOOP_COUNT 4
#define MPI_DEC_STREAM_SIZE (SZ_2K)
#define MPI_DEC_STREAM_SIZE (SZ_4K)
#define MAX_FILE_NAME_LENGTH 256
typedef struct {
@@ -100,9 +100,12 @@ static int decode_simple(MpiDecLoopData *data)
// write data to packet
mpp_packet_write(packet, 0, buf, read_size);
// reset pos
// reset pos and set valid length
mpp_packet_set_pos(packet, buf);
mpp_packet_set_length(packet, read_size);
// setup eos flag
if (pkt_eos)
mpp_packet_set_eos(packet);
do {
// send the packet first if packet is not done
@@ -139,12 +142,18 @@ static int decode_simple(MpiDecLoopData *data)
}
// if last packet is send but last frame is not found continue
if (pkt_eos && pkt_done && !frm_eos)
if (pkt_eos && pkt_done && !frm_eos) {
msleep(10);
continue;
}
if (frm_eos) {
mpp_log("found last frame\n");
break;
}
if (get_frm)
continue;
break;
} while (1);