@@ -48,6 +48,7 @@ struct AllocSize {
48
48
class MTSDecoderTSDemux : public AudioDecoder {
49
49
public:
50
50
MTSDecoderTSDemux () { self = this ; };
51
+ MTSDecoderTSDemux (AudioDecoder &dec) { p_dec = &dec; };
51
52
52
53
bool begin () override {
53
54
TRACED ();
@@ -56,6 +57,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
56
57
end ();
57
58
}
58
59
60
+ if (p_dec) p_dec->begin ();
61
+
59
62
is_active = true ;
60
63
61
64
// create the pids we plan on printing
@@ -94,6 +97,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
94
97
95
98
void end () override {
96
99
TRACED ();
100
+ if (p_dec) p_dec->begin ();
101
+
97
102
// finally end the demux process which will flush any remaining PES data.
98
103
tsd_demux_end (&ctx);
99
104
@@ -109,7 +114,7 @@ class MTSDecoderTSDemux : public AudioDecoder {
109
114
110
115
size_t write (const uint8_t *data, size_t len) override {
111
116
if (!is_active) return 0 ;
112
- LOGD (" MTSDecoder ::write: %d" , (int )len);
117
+ LOGD (" MTSDecoderTSDemux ::write: %d" , (int )len);
113
118
size_t result = buffer.writeArray ((uint8_t *)data, len);
114
119
// demux
115
120
demux (underflowLimit);
@@ -141,8 +146,35 @@ class MTSDecoderTSDemux : public AudioDecoder {
141
146
// / Activate logging for memory allocations
142
147
void setMemoryAllocationLogging (bool flag) { is_alloc_active = flag; }
143
148
149
+ // / Defines where the decoded result is written to
150
+ void setOutput (AudioStream &out_stream) override {
151
+ if (p_dec) {
152
+ p_dec->setOutput (out_stream);
153
+ } else {
154
+ AudioDecoder::setOutput (out_stream);
155
+ }
156
+ }
157
+
158
+ // / Defines where the decoded result is written to
159
+ void setOutput (AudioOutput &out_stream) override {
160
+ if (p_dec) {
161
+ p_dec->setOutput (out_stream);
162
+ } else {
163
+ AudioDecoder::setOutput (out_stream);
164
+ }
165
+ }
166
+
167
+ // / Defines where the decoded result is written to
168
+ void setOutput (Print &out_stream) override {
169
+ if (p_dec) {
170
+ p_dec->setOutput (out_stream);
171
+ } else {
172
+ AudioDecoder::setOutput (out_stream);
173
+ }
174
+ }
175
+
144
176
protected:
145
- static MTSDecoder *self;
177
+ static MTSDecoderTSDemux *self;
146
178
int underflowLimit = MTS_UNDERFLOW_LIMIT;
147
179
bool is_active = false ;
148
180
bool is_write_active = false ;
@@ -152,6 +184,7 @@ class MTSDecoderTSDemux : public AudioDecoder {
152
184
SingleBuffer<uint8_t > buffer{MTS_WRITE_BUFFER_SIZE};
153
185
Vector<TSDPMTStreamType> stream_types;
154
186
Vector<AllocSize> alloc_vector;
187
+ AudioDecoder *p_dec = nullptr ;
155
188
156
189
void set_write_active (bool flag) {
157
190
// LOGD("is_write_active: %s", flag ? "true":"false");
@@ -240,8 +273,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
240
273
static void event_cb (TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id,
241
274
void *data) {
242
275
TRACED ();
243
- if (MTSDecoder ::self != nullptr ) {
244
- MTSDecoder ::self->event_cb_local (ctx, pid, event_id, data);
276
+ if (MTSDecoderTSDemux ::self != nullptr ) {
277
+ MTSDecoderTSDemux ::self->event_cb_local (ctx, pid, event_id, data);
245
278
}
246
279
}
247
280
@@ -288,6 +321,16 @@ class MTSDecoderTSDemux : public AudioDecoder {
288
321
TRACEE ();
289
322
}
290
323
}
324
+ if (p_dec != nullptr ) {
325
+ // size_t eff = p_print->write(pes->data_bytes,
326
+ // pes->data_bytes_length);
327
+ size_t eff = writeDataT<uint8_t ,AudioDecoder>(
328
+ p_dec, (uint8_t *)pes->data_bytes , pes->data_bytes_length );
329
+ if (eff != pes->data_bytes_length ) {
330
+ // we should not get here
331
+ TRACEE ();
332
+ }
333
+ }
291
334
}
292
335
}
293
336
@@ -974,6 +1017,6 @@ class MTSDecoderTSDemux : public AudioDecoder {
974
1017
// }
975
1018
};
976
1019
// init static variable
977
- MTSDecoder *MTSDecoder ::self = nullptr ;
1020
+ MTSDecoderTSDemux *MTSDecoderTSDemux ::self = nullptr ;
978
1021
979
1022
} // namespace audio_tools
0 commit comments