9c3d33d6 |
/* |
406792e7 |
* Copyright (c) 2004 Roman Shaposhnik |
b38f008e |
* Copyright (c) 2008 Alexander Strange (astrange@ithinksw.com) |
115329f1 |
* |
a8eb52a8 |
* Many thanks to Steven M. Schultz for providing clever ideas and
* to Michael Niedermayer <michaelni@gmx.at> for writing initial
* implementation. |
9c3d33d6 |
* |
b78e7197 |
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or |
9c3d33d6 |
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either |
b78e7197 |
* version 2.1 of the License, or (at your option) any later version. |
9c3d33d6 |
* |
b78e7197 |
* FFmpeg is distributed in the hope that it will be useful, |
9c3d33d6 |
* 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 |
b78e7197 |
* License along with FFmpeg; if not, write to the Free Software |
5509bffa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
9c3d33d6 |
*/ |
b38f008e |
/**
* @file
* Multithreading support functions
* @see doc/multithreading.txt
*/
|
9c3d33d6 |
#include "avcodec.h" |
b93cb838 |
#include "internal.h" |
cc14ee03 |
#include "pthread_internal.h" |
b38f008e |
#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)
{ |
def97856 |
int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) |
7c6eb0a1 |
&& !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)
&& !(avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
&& !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS); |
b38f008e |
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; |
def97856 |
} else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS && |
94f7451a |
avctx->thread_type & FF_THREAD_SLICE) { |
b38f008e |
avctx->active_thread_type = FF_THREAD_SLICE; |
def97856 |
} else if (!(avctx->codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) { |
b4d44a45 |
avctx->thread_count = 1;
avctx->active_thread_type = 0; |
b38f008e |
} |
b68c4ac2 |
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); |
b38f008e |
}
|
46027c72 |
int ff_thread_init(AVCodecContext *avctx) |
b38f008e |
{ |
db8e336e |
validate_thread_parameters(avctx); |
b38f008e |
|
db8e336e |
if (avctx->active_thread_type&FF_THREAD_SLICE) |
cc14ee03 |
return ff_slice_thread_init(avctx); |
db8e336e |
else if (avctx->active_thread_type&FF_THREAD_FRAME) |
cc14ee03 |
return ff_frame_thread_init(avctx); |
b38f008e |
return 0;
}
|
043d2ff2 |
void ff_thread_free(AVCodecContext *avctx) |
b38f008e |
{
if (avctx->active_thread_type&FF_THREAD_FRAME) |
cc14ee03 |
ff_frame_thread_free(avctx, avctx->thread_count); |
b38f008e |
else |
cc14ee03 |
ff_slice_thread_free(avctx); |
e146c326 |
} |