winlin

update ts_info, parse header, adaption field and PAT

@@ -117,7 +117,7 @@ struct TSPacket @@ -117,7 +117,7 @@ struct TSPacket
117 117
118 return ret; 118 return ret;
119 } 119 }
120 - }header; 120 + } *header;
121 121
122 // variant ts packet adation field. 122 // variant ts packet adation field.
123 struct AdaptionField 123 struct AdaptionField
@@ -334,7 +334,7 @@ struct TSPacket @@ -334,7 +334,7 @@ struct TSPacket
334 334
335 return ret; 335 return ret;
336 } 336 }
337 - }adaption_field; 337 + } *adaption_field;
338 338
339 // variant ts packet payload. 339 // variant ts packet payload.
340 // PES packet or PSI table. 340 // PES packet or PSI table.
@@ -384,7 +384,7 @@ struct TSPacket @@ -384,7 +384,7 @@ struct TSPacket
384 { 384 {
385 int ret = 0; 385 int ret = 0;
386 386
387 - size = ppkt->payload.size - ppkt->payload.pointer_field_size; 387 + size = ppkt->payload->size - ppkt->payload->pointer_field_size;
388 388
389 // not parsed bytes. 389 // not parsed bytes.
390 if (size > 0) { 390 if (size > 0) {
@@ -526,12 +526,12 @@ struct TSPacket @@ -526,12 +526,12 @@ struct TSPacket
526 { 526 {
527 int ret = 0; 527 int ret = 0;
528 528
529 - if (ppkt->header.payload_unit_start_indicator) { 529 + if (ppkt->header->payload_unit_start_indicator) {
530 pointer_field = *p++; 530 pointer_field = *p++;
531 pointer_field_size = 1; 531 pointer_field_size = 1;
532 } 532 }
533 533
534 - if (ppkt->header.pid == PID_PAT) { 534 + if (ppkt->header->pid == PID_PAT) {
535 type = TypePAT; 535 type = TypePAT;
536 pat = new PAT(); 536 pat = new PAT();
537 return pat->demux(ppkt, start, last, p); 537 return pat->demux(ppkt, start, last, p);
@@ -546,29 +546,43 @@ struct TSPacket @@ -546,29 +546,43 @@ struct TSPacket
546 546
547 return ret; 547 return ret;
548 } 548 }
549 - }payload; 549 + } *payload;
  550 +
  551 + TSPacket()
  552 + {
  553 + header = new Header();
  554 + adaption_field = new AdaptionField();
  555 + payload = new Payload();
  556 + }
  557 +
  558 + virtual ~TSPacket()
  559 + {
  560 + srs_freep(header);
  561 + srs_freep(adaption_field);
  562 + srs_freep(payload);
  563 + }
550 564
551 int demux(u_int8_t* start, u_int8_t* last, u_int8_t*& p) 565 int demux(u_int8_t* start, u_int8_t* last, u_int8_t*& p)
552 { 566 {
553 int ret = 0; 567 int ret = 0;
554 568
555 - if ((ret = header.demux(this, start, last, p)) != 0) { 569 + if ((ret = header->demux(this, start, last, p)) != 0) {
556 return ret; 570 return ret;
557 } 571 }
558 572
559 - if (header.adaption_field_control == AFC_ADAPTION_ONLY || header.adaption_field_control == AFC_BOTH) {  
560 - if ((ret = adaption_field.demux(this, start, last, p)) != 0) { 573 + if (header->adaption_field_control == AFC_ADAPTION_ONLY || header->adaption_field_control == AFC_BOTH) {
  574 + if ((ret = adaption_field->demux(this, start, last, p)) != 0) {
561 trace("ts+header af(adaption field) decode error. ret=%d", ret); 575 trace("ts+header af(adaption field) decode error. ret=%d", ret);
562 return ret; 576 return ret;
563 } 577 }
564 - trace("ts+header af(adaption field decoded."); 578 + trace("ts+header af(adaption field) decoded.");
565 } 579 }
566 580
567 // calc the user defined data size for payload. 581 // calc the user defined data size for payload.
568 - payload.size = TS_PACKET_SIZE - header.get_size() - adaption_field.get_size(); 582 + payload->size = TS_PACKET_SIZE - header->get_size() - adaption_field->get_size();
569 583
570 - if (header.adaption_field_control == AFC_PAYLOAD_ONLY || header.adaption_field_control == AFC_BOTH) {  
571 - if ((ret = payload.demux(this, start, last, p)) != 0) { 584 + if (header->adaption_field_control == AFC_PAYLOAD_ONLY || header->adaption_field_control == AFC_BOTH) {
  585 + if ((ret = payload->demux(this, start, last, p)) != 0) {
572 trace("ts+header payload decode error. ret=%d", ret); 586 trace("ts+header payload decode error. ret=%d", ret);
573 return ret; 587 return ret;
574 } 588 }
@@ -576,8 +590,8 @@ struct TSPacket @@ -576,8 +590,8 @@ struct TSPacket
576 } 590 }
577 591
578 trace("ts+header parsed finished. parsed: %d left: %d header: %d payload: %d(%d+%d)", 592 trace("ts+header parsed finished. parsed: %d left: %d header: %d payload: %d(%d+%d)",
579 - (int)(p - start), (int)(last - p), header.get_size(), payload.size, payload.pointer_field_size,  
580 - payload.size - payload.pointer_field_size); 593 + (int)(p - start), (int)(last - p), header->get_size(), payload->size, payload->pointer_field_size,
  594 + payload->size - payload->pointer_field_size);
581 595
582 return finish(); 596 return finish();
583 } 597 }