# Error Resilience - Slices and Resync-Markers

Table of Contents

- [Error Resilience - Slices and Resync-Markers](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#error-resilience-slices-and-resync-markers)

    - [Slice and Resync-marker extensions](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#slice-and-resync-marker-extensions)
    - [Query capabilities](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#query-capabilities)
    - [Using the slice encode extensions](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#using-the-slice-encode-extensions)

Encoders can compress a frame with an independently decodable Group of Blocks (GOBs), which are also known as slices.
Since each slice is independently decodable, they are intended to be units of recovery in case of data loss or corruption.
There are multiple advantages to introducing slices in the encoded frame:

> 
> 
> - Decoders can ignore a corrupt slice and skip to the following slice, thus containing the corruption to a part of the frame instead of the entire frame.
> - Slices can be sized to fit within a network packet to help with transmission.
> - Erroneous slices can be re-transmitted to avoid sending the whole frame.
> - Applications can use slices to reduce latency in real-time communication. Slices can be transmitted and decoded in parallel without having to wait for the entire frame to be coded.

Slices also work as re-synchronization markers since the decoders can resume from the next slice (marker) in case of bit errors.
On Snapdragon, AVC and HEVC encoders support slicing. A slice boundary can be specified as the number of bits per slice or the number of macroblocks per slice.

## [Slice and Resync-marker extensions](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#id2)[](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#slice-and-resync-marker-extensions)

| API KEY | Value Type | Details |
| --- | --- | --- |
| [`KEY_RESYNC_MARKER_SIZE`](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#_CPPv4N3qti5video16QMediaExtensionsE) | Integer | Slice size in bits |
| [`KEY_SLICE_SPACING_SIZE`](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#_CPPv4N3qti5video16QMediaExtensionsE) | Integer | Slice size in macroblocks |

## [Query capabilities](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#id3)[](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#query-capabilities)

MediaCodec codec = MediaCodec.createByCodecName("c2.qti.hevc.encoder");
    // codec.getSupportedVendorParameters() should contain KEY_RESYNC_MARKER_SIZE for slicing based on size in bits
    
    // codec.getSupportedVendorParameters() should contain KEY_SLICE_SPACING_SIZE for slicing based on number of MBs
    
    // codec.getParameterDescriptor(KEY_RESYNC_MARKER_SIZE).getType() -> MediaFormat.TYPE_INTEGER
    QMediaCodecCapabilities qCodecCaps = QMediaCodecCapabilities.CreateForCodec("c2.qti.hevc.encoder", "video/hevc");
    SupportedValues<Integer> erResyncSizeValues = qCodecCaps.getParameterRangeInteger(KEY_RESYNC_MARKER_SIZE);
    // erResyncSizeValues.getType() -> SupportedValues.TYPE_RANGE
    
    // codec.getParameterDescriptor(KEY_SLICE_SPACING_SIZE).getType() -> MediaFormat.TYPE_INTEGER
    SupportedValues<Integer> erSliceSpacingValues = qCodecCaps.getParameterRangeInteger(KEY_SLICE_SPACING_SIZE);
    // erSliceSpacingValues.getType() -> SupportedValues.TYPE_RANGE
    Copy to clipboard

## [Using the slice encode extensions](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#id4)[](https://docs.qualcomm.com/doc/80-56386-10/topic/er_slice_resync_markers.html#using-the-slice-encode-extensions)

To set the resync marker (slice size) in terms of bits:

MediaCodec codec = MediaCodec.createEncoderByType("video/hevc");
    MediaFormat format = MediaFormat.createVideoFormat("video/hevc", 1280, 720);
    
    format.setInteger(KEY_RESYNC_MARKER_SIZE, 4096);
    codec.configure(format, ...);
    Copy to clipboard

To set the slice size in terms of macroblocks:

MediaCodec codec = MediaCodec.createEncoderByType("video/hevc");
    MediaFormat format = MediaFormat.createVideoFormat("video/hevc", 1280, 720);
    
    format.setInteger(KEY_SLICE_SPACING_SIZE, 6);
    codec.configure(format,...);
    Copy to clipboard

Last Published: Jun 13, 2023

[Previous Topic
Advanced Encoder Frame-QP Control](https://docs.qualcomm.com/bundle/publicresource/80-56386-10/topics/advance_qp_control.md) [Next Topic
Error Resilience - Long Term Reference Frames](https://docs.qualcomm.com/bundle/publicresource/80-56386-10/topics/er_long_term_reference_frames.md)