Closed menglingbo closed 1 year ago
H265实现是为了测试别的功能误提交的代码, 265的裸流参照H264实现即可。
static void h265_handler(void* param, const uint8_t* nalu, size_t bytes)
{
static int i = 0;
static int j = 0;
static uint8_t startcode[] = {0x00, 0x00, 0x00, 0x01};
struct mov_h265_test_t* ctx = (struct mov_h265_test_t*)param;
assert(ctx->ptr < nalu);
const uint8_t* ptr = nalu - 3;
// const uint8_t* end = (const uint8_t*)nalu + bytes;
uint8_t nalutype = (nalu[0] >> 1) & 0x3f;
if (ctx->vcl > 0 && h265_is_new_access_unit((const uint8_t*)nalu, bytes))
{
int r = h265_write(ctx, ctx->ptr, ptr - ctx->ptr);
if (-1 == r)
return; // wait for more data
ctx->ptr = ptr;
ctx->vcl = 0;
}
if (nalutype <= 31)
++ctx->vcl;
}
h264_handler我按照265的实现方式如下,是否可行呢? static void h264_handler(void param, const uint8_t nalu, size_t bytes) { struct mov_h264_test_t ctx = (struct mov_h264_test_t)param; static uint8_t startcode[] = {0x00, 0x00, 0x00, 0x01}; static int i = 0; static int j = 0; uint8_t nalutype = nalu[0] & 0x1f; if (ctx->vcl > 0 && h264_is_new_access_unit((const uint8_t*)nalu, bytes)) { int r = h264_write(ctx, ctx->buf, ctx->bytes); if (-1 == r) return; // wait for more data if ((j++) % 25 == 0) i = (i + 1) % ctx->vcl; ctx->bytes = 0; ctx->vcl = 0; }
} h264原来实现: static void h264_handler(void param, const uint8_t nalu, size_t bytes) { struct mov_h264_test_t ctx = (struct mov_h264_test_t)param; assert(ctx->ptr < nalu);
// const uint8_t end = (const uint8_t)nalu + bytes; uint8_t nalutype = nalu[0] & 0x1f; if (ctx->vcl > 0 && h264_is_new_access_unit((const uint8_t*)nalu, bytes)) { int r = h264_write(ctx, ctx->ptr, ptr - ctx->ptr); if (-1 == r) return; // wait for more data
} h265实现: static void h265_handler(void param, const uint8_t nalu, size_t bytes) { static int i = 0; static int j = 0; static uint8_t startcode[] = {0x00, 0x00, 0x00, 0x01};
// const uint8_t end = (const uint8_t)nalu + bytes; uint8_t nalutype = (nalu[0] >> 1) & 0x3f; if (ctx->vcl > 0 && h265_is_new_access_unit((const uint8_t*)nalu, bytes)) { //int r = h265_write(ctx, ctx->ptr, ptr - ctx->ptr); int r = h265_write(ctx, ctx->buf, ctx->bytes); if (-1 == r) return; // wait for more data
}