mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-26 20:02:21 +08:00
tab统一替换为4个空格键:#242
This commit is contained in:
@@ -46,51 +46,51 @@ namespace mediakit {
|
||||
class H264Decoder
|
||||
{
|
||||
public:
|
||||
H264Decoder(void){
|
||||
avcodec_register_all();
|
||||
AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||
if (!pCodec) {
|
||||
throw std::runtime_error("未找到H264解码器");
|
||||
}
|
||||
m_pContext.reset(avcodec_alloc_context3(pCodec), [](AVCodecContext *pCtx) {
|
||||
avcodec_close(pCtx);
|
||||
avcodec_free_context(&pCtx);
|
||||
});
|
||||
if (!m_pContext) {
|
||||
throw std::runtime_error("创建解码器失败");
|
||||
}
|
||||
if (pCodec->capabilities & AV_CODEC_CAP_TRUNCATED) {
|
||||
/* we do not send complete frames */
|
||||
m_pContext->flags |= AV_CODEC_FLAG_TRUNCATED;
|
||||
}
|
||||
if(avcodec_open2(m_pContext.get(), pCodec, NULL)< 0){
|
||||
throw std::runtime_error("打开编码器失败");
|
||||
}
|
||||
m_pFrame.reset(av_frame_alloc(),[](AVFrame *pFrame){
|
||||
av_frame_free(&pFrame);
|
||||
});
|
||||
if (!m_pFrame) {
|
||||
throw std::runtime_error("创建帧缓存失败");
|
||||
}
|
||||
}
|
||||
virtual ~H264Decoder(void){}
|
||||
bool inputVideo(unsigned char* data,unsigned int dataSize,uint32_t ui32Stamp,AVFrame **ppFrame){
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
pkt.data = data;
|
||||
pkt.size = dataSize;
|
||||
pkt.dts = ui32Stamp;
|
||||
int iGotPicture ;
|
||||
auto iLen = avcodec_decode_video2(m_pContext.get(), m_pFrame.get(), &iGotPicture, &pkt);
|
||||
if (!iGotPicture || iLen < 0) {
|
||||
return false;
|
||||
}
|
||||
*ppFrame = m_pFrame.get();
|
||||
return true;
|
||||
}
|
||||
H264Decoder(void){
|
||||
avcodec_register_all();
|
||||
AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||
if (!pCodec) {
|
||||
throw std::runtime_error("未找到H264解码器");
|
||||
}
|
||||
m_pContext.reset(avcodec_alloc_context3(pCodec), [](AVCodecContext *pCtx) {
|
||||
avcodec_close(pCtx);
|
||||
avcodec_free_context(&pCtx);
|
||||
});
|
||||
if (!m_pContext) {
|
||||
throw std::runtime_error("创建解码器失败");
|
||||
}
|
||||
if (pCodec->capabilities & AV_CODEC_CAP_TRUNCATED) {
|
||||
/* we do not send complete frames */
|
||||
m_pContext->flags |= AV_CODEC_FLAG_TRUNCATED;
|
||||
}
|
||||
if(avcodec_open2(m_pContext.get(), pCodec, NULL)< 0){
|
||||
throw std::runtime_error("打开编码器失败");
|
||||
}
|
||||
m_pFrame.reset(av_frame_alloc(),[](AVFrame *pFrame){
|
||||
av_frame_free(&pFrame);
|
||||
});
|
||||
if (!m_pFrame) {
|
||||
throw std::runtime_error("创建帧缓存失败");
|
||||
}
|
||||
}
|
||||
virtual ~H264Decoder(void){}
|
||||
bool inputVideo(unsigned char* data,unsigned int dataSize,uint32_t ui32Stamp,AVFrame **ppFrame){
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
pkt.data = data;
|
||||
pkt.size = dataSize;
|
||||
pkt.dts = ui32Stamp;
|
||||
int iGotPicture ;
|
||||
auto iLen = avcodec_decode_video2(m_pContext.get(), m_pFrame.get(), &iGotPicture, &pkt);
|
||||
if (!iGotPicture || iLen < 0) {
|
||||
return false;
|
||||
}
|
||||
*ppFrame = m_pFrame.get();
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<AVCodecContext> m_pContext;
|
||||
std::shared_ptr<AVFrame> m_pFrame;
|
||||
std::shared_ptr<AVCodecContext> m_pContext;
|
||||
std::shared_ptr<AVFrame> m_pFrame;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user