This guide covers configuring your manifest manipulator to request ad or
slate segments using the ad [pod
segment](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/reference/live#method_pod_segment)
method.

> [!IMPORTANT]
> **Important:** We recommend upgrading your manifest manipulator to support pre-roll ads and returning to the underlying content without slate. For details, see [Insert ads with ad break timing data](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/live/manipulator).

Select a streaming protocol:

<button value="hls" default="">HLS</button> <button value="dash">DASH</button>

## Prerequisites

Before you continue, you must set up a livestream event for the **Pod serving
redirect** Dynamic Ad Insertion (DAI) type and encoding profiles. To set up a
livestream event, choose one of the following methods:

- **Ad Manager UI:** [Set up a livestream for
  DAI](https://support.google.com/admanager/answer/7294289).
- **Ad Manager API:** Use a [client library](https://developers.google.com/ad-manager/api/clients) to call [`LiveStreamEventService.createLiveStreamEvents`](https://developers.google.com/ad-manager/api/reference/latest/LiveStreamEventService#createlivestreamevents) method. Set the `LiveStreamEvent.dynamicAdInsertionType` parameter to [`POD_SERVING_REDIRECT`](https://developers.google.com/ad-manager/api/reference/latest/LiveStreamEventService.DynamicAdInsertionType).
- **Authenticate requests:** Each segment request made using segment redirect pod serving must include an HMAC-signed token for authentication. Calculate this token once per ad break and share the token across all stream sessions. To calculate the HMAC token, see [Authenticate ad pod requests](https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/live/pod-request-overview).

After you set up the livestream event, retrieve the event's encoding profiles
from Ad Manager UI or API by calling
[`DaiEncodingProfileService.getDaiEncodingProfilesByStatement`](https://developers.google.com/ad-manager/api/reference/latest/DaiEncodingProfileService#getdaiencodingprofilesbystatement)
method.

## Retrieve the content stream

When a user selects a livestream event, the client app makes a stream
request to Google Ad Manager. In the stream response, the app extracts the
Google DAI session ID and metadata to include in the stream manifest request.

The following example passes a Google DAI session ID to a manifest manipulator:

    https://MANIFEST_MANIPULATOR_URL/manifest.m3u8?DAI_stream_ID=SESSION_ID&network_code=NETWORK_CODE&DAI_custom_asset_key=CUSTOM_ASSET_KEY

When processing the video content playback request, store the Google DAI session
ID and <var translate="no">CUSTOM_ASSET_KEY</var> from the request to prepare for
ad stitching.

## Identify ad break segments and insert discontinuities

As you process each variant manifest, identify the `EXT-X-CUE-IN` and
`EXT-X-CUE-OUT` tags in your stream, indicating the start and end of an ad
break.

Replace the `EXT-X-CUE-IN` and `EXT-X-CUE-OUT` tags with the
`EXT-X-DISCONTINUITY` elements for the client video player to switch between
content and ads.

The following example manifest replaces the `EXT-X-CUE-IN` and `EXT-X-CUE-OUT`
tags:

    #EXTM3U
    #EXT-X-VERSION:6
    #EXT-X-TARGETDURATION:6
    #EXT-X-MEDIA-SEQUENCE:0

    #EXTINF:5.000,
    contentorigin.com/1.ts
    #EXTINF:5.000,
    contentorigin.com/2.ts
    #EXT-X-CUE-OUT:17.450
    #EXTINF:5.000,
    contentorigin.com/3.ts
    #EXTINF:5.000,
    contentorigin.com/4.ts
    #EXTINF:5.000,
    contentorigin.com/5.ts
    #EXTINF:2.450,
    contentorigin.com/6.ts
    #EXT-X-CUE-IN
    #EXTINF:5.000,
    contentorigin.com/7.ts
    #EXTINF:5.000,
    contentorigin.com/8.ts

The following example shows a replaced manifest:

    #EXTM3U
    #EXT-X-VERSION:6
    #EXT-X-TARGETDURATION:6
    #EXT-X-MEDIA-SEQUENCE:0

    #EXTINF:5.000,
    contentorigin.com/1.ts
    #EXTINF:5.000,
    contentorigin.com/2.ts
    #EXTINF:5.000,
    #EXT-X-DISCONTINUITY
    {... Insert ad segments here ...}
    #EXT-X-DISCONTINUITY
    #EXTINF:5.000,
    contentorigin.com/7.ts
    #EXTINF:5.000,
    contentorigin.com/8.ts

Google DAI ad segments are not encrypted. If your content is encrypted, remove
encryption by inserting `EXT-X-KEY:METHOD=NONE` element prior to the first ad
segment of each ad break. At the end of the ad break, add encryption back by
inserting an appropriate `EXT-X-KEY`.

Keep track of the start time, duration, and index of the upcoming ad break.


## Build ad segment URLs

Replace each content segment between the `EXT-X-DISCONTINUITY` tags with a URL
pointing to the ad pod segment method.

The following example assembles an ad pod segment. Note that ad segments use a
zero-based index:

    https://dai.google.com/linear/pods/v1/seg/network/NETWORK_CODE/custom_asset/CUSTOM_ASSET_KEY/ad_break_id/AD_BREAK_ID/profile/ENCODING_PROFILE/0.ts?sd=AD_SEGMENT_DURATION&pd=AD_BREAK_DURATION&stream_id=SESSION_ID&auth-token=HMAC

The following example inserts the ad pod segments into the manifest:

    #EXTM3U
    #EXT-X-VERSION:6
    #EXT-X-TARGETDURATION:6
    #EXT-X-MEDIA-SEQUENCE:0

    #EXTINF:5.00,
    contentorigin.com/1.ts
    #EXTINF:5.00,
    contentorigin.com/2.ts
    #EXT-X-DISCONTINUITY
    #EXTINF:5.00,
    https://dai.google.com/linear/pods/v1/seg/network/
    NETWORK_CODE/custom_asset/CUSTOM_ASSET_KEY/ad_break_id/AD_BREAK_ID/profile/ENCODING_PROFILE/0.ts?sd=5000\&so=0\&pd=15000\&stream_id=SESSION_ID
    #EXTINF:5.00,
    https://dai.google.com/linear/pods/v1/seg/network/
    NETWORK_CODE/custom_asset/CUSTOM_ASSET_KEY/ad_break_id/AD_BREAK_ID/profile/ENCODING_PROFILE/1.ts?sd=5000\&so=5000\&pd=15000\&stream_id=SESSION_ID
    #EXTINF:5.00,
    https://dai.google.com/linear/pods/v1/seg/network/
    NETWORK_CODE/custom_asset/CUSTOM_ASSET_KEY/ad_break_id/AD_BREAK_ID/profile/ENCODING_PROFILE/2.ts?sd=5000\&so=10000\&pd=15000\&stream_id=SESSION_ID
    #EXT-X-DISCONTINUITY
    #EXTINF:5.00,
    contentorigin.com/6.mp4
    #EXTINF:5.00,
    contentorigin.com/7.mp4
    #EXTINF:5.00,
    contentorigin.com/8.mp4

## Optional: Schedule an ad break

To enhance your fill rate, send an Early Ad Break Notification (EABN) with the
ad pod duration, custom targeting parameters, and SCTE-35 signal data. For more
details, see [Send early ad break
notifications](https://developers.google.com/ad-manager/api/beta/ad-breaks).