From 0d5ec550ad724aac0a019a5cd619330af7cbc572 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 21 十一月 2019 16:47:36 +0800
Subject: [PATCH] updte
---
csrc/worker/decoder.cpp | 35 +++++++++++++++++++++++++++++------
csrc/worker/decoder.hpp | 4 +++-
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/csrc/worker/decoder.cpp b/csrc/worker/decoder.cpp
index 558d871..805356e 100644
--- a/csrc/worker/decoder.cpp
+++ b/csrc/worker/decoder.cpp
@@ -20,10 +20,14 @@
{
decoder::decoder(ffwrapper::FormatIn *dec)
:decRef_(dec)
+ ,conv_(NULL)
{}
decoder::~decoder(){
-
+ if (conv_){
+ delete conv_;
+ conv_ = NULL;
+ }
std::lock_guard<std::mutex> l(mutex_frm_);
for(auto i : list_frm_){
free(i.data);
@@ -48,13 +52,32 @@
}
int decoder::saveFrame(AVFrame *frame, const int64_t &id){
+ AVFrame *cFrame = NULL;
+ bool conv = false;
+ if (frame->format != AV_PIX_FMT_NV12){
+ if (!conv_){
+ conv_ = new cvbridge(
+ frame->width, frame->height, frame->format,
+ frame->width, frame->height, AV_PIX_FMT_NV12);
+ }
+ if (conv_){
+ cFrame = conv_->convert2Frame(frame);
+ if (!cFrame) return -1;
+ conv = true;
+ }
+ }
+ AVFrame * rFrame = frame;
+ if (conv && cFrame) rFrame = cFrame;
+
FRM frm;
- frm.width = frame->width;
- frm.height = frame->height;
- frm.format = frame->format;
+ frm.width = rFrame->width;
+ frm.height = rFrame->height;
+ frm.format = rFrame->format;
frm.id = id;
- frm.data = cvbridge::extractFrame(frame, &frm.length);
-
+ frm.data = cvbridge::extractFrame(rFrame, &frm.length);
+
+ if (conv && cFrame) av_frame_free(&cFrame);
+
std::lock_guard<std::mutex> l(mutex_frm_);
while(list_frm_.size() > 50){
for(int i = 0; i < 12; i++){
diff --git a/csrc/worker/decoder.hpp b/csrc/worker/decoder.hpp
index a1946bd..a2f226f 100644
--- a/csrc/worker/decoder.hpp
+++ b/csrc/worker/decoder.hpp
@@ -18,6 +18,7 @@
{
class FormatIn;
class CodedData;
+ class cvbridge;
} // namespace ffwrapper
namespace cffmpeg_wrap
@@ -36,7 +37,8 @@
private:
ffwrapper::FormatIn *decRef_;
-
+ ffwrapper::cvbridge *conv_;
+
std::list<FRM> list_frm_;
std::mutex mutex_frm_;
--
Gitblit v1.8.0