@@ -408,6 +408,12 @@ SrsTsContext::SrsTsContext()
408
408
409
409
SrsTsContext::~SrsTsContext ()
410
410
{
411
+ std::map<int , SrsTsChannel*>::iterator it;
412
+ for (it = pids.begin (); it != pids.end (); ++it) {
413
+ SrsTsChannel* channel = it->second ;
414
+ srs_freep (channel);
415
+ }
416
+ pids.clear ();
411
417
}
412
418
413
419
int SrsTsContext::decode (SrsStream* stream)
@@ -429,17 +435,28 @@ int SrsTsContext::decode(SrsStream* stream)
429
435
return ret;
430
436
}
431
437
432
- SrsTsPidApply SrsTsContext::get (int pid)
438
+ SrsTsChannel* SrsTsContext::get (int pid)
433
439
{
434
440
if (pids.find (pid) == pids.end ()) {
435
- return SrsTsPidApplyReserved ;
441
+ return NULL ;
436
442
}
437
443
return pids[pid];
438
444
}
439
445
440
- void SrsTsContext::set (int pid, SrsTsPidApply apply_pid)
446
+ void SrsTsContext::set (int pid, SrsTsPidApply apply_pid, SrsTsStream stream )
441
447
{
442
- pids[pid] = apply_pid;
448
+ SrsTsChannel* channel = NULL ;
449
+
450
+ if (pids.find (pid) == pids.end ()) {
451
+ channel = new SrsTsChannel ();
452
+ pids[pid] = channel;
453
+ } else {
454
+ channel = pids[pid];
455
+ }
456
+
457
+ channel->pid = pid;
458
+ channel->apply = apply_pid;
459
+ channel->stream = stream;
443
460
}
444
461
445
462
SrsTsPacket::SrsTsPacket (SrsTsContext* c)
@@ -523,11 +540,15 @@ int SrsTsPacket::decode(SrsStream* stream)
523
540
srs_freep (payload);
524
541
payload = new SrsTsPayloadPAT (this );
525
542
} else {
526
- SrsTsPidApply apply_pid = context->get (pid);
527
- if (apply_pid == SrsTsPidApplyPMT) {
543
+ SrsTsChannel* channel = context->get (pid);
544
+ if (channel && channel-> apply == SrsTsPidApplyPMT) {
528
545
// 2.4.4.8 Program Map Table
529
546
srs_freep (payload);
530
547
payload = new SrsTsPayloadPMT (this );
548
+ } else if (channel && (channel->apply == SrsTsPidApplyVideo || channel->apply == SrsTsPidApplyAudio)) {
549
+ // 2.4.3.6 PES packet
550
+ srs_freep (payload);
551
+ payload = new SrsTsPayloadPES (this );
531
552
} else {
532
553
// left bytes as reserved.
533
554
stream->skip (nb_payload);
@@ -793,6 +814,31 @@ SrsTsPayload::~SrsTsPayload()
793
814
{
794
815
}
795
816
817
+ SrsTsPayloadPES::SrsTsPayloadPES (SrsTsPacket* p) : SrsTsPayload(p)
818
+ {
819
+ PES_private_data = NULL ;
820
+ pack_field = NULL ;
821
+ PES_extension_field = NULL ;
822
+ nb_stuffings = 0 ;
823
+ nb_bytes = 0 ;
824
+ bytes = NULL ;
825
+ nb_paddings = 0 ;
826
+ }
827
+
828
+ SrsTsPayloadPES::~SrsTsPayloadPES ()
829
+ {
830
+ srs_freep (PES_private_data);
831
+ srs_freep (pack_field);
832
+ srs_freep (PES_extension_field);
833
+ srs_freep (bytes);
834
+ }
835
+
836
+ int SrsTsPayloadPES::decode (SrsStream* stream)
837
+ {
838
+ int ret = ERROR_SUCCESS;
839
+ return ret;
840
+ }
841
+
796
842
SrsTsPayloadPSI::SrsTsPayloadPSI (SrsTsPacket* p) : SrsTsPayload(p)
797
843
{
798
844
pointer_field = 0 ;
@@ -879,7 +925,19 @@ int SrsTsPayloadPSI::decode(SrsStream* stream)
879
925
880
926
// consume left stuffings
881
927
if (!stream->empty ()) {
882
- stream->skip (stream->size () - stream->pos ());
928
+ int nb_stuffings = stream->size () - stream->pos ();
929
+ char * stuffing = stream->data () + stream->pos ();
930
+
931
+ // all stuffing must be 0xff.
932
+ // TODO: FIXME: maybe need to remove the following.
933
+ for (int i = 0 ; i < nb_stuffings; i++) {
934
+ if ((u_int8_t )stuffing[i] != 0xff ) {
935
+ srs_warn (" ts: stuff is not 0xff, actual=%#x" , stuffing[i]);
936
+ break ;
937
+ }
938
+ }
939
+
940
+ stream->skip (nb_stuffings);
883
941
}
884
942
885
943
return ret;
@@ -1049,7 +1107,7 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* stream)
1049
1107
return ret;
1050
1108
}
1051
1109
1052
- info->stream_type = stream->read_1bytes ();
1110
+ info->stream_type = (SrsTsStream) stream->read_1bytes ();
1053
1111
info->elementary_PID = stream->read_2bytes ();
1054
1112
info->ES_info_length = stream->read_2bytes ();
1055
1113
@@ -1066,6 +1124,23 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* stream)
1066
1124
info->ES_info = new char [info->ES_info_length ];
1067
1125
stream->read_bytes (info->ES_info , info->ES_info_length );
1068
1126
}
1127
+
1128
+ // update the apply pid table
1129
+ switch (info->stream_type ) {
1130
+ case SrsTsStreamVideoH264:
1131
+ case SrsTsStreamVideoMpeg4:
1132
+ packet->context ->set (info->elementary_PID , SrsTsPidApplyVideo, info->stream_type );
1133
+ break ;
1134
+ case SrsTsStreamAudioAAC:
1135
+ case SrsTsStreamAudioAC3:
1136
+ case SrsTsStreamAudioDTS:
1137
+ case SrsTsStreamAudioMp3:
1138
+ packet->context ->set (info->elementary_PID , SrsTsPidApplyAudio, info->stream_type );
1139
+ break ;
1140
+ default :
1141
+ srs_warn (" ts: drop pid=%#x, stream=%#x" , info->elementary_PID , info->stream_type );
1142
+ break ;
1143
+ }
1069
1144
}
1070
1145
1071
1146
// update the apply pid table.
0 commit comments