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