frame = g_new0 (GstNvDecoderFrame, 1);
frame->index = index_to_use;
frame->decoder = gst_object_ref (decoder);
+ frame->ref_count = 1;
GST_LOG_OBJECT (decoder, "New frame %p (index %d)", frame, frame->index);
frame->mapped = FALSE;
}
+GstNvDecoderFrame *
+gst_nv_decoder_frame_ref (GstNvDecoderFrame * frame)
+{
+ g_assert (frame != NULL);
+
+ g_atomic_int_add (&frame->ref_count, 1);
+
+ return frame;
+}
+
void
-gst_nv_decoder_frame_free (GstNvDecoderFrame * frame)
+gst_nv_decoder_frame_unref (GstNvDecoderFrame * frame)
{
GstNvDecoder *self;
g_assert (frame != NULL);
- GST_LOG ("Free frame %p (index %d)", frame, frame->index);
+ if (g_atomic_int_dec_and_test (&frame->ref_count)) {
+ GST_LOG ("Free frame %p (index %d)", frame, frame->index);
- if (frame->decoder) {
- self = frame->decoder;
- if (frame->mapped && gst_cuda_context_push (self->context)) {
- gst_nv_decoder_frame_unmap (frame);
- gst_cuda_context_pop (NULL);
- }
+ if (frame->decoder) {
+ self = frame->decoder;
+ if (frame->mapped && gst_cuda_context_push (self->context)) {
+ gst_nv_decoder_frame_unmap (frame);
+ gst_cuda_context_pop (NULL);
+ }
- if (frame->index < self->pool_size) {
- self->frame_pool[frame->index].available = TRUE;
- } else {
- GST_WARNING_OBJECT (self,
- "Frame %p has invalid index %d", frame, frame->index);
+ if (frame->index < self->pool_size) {
+ self->frame_pool[frame->index].available = TRUE;
+ } else {
+ GST_WARNING_OBJECT (self,
+ "Frame %p has invalid index %d", frame, frame->index);
+ }
+
+ gst_object_unref (self);
}
- gst_object_unref (self);
+ g_free (frame);
}
-
- g_free (frame);
}
gboolean
/*< private >*/
GstNvDecoder *decoder;
+
+ gint ref_count;
} GstNvDecoderFrame;
typedef enum
GstNvDecoderFrame * gst_nv_decoder_new_frame (GstNvDecoder * decoder);
-void gst_nv_decoder_frame_free (GstNvDecoderFrame * frame);
+GstNvDecoderFrame * gst_nv_decoder_frame_ref (GstNvDecoderFrame * frame);
+
+void gst_nv_decoder_frame_unref (GstNvDecoderFrame * frame);
gboolean gst_nv_decoder_decode_picture (GstNvDecoder * decoder,
CUVIDPICPARAMS * params);
GST_LOG_OBJECT (self, "New decoder frame %p (index %d)", frame, frame->index);
gst_h265_picture_set_user_data (picture,
- frame, (GDestroyNotify) gst_nv_decoder_frame_free);
+ frame, (GDestroyNotify) gst_nv_decoder_frame_unref);
return TRUE;
}