| | |
| | | dst.data, dst.linesize); |
| | | sws_freeContext(convert_ctx); |
| | | |
| | | DBG("m.size is " << m.size()); |
| | | // DBG("m.size is " << m.size()); |
| | | // LOG_IF(); |
| | | |
| | | return m; |
| | | } |
| | |
| | | } |
| | | |
| | | BASICGB28181::FFmpegDecoderJPG::~FFmpegDecoderJPG() { |
| | | //清空队列 |
| | | while (m_rtpQueue.count_queue()) { |
| | | //#todo delete frameBuffInfo* |
| | | m_rtpQueue.popNotWait(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | #ifdef TestCode |
| | | DBG(" m_rtpQueue.push before "); |
| | | DBG(" m_rtpQueue.push befores "); |
| | | #endif |
| | | m_rtpQueue. |
| | | push(info); |
| | | m_rtpQueue.push(info); |
| | | #ifdef TestCode |
| | | DBG(" m_rtpQueue.push after "); |
| | | #endif |
| | |
| | | do { |
| | | |
| | | // DBG(" m_rtpQueue.pop before "); |
| | | //从缓存中获取buffinfo |
| | | frameBuffInfo *buffinfo = fFmpegDecoderJPG->m_rtpQueue.pop(); |
| | | // DBG(" m_rtpQueue.pop after "); |
| | | diff = len - buffinfo->buffLen; |
| | | // printf("bufsize is :%ld,len is :%ld, datalen:%d \n", bufsize, len, buffinfo->buffLen); |
| | | |
| | | //帧长大于bufsize |
| | | if (diff < 0) { |
| | | // DBG("/帧长大于bufsize" << diff); |
| | |
| | | delete[] buffinfo->buff; |
| | | delete buffinfo; |
| | | } while (diff > 0); |
| | | //#todo 触发信号 |
| | | |
| | | // DBG("emitSigal(\"read_dataOk\") begin"); |
| | | // gSignalLock.emitSigal("read_dataOk"); |
| | | fFmpegDecoderJPG->m_readData = true; |
| | |
| | | // avformat_network_init(); |
| | | p_this->ic = avformat_alloc_context(); |
| | | |
| | | //创建ffmpeg使用的内存空间 |
| | | p_this->iobuffer = (unsigned char *) av_malloc(p_this->m_buf_size); |
| | | if (!p_this->iobuffer) { |
| | | ERR("av_malloc: err======" << p_this->m_camIdx); |
| | | p_this->m_running = false; |
| | | continue; |
| | | } |
| | | // 使用回调函数和内存块创建 AVIOContext |
| | | p_this->avio = avio_alloc_context(p_this->iobuffer, p_this->m_buf_size, 0, p_this, p_this->read_data, NULL, |
| | | NULL); |
| | | if (!p_this->avio) { |
| | |
| | | vi = i; |
| | | break; |
| | | } |
| | | } |
| | | if(vi == -1)//无视频包 |
| | | { |
| | | ERR("no video packet!!"); |
| | | p_this->m_running = false; |
| | | continue; |
| | | } |
| | | p_this->stream = p_this->ic->streams[vi]; |
| | | p_this->video_st = p_this->stream; |
| | |
| | | av_init_packet(&p_this->pkt); |
| | | |
| | | p_this->frame = av_frame_alloc(); |
| | | unsigned int usleepTime = (1000 / p_this->m_fps) - 12; |
| | | usleepTime *= 1000; |
| | | // unsigned int usleepTime = (1000 / p_this->m_fps) - 12; |
| | | // usleepTime *= 1000; |
| | | DBG("===open ok, camid: " << p_this->m_camIdx); |
| | | while (p_this->m_running) { |
| | | #ifdef TestCode |
| | |
| | | |
| | | // BASICGB28181::avframe_to_cvmat(frame).copyTo(p_this->m_image); |
| | | p_this->m_image = std::move(BASICGB28181::avframe_to_cvmat(p_this->frame)); |
| | | |
| | | // 将i帧保存为快照 |
| | | if (p_this->m_SnapshotNotSaveRet && (p_this->pkt.flags & AV_PKT_FLAG_KEY)) { |
| | | try { |
| | | std::string strNewName = "./"; |
| | |
| | | #ifdef TestCode |
| | | DBG("emitSigal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | //触发信号 |
| | | //触发上层信号 |
| | | gSignalLock.emitSigal(p_this->m_camIdx + "DecoderImageOK"); |
| | | //#ifdef TestCode |
| | | // DBG("emitSigal(\"DecoderImageOK\") after"); |
| | | //#endif |
| | | |
| | | DBG("emitSigal(\"DecoderImageOK\") after"); |
| | | DBG("p_this->m_camIdx is " << p_this->m_camIdx << " queue size is " << p_this->m_rtpQueue.count_queue()); |
| | | // DBG("emitSigal(\"DecoderImageOK\") after"); |
| | | |
| | | // DBG("p_this->m_camIdx is " << p_this->m_camIdx << " queue size is " << p_this->m_rtpQueue.count_queue()); |
| | | |
| | | #ifdef TestCode |
| | | { |
| | |
| | | } |
| | | m_camIdx = camIdx; |
| | | DBG("BareFlowDecoderThd camIdx : " << camIdx); |
| | | // 启动解码线程 |
| | | std::thread t_BareFlowDecoder(BareFlowDecoderThd, this); |
| | | t_BareFlowDecoder.detach(); |
| | | ); |
| | |
| | | delete iter->m_packet.data; |
| | | iter = m_packetsVec.erase(iter); |
| | | while (!(iter->m_packet.flags & AV_PKT_FLAG_KEY)) { |
| | | INFO("DropFrame: " << iter->m_frameId); |
| | | // INFO("DropFrame: " << iter->m_frameId); |
| | | delete iter->m_packet.data; |
| | | iter = m_packetsVec.erase(iter); |
| | | } |