static int ProbeHEVC( const uint8_t *p_peek, size_t i_peek, void *p_priv ) { hevc_probe_ctx_t *p_ctx = (hevc_probe_ctx_t *) p_priv; if( i_peek < 2 ) return -1; if( p_peek[0] & 0x80 ) return -1; const uint8_t i_type = hevc_getNALType( p_peek ); const uint8_t i_layer = hevc_getNALLayer( p_peek ); if ( i_type == HEVC_NAL_VPS ) /* VPS */ { if( i_layer != 0 || i_peek < 6 || p_peek[4] != 0xFF || p_peek[5] != 0xFF ) /* Check reserved bits */ return -1; p_ctx->b_vps = true; return 0; } else if( i_type == HEVC_NAL_SPS ) /* SPS */ { if( i_layer != 0 ) return -1; p_ctx->b_sps = true; return 0; } else if( i_type == HEVC_NAL_PPS ) /* PPS */ { if( i_layer != 0 ) return -1; p_ctx->b_pps = true; return 0; } else if( i_type >= HEVC_NAL_BLA_W_LP && i_type <= HEVC_NAL_CRA ) /* Key Frame */ { if( p_ctx->b_vps && p_ctx->b_sps && p_ctx->b_pps && i_layer == 0 ) return 1; } else if( i_type == HEVC_NAL_AUD ) /* AU */ { if( i_peek < H26X_MIN_PEEK || p_peek[4] != 0 || p_peek[5] != 0 ) /* Must prefix another NAL */ return -1; } else if( i_type == HEVC_NAL_PREF_SEI ) /* Prefix SEI */ { if( p_peek[2] == 0xFF ) /* empty SEI */ return -1; } else { return -1; /* See 7.4.2.4.4 for sequence order */ } return 0; /* Probe more */ }
static block_t *ParseVCL(decoder_t *p_dec, uint8_t i_nal_type, block_t *p_frag) { decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_outputchain = NULL; const uint8_t *p_buffer = p_frag->p_buffer; size_t i_buffer = p_frag->i_buffer; if(unlikely(!hxxx_strip_AnnexB_startcode(&p_buffer, &i_buffer) || i_buffer < 3)) { block_ChainLastAppend(&p_sys->frame.pp_chain_last, p_frag); /* might be corrupted */ return NULL; } const uint8_t i_layer = hevc_getNALLayer( p_buffer ); bool b_first_slice_in_pic = p_buffer[2] & 0x80; if (b_first_slice_in_pic) { if(p_sys->frame.p_chain) { /* Starting new frame: return previous frame data for output */ p_outputchain = OutputQueues(p_sys, p_sys->b_init_sequence_complete); } switch(i_nal_type) { case HEVC_NAL_BLA_W_LP: case HEVC_NAL_BLA_W_RADL: case HEVC_NAL_BLA_N_LP: case HEVC_NAL_IDR_W_RADL: case HEVC_NAL_IDR_N_LP: case HEVC_NAL_CRA: p_frag->i_flags |= BLOCK_FLAG_TYPE_I; break; default: { hevc_slice_segment_header_t *p_sli = hevc_decode_slice_header( p_buffer, i_buffer, true, p_sys->rgi_p_decsps, p_sys->rgi_p_decpps ); if( p_sli ) { enum hevc_slice_type_e type; if( hevc_get_slice_type( p_sli, &type ) ) { if( type == HEVC_SLICE_TYPE_P ) p_frag->i_flags |= BLOCK_FLAG_TYPE_P; else p_frag->i_flags |= BLOCK_FLAG_TYPE_B; } hevc_rbsp_release_slice_header( p_sli ); } else p_frag->i_flags |= BLOCK_FLAG_TYPE_B; } break; } } if(!p_sys->b_init_sequence_complete && i_layer == 0 && (p_frag->i_flags & BLOCK_FLAG_TYPE_I) && XPSReady(p_sys)) { p_sys->b_init_sequence_complete = true; } if( !p_sys->b_init_sequence_complete ) cc_storage_reset( p_sys->p_ccs ); block_ChainLastAppend(&p_sys->frame.pp_chain_last, p_frag); return p_outputchain; }