1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2004 Roman Shaposhnik |
3 |
|
|
* Copyright (c) 2008 Alexander Strange (astrange@ithinksw.com) |
4 |
|
|
* |
5 |
|
|
* Many thanks to Steven M. Schultz for providing clever ideas and |
6 |
|
|
* to Michael Niedermayer <michaelni@gmx.at> for writing initial |
7 |
|
|
* implementation. |
8 |
|
|
* |
9 |
|
|
* This file is part of FFmpeg. |
10 |
|
|
* |
11 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
12 |
|
|
* modify it under the terms of the GNU Lesser General Public |
13 |
|
|
* License as published by the Free Software Foundation; either |
14 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
15 |
|
|
* |
16 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
17 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 |
|
|
* Lesser General Public License for more details. |
20 |
|
|
* |
21 |
|
|
* You should have received a copy of the GNU Lesser General Public |
22 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
23 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* @file |
28 |
|
|
* Multithreading support functions |
29 |
|
|
* @see doc/multithreading.txt |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
#include "avcodec.h" |
33 |
|
|
#include "internal.h" |
34 |
|
|
#include "pthread_internal.h" |
35 |
|
|
#include "thread.h" |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* Set the threading algorithms used. |
39 |
|
|
* |
40 |
|
|
* Threading requires more than one thread. |
41 |
|
|
* Frame threading requires entire frames to be passed to the codec, |
42 |
|
|
* and introduces extra decoding delay, so is incompatible with low_delay. |
43 |
|
|
* |
44 |
|
|
* @param avctx The context. |
45 |
|
|
*/ |
46 |
|
18797 |
static void validate_thread_parameters(AVCodecContext *avctx) |
47 |
|
|
{ |
48 |
|
37594 |
int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) |
49 |
✓✗ |
3054 |
&& !(avctx->flags & AV_CODEC_FLAG_TRUNCATED) |
50 |
✓✗ |
3054 |
&& !(avctx->flags & AV_CODEC_FLAG_LOW_DELAY) |
51 |
✓✓✓✓
|
21851 |
&& !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS); |
52 |
✓✓ |
18797 |
if (avctx->thread_count == 1) { |
53 |
|
16217 |
avctx->active_thread_type = 0; |
54 |
✓✓✓✗
|
2580 |
} else if (frame_threading_supported && (avctx->thread_type & FF_THREAD_FRAME)) { |
55 |
|
12 |
avctx->active_thread_type = FF_THREAD_FRAME; |
56 |
✓✓ |
2568 |
} else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS && |
57 |
✓✗ |
16 |
avctx->thread_type & FF_THREAD_SLICE) { |
58 |
|
16 |
avctx->active_thread_type = FF_THREAD_SLICE; |
59 |
✓✗ |
2552 |
} else if (!(avctx->codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) { |
60 |
|
2552 |
avctx->thread_count = 1; |
61 |
|
2552 |
avctx->active_thread_type = 0; |
62 |
|
|
} |
63 |
|
|
|
64 |
✗✓ |
18797 |
if (avctx->thread_count > MAX_AUTO_THREADS) |
65 |
|
|
av_log(avctx, AV_LOG_WARNING, |
66 |
|
|
"Application has requested %d threads. Using a thread count greater than %d is not recommended.\n", |
67 |
|
|
avctx->thread_count, MAX_AUTO_THREADS); |
68 |
|
18797 |
} |
69 |
|
|
|
70 |
|
18797 |
int ff_thread_init(AVCodecContext *avctx) |
71 |
|
|
{ |
72 |
|
18797 |
validate_thread_parameters(avctx); |
73 |
|
|
|
74 |
✓✓ |
18797 |
if (avctx->active_thread_type&FF_THREAD_SLICE) |
75 |
|
16 |
return ff_slice_thread_init(avctx); |
76 |
✓✓ |
18781 |
else if (avctx->active_thread_type&FF_THREAD_FRAME) |
77 |
|
12 |
return ff_frame_thread_init(avctx); |
78 |
|
|
|
79 |
|
18769 |
return 0; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
28 |
void ff_thread_free(AVCodecContext *avctx) |
83 |
|
|
{ |
84 |
✓✓ |
28 |
if (avctx->active_thread_type&FF_THREAD_FRAME) |
85 |
|
12 |
ff_frame_thread_free(avctx, avctx->thread_count); |
86 |
|
|
else |
87 |
|
16 |
ff_slice_thread_free(avctx); |
88 |
|
28 |
} |