Skip to content

Commit 32a288f

Browse files
committed
upipe_h265f: add parsing of luma/chroma depth
1 parent efd879a commit 32a288f

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

include/upipe-framers/upipe_h265_framer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333

3434
#define UPIPE_H265F_SIGNATURE UBASE_FOURCC('h','e','v','f')
3535
/** We only accept the ISO 14496-10 annex B elementary stream. */
36-
#define UPIPE_H265F_EXPECTED_FLOW_DEF "block.h265."
36+
#define UPIPE_H265F_EXPECTED_FLOW_DEF "block.hevc."
3737

3838
/** @This returns the management structure for all h265f pipes.
3939
*

lib/upipe-framers/upipe_h265_framer.c

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,73 @@ static bool upipe_h265f_activate_sps(struct upipe *upipe, uint32_t sps_id)
873873
upipe_h26xf_stream_ue(s); /* bottom offset */
874874
}
875875

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+
}
878943

879944
uint32_t log2_max_pic_order_cnt = upipe_h26xf_stream_ue(s) + 4;
880945
if (log2_max_pic_order_cnt > 16) {

0 commit comments

Comments
 (0)