MediaProcessors
proc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 2018 Rafael Antoniello
3  *
4  * This file is part of MediaProcessors.
5  *
6  * MediaProcessors is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * MediaProcessors is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MediaProcessors. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
48 #ifndef MEDIAPROCESSORS_SRC_PROC_H_
49 #define MEDIAPROCESSORS_SRC_PROC_H_
50 
51 #include <stdarg.h>
52 #include <pthread.h>
53 #include <libmediaprocsutils/mem_utils.h>
54 
55 /* **** Definitions **** */
56 
57 /* Forward definitions */
58 typedef struct proc_if_s proc_if_t;
59 typedef struct log_ctx_s log_ctx_t;
60 typedef struct fifo_ctx_s fifo_ctx_t;
61 typedef struct fair_lock_s fair_lock_t;
62 typedef struct proc_frame_ctx_s proc_frame_ctx_t;
64 
70 #define CJSON_PRINT(CJSON_PTR) cJSON_Print(CJSON_PTR)
71 //#define CJSON_PRINT(CJSON_PTR) cJSON_PrintUnformatted(CJSON_PTR)
72 
76 typedef enum {
77  PROC_IPUT= 0,
78  PROC_OPUT= 1,
79  PROC_IO_NUM= 2
80 } proc_io_t;
81 
85 typedef struct proc_ctx_s {
99  pthread_mutex_t api_mutex;
107  fifo_ctx_t *fifo_ctx_array[PROC_IO_NUM];
113 
121  volatile uint32_t bitrate[PROC_IO_NUM];
122  volatile uint32_t acc_io_bits[PROC_IO_NUM];
123  pthread_mutex_t acc_io_bits_mutex[PROC_IO_NUM];
125 
126 
131 #define IPUT_PTS_ARRAY_SIZE 128
132 #define IPUT_PTS_VAL 0
133 #define IPUT_PTS_STC_VAL 1
134  int64_t iput_pts_array[2][IPUT_PTS_ARRAY_SIZE];
135  volatile int iput_pts_array_idx;
137 
138 
148  volatile int64_t latency_avg_usec;
149  volatile int64_t latency_max_usec;
150  volatile int64_t latency_min_usec;
151  volatile int64_t acc_latency_nsec;
152  volatile int acc_latency_cnt;
153  pthread_mutex_t latency_mutex;
155 
156 
163  pthread_t stats_thread;
165 
169  volatile int flag_exit;
173  pthread_t proc_thread;
181  const void*(*start_routine)(void *);
182 } proc_ctx_t;
183 
184 /* **** Prototypes **** */
185 
204 proc_ctx_t* proc_open(const proc_if_t *proc_if, const char *settings_str,
205  int proc_instance_index, uint32_t fifo_ctx_maxsize[PROC_IO_NUM],
206  log_ctx_t *log_ctx, va_list arg);
207 
215 void proc_close(proc_ctx_t **ref_proc_ctx);
216 
231 int proc_send_frame(proc_ctx_t *proc_ctx,
232  const proc_frame_ctx_t *proc_frame_ctx);
233 
247 int proc_recv_frame(proc_ctx_t *proc_ctx,
248  proc_frame_ctx_t **ref_proc_frame_ctx);
249 
291 int proc_opt(proc_ctx_t *proc_ctx, const char *tag, ...);
292 
299 int proc_vopt(proc_ctx_t *proc_ctx, const char *tag, va_list arg);
300 
301 /* **** Utilities ****
302  * The following functions are available to be used by the specific
303  * implementations of the processor, but are not part of the public processor
304  * API.
305  */
306 
307 int proc_send_frame_default1(proc_ctx_t *proc_ctx,
308  const proc_frame_ctx_t *proc_frame_ctx);
309 
310 int proc_recv_frame_default1(proc_ctx_t *proc_ctx,
311  proc_frame_ctx_t **ref_proc_frame_ctx);
312 
313 void proc_stats_register_accumulated_latency(proc_ctx_t *proc_ctx,
314  const int64_t oput_frame_pts);
315 
316 #endif /* MEDIAPROCESSORS_SRC_PROC_H_ */
volatile int64_t latency_avg_usec
Definition: proc.h:148
proc_ctx_t * proc_open(const proc_if_t *proc_if, const char *settings_str, int proc_instance_index, uint32_t fifo_ctx_maxsize[PROC_IO_NUM], log_ctx_t *log_ctx, va_list arg)
Definition: proc.c:87
pthread_t proc_thread
Definition: proc.h:173
pthread_t stats_thread
Definition: proc.h:163
struct proc_ctx_s proc_ctx_t
proc_io_t
Definition: proc.h:76
#define IPUT_PTS_ARRAY_SIZE
Definition: proc.h:131
pthread_mutex_t api_mutex
Definition: proc.h:99
int proc_vopt(proc_ctx_t *proc_ctx, const char *tag, va_list arg)
Definition: proc.c:382
volatile int flag_exit
Definition: proc.h:169
interr_usleep_ctx_t * interr_usleep_ctx
Definition: proc.h:159
const proc_if_t * proc_if
Definition: proc.h:89
fifo_ctx_t * fifo_ctx_array[PROC_IO_NUM]
Definition: proc.h:107
int proc_instance_index
Definition: proc.h:95
void proc_close(proc_ctx_t **ref_proc_ctx)
Definition: proc.c:208
Definition: log.c:102
int proc_opt(proc_ctx_t *proc_ctx, const char *tag,...)
Definition: proc.c:368
int proc_send_frame(proc_ctx_t *proc_ctx, const proc_frame_ctx_t *proc_frame_ctx)
Definition: proc.c:287
fair_lock_t * fair_lock_io_array[PROC_IO_NUM]
Definition: proc.h:111
volatile uint32_t bitrate[PROC_IO_NUM]
Definition: proc.h:121
log_ctx_t * log_ctx
Definition: proc.h:103
int proc_recv_frame(proc_ctx_t *proc_ctx, proc_frame_ctx_t **ref_proc_frame_ctx)
Definition: proc.c:323