-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstreams.h
92 lines (77 loc) · 2.91 KB
/
streams.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* VBAN Receiver
*
* Copyright (C) 2017 Raman Shyshniou <rommer@ibuffed.com>
* All Rights Reserved.
*
* This 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; either version 2 of the License, or
* (at your option) any later version.
*
* This software 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 software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
#ifndef _STREAMS_H
#define _STREAMS_H 1
#include <time.h>
#include <stdint.h>
#include <net/if.h>
#include <sys/socket.h>
#include "vban.h"
/*
* Streams
*/
struct packet {
char *data; // packet data
int sent; // sent to output
};
struct stream {
// remote address
struct sockaddr_storage peer;
// receiving interface
char ifname[IF_NAMESIZE];
unsigned ifindex;
// stream name
char name[20];
// audio data
long frames; /* frames per packet */
long frame_size; /* frame size in bytes (i.e. one set of samples, one for each channel). */
long sample_size; /* sample size in bytes */
long sample_rate; /* sample rate */
long channels; /* channels */
long pktsize; /* total bytes in one packet (i.e. frames * frame_size) */
long format; /* sample format */
char *format_name; /* sample format name */
// stream counters
long lost; // total lost packets counter
uint32_t expected; // next expected packet number in this stream
struct packet curr; // current packet in stream
struct packet prev; // previous packet in stream
struct timespec ts_first; // first packet received time
struct timespec ts_last; // last packet received time
// statistics
double ewma_a1; // exponential moving average coefficients:
double ewma_a2; // 30 seconds average = 2 / (1 + pps * 30)
double dt_average; // average nanoseconds between packets, EWMA
double dt_variance; // average variance between packets, EWMV
// synchronization
long ignore; // ignore this stream
long insync; // synchronized with primary stream
int64_t offset; // stream offset
// next stream
struct stream *next;
};
extern struct stream *streams;
void forgetstreams(void);
void forgetstream(struct stream *);
struct stream *getstream(struct vbaninfo *, struct sockaddr *, unsigned ifindex);
struct stream *recvvban(int);
#endif