| | 433 | static int DemuxPacket( input_thread_t *p_input, vlc_bool_t b_play_audio ) |
|---|
| | 434 | { |
|---|
| | 435 | demux_sys_t *p_demux = p_input->p_demux_data; |
|---|
| | 436 | int i_data_packet_min = p_demux->p_fp->i_min_data_packet_size; |
|---|
| | 437 | uint8_t *p_peek; |
|---|
| | 438 | int i_skip; |
|---|
| | 439 | |
|---|
| | 440 | int i_packet_size_left; |
|---|
| | 441 | int i_packet_flags; |
|---|
| | 442 | int i_packet_property; |
|---|
| | 443 | |
|---|
| | 444 | int b_packet_multiple_payload; |
|---|
| | 445 | int i_packet_length; |
|---|
| | 446 | int i_packet_sequence; |
|---|
| | 447 | int i_packet_padding_length; |
|---|
| | 448 | |
|---|
| | 449 | uint32_t i_packet_send_time; |
|---|
| | 450 | uint16_t i_packet_duration; |
|---|
| | 451 | int i_payload; |
|---|
| | 452 | int i_payload_count; |
|---|
| | 453 | int i_payload_length_type; |
|---|
| | 454 | |
|---|
| | 455 | |
|---|
| | 456 | if( input_Peek( p_input, &p_peek, i_data_packet_min ) < i_data_packet_min ) |
|---|
| | 457 | { |
|---|
| | 458 | // EOF ? |
|---|
| | 459 | msg_Warn( p_input, "cannot peek while getting new packet, EOF ?" ); |
|---|
| | 460 | return( 0 ); |
|---|
| | 461 | } |
|---|
| | 462 | i_skip = 0; |
|---|
| | 463 | |
|---|
| | 464 | /* *** parse error correction if present *** */ |
|---|
| | 465 | if( p_peek[0]&0x80 ) |
|---|
| | 466 | { |
|---|
| | 467 | int i_error_correction_length_type; |
|---|
| | 468 | int i_error_correction_data_length; |
|---|
| | 469 | int i_opaque_data_present; |
|---|
| | 470 | |
|---|
| | 471 | i_error_correction_data_length = p_peek[0] & 0x0f; // 4bits |
|---|
| | 472 | i_opaque_data_present = ( p_peek[0] >> 4 )& 0x01; // 1bit |
|---|
| | 473 | i_error_correction_length_type = ( p_peek[0] >> 5 ) & 0x03; // 2bits |
|---|
| | 474 | i_skip += 1; // skip error correction flags |
|---|
| | 475 | |
|---|
| | 476 | if( i_error_correction_length_type != 0x00 || |
|---|
| | 477 | i_opaque_data_present != 0 || |
|---|
| | 478 | i_error_correction_data_length != 0x02 ) |
|---|
| | 479 | { |
|---|
| | 480 | goto loop_error_recovery; |
|---|
| | 481 | } |
|---|
| | 482 | |
|---|
| | 483 | i_skip += i_error_correction_data_length; |
|---|
| | 484 | } |
|---|
| | 485 | else |
|---|
| | 486 | { |
|---|
| | 487 | msg_Warn( p_input, "p_peek[0]&0x80 != 0x80" ); |
|---|
| | 488 | } |
|---|
| | 489 | |
|---|
| | 490 | i_packet_flags = p_peek[i_skip]; i_skip++; |
|---|
| | 491 | i_packet_property = p_peek[i_skip]; i_skip++; |
|---|
| | 492 | |
|---|
| | 493 | b_packet_multiple_payload = i_packet_flags&0x01; |
|---|
| | 494 | |
|---|
| | 495 | /* read some value */ |
|---|
| | 496 | GETVALUE2b( i_packet_flags >> 5, i_packet_length, i_data_packet_min ); |
|---|
| | 497 | GETVALUE2b( i_packet_flags >> 1, i_packet_sequence, 0 ); |
|---|
| | 498 | GETVALUE2b( i_packet_flags >> 3, i_packet_padding_length, 0 ); |
|---|
| | 499 | |
|---|
| | 500 | i_packet_send_time = GetDWLE( p_peek + i_skip ); i_skip += 4; |
|---|
| | 501 | i_packet_duration = GetWLE( p_peek + i_skip ); i_skip += 2; |
|---|
| | 502 | |
|---|
| | 503 | // i_packet_size_left = i_packet_length; // XXX donn� reellement lu |
|---|
| | 504 | /* FIXME I have to do that for some file, I don't known why */ |
|---|
| | 505 | i_packet_size_left = i_data_packet_min; |
|---|
| | 506 | |
|---|
| | 507 | if( b_packet_multiple_payload ) |
|---|
| | 508 | { |
|---|
| | 509 | i_payload_count = p_peek[i_skip] & 0x3f; |
|---|
| | 510 | i_payload_length_type = ( p_peek[i_skip] >> 6 )&0x03; |
|---|
| | 511 | i_skip++; |
|---|
| | 512 | } |
|---|
| | 513 | else |
|---|
| | 514 | { |
|---|
| | 515 | i_payload_count = 1; |
|---|
| | 516 | i_payload_length_type = 0x02; // unused |
|---|
| | 517 | } |
|---|
| | 518 | |
|---|
| | 519 | for( i_payload = 0; i_payload < i_payload_count ; i_payload++ ) |
|---|
| | 520 | { |
|---|
| | 521 | asf_stream_t *p_stream; |
|---|
| | 522 | |
|---|
| | 523 | int i_stream_number; |
|---|
| | 524 | int i_media_object_number; |
|---|
| | 525 | int i_media_object_offset; |
|---|
| | 526 | int i_replicated_data_length; |
|---|
| | 527 | int i_payload_data_length; |
|---|
| | 528 | int i_payload_data_pos; |
|---|
| | 529 | int i_sub_payload_data_length; |
|---|
| | 530 | int i_tmp; |
|---|
| | 531 | |
|---|
| | 532 | mtime_t i_pts; |
|---|
| | 533 | mtime_t i_pts_delta; |
|---|
| | 534 | |
|---|
| | 535 | if( i_skip >= i_packet_size_left ) |
|---|
| | 536 | { |
|---|
| | 537 | /* prevent some segfault with invalid file */ |
|---|
| | 538 | break; |
|---|
| | 539 | } |
|---|
| | 540 | |
|---|
| | 541 | i_stream_number = p_peek[i_skip] & 0x7f; |
|---|
| | 542 | i_skip++; |
|---|
| | 543 | |
|---|
| | 544 | GETVALUE2b( i_packet_property >> 4, i_media_object_number, 0 ); |
|---|
| | 545 | GETVALUE2b( i_packet_property >> 2, i_tmp, 0 ); |
|---|
| | 546 | GETVALUE2b( i_packet_property, i_replicated_data_length, 0 ); |
|---|
| | 547 | |
|---|
| | 548 | if( i_replicated_data_length > 1 ) // should be at least 8 bytes |
|---|
| | 549 | { |
|---|
| | 550 | i_pts = (mtime_t)GetDWLE( p_peek + i_skip + 4 ) * 1000; |
|---|
| | 551 | i_skip += i_replicated_data_length; |
|---|
| | 552 | i_pts_delta = 0; |
|---|
| | 553 | |
|---|
| | 554 | i_media_object_offset = i_tmp; |
|---|
| | 555 | } |
|---|
| | 556 | else if( i_replicated_data_length == 1 ) |
|---|
| | 557 | { |
|---|
| | 558 | |
|---|
| | 559 | msg_Dbg( p_input, "found compressed payload" ); |
|---|
| | 560 | |
|---|
| | 561 | i_pts = (mtime_t)i_tmp * 1000; |
|---|
| | 562 | i_pts_delta = (mtime_t)p_peek[i_skip] * 1000; i_skip++; |
|---|
| | 563 | |
|---|
| | 564 | i_media_object_offset = 0; |
|---|
| | 565 | } |
|---|
| | 566 | else |
|---|
| | 567 | { |
|---|
| | 568 | i_pts = (mtime_t)i_packet_send_time * 1000; |
|---|
| | 569 | i_pts_delta = 0; |
|---|
| | 570 | |
|---|
| | 571 | i_media_object_offset = i_tmp; |
|---|
| | 572 | } |
|---|
| | 573 | |
|---|
| | 574 | i_pts = __MAX( i_pts - p_demux->p_fp->i_preroll * 1000, 0 ); |
|---|
| | 575 | if( b_packet_multiple_payload ) |
|---|
| | 576 | { |
|---|
| | 577 | GETVALUE2b( i_payload_length_type, i_payload_data_length, 0 ); |
|---|
| | 578 | } |
|---|
| | 579 | else |
|---|
| | 580 | { |
|---|
| | 581 | i_payload_data_length = i_packet_length - |
|---|
| | 582 | i_packet_padding_length - i_skip; |
|---|
| | 583 | } |
|---|
| | 584 | |
|---|
| | 585 | #if 0 |
|---|
| | 586 | msg_Dbg( p_input, |
|---|
| | 587 | "payload(%d/%d) stream_number:%d media_object_number:%d media_object_offset:%d replicated_data_length:%d payload_data_length %d", |
|---|
| | 588 | i_payload + 1, |
|---|
| | 589 | i_payload_count, |
|---|
| | 590 | i_stream_number, |
|---|
| | 591 | i_media_object_number, |
|---|
| | 592 | i_media_object_offset, |
|---|
| | 593 | i_replicated_data_length, |
|---|
| | 594 | i_payload_data_length ); |
|---|
| | 595 | #endif |
|---|
| | 596 | |
|---|
| | 597 | if( !( p_stream = p_demux->stream[i_stream_number] ) ) |
|---|
| | 598 | { |
|---|
| | 599 | msg_Warn( p_input, |
|---|
| | 600 | "undeclared stream[Id 0x%x]", i_stream_number ); |
|---|
| | 601 | i_skip += i_payload_data_length; |
|---|
| | 602 | continue; // over payload |
|---|
| | 603 | } |
|---|
| | 604 | |
|---|
| | 605 | if( !p_stream->p_es || !p_stream->p_es->p_decoder_fifo ) |
|---|
| | 606 | { |
|---|
| | 607 | i_skip += i_payload_data_length; |
|---|
| | 608 | continue; |
|---|
| | 609 | } |
|---|
| | 610 | |
|---|
| | 611 | |
|---|
| | 612 | for( i_payload_data_pos = 0; |
|---|
| | 613 | i_payload_data_pos < i_payload_data_length && |
|---|
| | 614 | i_packet_size_left > 0; |
|---|
| | 615 | i_payload_data_pos += i_sub_payload_data_length ) |
|---|
| | 616 | { |
|---|
| | 617 | data_packet_t *p_data; |
|---|
| | 618 | int i_read; |
|---|
| | 619 | // read sub payload length |
|---|
| | 620 | if( i_replicated_data_length == 1 ) |
|---|
| | 621 | { |
|---|
| | 622 | i_sub_payload_data_length = p_peek[i_skip]; i_skip++; |
|---|
| | 623 | i_payload_data_pos++; |
|---|
| | 624 | } |
|---|
| | 625 | else |
|---|
| | 626 | { |
|---|
| | 627 | i_sub_payload_data_length = i_payload_data_length; |
|---|
| | 628 | } |
|---|
| | 629 | |
|---|
| | 630 | /* FIXME I don't use i_media_object_number, sould I ? */ |
|---|
| | 631 | if( p_stream->p_pes && i_media_object_offset == 0 ) { |
|---|
| | 632 | /* send complete packet to decoder */ |
|---|
| | 633 | if( p_stream->p_pes->i_pes_size > 0 ) |
|---|
| | 634 | { |
|---|
| | 635 | if( p_stream->p_es->p_decoder_fifo && |
|---|
| | 636 | ( b_play_audio || p_stream->i_cat != AUDIO_ES ) ) |
|---|
| | 637 | { |
|---|
| | 638 | input_DecodePES( p_stream->p_es->p_decoder_fifo, |
|---|
| | 639 | p_stream->p_pes ); |
|---|
| | 640 | } |
|---|
| | 641 | else |
|---|
| | 642 | { |
|---|
| | 643 | input_DeletePES( p_input->p_method_data, |
|---|
| | 644 | p_stream->p_pes ); |
|---|
| | 645 | } |
|---|
| | 646 | p_stream->p_pes = NULL; |
|---|
| | 647 | } |
|---|
| | 648 | } |
|---|
| | 649 | |
|---|
| | 650 | if( !p_stream->p_pes ) // add a new PES |
|---|
| | 651 | { |
|---|
| | 652 | p_stream->i_time = |
|---|
| | 653 | ( (mtime_t)i_pts + i_payload * (mtime_t)i_pts_delta ); |
|---|
| | 654 | |
|---|
| | 655 | if( p_demux->i_first_pts == -1 ) |
|---|
| | 656 | { |
|---|
| | 657 | p_demux->i_first_pts = p_stream->i_time; |
|---|
| | 658 | } |
|---|
| | 659 | p_stream->i_time -= p_demux->i_first_pts; |
|---|
| | 660 | |
|---|
| | 661 | p_stream->p_pes = input_NewPES( p_input->p_method_data ); |
|---|
| | 662 | p_stream->p_pes->i_dts = |
|---|
| | 663 | p_stream->p_pes->i_pts = |
|---|
| | 664 | input_ClockGetTS( p_input, |
|---|
| | 665 | p_input->stream.p_selected_program, |
|---|
| | 666 | ( p_stream->i_time+DEFAULT_PTS_DELAY) * 9 /100 ); |
|---|
| | 667 | |
|---|
| | 668 | p_stream->p_pes->p_next = NULL; |
|---|
| | 669 | p_stream->p_pes->i_nb_data = 0; |
|---|
| | 670 | p_stream->p_pes->i_pes_size = 0; |
|---|
| | 671 | } |
|---|
| | 672 | |
|---|
| | 673 | i_read = i_sub_payload_data_length + i_skip; |
|---|
| | 674 | if( input_SplitBuffer( p_input, &p_data, i_read ) < i_read ) |
|---|
| | 675 | { |
|---|
| | 676 | msg_Warn( p_input, "cannot read data" ); |
|---|
| | 677 | return( 0 ); |
|---|
| | 678 | } |
|---|
| | 679 | p_data->p_payload_start += i_skip; |
|---|
| | 680 | i_packet_size_left -= i_read; |
|---|
| | 681 | |
|---|
| | 682 | |
|---|
| | 683 | if( !p_stream->p_pes->p_first ) |
|---|
| | 684 | { |
|---|
| | 685 | p_stream->p_pes->p_first = p_stream->p_pes->p_last = p_data; |
|---|
| | 686 | } |
|---|
| | 687 | else |
|---|
| | 688 | { |
|---|
| | 689 | p_stream->p_pes->p_last->p_next = p_data; |
|---|
| | 690 | p_stream->p_pes->p_last = p_data; |
|---|
| | 691 | } |
|---|
| | 692 | p_stream->p_pes->i_pes_size += i_sub_payload_data_length; |
|---|
| | 693 | p_stream->p_pes->i_nb_data++; |
|---|
| | 694 | |
|---|
| | 695 | i_skip = 0; |
|---|
| | 696 | if( i_packet_size_left > 0 ) |
|---|
| | 697 | { |
|---|
| | 698 | if( input_Peek( p_input, &p_peek, i_packet_size_left ) < i_packet_size_left ) |
|---|
| | 699 | { |
|---|
| | 700 | // EOF ? |
|---|
| | 701 | msg_Warn( p_input, "cannot peek, EOF ?" ); |
|---|
| | 702 | return( 0 ); |
|---|
| | 703 | } |
|---|
| | 704 | } |
|---|
| | 705 | } |
|---|
| | 706 | } |
|---|
| | 707 | |
|---|
| | 708 | if( i_packet_size_left > 0 ) |
|---|
| | 709 | { |
|---|
| | 710 | if( !ASF_SkipBytes( p_input, i_packet_size_left ) ) |
|---|
| | 711 | { |
|---|
| | 712 | msg_Warn( p_input, "cannot skip data, EOF ?" ); |
|---|
| | 713 | return( 0 ); |
|---|
| | 714 | } |
|---|
| | 715 | } |
|---|
| | 716 | |
|---|
| | 717 | return( 1 ); |
|---|
| | 718 | |
|---|
| | 719 | loop_error_recovery: |
|---|
| | 720 | msg_Warn( p_input, "unsupported packet header" ); |
|---|
| | 721 | if( p_demux->p_fp->i_min_data_packet_size != p_demux->p_fp->i_max_data_packet_size ) |
|---|
| | 722 | { |
|---|
| | 723 | msg_Err( p_input, "unsupported packet header, fatal error" ); |
|---|
| | 724 | return( -1 ); |
|---|
| | 725 | } |
|---|
| | 726 | ASF_SkipBytes( p_input, i_data_packet_min ); |
|---|
| | 727 | |
|---|
| | 728 | return( 1 ); |
|---|
| | 729 | } |
|---|
| | 730 | |
|---|
| 470 | | int i_data_packet_min = p_demux->p_fp->i_min_data_packet_size; |
|---|
| 471 | | uint8_t *p_peek; |
|---|
| 472 | | int i_skip; |
|---|
| 473 | | |
|---|
| 474 | | int i_packet_size_left; |
|---|
| 475 | | int i_packet_flags; |
|---|
| 476 | | int i_packet_property; |
|---|
| 477 | | |
|---|
| 478 | | int b_packet_multiple_payload; |
|---|
| 479 | | int i_packet_length; |
|---|
| 480 | | int i_packet_sequence; |
|---|
| 481 | | int i_packet_padding_length; |
|---|
| 482 | | |
|---|
| 483 | | uint32_t i_packet_send_time; |
|---|
| 484 | | uint16_t i_packet_duration; |
|---|
| 485 | | int i_payload; |
|---|
| 486 | | int i_payload_count; |
|---|
| 487 | | int i_payload_length_type; |
|---|
| 488 | | |
|---|
| 489 | | |
|---|
| 490 | | if( input_Peek( p_input, &p_peek, i_data_packet_min ) < i_data_packet_min ) |
|---|
| 491 | | { |
|---|
| 492 | | // EOF ? |
|---|
| 493 | | msg_Warn( p_input, "cannot peek while getting new packet, EOF ?" ); |
|---|
| 494 | | return( 0 ); |
|---|
| 495 | | } |
|---|
| 496 | | i_skip = 0; |
|---|
| 497 | | |
|---|
| 498 | | /* *** parse error correction if present *** */ |
|---|
| 499 | | if( p_peek[0]&0x80 ) |
|---|
| 500 | | { |
|---|
| 501 | | int i_error_correction_length_type; |
|---|
| 502 | | int i_error_correction_data_length; |
|---|
| 503 | | int i_opaque_data_present; |
|---|
| 504 | | |
|---|
| 505 | | i_error_correction_data_length = p_peek[0] & 0x0f; // 4bits |
|---|
| 506 | | i_opaque_data_present = ( p_peek[0] >> 4 )& 0x01; // 1bit |
|---|
| 507 | | i_error_correction_length_type = ( p_peek[0] >> 5 ) & 0x03; // 2bits |
|---|
| 508 | | i_skip += 1; // skip error correction flags |
|---|
| 509 | | |
|---|
| 510 | | if( i_error_correction_length_type != 0x00 || |
|---|
| 511 | | i_opaque_data_present != 0 || |
|---|
| 512 | | i_error_correction_data_length != 0x02 ) |
|---|
| 513 | | { |
|---|
| 514 | | goto loop_error_recovery; |
|---|
| 515 | | } |
|---|
| 516 | | |
|---|
| 517 | | i_skip += i_error_correction_data_length; |
|---|
| 518 | | } |
|---|
| 519 | | else |
|---|
| 520 | | { |
|---|
| 521 | | msg_Warn( p_input, "p_peek[0]&0x80 != 0x80" ); |
|---|
| 522 | | } |
|---|
| 523 | | |
|---|
| 524 | | i_packet_flags = p_peek[i_skip]; i_skip++; |
|---|
| 525 | | i_packet_property = p_peek[i_skip]; i_skip++; |
|---|
| 526 | | |
|---|
| 527 | | b_packet_multiple_payload = i_packet_flags&0x01; |
|---|
| 528 | | |
|---|
| 529 | | /* read some value */ |
|---|
| 530 | | GETVALUE2b( i_packet_flags >> 5, i_packet_length, i_data_packet_min ); |
|---|
| 531 | | GETVALUE2b( i_packet_flags >> 1, i_packet_sequence, 0 ); |
|---|
| 532 | | GETVALUE2b( i_packet_flags >> 3, i_packet_padding_length, 0 ); |
|---|
| 533 | | |
|---|
| 534 | | i_packet_send_time = GetDWLE( p_peek + i_skip ); i_skip += 4; |
|---|
| 535 | | i_packet_duration = GetWLE( p_peek + i_skip ); i_skip += 2; |
|---|
| 536 | | |
|---|
| 537 | | // i_packet_size_left = i_packet_length; // XXX donn� reellement lu |
|---|
| 538 | | /* FIXME I have to do that for some file, I don't known why */ |
|---|
| 539 | | i_packet_size_left = i_data_packet_min; |
|---|
| 540 | | |
|---|
| 541 | | if( b_packet_multiple_payload ) |
|---|
| 542 | | { |
|---|
| 543 | | i_payload_count = p_peek[i_skip] & 0x3f; |
|---|
| 544 | | i_payload_length_type = ( p_peek[i_skip] >> 6 )&0x03; |
|---|
| 545 | | i_skip++; |
|---|
| 546 | | } |
|---|
| 547 | | else |
|---|
| 548 | | { |
|---|
| 549 | | i_payload_count = 1; |
|---|
| 550 | | i_payload_length_type = 0x02; // unused |
|---|
| 551 | | } |
|---|
| 552 | | |
|---|
| 553 | | for( i_payload = 0; i_payload < i_payload_count ; i_payload++ ) |
|---|
| 554 | | { |
|---|
| 555 | | asf_stream_t *p_stream; |
|---|
| 556 | | |
|---|
| 557 | | int i_stream_number; |
|---|
| 558 | | int i_media_object_number; |
|---|
| 559 | | int i_media_object_offset; |
|---|
| 560 | | int i_replicated_data_length; |
|---|
| 561 | | int i_payload_data_length; |
|---|
| 562 | | int i_payload_data_pos; |
|---|
| 563 | | int i_sub_payload_data_length; |
|---|
| 564 | | int i_tmp; |
|---|
| 565 | | |
|---|
| 566 | | mtime_t i_pts; |
|---|
| 567 | | mtime_t i_pts_delta; |
|---|
| 568 | | |
|---|
| 569 | | if( i_skip >= i_packet_size_left ) |
|---|
| 570 | | { |
|---|
| 571 | | /* prevent some segfault with invalid file */ |
|---|
| 572 | | break; |
|---|
| 573 | | } |
|---|
| 574 | | |
|---|
| 575 | | i_stream_number = p_peek[i_skip] & 0x7f; |
|---|
| 576 | | i_skip++; |
|---|
| 577 | | |
|---|
| 578 | | GETVALUE2b( i_packet_property >> 4, i_media_object_number, 0 ); |
|---|
| 579 | | GETVALUE2b( i_packet_property >> 2, i_tmp, 0 ); |
|---|
| 580 | | GETVALUE2b( i_packet_property, i_replicated_data_length, 0 ); |
|---|
| 581 | | |
|---|
| 582 | | if( i_replicated_data_length > 1 ) // should be at least 8 bytes |
|---|
| 583 | | { |
|---|
| 584 | | i_pts = (mtime_t)GetDWLE( p_peek + i_skip + 4 ) * 1000; |
|---|
| 585 | | i_skip += i_replicated_data_length; |
|---|
| 586 | | i_pts_delta = 0; |
|---|
| 587 | | |
|---|
| 588 | | i_media_object_offset = i_tmp; |
|---|
| 589 | | } |
|---|
| 590 | | else if( i_replicated_data_length == 1 ) |
|---|
| 591 | | { |
|---|
| 592 | | |
|---|
| 593 | | msg_Dbg( p_input, "found compressed payload" ); |
|---|
| 594 | | |
|---|
| 595 | | i_pts = (mtime_t)i_tmp * 1000; |
|---|
| 596 | | i_pts_delta = (mtime_t)p_peek[i_skip] * 1000; i_skip++; |
|---|
| 597 | | |
|---|
| 598 | | i_media_object_offset = 0; |
|---|
| 599 | | } |
|---|
| 600 | | else |
|---|
| 601 | | { |
|---|
| 602 | | i_pts = (mtime_t)i_packet_send_time * 1000; |
|---|
| 603 | | i_pts_delta = 0; |
|---|
| 604 | | |
|---|
| 605 | | i_media_object_offset = i_tmp; |
|---|
| 606 | | } |
|---|
| 607 | | |
|---|
| 608 | | i_pts = __MAX( i_pts - p_demux->p_fp->i_preroll * 1000, 0 ); |
|---|
| 609 | | if( b_packet_multiple_payload ) |
|---|
| 610 | | { |
|---|
| 611 | | GETVALUE2b( i_payload_length_type, i_payload_data_length, 0 ); |
|---|
| 612 | | } |
|---|
| 613 | | else |
|---|
| 614 | | { |
|---|
| 615 | | i_payload_data_length = i_packet_length - |
|---|
| 616 | | i_packet_padding_length - i_skip; |
|---|
| 617 | | } |
|---|
| 618 | | |
|---|
| 619 | | #if 0 |
|---|
| 620 | | msg_Dbg( p_input, |
|---|
| 621 | | "payload(%d/%d) stream_number:%d media_object_number:%d media_object_offset:%d replicated_data_length:%d payload_data_length %d", |
|---|
| 622 | | i_payload + 1, |
|---|
| 623 | | i_payload_count, |
|---|
| 624 | | i_stream_number, |
|---|
| 625 | | i_media_object_number, |
|---|
| 626 | | i_media_object_offset, |
|---|
| 627 | | i_replicated_data_length, |
|---|
| 628 | | i_payload_data_length ); |
|---|
| 629 | | #endif |
|---|
| 630 | | |
|---|
| 631 | | if( !( p_stream = p_demux->stream[i_stream_number] ) ) |
|---|
| 632 | | { |
|---|
| 633 | | msg_Warn( p_input, |
|---|
| 634 | | "undeclared stream[Id 0x%x]", i_stream_number ); |
|---|
| 635 | | i_skip += i_payload_data_length; |
|---|
| 636 | | continue; // over payload |
|---|
| 637 | | } |
|---|
| 638 | | |
|---|
| 639 | | if( !p_stream->p_es || !p_stream->p_es->p_decoder_fifo ) |
|---|
| 640 | | { |
|---|
| 641 | | i_skip += i_payload_data_length; |
|---|
| 642 | | continue; |
|---|
| 643 | | } |
|---|
| 644 | | |
|---|
| 645 | | |
|---|
| 646 | | for( i_payload_data_pos = 0; |
|---|
| 647 | | i_payload_data_pos < i_payload_data_length && |
|---|
| 648 | | i_packet_size_left > 0; |
|---|
| 649 | | i_payload_data_pos += i_sub_payload_data_length ) |
|---|
| 650 | | { |
|---|
| 651 | | data_packet_t *p_data; |
|---|
| 652 | | int i_read; |
|---|
| 653 | | // read sub payload length |
|---|
| 654 | | if( i_replicated_data_length == 1 ) |
|---|
| 655 | | { |
|---|
| 656 | | i_sub_payload_data_length = p_peek[i_skip]; i_skip++; |
|---|
| 657 | | i_payload_data_pos++; |
|---|
| 658 | | } |
|---|
| 659 | | else |
|---|
| 660 | | { |
|---|
| 661 | | i_sub_payload_data_length = i_payload_data_length; |
|---|
| 662 | | } |
|---|
| 663 | | |
|---|
| 664 | | /* FIXME I don't use i_media_object_number, sould I ? */ |
|---|
| 665 | | if( p_stream->p_pes && i_media_object_offset == 0 ) { |
|---|
| 666 | | /* send complete packet to decoder */ |
|---|
| 667 | | if( p_stream->p_pes->i_pes_size > 0 ) |
|---|
| 668 | | { |
|---|
| 669 | | input_DecodePES( p_stream->p_es->p_decoder_fifo, p_stream->p_pes ); |
|---|
| 670 | | p_stream->p_pes = NULL; |
|---|
| 671 | | } |
|---|
| 672 | | } |
|---|
| 673 | | |
|---|
| 674 | | if( !p_stream->p_pes ) // add a new PES |
|---|
| 675 | | { |
|---|
| 676 | | p_stream->i_time = |
|---|
| 677 | | ( (mtime_t)i_pts + i_payload * (mtime_t)i_pts_delta ); |
|---|
| 678 | | |
|---|
| 679 | | if( p_demux->i_first_pts == -1 ) |
|---|
| 680 | | { |
|---|
| 681 | | p_demux->i_first_pts = p_stream->i_time; |
|---|
| 682 | | } |
|---|
| 683 | | p_stream->i_time -= p_demux->i_first_pts; |
|---|
| 684 | | |
|---|
| 685 | | p_stream->p_pes = input_NewPES( p_input->p_method_data ); |
|---|
| 686 | | p_stream->p_pes->i_dts = |
|---|
| 687 | | p_stream->p_pes->i_pts = |
|---|
| 688 | | input_ClockGetTS( p_input, |
|---|
| 689 | | p_input->stream.p_selected_program, |
|---|
| 690 | | ( p_stream->i_time+DEFAULT_PTS_DELAY) * 9 /100 ); |
|---|
| 691 | | |
|---|
| 692 | | p_stream->p_pes->p_next = NULL; |
|---|
| 693 | | p_stream->p_pes->i_nb_data = 0; |
|---|
| 694 | | p_stream->p_pes->i_pes_size = 0; |
|---|
| 695 | | } |
|---|
| 696 | | |
|---|
| 697 | | i_read = i_sub_payload_data_length + i_skip; |
|---|
| 698 | | if( input_SplitBuffer( p_input, &p_data, i_read ) < i_read ) |
|---|
| 699 | | { |
|---|
| 700 | | msg_Warn( p_input, "cannot read data" ); |
|---|
| 701 | | return( 0 ); |
|---|
| 702 | | } |
|---|
| 703 | | p_data->p_payload_start += i_skip; |
|---|
| 704 | | i_packet_size_left -= i_read; |
|---|
| 705 | | |
|---|
| 706 | | |
|---|
| 707 | | if( !p_stream->p_pes->p_first ) |
|---|
| 708 | | { |
|---|
| 709 | | p_stream->p_pes->p_first = p_stream->p_pes->p_last = p_data; |
|---|
| 710 | | } |
|---|
| 711 | | else |
|---|
| 712 | | { |
|---|
| 713 | | p_stream->p_pes->p_last->p_next = p_data; |
|---|
| 714 | | p_stream->p_pes->p_last = p_data; |
|---|
| 715 | | } |
|---|
| 716 | | p_stream->p_pes->i_pes_size += i_sub_payload_data_length; |
|---|
| 717 | | p_stream->p_pes->i_nb_data++; |
|---|
| 718 | | |
|---|
| 719 | | i_skip = 0; |
|---|
| 720 | | if( i_packet_size_left > 0 ) |
|---|
| 721 | | { |
|---|
| 722 | | if( input_Peek( p_input, &p_peek, i_packet_size_left ) < i_packet_size_left ) |
|---|
| 723 | | { |
|---|
| 724 | | // EOF ? |
|---|
| 725 | | msg_Warn( p_input, "cannot peek, EOF ?" ); |
|---|
| 726 | | return( 0 ); |
|---|
| 727 | | } |
|---|
| 728 | | } |
|---|
| 729 | | } |
|---|
| 730 | | } |
|---|
| 731 | | |
|---|
| 732 | | if( i_packet_size_left > 0 ) |
|---|
| 733 | | { |
|---|
| 734 | | if( !ASF_SkipBytes( p_input, i_packet_size_left ) ) |
|---|
| 735 | | { |
|---|
| 736 | | msg_Warn( p_input, "cannot skip data, EOF ?" ); |
|---|
| 737 | | return( 0 ); |
|---|
| 738 | | } |
|---|
| 739 | | } |
|---|
| 740 | | |
|---|
| 741 | | continue; |
|---|
| 742 | | |
|---|
| 743 | | loop_error_recovery: |
|---|
| 744 | | msg_Warn( p_input, "unsupported packet header" ); |
|---|
| 745 | | if( p_demux->p_fp->i_min_data_packet_size != p_demux->p_fp->i_max_data_packet_size ) |
|---|
| 746 | | { |
|---|
| 747 | | msg_Err( p_input, "unsupported packet header, fatal error" ); |
|---|
| 748 | | return( -1 ); |
|---|
| 749 | | } |
|---|
| 750 | | ASF_SkipBytes( p_input, i_data_packet_min ); |
|---|
| 751 | | |
|---|
| 752 | | } // loop over packet |
|---|
| | 793 | int i_result; |
|---|
| | 794 | |
|---|
| | 795 | if( ( i_result = DemuxPacket( p_input, b_play_audio ) ) <= 0 ) |
|---|
| | 796 | { |
|---|
| | 797 | return i_result; |
|---|
| | 798 | } |
|---|
| | 799 | } |
|---|
| | 800 | |
|---|