3 Replies Latest reply on Jan 23, 2012 1:08 AM by ReDrUmNZ

    OSMF Shared NetConnection and NetStream

    ReDrUmNZ Level 1

      Hi,

       

      I'm wishing to setup a playlist using a single streaming video by segmenting it into shorter clips e.g.

       

      rtmp://myserver/mp4:myVideo (duration 40 minutes)

      track1: start time 05:10, end time: 08:30

      track2: start time: 08:31, end time: 12:15

      track3: start time: 15:00, end time: 16:35

      etc.

       

      Primarily these clip times will rollover seamlessly (e.g. between track1 and track2) however sometimes there may be gaps (e.g. between track 2 and track 3).

       

      In order to have seamless stream switching I realise I have to share the NetConnection, and probably the NetStream as well. I can easily achieve this in AS3 with my own NetConnection and NetStream code however how is something like this best achieved within OSMF? I'm happy to extend classes and roll my own solution but a brief overview of what/where would be much appreciated please.

       

      --------------------------------------------

       

      1. What is the best way to share a NetConnection between non-standard streaming URLs?

       

      My urls look like this: rtmpe://streaming.client.com/mp4:folder/filename

       

      We're using a CNAME to mask the FMS Application Instance name e.g. rtmpe://streaming.client.com is equal to rtmpe://fms.userID.edgecastcdn.net/userID/streaming/client

       

      I've tried the following with mixed success.

       

      Method 1 - StreamingURLResource - Seems to require a folder as part of the NetConnection path which isn't ideal for me:

       

      var factory:NetConnectionFactory = new NetConnectionFactory(true); // enable sharing NC's

      var netLoader:NetLoader = new NetLoader(factory);

       

      // These are less than ideal as they require a folder to connect e.g. rtmpe://streaming.client.com/folder/mp4:video1 instead of rtmpe://streaming.client.com/mp4:folder/video1

      var resource1:StreamingURLResource = new StreamingURLResource("rtmpe://streaming.client.com/folder/mp4:video1");

      resource1.clipStartTime = 500;

      resource1.clipEndTime = 530;

      var resource2:StreamingURLResource = new StreamingURLResource("rtmpe://streaming.client.com/folder/mp4:video1");

      resource2.clipStartTime = 531;

      resource2.clipEndTime = 600;

       

      // resource.urlIncludesFMSApplicationInstance = true; doesn't seem required and breaks the connection so it is not used.

       

      var serial:SerialElement = new SerialElement();

      serial.addChild(new VideoElement(resource1, netLoader)); // pass in the NetLoader in order to share the same NetConnection

      serial.addChild(new VideoElement(resource2, netLoader));

       

      Method 2 - DynamicStreamingResource - Doesn't require a folder as part of the NetConnection path however was not intended for a single bitrate:

       

      var segment1:DynamicStreamingItem = new DynamicStreamingItem("mp4:folder/video", 700, 640, 360);

       

      // These are better as they allow me to connect to the correct depth without require a folder.

      var resource3:DynamicStreamingResource = new DynamicStreamingResource("rtmpe://streaming.client.com", StreamType.RECORDED);

      resource3.streamItems = Vector.<DynamicStreamingItem>([segment1]);

      resource3.clipStartTime = 500;

      resource3.clipEndTime = 530;

      var resource4:DynamicStreamingResource = new DynamicStreamingResource("rtmpe://streaming.client.com", StreamType.RECORDED);

      resource4.streamItems = Vector.<DynamicStreamingItem>([segment1]);

      resource4.clipStartTime = 531;

      resource4.clipEndTime = 600;

       

      DynamicStreamingResource seems to work best regardless of the fact I'm not using it as intended (e.g. single bitrate). Also is there an easy way to verify that the same NC is being used at runtime other than manually comparing them?

       

      2. What is the best way to share NetStreams between resources?

       

      By using clip times on the resouces I believe it closes the NetStream and creates a new one which ends up causing a lag of up to 10 seconds between tracks. Is there a way to share the NS if it uses the same URL? I've done it before in custom AS3 code where I'm instead listening for the ns.time and manually switching resources when my custom end time is reached. In order to have seamless stream switching is using the following code:

       

      var nso:NetStreamPlayOptions = new NetStreamPlayOptions();

      nso.streamName = videoName; // shared resource

      ns.play2(nso);

      ns.seek(newStartTime);

       

      Does OSMF use netstream.play2() when available?

       

      Cheers for any help you can provide.

        • 1. Re: OSMF Shared NetConnection and NetStream
          Mykola3296 Level 2

          Hello!

           

          As far as I know play2 is used for MBR and reconnect features only (in OSMF, for now).

          In our project we planned to create a "NetStreamSharingVideoElement" but have not done it due to the lack of time.

           

          What we have thought about:

          1) Create a single load trait instance and share it between elements

          2) The first element in chain processes the load and the stream is held within load trait (as it is stored in OSMF right away)

          2) Each element should implement a custom play trait that uses play2 to play its stream portion.

           

          The main problem I remember (for now) is that it is impossible to switch seamlessly (IMHO) when using a chain of video elements. For Serial to switch the current element for another, current element should fire COMPLETE event - that means NetStream.Play.Stop or something. So that means that you have a stopped stream already and no play2 will help you here. What we have come to was the idea creatig a playlist element from scratch that is being loaded with all playlist items. It should create a server-side playlist using play2 and APPEND transition. This way it plays items one by one seamlessly. If the skip function is needed - the element should rebuild a server playlist.

          • 2. Re: OSMF Shared NetConnection and NetStream
            Mykola3296 Level 2

            An idea occured to me while writing a previous post...

             

            You may try to investigate if the NetStream.Play.Transition occures when switching between streams to get the current item playing.

            This leads to a possibility of creating a standart Serial with custom video elements (still sharing the same load trait or whatever) in them.

             

            Say:

            1) A loader "loads" a connection and a stream

            2) Each element in collection does a play2, forming a server-side playlist at the time of loading

            3) Element is listening for a NetStream.Play.Transition and fires a COMPLETE event upon it.

             

            This way you may end up with a standard Serial "switching" between individual substreams seamlessly and having a single element per single substream

            • 3. Re: OSMF Shared NetConnection and NetStream
              ReDrUmNZ Level 1

              Thanks for the idea's. I'll have a go with that tomorrow at work. Cheers