gstreamer memory cleanup in mediaplayer and stream

This commit is contained in:
brunoherbelin
2021-04-04 01:24:13 +02:00
parent a143360497
commit ceea9c10d5
5 changed files with 117 additions and 91 deletions

View File

@@ -195,6 +195,14 @@ bool Stream::failed() const
return failed_;
}
void Stream::Frame::unmap()
{
if ( full ) {
gst_video_frame_unmap(&vframe);
full = false;
}
}
void Stream::close()
{
// not openned?
@@ -208,9 +216,14 @@ void Stream::close()
// clean up GST
if (pipeline_ != nullptr) {
// force flush
GstState state;
gst_element_send_event(pipeline_, gst_event_new_seek (1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_END, 0) );
gst_element_get_state (pipeline_, &state, NULL, GST_CLOCK_TIME_NONE);
GstStateChangeReturn ret = gst_element_set_state (pipeline_, GST_STATE_NULL);
if (ret == GST_STATE_CHANGE_ASYNC) {
GstState state;
gst_element_get_state (pipeline_, &state, NULL, GST_CLOCK_TIME_NONE);
}
gst_object_unref (pipeline_);
@@ -220,10 +233,9 @@ void Stream::close()
// cleanup eventual remaining frame memory
for(guint i = 0; i < N_FRAME; i++){
if ( frame_[i].full ) {
gst_video_frame_unmap(&frame_[i].vframe);
frame_[i].status = INVALID;
}
frame_[i].access.lock();
frame_[i].unmap();
frame_[i].access.unlock();
}
write_index_ = 0;
last_index_ = 0;
@@ -510,6 +522,9 @@ void Stream::update()
// double update for pre-roll frame and dual PBO (ensure frame is displayed now)
if (frame_[read_index].status == PREROLL && pbo_size_ > 0)
fill_texture(read_index);
// free frame
frame_[read_index].unmap();
}
// avoid reading it again
@@ -545,11 +560,7 @@ bool Stream::fill_frame(GstBuffer *buf, FrameStatus status)
frame_[write_index_].access.lock();
// always empty frame before filling it again
if ( frame_[write_index_].full ) {
if ( GST_MINI_OBJECT_REFCOUNT_VALUE( &frame_[write_index_].vframe.buffer->mini_object ) > 0)
gst_video_frame_unmap(&frame_[write_index_].vframe);
frame_[write_index_].full = false;
}
frame_[write_index_].unmap();
// accept status of frame received
frame_[write_index_].status = status;
@@ -579,7 +590,9 @@ bool Stream::fill_frame(GstBuffer *buf, FrameStatus status)
// full but invalid frame : will be deleted next iteration
// (should never happen)
else {
#ifdef STREAM_DEBUG
Log::Info("Stream %s Received an Invalid frame", std::to_string(id_).c_str());
#endif
frame_[write_index_].status = INVALID;
frame_[write_index_].access.unlock();
return false;