UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
src
utils
parallel_conv.c
Go to the documentation of this file.
1
5
/*
6
* Copyright (c) 2021-2023 CESNET, z. s. p. o.
7
* All rights reserved.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, is permitted provided that the following conditions
11
* are met:
12
*
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
*
16
* 2. Redistributions in binary form must reproduce the above copyright
17
* notice, this list of conditions and the following disclaimer in the
18
* documentation and/or other materials provided with the distribution.
19
*
20
* 3. Neither the name of CESNET nor the names of its contributors may be
21
* used to endorse or promote products derived from this software without
22
* specific prior written permission.
23
*
24
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
*/
37
38
#include <assert.h>
39
40
#include "
utils/misc.h
"
41
#include "
utils/parallel_conv.h
"
42
#include "
utils/worker.h
"
43
44
struct
parallel_pix_conv_data
{
45
decoder_t
decode
;
46
int
height
;
47
unsigned
char
*
out_data
;
48
int
out_linesize
;
49
const
unsigned
char
*
in_data
;
50
int
in_linesize
;
51
};
52
53
static
void
*
parallel_pix_conv_task
(
void
*arg) {
54
struct
parallel_pix_conv_data
*data = arg;
55
for
(
int
y = 0; y < data->
height
; ++y) {
56
data->
decode
(data->
out_data
, data->
in_data
, data->
out_linesize
,
DEFAULT_R_SHIFT
,
DEFAULT_G_SHIFT
,
DEFAULT_B_SHIFT
);
57
data->
out_data
+= data->
out_linesize
;
58
data->
in_data
+= data->
in_linesize
;
59
}
60
return
NULL;
61
}
62
64
void
parallel_pix_conv
(
int
height
,
char
*out,
int
out_linesize
,
const
char
*in,
int
in_linesize
,
decoder_t
decode
,
int
threads)
65
{
66
if
(threads == 0) {
67
threads =
get_cpu_core_count
();
68
}
69
assert(threads > 0);
70
struct
parallel_pix_conv_data
data[threads];
71
72
for
(ptrdiff_t i = 0; i < threads; ++i) {
73
data[i].
decode
=
decode
;
74
data[i].
height
=
height
/ threads;
75
data[i].
out_data
= (
unsigned
char
*) out + i * data[i].
height
*
out_linesize
;
76
data[i].
out_linesize
=
out_linesize
;
77
data[i].
in_data
= (
const
unsigned
char
*) in + i * data[i].
height
*
in_linesize
;
78
data[i].
in_linesize
=
in_linesize
;
79
if
(i == threads - 1) {
80
data[i].
height
=
height
- (threads - 1) * (
height
/ threads);
81
}
82
}
83
84
task_run_parallel
(
parallel_pix_conv_task
, threads, data,
sizeof
data[0], NULL);
85
}
86
get_cpu_core_count
int get_cpu_core_count(void)
Definition
misc.cpp:218
parallel_pix_conv_task
static void * parallel_pix_conv_task(void *arg)
Definition
parallel_conv.c:53
parallel_pix_conv
void parallel_pix_conv(int height, char *out, int out_linesize, const char *in, int in_linesize, decoder_t decode, int threads)
Definition
parallel_conv.c:64
parallel_conv.h
DEFAULT_B_SHIFT
#define DEFAULT_B_SHIFT
Definition
pixfmt_conv.h:72
DEFAULT_R_SHIFT
#define DEFAULT_R_SHIFT
Definition
pixfmt_conv.h:70
decoder_t
decoder_func_t * decoder_t
Definition
pixfmt_conv.h:96
DEFAULT_G_SHIFT
#define DEFAULT_G_SHIFT
Definition
pixfmt_conv.h:71
parallel_pix_conv_data
Definition
parallel_conv.c:44
parallel_pix_conv_data::in_linesize
int in_linesize
Definition
parallel_conv.c:50
parallel_pix_conv_data::out_linesize
int out_linesize
Definition
parallel_conv.c:48
parallel_pix_conv_data::in_data
const unsigned char * in_data
Definition
parallel_conv.c:49
parallel_pix_conv_data::out_data
unsigned char * out_data
Definition
parallel_conv.c:47
parallel_pix_conv_data::height
int height
Definition
parallel_conv.c:46
parallel_pix_conv_data::decode
decoder_t decode
Definition
parallel_conv.c:45
misc.h
task_run_parallel
void task_run_parallel(runnable_t task, int worker_count, void *data, size_t data_size, void **res)
Definition
worker.cpp:294
worker.h
Generated on Wed Sep 25 2024 14:27:19 for UltraGrid by
1.12.0