1 Star 0 Fork 0

linshl/jessibuca

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
broadway.h 3.02 KB
一键复制 编辑 原始数据 按行查看 历史
langhuihui 提交于 2019-08-21 20:39 . Jessibuca
#pragma once
#include "H264SwDecApi.h"
class Broadway : public VideoDecoder
{
public:
H264SwDecInst decInst;
H264SwDecInput decInput;
H264SwDecOutput decOutput;
H264SwDecPicture decPicture;
H264SwDecInfo decInfo;
u32 picDecodeNumber;
u32 picDisplayNumber;
Broadway()
{
H264SwDecRet ret;
u32 disableOutputReordering = 0;
ret = H264SwDecInit(&decInst, disableOutputReordering);
if (ret != H264SWDEC_OK)
{
emscripten_log(0, "DECODER INITIALIZATION FAILED\n");
return;
}
picDecodeNumber = picDisplayNumber = 1;
emscripten_log(0, "H264 init");
}
~Broadway()
{
if (decInst)
{
H264SwDecRelease(decInst);
decInst = nullptr;
}
}
void _decode(IOBuffer data) override
{
u8 naluType = data[0] & 0x1f;
// if (!decInst || (naluType != 1 && naluType != 5))
// return;
decInput.pStream = (u8 *)data;
decInput.dataLen = data.length;
u32 i = 0;
do
{
u8 *start = decInput.pStream;
u32 ret = broadwayDecode();
//emscripten_log(0, "Decoded Unit #%d, Size: %x, Result: %i\n", i++, (decInput.pStream - start), ret);
} while (decInput.dataLen > 0);
}
u32 broadwayDecode()
{
H264SwDecRet ret = H264SwDecDecode(decInst, &decInput, &decOutput);
switch (ret)
{
case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY:
/* Stream headers were successfully decoded, thus stream information is available for query now. */
ret = H264SwDecGetInfo(decInst, &decInfo);
if (ret != H264SWDEC_OK)
{
return -1;
}
decodeVideoSize(decInfo.picWidth, decInfo.picHeight);
/*picSize = decInfo.picWidth * decInfo.picHeight;
picSize = (3 * picSize) / 2;
printf("picSize:%d", picSize);*/
//broadwayOnHeadersDecoded();
decInput.dataLen -= decOutput.pStrmCurrPos - decInput.pStream;
decInput.pStream = decOutput.pStrmCurrPos;
break;
case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY:
/* Picture is ready and more data remains in the input buffer,
* update input structure.
*/
decInput.dataLen -= decOutput.pStrmCurrPos - decInput.pStream;
decInput.pStream = decOutput.pStrmCurrPos;
/* fall through */
case H264SWDEC_PIC_RDY:
if (ret == H264SWDEC_PIC_RDY)
{
decInput.dataLen = 0;
}
/* Increment decoding number for every decoded picture */
picDecodeNumber++;
while (H264SwDecNextPicture(decInst, &decPicture, 0) == H264SWDEC_PIC_RDY)
{
//printf(" Decoded Picture Decode: %d, Display: %d, Type: %s\n", picDecodeNumber, picDisplayNumber, decPicture.isIdrPicture ? "IDR" : "NON-IDR");
/* Increment display number for every displayed picture */
picDisplayNumber++;
p_yuv[0] = (u32)decPicture.pOutputPicture;
p_yuv[1] = p_yuv[0] + decInfo.picWidth * decInfo.picHeight;
p_yuv[2] = p_yuv[1] + (decInfo.picWidth * decInfo.picHeight >> 2);
decodeYUV420();
}
break;
case H264SWDEC_STRM_PROCESSED:
case H264SWDEC_STRM_ERR:
/* Input stream was decoded but no picture is ready, thus get more data. */
decInput.dataLen = 0;
break;
default:
emscripten_log(0, "video decode %d", -ret);
decInput.dataLen = 0;
break;
}
return ret;
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linshl/jessibuca.git
git@gitee.com:linshl/jessibuca.git
linshl
jessibuca
jessibuca
worker

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385