forked from nostar/tcd
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTranscoderPacket.cpp
More file actions
194 lines (161 loc) · 3.88 KB
/
TranscoderPacket.cpp
File metadata and controls
194 lines (161 loc) · 3.88 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// tcd - a hybid transcoder using DVSI hardware and Codec2 software
// Copyright © 2021 Thomas A. Early N7TAE
// 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, either version 3 of the License, or
// (at your option) any later version.
// 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 <https://www.gnu.org/licenses/>.
#include <arpa/inet.h>
#include <iostream>
#include "TranscoderPacket.h"
CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), dmr_set(false), p25_set(false), m17_set(false), usrp_set(false), not_sent(true)
{
tcpacket.module = tcp.module;
tcpacket.is_last = tcp.is_last;
tcpacket.streamid = tcp.streamid;
tcpacket.codec_in = tcp.codec_in;
tcpacket.sequence = tcp.sequence;
switch (tcp.codec_in)
{
case ECodecType::dstar:
SetDStarData(tcp.dstar);
break;
case ECodecType::dmr:
SetDMRData(tcp.dmr);
break;
case ECodecType::p25:
SetP25Data(tcp.p25);
break;
case ECodecType::usrp:
SetUSRPData(tcp.usrp);
break;
case ECodecType::c2_1600:
case ECodecType::c2_3200:
SetM17Data(tcp.m17);
break;
default:
std::cerr << "Trying to allocate CTranscoderPacket with an unknown codec type!" << std::endl;
break;
}
}
char CTranscoderPacket::GetModule() const
{
return tcpacket.module;
}
const uint8_t *CTranscoderPacket::GetDStarData() const
{
return tcpacket.dstar;
}
const uint8_t *CTranscoderPacket::GetDMRData() const
{
return tcpacket.dmr;
}
const uint8_t *CTranscoderPacket::GetP25Data() const
{
return tcpacket.p25;
}
const int16_t *CTranscoderPacket::GetUSRPData() const
{
return tcpacket.usrp;
}
const uint8_t *CTranscoderPacket::GetM17Data() const
{
return tcpacket.m17;
}
const STCPacket *CTranscoderPacket::GetTCPacket() const
{
return &tcpacket;
}
void CTranscoderPacket::SetM17Data(const uint8_t *data)
{
memcpy(tcpacket.m17, data, 16);
m17_set = true;
}
void CTranscoderPacket::SetDStarData(const uint8_t *dstar)
{
memcpy(tcpacket.dstar, dstar, 9);
dstar_set = true;
}
void CTranscoderPacket::SetDMRData(const uint8_t *dmr)
{
memcpy(tcpacket.dmr, dmr, 9);
dmr_set = true;
}
void CTranscoderPacket::SetP25Data(const uint8_t *p25)
{
memcpy(tcpacket.p25, p25, 11);
p25_set = true;
}
void CTranscoderPacket::SetUSRPData(const int16_t *usrp)
{
for(int i = 0; i < 160; ++i){
tcpacket.usrp[i] = usrp[i];
}
usrp_set = true;
}
void CTranscoderPacket::SetAudioSamples(const int16_t *sample, bool swap)
{
for (unsigned int i=0; i<160; i++)
audio[i] = swap ? ntohs(sample[i]) : sample[i];
}
const int16_t *CTranscoderPacket::GetAudioSamples() const
{
return audio;
}
ECodecType CTranscoderPacket::GetCodecIn() const
{
return tcpacket.codec_in;
}
uint16_t CTranscoderPacket::GetStreamId() const
{
return tcpacket.streamid;
}
uint32_t CTranscoderPacket::GetSequence() const
{
return tcpacket.sequence;
}
bool CTranscoderPacket::IsLast() const
{
return tcpacket.is_last;
}
bool CTranscoderPacket::IsSecond() const
{
return (1 == tcpacket.sequence % 2);
}
bool CTranscoderPacket::DStarIsSet() const
{
return dstar_set;
}
bool CTranscoderPacket::DMRIsSet() const
{
return dmr_set;
}
bool CTranscoderPacket::P25IsSet() const
{
return p25_set;
}
bool CTranscoderPacket::USRPIsSet() const
{
return usrp_set;
}
bool CTranscoderPacket::M17IsSet() const
{
return m17_set;
}
bool CTranscoderPacket::AllCodecsAreSet() const
{
return (dstar_set && dmr_set && m17_set && p25_set && usrp_set);
}
void CTranscoderPacket::Sent()
{
not_sent = false;
}
bool CTranscoderPacket::HasNotBeenSent() const
{
return not_sent;
}