-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathac3_sink.h
73 lines (56 loc) · 1.96 KB
/
ac3_sink.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* This file is part of audio_async_loopback
* Copyright (c) 2020 Jacob Moroni.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AC3_SINK_H_
#define _AC3_SINK_H_
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <pthread.h>
#include <samplerate.h>
#include <pulse/simple.h>
#include <libavcodec/avcodec.h>
#include "config.h"
#define AC3_SINK_NUM_CHANNELS 6
struct ac3_sink {
pthread_mutex_t lock;
pthread_t thread;
pthread_cond_t cond;
bool thread_run;
SRC_STATE *rate_converter[AC3_SINK_NUM_CHANNELS];
pa_simple *pa_inst;
/* This needs to be large enough to store an entire AC3 frame worth of
* samples _after_ resampling. The AC3 frames are typically 1536 samples,
* so add some padding to account for a ratio > 1.
*/
float tmp_output_buf[AC3_SINK_NUM_CHANNELS][4096];
float buffer[AC3_SINK_SAMPLE_BUFFER_SIZE];
uint32_t read_idx;
uint32_t write_idx;
SRC_DATA src_data;
const AVCodec *codec;
AVCodecContext *cctx;
AVPacket *packet;
AVFrame *frame;
int32_t history[AC3_SINK_BUFFER_HIST_SIZE];
uint32_t histidx;
int32_t average; /* Informational only */
};
void ac3_sink_open(struct ac3_sink *inst, uint32_t latency_us);
void ac3_sink_close(struct ac3_sink *inst);
/* Data is a pointer to a complete AC3 frame. */
void ac3_sink_process(struct ac3_sink *inst, uint8_t *data, size_t len);
#endif /* _AC3_SINK_H_ */