4 Replies Latest reply: May 4, 2012 8:20 AM by Silviu Vergoti RSS

    not able to Retrieve the metadata from the NetStream in OSMF2.0

    ram_krish

      Hi,

       

           i was not able to Retrieve the metadata from the NetStream in strobe player which using OSMF2.0 i can able to do this in OSMF 1.6.

       

       

      To retrive my metadata i have added following code in my PlaybackOptimizationMetrics.as

       

      NetClient(netStream.client).addHandler("InjectData", onMetaData2);

                  function onMetaData2(value:Object):void

                  {

                      NetClient(netStream.client).removeHandler("InjectData", onMetaData2);

                      // We assume that the asset metadata has the most accurate value,

                      // that's why we overwrite any existing value.

       

                      ExternalInterface.call("alert","inject");

       

                      // audiodatarate and videodatarate are set in kilobits. We need to transform it to bytes.

                      averagePlaybackBytesPerSecond = StrobeUtils.kbitsPerSecond2BytesPerSecond(value.audiodatarate + value.videodatarate);           

                      duration = value.duration;

                  }

       

       

      my streaming server inject data into the stream suessfully. but the strobe player couldn't able to retrive the data when play the stream.

       

      can anyone please check it and tell me the above thing working in OSMF 2.0 or not?

       

      Thanks,

        • 1. Re: not able to Retrieve the metadata from the NetStream in OSMF2.0
          Silviu Vergoti Adobe Employee

          Hi,

           

          do you use FMS?

           

          can you provide an example stream and a working code snippet that works in 1.6 and does not work in 2.0?

           

          S.

          • 2. Re: not able to Retrieve the metadata from the NetStream in OSMF2.0
            ram_krish Community Member

            thank you for your reply..

             

            sorry i am using wowza.

             

            this is my server code:


            public void setCaption (IClient client, RequestFunction function, AMFDataList params)

                {

                    String streamname = params.getString(PARAM1);

                    String PId =  params.getString(PARAM2);

                    String Src =  params.getString(PARAM3);

                    getLogger().info("Caption PlayerId: " + PId);

                   

                    IMediaStream stream = client.getAppInstance().getStreams().getStream(streamname);

                   

                    //essential code

                    AMFDataMixedArray data = new AMFDataMixedArray();

                    data.put("captionPd", new AMFDataItem(PId));

                    data.put("Src", new AMFDataItem(Src));

                    stream.sendDirect("setCaption", data);

                    getLogger().info("Src: " + Src);

                   

                }

             

             

            Inject code:

             

            var StreamName:String="sample"

                var PId:String="111";

                var slideSrc:String="my slide src";

                nc.call("setCaption",null,StreamName,PId,"value1","value2","value3");

             

             

            Strobe player code:

             

            PlaybackOptimizationMetrics.as

             

            /***********************************************************

            * Copyright 2010 Adobe Systems Incorporated.  All Rights Reserved.

            *

            * *********************************************************

            * The contents of this file are subject to the Berkeley Software Distribution (BSD) Licence

            * (the "License"); you may not use this file except in

            * compliance with the License.

            *

            * Software distributed under the License is distributed on an "AS IS"

            * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the

            * License for the specific language governing rights and limitations

            * under the License.

            *

            *

            * The Initial Developer of the Original Code is Adobe Systems Incorporated.

            * Portions created by Adobe Systems Incorporated are Copyright (C) 2010 Adobe Systems

            * Incorporated. All Rights Reserved.

            **********************************************************/

             

            package org.osmf.net

            {

                import flash.events.NetStatusEvent;

                import flash.net.NetStream;

                import flash.net.SharedObject;

                import flash.system.System;

                import flash.external.*;

                import org.osmf.player.utils.StrobeUtils;

               

                CONFIG::LOGGING

                {

                import org.osmf.logging.Log;

                import org.osmf.player.debug.StrobeLogger;

                }

               

                public class PlaybackOptimizationMetrics extends NetStreamMetricsBase

                {

                    public static const ID:String = "PlaybackOptimizationMetrics";

                   

                    /**

                     * Constructor.

                     *

                     * @param netStream The NetStream to provide metrics for.

                     **/

                    public function PlaybackOptimizationMetrics(netStream:NetStream)

                    {

                        super(netStream);

                        // Retrieve the metadata from the NetStream

                        NetClient(netStream.client).addHandler(NetStreamCodes.ON_META_DATA, onMetaData);

                        function onMetaData(value:Object):void

                        {

                            NetClient(netStream.client).removeHandler(NetStreamCodes.ON_META_DATA, onMetaData);

                            // We assume that the asset metadata has the most accurate value,

                            // that's why we overwrite any existing value.

                            //ExternalInterface.call("alert","dffshujhu");

                            // audiodatarate and videodatarate are set in kilobits. We need to transform it to bytes.

                            averagePlaybackBytesPerSecond = StrobeUtils.kbitsPerSecond2BytesPerSecond(value.audiodatarate + value.videodatarate);           

                            duration = value.duration;

                        }

                       

                        NetClient(netStream.client).addHandler("setCaption", onMetaData2);

                        function onMetaData2(value:Object):void

                        {

                            NetClient(netStream.client).removeHandler("setCaption", onMetaData2);

                            // We assume that the asset metadata has the most accurate value,

                            // that's why we overwrite any existing value.

                            ExternalInterface.call("alert","inject");

                            // audiodatarate and videodatarate are set in kilobits. We need to transform it to bytes.

                            averagePlaybackBytesPerSecond = StrobeUtils.kbitsPerSecond2BytesPerSecond(value.audiodatarate + value.videodatarate);           

                            duration = value.duration;

                        }

                       

                       

                        try

                        {

                            var sharedObject:SharedObject = SharedObject.getLocal(STROBE_LSO_NAMESPACE);

                            averageDownloadBytesPerSecond = StrobeUtils.kbitsPerSecond2BytesPerSecond(sharedObject.data.downloadKbitsPerSecond);

                            CONFIG::LOGGING

                            {

                                logger.qos.lsoDownloadKbps = sharedObject.data.downloadKbitsPerSecond;

                            }

                        }

                        catch(ignore: Error)

                        {

                            // Ignore this error

                            CONFIG::LOGGING

                            {

                                logger.info("LSO access is disabled.");

                            }

                        }

                       

                        // Register a NET_STATUS handler, so that we update the local SharedObject with the new bandwidth measurement.

                        netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                        function onNetStatus(event:NetStatusEvent):void

                        {   

                            if (event.info.code == NetStreamCodes.NETSTREAM_PLAY_STOP || event.info.code == NetStreamCodes.NETSTREAM_PAUSE_NOTIFY)

                            {

                                if (averageDownloadBytesPerSecond > 0)

                                {

                                    try

                                    {                           

                                        // Update the Local SharedObject with the latest bandwidth measurement.

                                        var sharedObject:SharedObject = SharedObject.getLocal(STROBE_LSO_NAMESPACE);

                                        sharedObject.data.downloadKbitsPerSecond = Math.round(StrobeUtils.bytesPerSecond2kbitsPerSecond(averageDownloadBytesPerSecond));

                                        sharedObject.flush(10000);

                                        CONFIG::LOGGING

                                        {

                                            logger.qos.lsoDownloadKbps = sharedObject.data.downloadKbitsPerSecond;

                                        }

                                    }

                                    catch (ingore:Error)

                                    {

                                        // Ignore this error

                                        CONFIG::LOGGING

                                        {

                                            logger.info("lsoDownloadKbps value is not updated since LSO access is disabled.");

                                        }

                                    }

                                }

                            }

                        }

                    }

                   

                    public function get duration():Number

                    {

                        return _duration;

                    }

             

                    public function set duration(value:Number):void

                    {

                        _duration = value;

                    }

             

                    /**

                     * The average download ration per second value, calculated based on a

                     * recent set of samples.

                     * 

                     *  @langversion 3.0

                     *  @playerversion Flash 10

                     *  @playerversion AIR 1.5

                     *  @productversion OSMF 1.0

                     */

                    public function get downloadRatio():Number

                    {

                        return averageDownloadBytesPerSecond / averagePlaybackBytesPerSecond;

                    }

                   

                    /**

                     * The average playback bytes per second value, calculated based on a

                     * recent set of samples.

                     * 

                     *  @langversion 3.0

                     *  @playerversion Flash 10

                     *  @playerversion AIR 1.5

                     *  @productversion OSMF 1.0

                     */

                    public function get averagePlaybackBytesPerSecond():Number

                    {

                        return avgPlaybackBytesPerSecond.average;

                    }

                   

                    public function set averagePlaybackBytesPerSecond(value:Number):void

                    {

                        avgPlaybackBytesPerSecond.clearSamples();

                        avgPlaybackBytesPerSecond.addSample(value);

                    }

                   

                    /**

                     * The average max bytes per second value, calculated based on a

                     * recent set of samples.

                     * 

                     *  @langversion 3.0

                     *  @playerversion Flash 10

                     *  @playerversion AIR 1.5

                     *  @productversion OSMF 1.0

                     */

                    public function get averageDownloadBytesPerSecond():Number

                    {

                        return avgMaxBytesPerSecond.average;

                    }

                   

                    public function set averageDownloadBytesPerSecond(value:Number):void

                    {

                        avgPlaybackBytesPerSecond.clearSamples();

                        return avgMaxBytesPerSecond.addSample(value);

                    }

                   

                    public function get averageDownloadKbps():Number

                    {

                        return averageDownloadBytesPerSecond  / 128;

                    }

                   

                    public function get averagePlaybackKbps():Number

                    {

                        return averagePlaybackBytesPerSecond / 128;

                    }

             

                    /**

                     * @private

                     **/

                    override protected function calculateMetrics():void

                    {

                        super.calculateMetrics();   

                        // XXX cdobre - this needs to be refactored in order

                        // to eliminate the dynamic dependency on property name

                        if (netStream.hasOwnProperty("qosInfo") && netStream["qosInfo"] != null)

                        {               

                            // HTTPStreaming content.

                            if (netStream.info.videoBufferLength > 0)

                            {

                                avgPlaybackBytesPerSecond.addSample(netStream.info.videoBufferByteLength / netStream.info.videoBufferLength);

                            }

                            maxBytesPerSecond = netStream["qosInfo"]["downloadRatio"] * netStream.info.videoBufferByteLength / netStream.info.videoBufferLength;

                            if (maxBytesPerSecond > 0)

                            {

                                avgMaxBytesPerSecond.addSample(maxBytesPerSecond);

                            }

                        }

                        else

                        {           

                            if (netStream.bytesLoaded > 0 )

                            {               

                                // Progressive content

                                if (netStream.bytesLoaded < netStream.bytesTotal)

                                {

                                    if (netStream.info.videoBufferLength > 0)

                                    {

                                        avgPlaybackBytesPerSecond.addSample(netStream.info.videoBufferByteLength / netStream.info.videoBufferLength);

                                    }

                                    avgMaxBytesPerSecond.addDeltaTimeRatioSample(netStream.bytesLoaded, new Date().time / 1000);

                                }

                            }

                            else

                            {

                                // RTMP Content

                                var playbackBytesPerSecond:Number = netStream.info.playbackBytesPerSecond;

                                var maxBytesPerSecond:Number = netStream.info.maxBytesPerSecond;

                                if (playbackBytesPerSecond > 0)

                                {

                                    avgPlaybackBytesPerSecond.addSample(playbackBytesPerSecond);

                                }

                           

                                if (maxBytesPerSecond > 0)

                                {

                                    avgMaxBytesPerSecond.addSample(maxBytesPerSecond);

                                }

                            }               

                        }

                       

                        CONFIG::LOGGING

                        {

                        logger.qos.duration = _duration;

                       

                        logger.qos.downloadRatio = this.downloadRatio;

                        logger.qos.playbackKbps  = this.averagePlaybackBytesPerSecond / 128;

                        logger.qos.downloadKbps  = this.averageDownloadBytesPerSecond / 128;

                        logger.qos.avgDroppedFPS = averageDroppedFPS;

             

                        logger.trackObject("PlaybackOptimizationMetrics", this);

                        }

                    }

                   

                    // Internals

                    //       

                    private var _duration:Number;

             

                    private var avgPlaybackBytesPerSecond:RunningAverage = new RunningAverage(DEFAULT_AVG_MAX_BYTES_SAMPLE_SIZE);

                    private var avgMaxBytesPerSecond:RunningAverage = new RunningAverage(DEFAULT_AVG_MAX_BYTES_SAMPLE_SIZE);

             

                    private var previousMeasurementTimestamp:Number = NaN;

                    private static const DEFAULT_AVG_MAX_BYTES_SAMPLE_SIZE:Number = 50;   

                   

                    private const STROBE_LSO_NAMESPACE:String = "org.osmf.strobemediaplayback.lso";

               

                    CONFIG::LOGGING       

                    private var logger:StrobeLogger = Log.getLogger("StrobeMediaPlayback") as StrobeLogger;

                   

                }

            }

             

             

            Note: if i remove OSMF2.0. swc from my project and add OSMF1.6.swc mean its working. when i add OSMF2.0, it's not working.

             

            Thanks,

            • 3. Re: not able to Retrieve the metadata from the NetStream in OSMF2.0
              ram_krish Community Member

              Hi Silviu Vergoti,

               

                        Have you seen my code? i would like to know this problem because of OSMF 2.0 or my code?  when i remove OSMF2.0.swc and add OSMF 1.6.swc in this same project its working well. is it there any extra functionality or code to retrive MetaData from stream in OSMF 2.0?  can you please help me to find soln for this problem?

               

               

               

               

               

              Thanks,

              • 4. Re: not able to Retrieve the metadata from the NetStream in OSMF2.0
                Silviu Vergoti Adobe Employee

                I've seen the code and I ran the SMP on a HDS video stream and I did not receive the desired metadata values, but we receive the metadata object. It might be linked to a Flash Player change.

                 

                Please raise a bug on http://bugs.adobe.com/jira/browse/FM so we could track this problem.