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
9494
9595 static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
9696
97−static void lock_avcodec(const AVCodec *codec)
97+static void lock_avcodec(const FFCodec *codec)
9898 {
9999 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)
100100 ff_mutex_lock(&codec_mutex);
101101 }
102102
103−static void unlock_avcodec(const AVCodec *codec)
103+static void unlock_avcodec(const FFCodec *codec)
104104 {
105105 if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init)
106106 ff_mutex_unlock(&codec_mutex);
@@ -140,6 +140,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 33 unmodified lines
140140 {
141141 int ret = 0;
142142 AVCodecInternal *avci;
143+ const FFCodec *codec2;
143144
144145 if (avcodec_is_open(avctx))
145146 return 0;
@@ -155,6 +156,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 9 unmodified lines
155156 }
156157 if (!codec)
157158 codec = avctx->codec;
159+ codec2 = ffcodec(codec);
158160
159161 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
160162 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
194196
195197 avci->skip_samples_multiplier = 1;
196198
197− if (codec->priv_data_size > 0) {
199+ if (codec2->priv_data_size > 0) {
198200 if (!avctx->priv_data) {
199− avctx->priv_data = av_mallocz(codec->priv_data_size);
201+ avctx->priv_data = av_mallocz(codec2->priv_data_size);
200202 if (!avctx->priv_data) {
201203 ret = AVERROR(ENOMEM);
202204 goto free_and_end;
@@ -327,25 +329,25 @@ FF_ENABLE_DEPRECATION_WARNINGS · 124 unmodified lines
327329
328330 if (HAVE_THREADS
329331 && !(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);
332334 ret = ff_thread_init(avctx);
333− unlock_avcodec(codec);
335+ unlock_avcodec(codec2);
334336 if (ret < 0) {
335337 goto free_and_end;
336338 }
337339 }
338− if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
340+ if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
339341 avctx->thread_count = 1;
340342
341343 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
342344 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);
347349 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;
349351 goto free_and_end;
350352 }
351353 }
@@ -439,8 +441,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx) · 87 unmodified lines
439441
440442 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
441443 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);
444446
445447 avctx->pts_correction_last_pts =
446448 avctx->pts_correction_last_dts = INT64_MIN;
@@ -484,8 +486,8 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 37 unmodified lines
484486 }
485487 if (HAVE_THREADS && avci->thread_ctx)
486488 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);
489491 avci->byte_buffer_size = 0;
490492 av_freep(&avci->byte_buffer);
491493 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