Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean.
Showing the changes to libavcodec/avcodec.c (1 of 513 files). Show all
Unified · Split
| @@ -94,13 +94,13 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, · 93 unmodified lines | ||
| 94 | 94 | |
| 95 | 95 | static AVMutex codec_mutex = AV_MUTEX_INITIALIZER; |
| 96 | 96 | |
| 97 | −static void lock_avcodec(const AVCodec *codec) | |
| 97 | +static void lock_avcodec(const FFCodec *codec) | |
| 98 | 98 | { |
| 99 | 99 | if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init) |
| 100 | 100 | ff_mutex_lock(&codec_mutex); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | −static void unlock_avcodec(const AVCodec *codec) | |
| 103 | +static void unlock_avcodec(const FFCodec *codec) | |
| 104 | 104 | { |
| 105 | 105 | if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init) |
| 106 | 106 | ff_mutex_unlock(&codec_mutex); |
| @@ -140,6 +140,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 33 unmodified lines | ||
| 140 | 140 | { |
| 141 | 141 | int ret = 0; |
| 142 | 142 | AVCodecInternal *avci; |
| 143 | + const FFCodec *codec2; | |
| 143 | 144 | |
| 144 | 145 | if (avcodec_is_open(avctx)) |
| 145 | 146 | return 0; |
| @@ -155,6 +156,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 9 unmodified lines | ||
| 155 | 156 | } |
| 156 | 157 | if (!codec) |
| 157 | 158 | codec = avctx->codec; |
| 159 | + codec2 = ffcodec(codec); | |
| 158 | 160 | |
| 159 | 161 | if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && |
| 160 | 162 | avctx->codec_id == AV_CODEC_ID_NONE) { |
| @@ -194,9 +196,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 33 unmodified lines | ||
| 194 | 196 | |
| 195 | 197 | avci->skip_samples_multiplier = 1; |
| 196 | 198 | |
| 197 | − if (codec->priv_data_size > 0) { | |
| 199 | + if (codec2->priv_data_size > 0) { | |
| 198 | 200 | if (!avctx->priv_data) { |
| 199 | − avctx->priv_data = av_mallocz(codec->priv_data_size); | |
| 201 | + avctx->priv_data = av_mallocz(codec2->priv_data_size); | |
| 200 | 202 | if (!avctx->priv_data) { |
| 201 | 203 | ret = AVERROR(ENOMEM); |
| 202 | 204 | goto free_and_end; |
| @@ -327,25 +329,25 @@ FF_ENABLE_DEPRECATION_WARNINGS · 124 unmodified lines | ||
| 327 | 329 | |
| 328 | 330 | if (HAVE_THREADS |
| 329 | 331 | && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) { |
| 330 | − /* Frame-threaded decoders call AVCodec.init for their child contexts. */ | |
| 331 | − lock_avcodec(codec); | |
| 332 | + /* Frame-threaded decoders call FFCodec.init for their child contexts. */ | |
| 333 | + lock_avcodec(codec2); | |
| 332 | 334 | ret = ff_thread_init(avctx); |
| 333 | − unlock_avcodec(codec); | |
| 335 | + unlock_avcodec(codec2); | |
| 334 | 336 | if (ret < 0) { |
| 335 | 337 | goto free_and_end; |
| 336 | 338 | } |
| 337 | 339 | } |
| 338 | − if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) | |
| 340 | + if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) | |
| 339 | 341 | avctx->thread_count = 1; |
| 340 | 342 | |
| 341 | 343 | if (!(avctx->active_thread_type & FF_THREAD_FRAME) || |
| 342 | 344 | avci->frame_thread_encoder) { |
| 343 | − if (avctx->codec->init) { | |
| 344 | − lock_avcodec(codec); | |
| 345 | − ret = avctx->codec->init(avctx); | |
| 346 | − unlock_avcodec(codec); | |
| 345 | + if (codec2->init) { | |
| 346 | + lock_avcodec(codec2); | |
| 347 | + ret = codec2->init(avctx); | |
| 348 | + unlock_avcodec(codec2); | |
| 347 | 349 | if (ret < 0) { |
| 348 | − avci->needs_close = avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP; | |
| 350 | + avci->needs_close = codec2->caps_internal & FF_CODEC_CAP_INIT_CLEANUP; | |
| 349 | 351 | goto free_and_end; |
| 350 | 352 | } |
| 351 | 353 | } |
| @@ -439,8 +441,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx) · 87 unmodified lines | ||
| 439 | 441 | |
| 440 | 442 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) |
| 441 | 443 | ff_thread_flush(avctx); |
| 442 | − else if (avctx->codec->flush) | |
| 443 | − avctx->codec->flush(avctx); | |
| 444 | + else if (ffcodec(avctx->codec)->flush) | |
| 445 | + ffcodec(avctx->codec)->flush(avctx); | |
| 444 | 446 | |
| 445 | 447 | avctx->pts_correction_last_pts = |
| 446 | 448 | avctx->pts_correction_last_dts = INT64_MIN; |
| @@ -484,8 +486,8 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 37 unmodified lines | ||
| 484 | 486 | } |
| 485 | 487 | if (HAVE_THREADS && avci->thread_ctx) |
| 486 | 488 | ff_thread_free(avctx); |
| 487 | − if (avci->needs_close && avctx->codec->close) | |
| 488 | − avctx->codec->close(avctx); | |
| 489 | + if (avci->needs_close && ffcodec(avctx->codec)->close) | |
| 490 | + ffcodec(avctx->codec)->close(avctx); | |
| 489 | 491 | avci->byte_buffer_size = 0; |
| 490 | 492 | av_freep(&avci->byte_buffer); |
| 491 | 493 | av_frame_free(&avci->buffer_frame); |