@@ -873,8 +873,73 @@ static bool upipe_h265f_activate_sps(struct upipe *upipe, uint32_t sps_id)
873
873
upipe_h26xf_stream_ue (s ); /* bottom offset */
874
874
}
875
875
876
- upipe_h26xf_stream_ue (s ); /* bit_depth_luma */
877
- upipe_h26xf_stream_ue (s ); /* bit_depth_chroma */
876
+ uint32_t luma_depth = upipe_h26xf_stream_ue (s ) + 8 ;
877
+ if (luma_depth > 16 ) {
878
+ upipe_err_va (upipe , "invalid SPS (bit_depth_luma %" PRIu32 ")" ,
879
+ luma_depth );
880
+ ubuf_block_stream_clean (s );
881
+ return false;
882
+ }
883
+
884
+ uint32_t chroma_depth = upipe_h26xf_stream_ue (s ) + 8 ;
885
+ if (chroma_depth > 16 ) {
886
+ upipe_err_va (upipe , "invalid SPS (bit_depth_chroma %" PRIu32 ")" ,
887
+ chroma_depth );
888
+ ubuf_block_stream_clean (s );
889
+ return false;
890
+ }
891
+
892
+ #ifdef UPIPE_WORDS_BIGENDIAN
893
+ # define ENDIANNESS "b"
894
+ #else
895
+ # define ENDIANNESS "l"
896
+ #endif
897
+
898
+ UBASE_FATAL (upipe , uref_pic_flow_set_macropixel (flow_def , 1 ))
899
+ UBASE_FATAL (upipe , uref_pic_flow_set_planes (flow_def , 0 ))
900
+ UBASE_FATAL (upipe , uref_pic_flow_add_plane_va (
901
+ flow_def , 1 , 1 , (luma_depth + 7 ) / 8 , "y%" PRIu8 "%s" ,
902
+ luma_depth , luma_depth > 8 ? ENDIANNESS : "" ))
903
+ if (chroma_idc == H265SPS_CHROMA_MONO ) {
904
+ UBASE_FATAL (upipe , uref_flow_set_def_va (flow_def ,
905
+ UPIPE_H265F_EXPECTED_FLOW_DEF "pic.planar%" PRIu8 "_mono." ,
906
+ luma_depth ))
907
+ } else {
908
+ uint8_t hsub , vsub ;
909
+ const char * chroma ;
910
+ switch (chroma_idc ) {
911
+ case H265SPS_CHROMA_420 :
912
+ hsub = 2 ;
913
+ vsub = 2 ;
914
+ chroma = "420" ;
915
+ break ;
916
+ case H265SPS_CHROMA_422 :
917
+ hsub = 2 ;
918
+ vsub = 1 ;
919
+ chroma = "422" ;
920
+ break ;
921
+ case H265SPS_CHROMA_444 :
922
+ hsub = 1 ;
923
+ vsub = 1 ;
924
+ chroma = "444" ;
925
+ break ;
926
+ default :
927
+ upipe_err_va (upipe , "invalid chroma format %" PRIu32 ,
928
+ chroma_idc );
929
+ ubuf_block_stream_clean (s );
930
+ return false;
931
+ }
932
+ uint8_t msize = (chroma_depth + 7 ) / 8 ;
933
+ UBASE_FATAL (upipe , uref_pic_flow_add_plane_va (
934
+ flow_def , hsub , vsub , msize , "u%" PRIu8 "%s" ,
935
+ chroma_depth , chroma_depth > 8 ? ENDIANNESS : "" ))
936
+ UBASE_FATAL (upipe , uref_pic_flow_add_plane_va (
937
+ flow_def , hsub , vsub , msize , "v%" PRIu8 "%s" ,
938
+ chroma_depth , chroma_depth > 8 ? ENDIANNESS : "" ))
939
+ UBASE_FATAL (upipe , uref_flow_set_def_va (flow_def ,
940
+ UPIPE_H265F_EXPECTED_FLOW_DEF "pic.planar%" PRIu8 "_%" PRIu8 "_%s." ,
941
+ luma_depth , chroma_depth , chroma ))
942
+ }
878
943
879
944
uint32_t log2_max_pic_order_cnt = upipe_h26xf_stream_ue (s ) + 4 ;
880
945
if (log2_max_pic_order_cnt > 16 ) {
0 commit comments