Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Configuration options:
--disable-static do not build static libraries [no]
--enable-shared build shared libraries [no]
--enable-small optimize for size instead of speed
--enable-tracy enable Tracy profiler instrumentation
--disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary)
--enable-gray enable full grayscale support (slower color)
--disable-swscale-alpha disable alpha channel support in swscale
Expand Down Expand Up @@ -2048,6 +2049,7 @@ FEATURE_LIST="
small
static
swscale_alpha
tracy
"

# this list should be kept in linking order
Expand Down Expand Up @@ -4048,7 +4050,7 @@ swscale_suggest="libm stdatomic"

avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs lcms2_extralibs"
avfilter_extralibs="pthreads_extralibs"
avutil_extralibs="d3d11va_extralibs d3d12va_extralibs mediacodec_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vaapi_win32_extralibs vdpau_x11_extralibs"
avutil_extralibs="d3d11va_extralibs d3d12va_extralibs mediacodec_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vaapi_win32_extralibs vdpau_x11_extralibs tracy_extralibs"

# programs
ffmpeg_deps="avcodec avfilter avformat threads"
Expand Down Expand Up @@ -7532,6 +7534,13 @@ EOF
fi

if [ -z "$optflags" ]; then
if enabled tracy; then
check_cppflags -DTRACY_ENABLE
tracy_extralibs="-ltracy"
if [ "$target_os" = "darwin" ]; then
tracy_extralibs="$tracy_extralibs -lc++ -lc++abi"
fi
fi
if enabled small; then
optflags=$cflags_size
elif enabled optimizations; then
Expand Down Expand Up @@ -7975,6 +7984,7 @@ fi
echo "debug symbols ${debug-no}"
echo "strip symbols ${stripping-no}"
echo "optimize for size ${small-no}"
echo "enable tracy ${tracy-no}"
echo "optimizations ${optimizations-no}"
echo "static ${static-no}"
echo "shared ${shared-no}"
Expand Down
4 changes: 4 additions & 0 deletions libavcodec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,10 @@ CLEANFILES = *_tables.c *_tables.h *_tablegen$(HOSTEXESUF)
$(SUBDIR)tests/dct$(EXESUF): $(SUBDIR)dctref.o $(SUBDIR)aandcttab.o
$(SUBDIR)dv_tablegen$(HOSTEXESUF): $(SUBDIR)dvdata_host.o

ifdef CONFIG_TRACY
$(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DTRACY_ENABLE
endif

ifdef CONFIG_SMALL
$(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=1
else
Expand Down
29 changes: 27 additions & 2 deletions libavcodec/avcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "refstruct.h"
#include "thread.h"

#include "../tracy_c.h"

/**
* Maximum size in bytes of extradata.
* This value was chosen such that every bit of the buffer is
Expand Down Expand Up @@ -142,21 +144,27 @@ static int64_t get_bit_rate(AVCodecContext *ctx)

int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
{
TRACY_ZONE_START("avcodec_open2")
int ret = 0;
AVCodecInternal *avci;
const FFCodec *codec2;
const AVDictionaryEntry *e;

if (avcodec_is_open(avctx))
{
TRACY_ZONE_END_ERROR("already_opened");
return 0;
}

if (!codec && !avctx->codec) {
av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
TRACY_ZONE_END_ERROR("no_codec_provided");
return AVERROR(EINVAL);
}
if (codec && avctx->codec && codec != avctx->codec) {
av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
"but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
TRACY_ZONE_END_ERROR("codec_mismatch");
return AVERROR(EINVAL);
}
if (!codec)
Expand All @@ -166,6 +174,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
(avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
TRACY_ZONE_END_ERROR("codec_type_id_mismatch");
return AVERROR(EINVAL);
}

Expand All @@ -174,19 +183,25 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
avctx->codec = codec;

if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
{
TRACY_ZONE_END_ERROR("invalid_extradata_size");
return AVERROR(EINVAL);
}

// set the whitelist from provided options dict,
// so we can check it immediately
e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL;
if (e) {
ret = av_opt_set(avctx, e->key, e->value, 0);
if (ret < 0)
if (ret < 0) {
TRACY_ZONE_END_ERROR("av_opt_set_failed");
return ret;
}
}

if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
TRACY_ZONE_END_ERROR("codec_not_on_whitelist");
return AVERROR(EINVAL);
}

Expand Down Expand Up @@ -364,7 +379,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);

end:

TRACY_ZONE_END_OR_ERROR_CODE_TEXT("avcodec_open2", ret);
return ret;
free_and_end:
ff_codec_close(avctx);
Expand All @@ -373,6 +388,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code

void avcodec_flush_buffers(AVCodecContext *avctx)
{
TRACY_ZONE_START("avcodec_flush_buffers")
AVCodecInternal *avci = avctx->internal;

if (av_codec_is_encoder(avctx->codec)) {
Expand All @@ -383,6 +399,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
// flushed. Otherwise, this is a no-op.
av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder "
"that doesn't support it\n");
TRACY_ZONE_END_ERROR("flush_unsupported_encoder");
return;
}
ff_encode_flush_buffers(avctx);
Expand All @@ -401,6 +418,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
ff_thread_flush(avctx);
else if (ffcodec(avctx->codec)->flush)
ffcodec(avctx->codec)->flush(avctx);
TRACY_ZONE_END;
}

void avsubtitle_free(AVSubtitle *sub)
Expand All @@ -427,12 +445,17 @@ void avsubtitle_free(AVSubtitle *sub)

av_cold void ff_codec_close(AVCodecContext *avctx)
{
TRACY_ZONE_START("ff_codec_close")
int i;

if (!avctx)
{
TRACY_ZONE_END_ERROR("ff_codec_close: avctx is NULL");
return;
}

if (avcodec_is_open(avctx)) {
TRACY_ZONE_START_CTX(tracy_ctx_open, "is_open")
AVCodecInternal *avci = avctx->internal;

if (CONFIG_FRAME_THREAD_ENCODER &&
Expand Down Expand Up @@ -471,6 +494,7 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
#endif

av_freep(&avctx->internal);
TRACY_ZONE_END_CTX(tracy_ctx_open);
}

for (i = 0; i < avctx->nb_coded_side_data; i++)
Expand All @@ -495,6 +519,7 @@ av_cold void ff_codec_close(AVCodecContext *avctx)

avctx->codec = NULL;
avctx->active_thread_type = 0;
TRACY_ZONE_END;
}

#if FF_API_AVCODEC_CLOSE
Expand Down
Loading