UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
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
46 int height;
47 unsigned char *out_data;
49 const unsigned char *in_data;
51};
52
53static void *parallel_pix_conv_task(void *arg) {
54 struct parallel_pix_conv_data *data = arg;
55 for (int y = 0; y < data->height; ++y) {
57 data->out_data += data->out_linesize;
58 data->in_data += data->in_linesize;
59 }
60 return NULL;
61}
62
64void 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
int get_cpu_core_count(void)
Definition misc.cpp:218
static void * parallel_pix_conv_task(void *arg)
void parallel_pix_conv(int height, char *out, int out_linesize, const char *in, int in_linesize, decoder_t decode, int threads)
#define DEFAULT_B_SHIFT
Definition pixfmt_conv.h:72
#define DEFAULT_R_SHIFT
Definition pixfmt_conv.h:70
decoder_func_t * decoder_t
Definition pixfmt_conv.h:96
#define DEFAULT_G_SHIFT
Definition pixfmt_conv.h:71
const unsigned char * in_data
unsigned char * out_data
void task_run_parallel(runnable_t task, int worker_count, void *data, size_t data_size, void **res)
Definition worker.cpp:294