History

avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec

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.

Andreas Rheinhardt committed 4 years ago

Commit 20f97271 parent a688f3c513 files · +5330 −5260Browse files

Showing the changes to libavcodec/avcodec.c (1 of 513 files). Show all

Unified · Split

libavcodec/avcodec.c+19−17
@@ -94,13 +94,13 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, · 93 unmodified lines
94 94
95static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;95static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
96 96
97static void lock_avcodec(const AVCodec *codec)97static void lock_avcodec(const FFCodec *codec)
98{98{
99 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)99 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)
100 ff_mutex_lock(&codec_mutex);100 ff_mutex_lock(&codec_mutex);
101}101}
102 102
103static void unlock_avcodec(const AVCodec *codec)103static void unlock_avcodec(const FFCodec *codec)
104{104{
105 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)105 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)
106 ff_mutex_unlock(&codec_mutex);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 int ret = 0;141 int ret = 0;
142 AVCodecInternal *avci;142 AVCodecInternal *avci;
143 const FFCodec *codec2;
143 144
144 if (avcodec_is_open(avctx))145 if (avcodec_is_open(avctx))
145 return 0;146 return 0;
@@ -155,6 +156,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 9 unmodified lines
155 }156 }
156 if (!codec)157 if (!codec)
157 codec = avctx->codec;158 codec = avctx->codec;
159 codec2 = ffcodec(codec);
158 160
159 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&161 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
160 avctx->codec_id == AV_CODEC_ID_NONE) {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 avci->skip_samples_multiplier = 1;197 avci->skip_samples_multiplier = 1;
196 198
197 if (codec->priv_data_size > 0) {199 if (codec2->priv_data_size > 0) {
198 if (!avctx->priv_data) {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 if (!avctx->priv_data) {202 if (!avctx->priv_data) {
201 ret = AVERROR(ENOMEM);203 ret = AVERROR(ENOMEM);
202 goto free_and_end;204 goto free_and_end;
@@ -327,25 +329,25 @@ FF_ENABLE_DEPRECATION_WARNINGS · 124 unmodified lines
327 329
328 if (HAVE_THREADS330 if (HAVE_THREADS
329 && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {331 && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
330 /* Frame-threaded decoders call AVCodec.init for their child contexts. */332 /* Frame-threaded decoders call FFCodec.init for their child contexts. */
331 lock_avcodec(codec);333 lock_avcodec(codec2);
332 ret = ff_thread_init(avctx);334 ret = ff_thread_init(avctx);
333 unlock_avcodec(codec);335 unlock_avcodec(codec2);
334 if (ret < 0) {336 if (ret < 0) {
335 goto free_and_end;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 avctx->thread_count = 1;341 avctx->thread_count = 1;
340 342
341 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||343 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
342 avci->frame_thread_encoder) {344 avci->frame_thread_encoder) {
343 if (avctx->codec->init) {345 if (codec2->init) {
344 lock_avcodec(codec);346 lock_avcodec(codec2);
345 ret = avctx->codec->init(avctx);347 ret = codec2->init(avctx);
346 unlock_avcodec(codec);348 unlock_avcodec(codec2);
347 if (ret < 0) {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 goto free_and_end;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 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)442 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
441 ff_thread_flush(avctx);443 ff_thread_flush(avctx);
442 else if (avctx->codec->flush)444 else if (ffcodec(avctx->codec)->flush)
443 avctx->codec->flush(avctx);445 ffcodec(avctx->codec)->flush(avctx);
444 446
445 avctx->pts_correction_last_pts =447 avctx->pts_correction_last_pts =
446 avctx->pts_correction_last_dts = INT64_MIN;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 if (HAVE_THREADS && avci->thread_ctx)487 if (HAVE_THREADS && avci->thread_ctx)
486 ff_thread_free(avctx);488 ff_thread_free(avctx);
487 if (avci->needs_close && avctx->codec->close)489 if (avci->needs_close && ffcodec(avctx->codec)->close)
488 avctx->codec->close(avctx);490 ffcodec(avctx->codec)->close(avctx);
489 avci->byte_buffer_size = 0;491 avci->byte_buffer_size = 0;
490 av_freep(&avci->byte_buffer);492 av_freep(&avci->byte_buffer);
491 av_frame_free(&avci->buffer_frame);493 av_frame_free(&avci->buffer_frame);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t