FIX: ffmpeg decoder memory leak

Change-Id: I997572b5730618a969959f9b24c405d80fa9f83c
Jira: STUDIO-7597
This commit is contained in:
chunmao.guo 2024-07-12 17:00:24 +08:00 committed by Lane.Wei
parent 28d9c6743f
commit 342cea29bd
3 changed files with 14 additions and 15 deletions

View File

@ -81,17 +81,16 @@ bool AVVideoDecoder::toWxImage(wxImage &image, wxSize const &size2)
size.GetWidth(), size.GetHeight(), wxFmt,
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
nullptr, nullptr, nullptr);
uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 3);
if (data == nullptr)
return false;
uint8_t * datas[] = {data };
int strides[] = {size.GetWidth() * 3};
int length = size.GetWidth() * size.GetHeight() * 3;
if (bits_.size() < length)
bits_.resize(length);
uint8_t * datas[] = { bits_.data() };
int strides[] = { size.GetWidth() * 3 };
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
if (result_h != size.GetHeight()) {
delete[] data;
return false;
}
image = wxImage(size.GetWidth(), size.GetHeight(), data);
image = wxImage(size.GetWidth(), size.GetHeight(), bits_.data());
return true;
}
@ -111,16 +110,15 @@ bool AVVideoDecoder::toWxBitmap(wxBitmap &bitmap, wxSize const &size2)
size.GetWidth(), size.GetHeight(), wxFmt,
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
nullptr, nullptr, nullptr);
uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 4);
if (data == nullptr)
return false;
uint8_t *datas[] = {data};
int strides[] = {size.GetWidth() * 4};
int length = size.GetWidth() * size.GetHeight() * 4;
if (bits_.size() < length)
bits_.resize(length);
uint8_t *datas[] = { bits_.data() };
int strides[] = { size.GetWidth() * 4 };
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
if (result_h != size.GetHeight()) {
delete[] data;
return false;
}
bitmap = wxBitmap((char *) data, size.GetWidth(), size.GetHeight(), 32);
bitmap = wxBitmap((char const *) bits_.data(), size.GetWidth(), size.GetHeight(), 32);
return true;
}

View File

@ -34,6 +34,7 @@ private:
AVFrame * frame_ = nullptr;
SwsContext * sws_ctx_ = nullptr;
bool got_frame_ = false;
std::vector<uint8_t> bits_;
};
#endif // AVVIDEODECODER_HPP

View File

@ -27,7 +27,7 @@ wxMediaCtrl3::wxMediaCtrl3(wxWindow *parent)
, BambuLib(StaticBambuLib::get(this))
, m_thread([this] { PlayThread(); })
{
SetBackgroundColour(*wxBLACK);
SetBackgroundColour("#000001ff");
}
wxMediaCtrl3::~wxMediaCtrl3()