sub->pts = AV_NOPTS_VALUE;
}
-static int get_bit_rate(AVCodecContext *ctx)
+static int64_t get_bit_rate(AVCodecContext *ctx)
{
- int bit_rate;
+ int64_t bit_rate;
int bits_per_sample;
switch (ctx->codec_type) {
{
int ret = 0;
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
ret = avcodec_open2(avctx, codec, options);
av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
if (CONFIG_FRAME_THREAD_ENCODER) {
- ff_unlock_avcodec(); //we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
+ ff_unlock_avcodec(codec); //we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
ff_lock_avcodec(avctx, codec);
if (ret < 0)
}
if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
&& avctx->bit_rate>0 && avctx->bit_rate<1000) {
- av_log(avctx, AV_LOG_WARNING, "Bitrate %d is extremely low, maybe you mean %dk\n", avctx->bit_rate, avctx->bit_rate);
+ av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", (int64_t)avctx->bit_rate, (int64_t)avctx->bit_rate);
}
if (!avctx->rc_initial_buffer_occupancy)
}
end:
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
if (options) {
av_dict_free(options);
*options = tmp;
const char *codec_name;
const char *profile = NULL;
const AVCodec *p;
- int bitrate;
+ int64_t bitrate;
int new_line = 0;
AVRational display_aspect_ratio;
const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
bitrate = get_bit_rate(enc);
if (bitrate != 0) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d kb/s", bitrate / 1000);
+ ", %"PRId64" kb/s", bitrate / 1000);
} else if (enc->rc_max_rate > 0) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", max. %d kb/s", enc->rc_max_rate / 1000);
+ ", max. %"PRId64" kb/s", (int64_t)enc->rc_max_rate / 1000);
}
}
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
{
+ if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)
+ return 0;
+
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
return -1;
}
- if (avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, 1) != 1 &&
- !(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
+ if (avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, 1) != 1) {
av_log(log_ctx, AV_LOG_ERROR,
"Insufficient thread locking. At least %d threads are "
"calling avcodec_open2() at the same time right now.\n",
if (!lockmgr_cb)
av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
ff_avcodec_locked = 1;
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
return AVERROR(EINVAL);
}
av_assert0(!ff_avcodec_locked);
return 0;
}
-int ff_unlock_avcodec(void)
+int ff_unlock_avcodec(const AVCodec *codec)
{
+ if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)
+ return 0;
+
av_assert0(ff_avcodec_locked);
ff_avcodec_locked = 0;
avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, -1);
#endif
-enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
-{
- AVCodec *c= avcodec_find_decoder(codec_id);
- if(!c)
- c= avcodec_find_encoder(codec_id);
- if(c)
- return c->type;
-
- if (codec_id <= AV_CODEC_ID_NONE)
- return AVMEDIA_TYPE_UNKNOWN;
- else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
- return AVMEDIA_TYPE_VIDEO;
- else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
- return AVMEDIA_TYPE_AUDIO;
- else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
- return AVMEDIA_TYPE_SUBTITLE;
-
- return AVMEDIA_TYPE_UNKNOWN;
-}
-
int avcodec_is_open(AVCodecContext *s)
{
return !!s->internal;