avformat/mpeg: demux ivtv captions
[ffmpeg.git] / libavcodec / pthread_internal.h
blobd0b6a7a673b69980631e9c154804a031c7ac7dab
1 /*
2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVCODEC_PTHREAD_INTERNAL_H
20 #define AVCODEC_PTHREAD_INTERNAL_H
22 #include "avcodec.h"
24 /* H.264 slice threading seems to be buggy with more than 16 threads,
25 * limit the number of threads to 16 for automatic detection */
26 #define MAX_AUTO_THREADS 16
28 int ff_slice_thread_init(AVCodecContext *avctx);
29 void ff_slice_thread_free(AVCodecContext *avctx);
31 int ff_frame_thread_init(AVCodecContext *avctx);
32 void ff_frame_thread_free(AVCodecContext *avctx, int thread_count);
34 #define THREAD_SENTINEL 0 // This forbids putting a mutex/condition variable at the front.
35 /**
36 * Initialize/destroy a list of mutexes/conditions contained in a structure.
37 * The positions of these mutexes/conditions in the structure are given by
38 * their offsets. Because it is undefined behaviour to destroy
39 * an uninitialized mutex/condition, ff_pthread_init() stores the number
40 * of successfully initialized mutexes and conditions in the object itself
41 * and ff_pthread_free() uses this number to destroy exactly the mutexes and
42 * condition variables that have been successfully initialized.
44 * @param obj The object containing the mutexes/conditions.
45 * @param[in] offsets An array of offsets. Its first member gives the offset
46 * of the variable that contains the count of successfully
47 * initialized mutexes/condition variables; said variable
48 * must be an unsigned int. Two arrays of offsets, each
49 * delimited by a THREAD_SENTINEL follow. The first
50 * contains the offsets of all the mutexes, the second
51 * contains the offsets of all the condition variables.
53 int ff_pthread_init(void *obj, const unsigned offsets[]);
54 void ff_pthread_free(void *obj, const unsigned offsets[]);
56 /**
57 * Macros to help creating the above lists. mutexes and conds need
58 * to be parentheses-enclosed lists of offsets in the containing structure.
60 #define OFFSET_ARRAY(...) __VA_ARGS__, THREAD_SENTINEL
61 #define DEFINE_OFFSET_ARRAY(type, name, cnt_variable, mutexes, conds) \
62 static const unsigned name ## _offsets[] = { offsetof(type, cnt_variable), \
63 OFFSET_ARRAY mutexes, \
64 OFFSET_ARRAY conds }
66 #endif // AVCODEC_PTHREAD_INTERNAL_H