Changeset b160af605b251682ad86348cc4e07287084e891c
- Timestamp:
- 02/27/07 20:39:41 (2 years ago)
- git-parent:
- Files:
-
- modules/packetizer/h264.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/packetizer/h264.c
rd3fe7f2 rb160af6 59 59 static block_t *PacketizeAVC1( decoder_t *, block_t ** ); 60 60 61 typedef struct 62 { 63 int i_nal_type; 64 int i_nal_ref_idc; 65 66 int i_frame_type; 67 int i_pic_parameter_set_id; 68 int i_frame_num; 69 70 int i_field_pic_flag; 71 int i_bottom_field_flag; 72 73 int i_idr_pic_id; 74 75 int i_pic_order_cnt_lsb; 76 int i_delta_pic_order_cnt_bottom; 77 78 int i_delta_pic_order_cnt0; 79 int i_delta_pic_order_cnt1; 80 } slice_t; 81 61 82 struct decoder_sys_t 62 83 { … … 82 103 int i_log2_max_frame_num; 83 104 int b_frame_mbs_only; 105 int i_pic_order_cnt_type; 106 int i_delta_pic_order_always_zero_flag; 107 int i_log2_max_pic_order_cnt_lsb; 108 109 /* Value from Picture Parameter Set */ 110 int i_pic_order_present_flag; 84 111 85 112 /* Useful values of the Slice Header */ 86 int i_nal_type; 87 int i_nal_ref_idc; 88 int i_idr_pic_id; 89 int i_frame_num; 90 int i_frame_type; 113 slice_t slice; 91 114 }; 92 115 … … 166 189 p_sys->b_header= VLC_FALSE; 167 190 168 p_sys->i_nal_type = -1; 169 p_sys->i_nal_ref_idc = -1; 170 p_sys->i_idr_pic_id = -1; 171 p_sys->i_frame_num = -1; 172 p_sys->i_frame_type = 0; 191 p_sys->slice.i_nal_type = -1; 192 p_sys->slice.i_nal_ref_idc = -1; 193 p_sys->slice.i_idr_pic_id = -1; 194 p_sys->slice.i_frame_num = -1; 195 p_sys->slice.i_frame_type = 0; 196 p_sys->slice.i_pic_parameter_set_id = -1; 197 p_sys->slice.i_field_pic_flag = 0; 198 p_sys->slice.i_bottom_field_flag = -1; 199 p_sys->slice.i_pic_order_cnt_lsb = -1; 200 p_sys->slice.i_delta_pic_order_cnt_bottom = -1; 173 201 174 202 /* Setup properties */ … … 223 251 p_dec->fmt_out.i_extra = p_sys->p_pps->i_buffer + p_sys->p_sps->i_buffer; 224 252 p_dec->fmt_out.p_extra = (uint8_t*)malloc( p_dec->fmt_out.i_extra ); 225 memcpy( p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);226 memcpy( p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);253 memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer); 254 memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer); 227 255 p_sys->b_header = VLC_TRUE; 228 256 … … 336 364 337 365 /* Remove trailing 0 bytes */ 338 while( p_pic->i_buffer && (!p_pic->p_buffer[p_pic->i_buffer-1] ) ) p_pic->i_buffer--; 366 while( p_pic->i_buffer && (!p_pic->p_buffer[p_pic->i_buffer-1] ) ) 367 p_pic->i_buffer--; 339 368 p_sys->i_offset = 0; 340 369 … … 484 513 #define OUTPUT \ 485 514 do { \ 486 if( !p_sys->b_header && p_sys-> i_frame_type != BLOCK_FLAG_TYPE_I) \515 if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I) \ 487 516 break; \ 488 517 \ 489 p_pic = block_ChainGather( p_sys->p_frame ); \ 518 if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps && !p_sys->b_header ) \ 519 { \ 520 block_t *p_sps = block_Duplicate( p_sys->p_sps ); \ 521 block_t *p_pps = block_Duplicate( p_sys->p_pps ); \ 522 p_sps->i_dts = p_sys->p_frame->i_dts; \ 523 p_sps->i_pts = p_sys->p_frame->i_pts; \ 524 block_ChainAppend( &p_sps, p_pps ); \ 525 block_ChainAppend( &p_sps, p_sys->p_frame ); \ 526 p_sys->b_header = VLC_TRUE; \ 527 p_pic = block_ChainGather( p_sps ); \ 528 } else { \ 529 p_pic = block_ChainGather( p_sys->p_frame ); \ 530 } \ 490 531 p_pic->i_length = 0; /* FIXME */ \ 491 p_pic->i_flags |= p_sys-> i_frame_type;\492 \493 p_sys-> i_frame_type = 0;\532 p_pic->i_flags |= p_sys->slice.i_frame_type; \ 533 \ 534 p_sys->slice.i_frame_type = 0; \ 494 535 p_sys->p_frame = NULL; \ 495 536 p_sys->b_slice = VLC_FALSE; \ 496 \497 if( ( p_pic->i_flags & BLOCK_FLAG_TYPE_I ) && \498 p_sys->p_sps && p_sys->p_pps ) \499 { \500 block_t *p_sps = block_Duplicate( p_sys->p_sps ); \501 block_t *p_pps = block_Duplicate( p_sys->p_pps ); \502 p_sps->i_dts = p_pps->i_dts = p_pic->i_dts; \503 p_sps->i_pts = p_pps->i_pts = p_pic->i_pts; \504 block_ChainAppend( &p_sps, p_pps ); \505 block_ChainAppend( &p_sps, p_pic ); \506 p_pic = p_sps; \507 p_sys->b_header = VLC_TRUE; \508 } \509 537 } while(0) 510 538 511 512 if( p_sys->b_slice && !p_sys->b_sps ) 539 if( p_sys->b_slice && ( !p_sys->b_sps || !p_sys->b_pps ) ) 513 540 { 514 541 block_ChainRelease( p_sys->p_frame ); 515 msg_Warn( p_dec, "waiting for SPS " );542 msg_Warn( p_dec, "waiting for SPS/PPS" ); 516 543 517 544 /* Reset context */ 545 p_sys->slice.i_frame_type = 0; 518 546 p_sys->p_frame = NULL; 519 547 p_sys->b_slice = VLC_FALSE; 520 548 } 521 549 522 if( !p_sys->b_sps&&550 if( ( !p_sys->b_sps || !p_sys->b_pps ) && 523 551 i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR ) 524 552 { … … 529 557 { 530 558 uint8_t *dec; 531 int i_dec, i_first_mb, i_slice_type, i_frame_num; 532 vlc_bool_t b_pic = VLC_FALSE; 559 int i_dec, i_first_mb, i_slice_type; 560 slice_t slice; 561 vlc_bool_t b_pic; 533 562 bs_t s; 534 563 … … 545 574 { 546 575 case 0: case 5: 547 p_sys->i_frame_type = BLOCK_FLAG_TYPE_P;576 slice.i_frame_type = BLOCK_FLAG_TYPE_P; 548 577 break; 549 578 case 1: case 6: 550 p_sys->i_frame_type = BLOCK_FLAG_TYPE_B;579 slice.i_frame_type = BLOCK_FLAG_TYPE_B; 551 580 break; 552 581 case 2: case 7: 553 p_sys->i_frame_type = BLOCK_FLAG_TYPE_I;582 slice.i_frame_type = BLOCK_FLAG_TYPE_I; 554 583 break; 555 584 case 3: case 8: /* SP */ 556 p_sys->i_frame_type = BLOCK_FLAG_TYPE_P;585 slice.i_frame_type = BLOCK_FLAG_TYPE_P; 557 586 break; 558 587 case 4: case 9: 559 p_sys->i_frame_type = BLOCK_FLAG_TYPE_I;588 slice.i_frame_type = BLOCK_FLAG_TYPE_I; 560 589 break; 561 } 562 563 /* pic_parameter_set_id */ 564 bs_read_ue( &s ); 565 /* frame_num */ 566 i_frame_num = bs_read( &s, p_sys->i_log2_max_frame_num + 4 ); 590 default: 591 slice.i_frame_type = 0; 592 break; 593 } 594 595 /* */ 596 slice.i_nal_type = i_nal_type; 597 slice.i_nal_ref_idc = i_nal_ref_idc; 598 599 slice.i_pic_parameter_set_id = bs_read_ue( &s ); 600 slice.i_frame_num = bs_read( &s, p_sys->i_log2_max_frame_num + 4 ); 601 602 slice.i_field_pic_flag = 0; 603 slice.i_bottom_field_flag = -1; 604 if( !p_sys->b_frame_mbs_only ) 605 { 606 /* field_pic_flag */ 607 slice.i_field_pic_flag = bs_read( &s, 1 ); 608 if( slice.i_field_pic_flag ) 609 slice.i_bottom_field_flag = bs_read( &s, 1 ); 610 } 611 612 slice.i_idr_pic_id = p_sys->slice.i_idr_pic_id; 613 if( slice.i_nal_type == NAL_SLICE_IDR ) 614 slice.i_idr_pic_id = bs_read_ue( &s ); 615 616 slice.i_pic_order_cnt_lsb = -1; 617 slice.i_delta_pic_order_cnt_bottom = -1; 618 slice.i_delta_pic_order_cnt0 = 0; 619 slice.i_delta_pic_order_cnt1 = 0; 620 if( p_sys->i_pic_order_cnt_type == 0 ) 621 { 622 slice.i_pic_order_cnt_lsb = bs_read( &s, p_sys->i_log2_max_pic_order_cnt_lsb + 4 ); 623 if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag ) 624 slice.i_delta_pic_order_cnt_bottom = bs_read_se( &s ); 625 } 626 else if( p_sys->i_pic_order_cnt_type == 1 && !p_sys->i_delta_pic_order_always_zero_flag ) 627 { 628 slice.i_delta_pic_order_cnt0 = bs_read_se( &s ); 629 if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag ) 630 slice.i_delta_pic_order_cnt1 = bs_read_se( &s ); 631 } 567 632 568 633 /* Detection of the first VCL NAL unit of a primary coded picture 569 634 * (cf. 7.4.1.2.4) */ 570 if( i_frame_num != p_sys->i_frame_num || 571 ( (i_nal_ref_idc != p_sys->i_nal_ref_idc) && 572 (!i_nal_ref_idc || !p_sys->i_nal_ref_idc) ) ) 573 { 635 b_pic = VLC_FALSE; 636 if( slice.i_frame_num != p_sys->slice.i_frame_num || 637 slice.i_pic_parameter_set_id != p_sys->slice.i_pic_parameter_set_id || 638 slice.i_field_pic_flag != p_sys->slice.i_field_pic_flag || 639 slice.i_nal_ref_idc != p_sys->slice.i_nal_ref_idc ) 574 640 b_pic = VLC_TRUE; 575 } 576 p_sys->i_frame_num = i_frame_num; 577 p_sys->i_nal_ref_idc = i_nal_ref_idc; 578 579 if( !p_sys->b_frame_mbs_only ) 580 { 581 /* field_pic_flag */ 582 if( bs_read( &s, 1 ) ) 583 { 584 /* bottom_field_flag */ 585 bs_read( &s, 1 ); 586 } 587 } 588 589 if( i_nal_type == NAL_SLICE_IDR ) 590 { 591 /* id_pic_id */ 592 int i_idr_pic_id = bs_read_ue( &s ); 593 if( p_sys->i_nal_type != i_nal_type ) b_pic = VLC_TRUE; 594 if( p_sys->i_idr_pic_id != i_idr_pic_id ) b_pic = VLC_TRUE; 595 p_sys->i_idr_pic_id = i_idr_pic_id; 596 } 597 p_sys->i_nal_type = i_nal_type; 598 599 if( b_pic && p_sys->b_slice ) OUTPUT; 641 if( slice.i_bottom_field_flag != -1 && p_sys->slice.i_bottom_field_flag != -1 && slice.i_bottom_field_flag != p_sys->slice.i_bottom_field_flag ) 642 b_pic = VLC_TRUE; 643 if( p_sys->i_pic_order_cnt_type == 0 && 644 ( slice.i_pic_order_cnt_lsb != p_sys->slice.i_pic_order_cnt_lsb || 645 slice.i_delta_pic_order_cnt_bottom != p_sys->slice.i_delta_pic_order_cnt_bottom ) ) 646 b_pic = VLC_TRUE; 647 else if( p_sys->i_pic_order_cnt_type == 1 && 648 ( slice.i_delta_pic_order_cnt0 != p_sys->slice.i_delta_pic_order_cnt0 || 649 slice.i_delta_pic_order_cnt1 != p_sys->slice.i_delta_pic_order_cnt1 ) ) 650 b_pic = VLC_TRUE; 651 if( ( slice.i_nal_type == NAL_SLICE_IDR || p_sys->slice.i_nal_type == NAL_SLICE_IDR ) && 652 ( slice.i_nal_type != p_sys->slice.i_nal_type || slice.i_idr_pic_id != p_sys->slice.i_idr_pic_id ) ) 653 b_pic = VLC_TRUE; 654 655 /* */ 656 p_sys->slice = slice; 657 658 if( b_pic && p_sys->b_slice ) 659 OUTPUT; 600 660 601 661 p_sys->b_slice = VLC_TRUE; … … 624 684 /* Skip i_log2_max_frame_num */ 625 685 p_sys->i_log2_max_frame_num = bs_read_ue( &s ); 686 if( p_sys->i_log2_max_frame_num > 12) 687 p_sys->i_log2_max_frame_num = 12; 626 688 /* Read poc_type */ 627 i_tmp= bs_read_ue( &s );628 if( i_tmp== 0 )689 p_sys->i_pic_order_cnt_type = bs_read_ue( &s ); 690 if( p_sys->i_pic_order_cnt_type == 0 ) 629 691 { 630 692 /* skip i_log2_max_poc_lsb */ 631 bs_read_ue( &s ); 632 } 633 else if( i_tmp == 1 ) 693 p_sys->i_log2_max_pic_order_cnt_lsb = bs_read_ue( &s ); 694 if( p_sys->i_log2_max_pic_order_cnt_lsb > 12 ) 695 p_sys->i_log2_max_pic_order_cnt_lsb = 12; 696 } 697 else if( p_sys->i_pic_order_cnt_type == 1 ) 634 698 { 635 699 int i_cycle; 636 700 /* skip b_delta_pic_order_always_zero */ 637 bs_skip( &s, 1 );701 p_sys->i_delta_pic_order_always_zero_flag = bs_read( &s, 1 ); 638 702 /* skip i_offset_for_non_ref_pic */ 639 703 bs_read_se( &s ); … … 732 796 { 733 797 bs_t s; 798 734 799 bs_init( &s, &p_frag->p_buffer[5], p_frag->i_buffer - 5 ); 800 bs_read_ue( &s ); // pps id 801 bs_read_ue( &s ); // sps id 802 bs_skip( &s, 1 ); // entropy coding mode flag 803 p_sys->i_pic_order_present_flag = bs_read( &s, 1 ); 735 804 736 805 if( !p_sys->b_pps ) msg_Dbg( p_dec, "found NAL_PPS" );
