@@ -545,6 +545,263 @@ de265_error decoder_context::read_vps_NAL(bitreader& reader)
545
545
return DE265_OK;
546
546
}
547
547
548
+ // implemented as freestanding functions to avoid changing API
549
+
550
+ bool operator ==(const profile_data &lhs, const profile_data &rhs) {
551
+ if (&lhs == &rhs) return true ;
552
+ if (lhs.profile_present_flag != rhs.profile_present_flag ) return false ;
553
+ if (lhs.profile_present_flag ) {
554
+ if (lhs.profile_space != rhs.profile_space ) return false ;
555
+ if (lhs.tier_flag != rhs.tier_flag ) return false ;
556
+ if (lhs.profile_idc != rhs.profile_idc ) return false ;
557
+
558
+ if (memcmp (lhs.profile_compatibility_flag , rhs.profile_compatibility_flag , sizeof (rhs.profile_compatibility_flag )) ) return false ;
559
+
560
+ if (lhs.progressive_source_flag != rhs.progressive_source_flag ) return false ;
561
+ if (lhs.interlaced_source_flag != rhs.interlaced_source_flag ) return false ;
562
+ if (lhs.non_packed_constraint_flag != rhs.non_packed_constraint_flag ) return false ;
563
+ if (lhs.frame_only_constraint_flag != rhs.frame_only_constraint_flag ) return false ;
564
+ }
565
+
566
+ if (lhs.level_present_flag != rhs.level_present_flag ) return false ;
567
+ if (lhs.level_present_flag && lhs.level_idc != rhs.level_idc ) return false ;
568
+
569
+ return true ;
570
+ }
571
+
572
+ bool operator !=(const profile_data &lhs, const profile_data &rhs) {
573
+ if (&lhs == &rhs) return false ;
574
+ return (!(lhs==rhs));
575
+ }
576
+
577
+ // class does not store max_sub_layers, so operator == cannot be done.
578
+ bool isEqual (const profile_tier_level &lhs , const profile_tier_level &rhs, int sps_max_sub_layers ) {
579
+ if (&lhs == &rhs) return true ;
580
+
581
+ if (lhs.general != rhs.general ) return false ;
582
+ for (int i = 0 ; i < sps_max_sub_layers; i++ ) {
583
+ if (lhs.sub_layer [i] != rhs.sub_layer [i]) return false ;
584
+ }
585
+ return true ;
586
+ }
587
+
588
+ bool isEqual (const video_usability_information &lhs, const video_usability_information &rhs, const seq_parameter_set &sps) {
589
+ if (&lhs == &rhs) return true ;
590
+
591
+ // not seen yet if(lhs.nal_hrd_parameters_present_flag != rhs.nal_hrd_parameters_present_flag ) return false;
592
+
593
+ // populated by video_usability_information::read()
594
+ if (lhs.aspect_ratio_info_present_flag != rhs.aspect_ratio_info_present_flag ) return false ;
595
+ if (lhs.aspect_ratio_info_present_flag ) {
596
+ if (lhs.sar_width != rhs.sar_width ) return false ;
597
+ if (lhs.sar_height != rhs.sar_height ) return false ;
598
+ }
599
+
600
+ if (lhs.overscan_info_present_flag != rhs.overscan_info_present_flag ) return false ;
601
+ if (lhs.overscan_info_present_flag ) {
602
+ if (lhs.overscan_appropriate_flag != rhs.overscan_appropriate_flag ) return false ;
603
+ }
604
+
605
+ if (lhs.video_signal_type_present_flag != rhs.video_signal_type_present_flag ) return false ;
606
+ if (lhs.video_signal_type_present_flag ) {
607
+ if (lhs.video_format != rhs.video_format ) return false ;
608
+ if (lhs.video_full_range_flag != rhs.video_full_range_flag ) return false ;
609
+ if (lhs.colour_description_present_flag != rhs.colour_description_present_flag ) return false ;
610
+ if (lhs.colour_primaries != rhs.colour_primaries ) return false ;
611
+ if (lhs.transfer_characteristics != rhs.transfer_characteristics ) return false ;
612
+ if (lhs.matrix_coeffs != rhs.matrix_coeffs ) return false ;
613
+ }
614
+
615
+ if (lhs.chroma_loc_info_present_flag != rhs.chroma_loc_info_present_flag ) return false ;
616
+ if (lhs.chroma_loc_info_present_flag ) {
617
+ if (lhs.chroma_sample_loc_type_top_field != rhs.chroma_sample_loc_type_top_field ) return false ;
618
+ if (lhs.chroma_sample_loc_type_bottom_field != rhs.chroma_sample_loc_type_bottom_field ) return false ;
619
+ }
620
+ if (lhs.neutral_chroma_indication_flag != rhs.neutral_chroma_indication_flag ) return false ;
621
+ if (lhs.field_seq_flag != rhs.field_seq_flag ) return false ;
622
+ if (lhs.frame_field_info_present_flag != rhs.frame_field_info_present_flag ) return false ;
623
+
624
+ if (lhs.default_display_window_flag != rhs.default_display_window_flag ) return false ;
625
+ if (lhs.default_display_window_flag ) {
626
+ if (lhs.def_disp_win_left_offset != rhs.def_disp_win_left_offset ) return false ;
627
+ if (lhs.def_disp_win_right_offset != rhs.def_disp_win_right_offset ) return false ;
628
+ if (lhs.def_disp_win_top_offset != rhs.def_disp_win_top_offset ) return false ;
629
+ if (lhs.def_disp_win_bottom_offset != rhs.def_disp_win_bottom_offset ) return false ;
630
+ }
631
+
632
+ if (lhs.vui_timing_info_present_flag != rhs.vui_timing_info_present_flag ) return false ;
633
+ if (lhs.vui_timing_info_present_flag ) {
634
+ if (lhs.vui_num_units_in_tick != rhs.vui_num_units_in_tick ) return false ;
635
+ if (lhs.vui_time_scale != rhs.vui_time_scale ) return false ;
636
+ if (lhs.vui_timing_info_present_flag != rhs.vui_timing_info_present_flag ) return false ;
637
+ if (lhs.vui_timing_info_present_flag ) {
638
+ if (lhs.vui_num_ticks_poc_diff_one != rhs.vui_num_ticks_poc_diff_one ) return false ;
639
+ }
640
+ }
641
+
642
+ if (lhs.vui_hrd_parameters_present_flag != rhs.vui_hrd_parameters_present_flag ) return false ;
643
+
644
+
645
+ if (lhs.vui_hrd_parameters_present_flag ) {
646
+ // check things made by hrd_parametes
647
+
648
+ if (lhs.vui_hrd_parameters_present_flag != rhs.vui_hrd_parameters_present_flag ) return false ;
649
+ if (lhs.vcl_hrd_parameters_present_flag != rhs.vcl_hrd_parameters_present_flag ) return false ;
650
+
651
+ if (lhs.nal_hrd_parameters_present_flag || lhs.vcl_hrd_parameters_present_flag ) {
652
+ if (lhs.sub_pic_hrd_params_present_flag != rhs.sub_pic_hrd_params_present_flag ) return false ;
653
+ if (lhs.sub_pic_hrd_params_present_flag ) {
654
+ if (lhs.tick_divisor_minus2 != rhs.tick_divisor_minus2 ) return false ;
655
+ if (lhs.du_cpb_removal_delay_increment_length_minus1 != rhs.du_cpb_removal_delay_increment_length_minus1 ) return false ;
656
+ if (lhs.sub_pic_cpb_params_in_pic_timing_sei_flag != rhs.sub_pic_cpb_params_in_pic_timing_sei_flag ) return false ;
657
+ if (lhs.dpb_output_delay_du_length_minus1 != rhs.dpb_output_delay_du_length_minus1 ) return false ;
658
+ }
659
+ if (lhs.bit_rate_scale != rhs.bit_rate_scale ) return false ;
660
+ if (lhs.cpb_size_scale != rhs.cpb_size_scale ) return false ;
661
+ if (lhs.sub_pic_hrd_params_present_flag ) {
662
+ if (lhs.cpb_size_du_scale != rhs.cpb_size_du_scale ) return false ;
663
+ }
664
+ if (lhs.initial_cpb_removal_delay_length_minus1 != rhs.initial_cpb_removal_delay_length_minus1 ) return false ;
665
+ if (lhs.au_cpb_removal_delay_length_minus1 != rhs.au_cpb_removal_delay_length_minus1 ) return false ;
666
+ if (lhs.dpb_output_delay_length_minus1 != rhs.dpb_output_delay_length_minus1 ) return false ;
667
+ }
668
+
669
+ int i;
670
+ unsigned int j, nalOrVcl;
671
+
672
+ for (i = 0 ; i < sps.sps_max_sub_layers ; i++) {
673
+ if (lhs.fixed_pic_rate_general_flag [i] != rhs.fixed_pic_rate_general_flag [i] ) return false ;
674
+ if (lhs.fixed_pic_rate_general_flag [i]) {
675
+ if (lhs.elemental_duration_in_tc_minus1 [i] != rhs.elemental_duration_in_tc_minus1 [i] ) return false ;
676
+ }
677
+ if (lhs.low_delay_hrd_flag [i] != rhs.low_delay_hrd_flag [i] ) return false ;
678
+ if (lhs.cpb_cnt_minus1 [i] != rhs.cpb_cnt_minus1 [i] ) return false ;
679
+
680
+ for (nalOrVcl = 0 ; nalOrVcl < 2 ; nalOrVcl++) {
681
+ if (((nalOrVcl == 0 ) && lhs.nal_hrd_parameters_present_flag ) || ((nalOrVcl == 1 ) && lhs.vcl_hrd_parameters_present_flag )) {
682
+ for (j = 0 ; j <= lhs.cpb_cnt_minus1 [i]; j++) {
683
+ if (lhs.bit_rate_value_minus1 [i][j][nalOrVcl] != rhs.bit_rate_value_minus1 [i][j][nalOrVcl]) return false ;
684
+ if (lhs.cpb_size_value_minus1 [i][j][nalOrVcl] != rhs.cpb_size_value_minus1 [i][j][nalOrVcl]) return false ;
685
+
686
+ if (lhs.sub_pic_hrd_params_present_flag ) {
687
+ if (lhs.cpb_size_du_value_minus1 [i][j][nalOrVcl] != rhs.cpb_size_du_value_minus1 [i][j][nalOrVcl]) return false ;
688
+ if (lhs.bit_rate_du_value_minus1 [i][j][nalOrVcl] != rhs.bit_rate_du_value_minus1 [i][j][nalOrVcl]) return false ;
689
+ }
690
+ if ( lhs.cbr_flag [i][j][nalOrVcl] != rhs.cbr_flag [i][j][nalOrVcl]) return false ;
691
+ }
692
+ }
693
+ }
694
+ }
695
+ }
696
+ return true ;
697
+ }
698
+
699
+ bool operator ==(const sps_range_extension &lhs, const sps_range_extension &rhs) {
700
+ if (&lhs == &rhs) return true ;
701
+ if (lhs.transform_skip_rotation_enabled_flag != rhs.transform_skip_rotation_enabled_flag ) return false ;
702
+ if (lhs.transform_skip_context_enabled_flag != rhs.transform_skip_context_enabled_flag ) return false ;
703
+ if (lhs.implicit_rdpcm_enabled_flag != rhs.implicit_rdpcm_enabled_flag ) return false ;
704
+ if (lhs.explicit_rdpcm_enabled_flag != rhs.explicit_rdpcm_enabled_flag ) return false ;
705
+ if (lhs.extended_precision_processing_flag != rhs.extended_precision_processing_flag ) return false ;
706
+ if (lhs.intra_smoothing_disabled_flag != rhs.intra_smoothing_disabled_flag ) return false ;
707
+ if (lhs.high_precision_offsets_enabled_flag != rhs.high_precision_offsets_enabled_flag ) return false ;
708
+ if (lhs.persistent_rice_adaptation_enabled_flag != rhs.persistent_rice_adaptation_enabled_flag ) return false ;
709
+ if (lhs.cabac_bypass_alignment_enabled_flag != rhs.cabac_bypass_alignment_enabled_flag ) return false ;
710
+ return true ;
711
+ }
712
+
713
+ bool operator !=(const sps_range_extension &lhs, const sps_range_extension &rhs) {
714
+ if (&lhs == &rhs) return false ;
715
+ return !(lhs==rhs);
716
+ }
717
+
718
+
719
+ bool operator ==(const seq_parameter_set &lhs, const seq_parameter_set &rhs) {
720
+
721
+ if (&lhs== &rhs) return true ;
722
+
723
+ if (lhs.sps_read != rhs.sps_read ) return false ;
724
+
725
+ if (lhs.video_parameter_set_id != rhs.video_parameter_set_id ) return false ;
726
+ if (lhs.sps_max_sub_layers != rhs.sps_max_sub_layers ) return false ;
727
+ if (lhs.sps_temporal_id_nesting_flag != rhs.sps_temporal_id_nesting_flag ) return false ;
728
+
729
+ if (!isEqual (lhs.profile_tier_level_ , rhs.profile_tier_level_ , lhs.sps_max_sub_layers )) return false ;
730
+
731
+ if (lhs.seq_parameter_set_id != rhs.seq_parameter_set_id ) return false ;
732
+ if (lhs.chroma_format_idc != rhs.chroma_format_idc ) return false ;
733
+
734
+ if (lhs.separate_colour_plane_flag != rhs.separate_colour_plane_flag ) return false ;
735
+ if (lhs.pic_width_in_luma_samples != rhs.pic_width_in_luma_samples ) return false ;
736
+ if (lhs.pic_height_in_luma_samples != rhs.pic_height_in_luma_samples ) return false ;
737
+ if (lhs.conformance_window_flag != rhs.conformance_window_flag ) return false ;
738
+
739
+ if (lhs.conformance_window_flag ) {
740
+ if (lhs.conf_win_left_offset != rhs.conf_win_left_offset ) return false ;
741
+ if (lhs.conf_win_right_offset != rhs.conf_win_right_offset ) return false ;
742
+ if (lhs.conf_win_top_offset != rhs.conf_win_top_offset ) return false ;
743
+ if (lhs.conf_win_bottom_offset != rhs.conf_win_bottom_offset ) return false ;
744
+ }
745
+
746
+ if (lhs.bit_depth_luma != rhs.bit_depth_luma ) return false ;
747
+ if (lhs.bit_depth_chroma != rhs.bit_depth_chroma ) return false ;
748
+
749
+ if (lhs.log2_max_pic_order_cnt_lsb != rhs.log2_max_pic_order_cnt_lsb ) return false ;
750
+ if (lhs.sps_sub_layer_ordering_info_present_flag != rhs.sps_sub_layer_ordering_info_present_flag ) return false ;
751
+
752
+ if (memcmp (lhs.sps_max_dec_pic_buffering , rhs.sps_max_dec_pic_buffering , sizeof (rhs.sps_max_dec_pic_buffering ))) return false ;
753
+ if (memcmp (lhs.sps_max_num_reorder_pics , rhs.sps_max_num_reorder_pics , sizeof (rhs.sps_max_num_reorder_pics ))) return false ;
754
+ if (memcmp (lhs.sps_max_latency_increase_plus1 , rhs.sps_max_latency_increase_plus1 , sizeof (rhs.sps_max_latency_increase_plus1 ))) return false ;
755
+
756
+ if (lhs.log2_min_luma_coding_block_size != rhs.log2_min_luma_coding_block_size ) return false ;
757
+ if (lhs.log2_diff_max_min_luma_coding_block_size != rhs.log2_diff_max_min_luma_coding_block_size ) return false ;
758
+ if (lhs.log2_min_transform_block_size != rhs.log2_min_transform_block_size ) return false ;
759
+ if (lhs.log2_diff_max_min_transform_block_size != rhs.log2_diff_max_min_transform_block_size ) return false ;
760
+ if (lhs.max_transform_hierarchy_depth_inter != rhs.max_transform_hierarchy_depth_inter ) return false ;
761
+ if (lhs.max_transform_hierarchy_depth_intra != rhs.max_transform_hierarchy_depth_intra ) return false ;
762
+
763
+ if (lhs.scaling_list_enable_flag != rhs.scaling_list_enable_flag ) return false ;
764
+ if (lhs.scaling_list_enable_flag ) {
765
+ if (lhs.sps_scaling_list_data_present_flag != rhs.sps_scaling_list_data_present_flag ) return false ;
766
+ if (lhs.sps_scaling_list_data_present_flag ) {
767
+ // compare only needed if present, otherwise it is the default scaling list.
768
+ if (memcmp (&lhs.scaling_list , &rhs.scaling_list , sizeof (rhs.scaling_list ))) return false ;
769
+ }
770
+ }
771
+
772
+ if (lhs.amp_enabled_flag != rhs.amp_enabled_flag ) return false ;
773
+ if (lhs.sample_adaptive_offset_enabled_flag != rhs.sample_adaptive_offset_enabled_flag ) return false ;
774
+ if (lhs.pcm_enabled_flag != rhs.pcm_enabled_flag ) return false ;
775
+
776
+ if (lhs.pcm_enabled_flag ) {
777
+ if (lhs.pcm_sample_bit_depth_luma != rhs.pcm_sample_bit_depth_luma ) return false ;
778
+ if (lhs.pcm_sample_bit_depth_chroma != rhs.pcm_sample_bit_depth_chroma ) return false ;
779
+ if (lhs.log2_min_pcm_luma_coding_block_size != rhs.log2_min_pcm_luma_coding_block_size ) return false ;
780
+ if (lhs.log2_diff_max_min_pcm_luma_coding_block_size != rhs.log2_diff_max_min_pcm_luma_coding_block_size ) return false ;
781
+ if (lhs.pcm_loop_filter_disable_flag != rhs.pcm_loop_filter_disable_flag ) return false ;
782
+ }
783
+
784
+ // (longterm) reference pics likely to change with a new sps, so ignored here.
785
+
786
+ if (lhs.sps_temporal_mvp_enabled_flag != rhs.sps_temporal_mvp_enabled_flag ) return false ;
787
+ if (lhs.strong_intra_smoothing_enable_flag != rhs.strong_intra_smoothing_enable_flag ) return false ;
788
+
789
+ if (lhs.vui_parameters_present_flag != rhs.vui_parameters_present_flag ) return false ;
790
+ if (lhs.vui_parameters_present_flag ) {
791
+ if (!isEqual (lhs.vui , rhs.vui , lhs )) return false ;
792
+ }
793
+
794
+ if (lhs.sps_extension_present_flag != rhs.sps_extension_present_flag ) return false ;
795
+ if (lhs.sps_extension_present_flag ) {
796
+ if (lhs.sps_range_extension_flag != rhs.sps_range_extension_flag ) return false ;
797
+ if (lhs.sps_multilayer_extension_flag != rhs.sps_multilayer_extension_flag ) return false ;
798
+ if (lhs.sps_extension_6bits != rhs.sps_extension_6bits ) return false ;
799
+ if (lhs.range_extension != rhs.range_extension ) return false ;
800
+ }
801
+
802
+ return true ;
803
+ }
804
+
548
805
de265_error decoder_context::read_sps_NAL (bitreader& reader)
549
806
{
550
807
logdebug (LogHeaders," ----> read SPS\n " );
@@ -560,6 +817,22 @@ de265_error decoder_context::read_sps_NAL(bitreader& reader)
560
817
new_sps->dump (param_sps_headers_fd);
561
818
}
562
819
820
+ if ( sps[ new_sps->seq_parameter_set_id ] ) {
821
+ auto old_sps = sps[ new_sps->seq_parameter_set_id ].get ();
822
+ if ( *old_sps == *new_sps ) {
823
+ printf (" **** keeping sps *****\n " );
824
+ // the new sps is identical to the old one, so no replacing needed.
825
+ // however, reference pics and long-term reference pics might need updating.
826
+ old_sps->ref_pic_sets = new_sps->ref_pic_sets ;
827
+ old_sps->long_term_ref_pics_present_flag = new_sps->long_term_ref_pics_present_flag ;
828
+ memcpy (old_sps->lt_ref_pic_poc_lsb_sps , new_sps->lt_ref_pic_poc_lsb_sps , sizeof (old_sps->lt_ref_pic_poc_lsb_sps ));
829
+ memcpy (old_sps->used_by_curr_pic_lt_sps_flag , new_sps->used_by_curr_pic_lt_sps_flag , sizeof (old_sps->used_by_curr_pic_lt_sps_flag ));
830
+ return DE265_OK;
831
+ }
832
+ printf (" **** replacing sps *****\n " );
833
+
834
+ }
835
+
563
836
sps[ new_sps->seq_parameter_set_id ] = new_sps;
564
837
565
838
// Remove the all PPS that referenced the old SPS because parameters may have changed and we do not want to
0 commit comments