mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
444e9874a7
* commit 'def97856de6021965db86c25a732d78689bd6bb0': lavc: AV-prefix all codec capabilities Conflicts: cmdutils.c ffmpeg.c ffplay.c libavcodec/8svx.c libavcodec/aacenc.c libavcodec/ac3dec.c libavcodec/adpcm.c libavcodec/alac.c libavcodec/atrac3plusdec.c libavcodec/bink.c libavcodec/dnxhddec.c libavcodec/dvdec.c libavcodec/dvenc.c libavcodec/ffv1dec.c libavcodec/ffv1enc.c libavcodec/fic.c libavcodec/flacdec.c libavcodec/flacenc.c libavcodec/flvdec.c libavcodec/fraps.c libavcodec/frwu.c libavcodec/gifdec.c libavcodec/h261dec.c libavcodec/hevc.c libavcodec/iff.c libavcodec/imc.c libavcodec/libopenjpegdec.c libavcodec/libvo-aacenc.c libavcodec/libvorbisenc.c libavcodec/libvpxdec.c libavcodec/libvpxenc.c libavcodec/libx264.c libavcodec/mjpegbdec.c libavcodec/mjpegdec.c libavcodec/mpegaudiodec_float.c libavcodec/msmpeg4dec.c libavcodec/mxpegdec.c libavcodec/nvenc_h264.c libavcodec/nvenc_hevc.c libavcodec/pngdec.c libavcodec/qpeg.c libavcodec/ra288.c libavcodec/rv10.c libavcodec/s302m.c libavcodec/sp5xdec.c libavcodec/takdec.c libavcodec/tiff.c libavcodec/tta.c libavcodec/utils.c libavcodec/v210dec.c libavcodec/vp6.c libavcodec/vp9.c libavcodec/wavpack.c libavcodec/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
89 lines
3.1 KiB
C
89 lines
3.1 KiB
C
/*
|
|
* Copyright (c) 2004 Roman Shaposhnik
|
|
* Copyright (c) 2008 Alexander Strange (astrange@ithinksw.com)
|
|
*
|
|
* Many thanks to Steven M. Schultz for providing clever ideas and
|
|
* to Michael Niedermayer <michaelni@gmx.at> for writing initial
|
|
* implementation.
|
|
*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* Multithreading support functions
|
|
* @see doc/multithreading.txt
|
|
*/
|
|
|
|
#include "avcodec.h"
|
|
#include "internal.h"
|
|
#include "pthread_internal.h"
|
|
#include "thread.h"
|
|
|
|
/**
|
|
* Set the threading algorithms used.
|
|
*
|
|
* Threading requires more than one thread.
|
|
* Frame threading requires entire frames to be passed to the codec,
|
|
* and introduces extra decoding delay, so is incompatible with low_delay.
|
|
*
|
|
* @param avctx The context.
|
|
*/
|
|
static void validate_thread_parameters(AVCodecContext *avctx)
|
|
{
|
|
int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
|
|
&& !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)
|
|
&& !(avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
|
|
&& !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS);
|
|
if (avctx->thread_count == 1) {
|
|
avctx->active_thread_type = 0;
|
|
} else if (frame_threading_supported && (avctx->thread_type & FF_THREAD_FRAME)) {
|
|
avctx->active_thread_type = FF_THREAD_FRAME;
|
|
} else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS &&
|
|
avctx->thread_type & FF_THREAD_SLICE) {
|
|
avctx->active_thread_type = FF_THREAD_SLICE;
|
|
} else if (!(avctx->codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) {
|
|
avctx->thread_count = 1;
|
|
avctx->active_thread_type = 0;
|
|
}
|
|
|
|
if (avctx->thread_count > MAX_AUTO_THREADS)
|
|
av_log(avctx, AV_LOG_WARNING,
|
|
"Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",
|
|
avctx->thread_count, MAX_AUTO_THREADS);
|
|
}
|
|
|
|
int ff_thread_init(AVCodecContext *avctx)
|
|
{
|
|
validate_thread_parameters(avctx);
|
|
|
|
if (avctx->active_thread_type&FF_THREAD_SLICE)
|
|
return ff_slice_thread_init(avctx);
|
|
else if (avctx->active_thread_type&FF_THREAD_FRAME)
|
|
return ff_frame_thread_init(avctx);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void ff_thread_free(AVCodecContext *avctx)
|
|
{
|
|
if (avctx->active_thread_type&FF_THREAD_FRAME)
|
|
ff_frame_thread_free(avctx, avctx->thread_count);
|
|
else
|
|
ff_slice_thread_free(avctx);
|
|
}
|