ApsaraVideo Live provides callbacks for stream ingest status, live stream recording, live stream snapshot, and content moderation. This topic describes how to configure these callbacks in the ApsaraVideo Live console.
Usage notes
ApsaraVideo Live supports event notifications by using HTTP and HTTPS callbacks. You must deploy an HTTP service to receive callback messages and configure a callback URL by using the ApsaraVideo Live console or calling an API operation.
When stream ingest is initiated or interrupted, ApsaraVideo Live sends an HTTP GET request to the specified callback URL. The specific event content is included in the URL parameters.
When other events are triggered, ApsaraVideo Live sends an HTTP POST request to the specified callback URL. The specific event content is included in the JSON-formatted request body.
Scenarios
When an event is triggered during live streaming, Alibaba Cloud sends a request to your server and your server then responds to the request. After the request passes verification, a callback message that contains JSON-formatted data is returned to you.
ApsaraVideo Live supports callbacks for events such as stream ingest status, live stream recording (on-demand recording), live stream snapshot, and content moderation (video moderation and audio moderation). For information about the callback parameters and examples for different callback events, see Manage callbacks.
Limits
A callback URL requires no identifier but must be accessible. If no response is returned from the URL within a specific timeout period, ApsaraVideo Live performs retries to access the URL. The current timeout period is 5 seconds. If no response is returned within 5 seconds, ApsaraVideo Live performs retries to access the URL for a maximum of five times at an interval of 1 second.
You can configure and modify stream ingest callbacks for only ingest domains. You can configure and modify recording callbacks, snapshot callbacks, video moderation callbacks, and audio moderation callbacks for only streaming domains.
Feature description
Callbacks are divided into stream ingest callbacks and streaming callbacks.
Stream ingest callbacks: You can configure stream ingest callbacks and callback authentication for an ingest domain.
Streaming callbacks: You can configure streaming callbacks, including recording callbacks, snapshot callbacks, video moderation callbacks, and audio moderation callbacks, for a streaming domain.
You can view recording-in-OSS callback records and the callback content. For more information, see View callback records.
Procedure
- Log on to the ApsaraVideo Live console.
In the left-side navigation pane, choose Feature Management > Callbacks. The Callbacks page appears.
Select the ingest domain or streaming domain that you want to configure. An ingest domain supports stream ingest callbacks, while a streaming domain supports recording callbacks, snapshot callbacks, video moderation callbacks, and audio moderation callbacks.
On the Callback Settings tab, configure the callbacks.
Stream ingest callback logic
Callback logic for stream ingest status:
During stream ingest over Real-Time Messaging Protocol (RTMP), ApsaraVideo Live checks whether the stream ingest client closes the connection within 2 seconds after ApsaraVideo Live receives an OnPublish message. If the stream ingest client does not close the connection, ApsaraVideo Live sends a callback notification about the successful stream ingest.
For example, you have Ingest Domain A and Streaming Domain B. You can configure regular stream pulling and triggered stream pulling for Streaming Domain B. If you want to receive callback notifications about the stream pulling status, configure stream ingest callbacks for Ingest Domain A. After the configuration, ApsaraVideo Live uses the same callback logic as that for stream ingest status to send callback notifications about the stream pulling status under Streaming Domain B. By default, ApsaraVideo Live sends a callback notification about successful stream pulling if the stream pulling client does not close the connection within 2 seconds after the connection is established. In this case, live streaming data is received.
We recommend that you deliver the streaming URL only after you determine that the stream ingest or pulling is successful based on callback notifications and the list of active streams.
Callback authentication
By default, authentication for stream ingest callbacks is disabled. You can enable the feature when you specify the stream ingest callback URL. After you enable the feature, the following authentication logic applies:
When ApsaraVideo Live initiates a callback request, the ALI-LIVE-TIMESTAMP and ALI-LIVE-SIGNATURE fields are included in the HTTP(S) request header. The callback message receiving server authenticates and signs the fields. The value of ALI-LIVE-SIGNATURE is calculated based on the following formula:
ALI-LIVE-SIGNATURE = MD5SUM (MD5CONTENT) MD5CONTENT = Domain name|ALI-LIVE-TIMESTAMP value|Cryptographic key
NoteDomain name is the ingest domain for which you configure the callback URL. Cryptographic key is the cryptographic key that you specify for the callback URL.
After receiving a callback message, the callback message receiving server concatenates the domain name of the callback, value of the ALI-LIVE-TIMESTAMP header, and cryptographic key in the preceding format. The server calculates the MD5 value of the string to obtain an encrypted string. Then, the server compares the encrypted string with the value of the ALI-LIVE-SIGNATURE header in the HTTP or HTTPS request initiated by ApsaraVideo Live. If the two values are different, the request is invalid.