@@ -48,6 +48,7 @@ struct AllocSize {
4848class MTSDecoderTSDemux : public AudioDecoder {
4949 public:
5050 MTSDecoderTSDemux () { self = this ; };
51+ MTSDecoderTSDemux (AudioDecoder &dec) { p_dec = &dec; };
5152
5253 bool begin () override {
5354 TRACED ();
@@ -56,6 +57,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
5657 end ();
5758 }
5859
60+ if (p_dec) p_dec->begin ();
61+
5962 is_active = true ;
6063
6164 // create the pids we plan on printing
@@ -94,6 +97,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
9497
9598 void end () override {
9699 TRACED ();
100+ if (p_dec) p_dec->begin ();
101+
97102 // finally end the demux process which will flush any remaining PES data.
98103 tsd_demux_end (&ctx);
99104
@@ -109,7 +114,7 @@ class MTSDecoderTSDemux : public AudioDecoder {
109114
110115 size_t write (const uint8_t *data, size_t len) override {
111116 if (!is_active) return 0 ;
112- LOGD (" MTSDecoder ::write: %d" , (int )len);
117+ LOGD (" MTSDecoderTSDemux ::write: %d" , (int )len);
113118 size_t result = buffer.writeArray ((uint8_t *)data, len);
114119 // demux
115120 demux (underflowLimit);
@@ -141,8 +146,35 @@ class MTSDecoderTSDemux : public AudioDecoder {
141146 // / Activate logging for memory allocations
142147 void setMemoryAllocationLogging (bool flag) { is_alloc_active = flag; }
143148
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+
144176 protected:
145- static MTSDecoder *self;
177+ static MTSDecoderTSDemux *self;
146178 int underflowLimit = MTS_UNDERFLOW_LIMIT;
147179 bool is_active = false ;
148180 bool is_write_active = false ;
@@ -152,6 +184,7 @@ class MTSDecoderTSDemux : public AudioDecoder {
152184 SingleBuffer<uint8_t > buffer{MTS_WRITE_BUFFER_SIZE};
153185 Vector<TSDPMTStreamType> stream_types;
154186 Vector<AllocSize> alloc_vector;
187+ AudioDecoder *p_dec = nullptr ;
155188
156189 void set_write_active (bool flag) {
157190 // LOGD("is_write_active: %s", flag ? "true":"false");
@@ -240,8 +273,8 @@ class MTSDecoderTSDemux : public AudioDecoder {
240273 static void event_cb (TSDemuxContext *ctx, uint16_t pid, TSDEventId event_id,
241274 void *data) {
242275 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);
245278 }
246279 }
247280
@@ -288,6 +321,16 @@ class MTSDecoderTSDemux : public AudioDecoder {
288321 TRACEE ();
289322 }
290323 }
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+ }
291334 }
292335 }
293336
@@ -974,6 +1017,6 @@ class MTSDecoderTSDemux : public AudioDecoder {
9741017 // }
9751018};
9761019// init static variable
977- MTSDecoder *MTSDecoder ::self = nullptr ;
1020+ MTSDecoderTSDemux *MTSDecoderTSDemux ::self = nullptr ;
9781021
9791022} // namespace audio_tools
0 commit comments