/

Subscribing with Flash


Subscribing with Flash

When using Flash, the video streams cannot be dynamically switched by the Red5 Pro Server. The Adaptive Bitrate control switching logic is implemented within the Flash-based subscriber of the Red5 Pro HTML SDK. The logic to downgrade the stream is based on the InsufficientBandwidth event which is sent by the server when the client is recognized to not have enough bandwidth for the current stream variant. On the other hand, the logic to upgrade variants is a time-based polling solution in the lapse of having received InsufficientBandwidth events. This logic is triggered by providing the provision configuration, that was provided to the Stream Manager, and an optional stream switch setting configuration to the Flash-based subscriber.

The existing provision can be retrieved from the Stream Manager with the following call:

Method:GET

URL: https://yourstreammanager.com/streammanager/api/3.1/admin/event/meta/live/mystream?accessToken=myaccessToken

Where:

  • yourstreammanager.com: is the host of your Stream Manager.
  • mystream: is the top-level name of the stream.
  • accessToken: is the token defined in the Stream Manager configuration.

A successful response will return a JSON object similar to the following:

{
  "name": "mystream",
  "scope":"live",
  "data": {
    "meta": {
      "authentication": {
        "password": "",
        "username": ""
      },
      "qos": 3,
      "georules": {
        "regions": ["US", "UK"],
        "restricted": false,
      },
      "stream": [
        {
          "level": 3,
          "name": "mystream_3",
          "properties": [
            "videoBR": 128000,
            "videoHeight": 180,
            "videoWidth": 320
          ]
        },
        {
          "level": 2,
          "name": "mystream_2",
          "properties": [
            "videoBR": 512000,
            "videoHeight": 360,
            "videoWidth": 640
          ]
        },
        {
          "level": 3,
          "name": "mystream_1",
          "properties": [
            "videoBR": 1000000,
            "videoHeight": 720,
            "videoWidth": 1280
          ]
        }
      ]
    }
  }
}

In addition to the provision, it is also necessary to request the edge endpoint information from the Stream Manager and specify the stream variant that you want to subscribe to. The request is as follows:

Method:GET

URL: https://yourstreammanager.com/streammanager/api/3.1/event/live/mystream_2?action=subscribe

Where:

  • yourstreammanager.com: is the host of your Stream Manager.
  • mystream_2: is the name of the stream variant that you want to subscribe to.

A successful response will look like the following:

{
  "serverAddress": "10.0.0.0",
  "scope": "live",
  "name": "mystream_2"
}

Once both requests have been made successfully it is possible to initialize the RTMPSubscriber. Assuming that the JSON object returned by the provision request has been assigned to a variable named provision , then the RTMPSubscriber can be initialized as follows:

(function (red5prosdk) {

  var subscriber = new red5prosdk.RTMPSubscriber();

  // On embed success, provide the provisioning and target level.
  subscriber.on('FlashPlayer.Embed.Success', function () {
    subscriber.setABRVariants(provision.data, 2);
  });

  subscriber.init({
    host: '10.0.0.0',
    app: 'live',
    streamName: 'mystream_2',
    protocol: 'rtmp',
    port: 1935,
    useAdaptiveBitrateController: true
  })
  .then(function () {
    subscriber.subscribe()
  })
  .catch(function (e) {
    console.error(e)
  })

})(window.red5prosdk)

It is important to note that useAdaptiveBitrateController needs to be specified to notify the Flash client that it will require the logic for Adaptive Bitrate control.