| @@ -32,6 +32,7 @@ · 31 unmodified lines |
| 32 | 32 | #include "libavutil/pixdesc.h" |
| 33 | 33 | #include "libavutil/imgutils.h" |
| 34 | 34 | #include "libavutil/pixfmt.h" |
| 35 | +#include "refstruct.h" |
| 35 | 36 | #include "v4l2_context.h" |
| 36 | 37 | #include "v4l2_fmt.h" |
| 37 | 38 | #include "v4l2_m2m.h" |
| @@ -247,9 +248,9 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *s) · 209 unmodified lines |
| 247 | 248 | return 0; |
| 248 | 249 | } |
| 249 | 250 | |
| 250 | | −static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context) |
| 251 | +static void v4l2_m2m_destroy_context(FFRefStructOpaque unused, void *context) |
| 251 | 252 | { |
| 252 | | − V4L2m2mContext *s = (V4L2m2mContext*)context; |
| 253 | + V4L2m2mContext *s = context; |
| 253 | 254 | |
| 254 | 255 | ff_v4l2_context_release(&s->capture); |
| 255 | 256 | sem_destroy(&s->refsync); |
| @@ -258,8 +259,6 @@ static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context) · 2 unmodified lines |
| 258 | 259 | close(s->fd); |
| 259 | 260 | av_frame_free(&s->frame); |
| 260 | 261 | av_packet_unref(&s->buf_pkt); |
| 261 | | − |
| 262 | | − av_free(s); |
| 263 | 262 | } |
| 264 | 263 | |
| 265 | 264 | int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv) |
| @@ -283,7 +282,7 @@ int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv) · 17 unmodified lines |
| 283 | 282 | ff_v4l2_context_release(&s->output); |
| 284 | 283 | |
| 285 | 284 | s->self_ref = NULL; |
| 286 | | − av_buffer_unref(&priv->context_ref); |
| 285 | + ff_refstruct_unref(&priv->context); |
| 287 | 286 | |
| 288 | 287 | return 0; |
| 289 | 288 | } |
| @@ -328,17 +327,11 @@ int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv) · 38 unmodified lines |
| 328 | 327 | |
| 329 | 328 | int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s) |
| 330 | 329 | { |
| 331 | | − *s = av_mallocz(sizeof(V4L2m2mContext)); |
| 330 | + *s = ff_refstruct_alloc_ext(sizeof(**s), 0, NULL, |
| 331 | + &v4l2_m2m_destroy_context); |
| 332 | 332 | if (!*s) |
| 333 | 333 | return AVERROR(ENOMEM); |
| 334 | 334 | |
| 335 | | − priv->context_ref = av_buffer_create((uint8_t *) *s, sizeof(V4L2m2mContext), |
| 336 | | − &v4l2_m2m_destroy_context, NULL, 0); |
| 337 | | − if (!priv->context_ref) { |
| 338 | | − av_freep(s); |
| 339 | | − return AVERROR(ENOMEM); |
| 340 | | − } |
| 341 | | − |
| 342 | 335 | /* assign the context */ |
| 343 | 336 | priv->context = *s; |
| 344 | 337 | (*s)->priv = priv; |
| @@ -346,13 +339,13 @@ int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s) · 1 unmodified line |
| 346 | 339 | /* populate it */ |
| 347 | 340 | priv->context->capture.num_buffers = priv->num_capture_buffers; |
| 348 | 341 | priv->context->output.num_buffers = priv->num_output_buffers; |
| 349 | | − priv->context->self_ref = priv->context_ref; |
| 342 | + priv->context->self_ref = priv->context; |
| 350 | 343 | priv->context->fd = -1; |
| 351 | 344 | |
| 352 | 345 | priv->context->frame = av_frame_alloc(); |
| 353 | 346 | if (!priv->context->frame) { |
| 354 | | − av_buffer_unref(&priv->context_ref); |
| 355 | | − *s = NULL; /* freed when unreferencing context_ref */ |
| 347 | + ff_refstruct_unref(&priv->context); |
| 348 | + *s = NULL; /* freed when unreferencing context */ |
| 356 | 349 | return AVERROR(ENOMEM); |
| 357 | 350 | } |
| 358 | 351 | |