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
33
38
39 /**
40 * Set the threading algorithms used.
41 *
42 * Threading requires more than one thread.
43 * Frame threading requires entire frames to be passed to the codec,
44 * and introduces extra decoding delay, so is incompatible with low_delay.
45 *
46 * @param avctx The context.
47 */
49 {
63 }
64
67 "Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",
69 }
70
72 {
74
79
80 return 0;
81 }
82
84 {
87 else
89 }
90
92 {
93 unsigned cnt = *(
unsigned*)((
char*)obj +
offsets[0]);
94 const unsigned *cur_offset =
offsets;
95
96 *(
unsigned*)((
char*)obj +
offsets[0]) = 0;
97
102 }
103
105 {
106 const unsigned *cur_offset =
offsets;
107 unsigned cnt = 0;
108 int err;
109
110 #define PTHREAD_INIT_LOOP(type) \
111 for (; *(++cur_offset) != THREAD_SENTINEL; cnt++) { \
112 pthread_ ## type ## _t *dst = (void*)((char*)obj + *cur_offset); \
113 err = pthread_ ## type ## _init(dst, NULL); \
114 if (err) { \
115 err = AVERROR(err); \
116 goto fail; \
117 } \
118 }
121
123 *(
unsigned*)((
char*)obj +
offsets[0]) = cnt;
124 return err;
125 }