That feature is overkill for a constant pointer to AVFilterLink which can be stored in AVCodecContext.opaque (indirectly, because the link is not allocated yet at the time the codec is opened). This also avoids leaking non-NULL AVFrame.opaque to callers.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -51,6 +51,7 @@ · 50 unmodified lines | ||
| 51 | 51 | #include "video.h" |
| 52 | 52 | |
| 53 | 53 | typedef struct MovieStream { |
| 54 | + AVFilterLink *link; | |
| 54 | 55 | AVStream *st; |
| 55 | 56 | AVCodecContext *codec_ctx; |
| 56 | 57 | int64_t discontinuity_threshold; |
| @@ -162,7 +163,8 @@ static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec) · 105 unmodified lines | ||
| 162 | 163 | static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) |
| 163 | 164 | { |
| 164 | 165 | int linesize_align[AV_NUM_DATA_POINTERS]; |
| 165 | − AVFilterLink *outlink = frame->opaque; | |
| 166 | + MovieStream *st = avctx->opaque; | |
| 167 | + AVFilterLink *outlink = st->link; | |
| 166 | 168 | int w, h, ow, oh, copy = 0; |
| 167 | 169 | AVFrame *new; |
| 168 | 170 | |
| @@ -202,7 +204,6 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) · 33 unmodified lines | ||
| 202 | 204 | av_frame_move_ref(frame, new); |
| 203 | 205 | av_frame_free(&new); |
| 204 | 206 | |
| 205 | − frame->opaque = outlink; | |
| 206 | 207 | frame->width = ow; |
| 207 | 208 | frame->height = oh; |
| 208 | 209 | |
| @@ -224,7 +225,7 @@ static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads) · 15 unmodified lines | ||
| 224 | 225 | if (!st->codec_ctx) |
| 225 | 226 | return AVERROR(ENOMEM); |
| 226 | 227 | |
| 227 | − st->codec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE; | |
| 228 | + st->codec_ctx->opaque = st; | |
| 228 | 229 | st->codec_ctx->get_buffer2 = get_buffer; |
| 229 | 230 | ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar); |
| 230 | 231 | if (ret < 0) |
| @@ -469,6 +470,8 @@ static int movie_config_output_props(AVFilterLink *outlink) · 238 unmodified lines | ||
| 469 | 470 | break; |
| 470 | 471 | } |
| 471 | 472 | |
| 473 | + st->link = outlink; | |
| 474 | + | |
| 472 | 475 | return 0; |
| 473 | 476 | } |
| 474 | 477 | |
| @@ -581,7 +584,6 @@ static int activate(AVFilterContext *ctx) · 106 unmodified lines | ||
| 581 | 584 | movie->out_index[movie->pkt->stream_index]; |
| 582 | 585 | |
| 583 | 586 | if (pkt_out_id >= 0) { |
| 584 | − movie->pkt->opaque = ctx->outputs[pkt_out_id]; | |
| 585 | 587 | ret = decode_packet(ctx, pkt_out_id); |
| 586 | 588 | } |
| 587 | 589 | av_packet_unref(movie->pkt); |