FIX: ffmpeg decoder memory leak
Change-Id: I997572b5730618a969959f9b24c405d80fa9f83c Jira: STUDIO-7597
This commit is contained in:
parent
28d9c6743f
commit
342cea29bd
|
@ -81,17 +81,16 @@ bool AVVideoDecoder::toWxImage(wxImage &image, wxSize const &size2)
|
||||||
size.GetWidth(), size.GetHeight(), wxFmt,
|
size.GetWidth(), size.GetHeight(), wxFmt,
|
||||||
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
|
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
|
||||||
nullptr, nullptr, nullptr);
|
nullptr, nullptr, nullptr);
|
||||||
uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 3);
|
int length = size.GetWidth() * size.GetHeight() * 3;
|
||||||
if (data == nullptr)
|
if (bits_.size() < length)
|
||||||
return false;
|
bits_.resize(length);
|
||||||
uint8_t * datas[] = {data };
|
uint8_t * datas[] = { bits_.data() };
|
||||||
int strides[] = {size.GetWidth() * 3};
|
int strides[] = { size.GetWidth() * 3 };
|
||||||
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
||||||
if (result_h != size.GetHeight()) {
|
if (result_h != size.GetHeight()) {
|
||||||
delete[] data;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
image = wxImage(size.GetWidth(), size.GetHeight(), data);
|
image = wxImage(size.GetWidth(), size.GetHeight(), bits_.data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,16 +110,15 @@ bool AVVideoDecoder::toWxBitmap(wxBitmap &bitmap, wxSize const &size2)
|
||||||
size.GetWidth(), size.GetHeight(), wxFmt,
|
size.GetWidth(), size.GetHeight(), wxFmt,
|
||||||
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
|
SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC
|
||||||
nullptr, nullptr, nullptr);
|
nullptr, nullptr, nullptr);
|
||||||
uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 4);
|
int length = size.GetWidth() * size.GetHeight() * 4;
|
||||||
if (data == nullptr)
|
if (bits_.size() < length)
|
||||||
return false;
|
bits_.resize(length);
|
||||||
uint8_t *datas[] = {data};
|
uint8_t *datas[] = { bits_.data() };
|
||||||
int strides[] = {size.GetWidth() * 4};
|
int strides[] = { size.GetWidth() * 4 };
|
||||||
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides);
|
||||||
if (result_h != size.GetHeight()) {
|
if (result_h != size.GetHeight()) {
|
||||||
delete[] data;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bitmap = wxBitmap((char *) data, size.GetWidth(), size.GetHeight(), 32);
|
bitmap = wxBitmap((char const *) bits_.data(), size.GetWidth(), size.GetHeight(), 32);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
AVFrame * frame_ = nullptr;
|
AVFrame * frame_ = nullptr;
|
||||||
SwsContext * sws_ctx_ = nullptr;
|
SwsContext * sws_ctx_ = nullptr;
|
||||||
bool got_frame_ = false;
|
bool got_frame_ = false;
|
||||||
|
std::vector<uint8_t> bits_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AVVIDEODECODER_HPP
|
#endif // AVVIDEODECODER_HPP
|
||||||
|
|
|
@ -27,7 +27,7 @@ wxMediaCtrl3::wxMediaCtrl3(wxWindow *parent)
|
||||||
, BambuLib(StaticBambuLib::get(this))
|
, BambuLib(StaticBambuLib::get(this))
|
||||||
, m_thread([this] { PlayThread(); })
|
, m_thread([this] { PlayThread(); })
|
||||||
{
|
{
|
||||||
SetBackgroundColour(*wxBLACK);
|
SetBackgroundColour("#000001ff");
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMediaCtrl3::~wxMediaCtrl3()
|
wxMediaCtrl3::~wxMediaCtrl3()
|
||||||
|
|
Loading…
Reference in New Issue