本文共 1429 字,大约阅读时间需要 4 分钟。
测试通过,并进行了优化。思路:
为了保证性能,由调用方传递一个临时缓冲区。
具体代码如下,测试通过:
static int tdav_codec_h264_get_stapa_pay(const uint8_t* in_data, tsk_size_t in_size, const void** out_data, tsk_size_t *out_size, void** temp_buffer, tsk_size_t* temp_size){ uint8_t* buf = in_data; tsk_size_t len = in_size; int dst_len = 0; uint8_t *dst = NULL; if (in_size <= H264_FUA_HEADER_SIZE) { TSK_DEBUG_ERROR("Too short"); return -1; } if (*temp_size < (in_size*2)) { *temp_size = in_size*2; *temp_buffer = tsk_realloc(*temp_buffer, *temp_size); } dst = *temp_buffer; buf ++; len --; const uint8_t *src = buf; int src_len = len; while (src_len > 2) { uint16_t nal_size = (src[0] << 8 | src[1]); src += 2; src_len -= 2; if (nal_size <= src_len) { memcpy(dst, NAL_START_SEQUENCE, sizeof(NAL_START_SEQUENCE)); dst += sizeof(NAL_START_SEQUENCE); dst_len += sizeof(NAL_START_SEQUENCE); memcpy(dst, src, nal_size); dst += nal_size; dst_len += nal_size; } else { TSK_DEBUG_ERROR("nal size exceeds length: %d %d\n", nal_size, src_len); return -1; } src += nal_size; src_len -= nal_size; } *out_data = *temp_buffer; *out_size = dst_len; return 0;}
转载地址:http://snuaf.baihongyu.com/