14
14
#include "mpegSystemHeader.h"
20
// we do a fast mod based lookup pid->Map
17
24
MpegSystemHeader::MpegSystemHeader() {
23
layer=_PACKET_UNKNOWN_LAYER;
25
// MPEG2 Stuff [START]
30
lDataAlignmentIndicator=false;
39
lADDITIONAL_COPY_FLAG=false;
42
nPES_HEADER_DATA_LENGTH=0;
46
lPrivateDataFlag=false;
47
lPackHeaderFieldFlag=false;
48
lSequenceCounterFlag=false;
50
lPES_EXT_FLAG_2=false;
51
nPES_EXT_FIELD_LENGTH=0;
36
layer=_PACKET_UNKNOWN_LAYER;
40
// MPEG2 Stuff [START]
45
lDataAlignmentIndicator=false;
54
lADDITIONAL_COPY_FLAG=false;
57
nPES_HEADER_DATA_LENGTH=0;
61
lPrivateDataFlag=false;
62
lPackHeaderFieldFlag=false;
63
lSequenceCounterFlag=false;
65
lPES_EXT_FLAG_2=false;
66
nPES_EXT_FIELD_LENGTH=0;
77
programNumber=INVALID_PROGRAM;
80
mapPidStreamArray=new MapPidStream*[MAX_PIDS];
82
for(i=0;i<MAX_PIDS;i++) {
83
mapPidStreamArray[i]=new MapPidStream();
84
mapPidStreamArray[i]->isValid=false;
62
94
MpegSystemHeader::~MpegSystemHeader() {
96
for(i=0;i<MAX_PIDS;i++) {
97
delete mapPidStreamArray[i];
99
delete mapPidStreamArray;
103
void MpegSystemHeader::setHeader(unsigned int header) {
109
int MpegSystemHeader::hasRAWHeader() {
110
return header==_SEQ_START_CODE;
114
unsigned int MpegSystemHeader::getHeader() {
66
118
double MpegSystemHeader::getSCRTimeStamp() {
533
// Transport Stream Header [START]
536
int MpegSystemHeader:: hasTSHeader() {
540
void MpegSystemHeader::setTSHeader(unsigned int header) {
544
int byte3=header & 0xff;
546
int byte2=header & 0xff;
548
int byte1=header & 0xff;
550
int byte0=header & 0xff;
555
transport_error_indicator = (byte1 >> 7) & 0x01;
556
payload_unit_start_indicator = (byte1 >> 6) & 0x01;
557
transport_priority = (byte1 >> 5) & 0x01;
558
pid = ((byte1 << 8) | byte2) & 0x1fff;
559
transport_scrambling_control = (byte3 >> 6) & 0x03;
560
adaption_field_control = (byte3 >> 4) & 0x03;
561
continuity_counter = byte3 & 0x0f;
563
if (sync_byte != 0x47) {
566
if (transport_error_indicator) {
575
unsigned int MpegSystemHeader::getSync_byte() {
580
unsigned int MpegSystemHeader::getTransport_error_indicator() {
581
return transport_error_indicator;
585
unsigned int MpegSystemHeader::getPayload_unit_start_indicator() {
586
return payload_unit_start_indicator;
590
unsigned int MpegSystemHeader::getTransport_priority() {
591
return transport_priority;
595
unsigned int MpegSystemHeader::getPid() {
600
unsigned int MpegSystemHeader::getTransport_scrambling_control() {
601
return transport_scrambling_control;
605
unsigned int MpegSystemHeader::getAdaption_field_control() {
606
return adaption_field_control;
610
unsigned int MpegSystemHeader::getContinuity_counter() {
611
return continuity_counter;
614
unsigned int MpegSystemHeader::getPrograms() {
619
void MpegSystemHeader::setPrograms(unsigned int programs) {
620
this->programs=programs;
624
unsigned int MpegSystemHeader::getProgramNumber() {
625
return programNumber;
629
void MpegSystemHeader::setProgramNumber(unsigned int programNumber) {
630
this->programNumber=programNumber;
634
unsigned int MpegSystemHeader::getPMTPID() {
639
void MpegSystemHeader::setPMTPID(unsigned int pmtPID) {
644
MapPidStream* MpegSystemHeader::lookup(unsigned int pid) {
645
return mapPidStreamArray[pid % MAX_PIDS];
650
Here we do a mapping from the pid to the "meaning" for the
651
pid (defined in the TS spec) and then we map this to
652
a normal mpeg stream ID.
653
(Which is used in the MpegSystemHeder to identify the
654
kind of packet we have)
656
void MpegSystemHeader::insert(unsigned int pid,unsigned int tsType,
657
MpegSystemHeader* mpegHeader) {
658
if (currentPos >= MAX_PIDS) {
659
cout << "error to much pids in stream.TSSystemStream::insert"<<endl;
662
printf("tsType:%x\n",tsType);
664
case ISO_11172_VIDEO:
665
case ISO_13818_VIDEO:
666
case ISO_11172_AUDIO:
667
case ISO_13818_AUDIO:
668
case ISO_13818_PRIVATE:
669
case ISO_13818_PES_PRIVATE:
671
case ISO_13818_DSMCC:
672
case ISO_13818_TYPE_A:
673
case ISO_13818_TYPE_B:
674
case ISO_13818_TYPE_C:
675
case ISO_13818_TYPE_D:
676
case ISO_13818_TYPE_E:
680
cout << "ignoring unknown tsType in TSSystemStream::insert"<<endl;
684
MapPidStream* mapPidStream=lookup(pid);
685
int psType=_PAKET_ID_NUKE;
687
mapPidStream->pid=pid;
688
mapPidStream->tsType=tsType;
689
mapPidStream->psType=psType;
690
mapPidStream->isValid=true;
696
void MpegSystemHeader::printTSHeader() {
697
if (hasTSHeader() == false) {
698
cout << "MpegSystemHeader::printTSHeader: NO TS HEADER"<<endl;
702
printf("sync:%02X TE:%02X PUS:%02X TP:%02X PID:%04X TSC:%02X "
703
"AFC:%02X CC:%02X\n",
705
transport_error_indicator,
706
payload_unit_start_indicator,
709
transport_scrambling_control,
710
adaption_field_control,
716
void MpegSystemHeader::printProgramInfo() {
718
cout << "MpegSystemHeader::printProgramInfo: NO programs"<<endl;
720
cout << "MpegSystemHeader::printProgramInfo: programs:"<<programs<<endl;
722
printf("MPTS: programNumber=%x pmtPid=%x\n",programNumber, pmtPID);
726
void MpegSystemHeader::printMap(MapPidStream* mapPidStream) {
727
if (mapPidStream->isValid == false) {
728
cout << "TSSystemStream::printMap ** INVALID** "<<endl;
732
printf("printMap->isValid:%x\n",mapPidStream->isValid);
733
printf("printMap->pid:%x\n",mapPidStream->pid);
734
printf("printMap->tsType:%x\n",mapPidStream->tsType);
735
printf("printMap->psType:%x\n",mapPidStream->psType);
741
// Transport Stream Header [END]
454
746
void MpegSystemHeader::setMPEG2(int lmpeg2) {
455
747
this->lmpeg2=lmpeg2;