Expand my Community achievements bar.

SOLVED

video chat delay

Avatar

Former Community Member

Hi,

I'm using WebCam Publisher/Subscriber components to have a user publish his webcam feed and another user subscribe to it.

However I'm seeing a delay of over 4-5 seconds for the webcam feed. On the publisher side I'm checking the connection to the LCCS chat room and the UserManager's isP2P and isRTMFP properties are both true.

The subscriber being on the same network I would obviously assume that it also is connected via RTMFP.

My question is, is when we have the publish/subscribe model for WebCam feed sharing is the feed P2P between the Publisher and the Subscriber??

Looks like it isn't.

Thanks,

Soumik

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi Soumik,

I got a chance to look and run your Publisher/Subscriber. I ran against your room. There is a fix I did on my side, you can put that on your source code , link your project to source and let me know if you still face the issue. I will put the fix in the next release coming in next few weeks so that you don’t need to link to source in future and can directly use the swc.

But there are some changes I want to suggest to your code also, specially the subscriber.

In the playPubStream function, you don't need to do

webCamSub.publisherIDs = [];

audioSub.publisherIDs = [];

as whenever you set the this property later in your function, it automatically will clean the previous streams.

Instead, you should do something like

var array:Array = new Array();

array.push(pubID);

webCamSub.publisherIDs = array ;

Also when you declare your rtc:WebcamSubscriber in mxml, it is automatically subscribed, you don't need to call webCamSub.subscribe() unless you are creating it in actionscript. Similarly for audioSub.subscribe().

Lastly if there are only two users in room, and one publishes and other subscribes, you don't need to set the publisherIDs property because by default, the stream goes to everyone in room who has a WebcamSubscriber.

My fix goes like this. You should modify your WebcamSubscriber's onPeerTimeout function to be the one below

protected function onPeerTimeout(p_evt:TimerEvent):void

{

// Peer to peer connection fails , and hence we switch back to the hub and spoke connection...

var userDesc:UserDescriptor = userManager.getUserDescriptor(userManager.myUserID) ;

for (var id:String in _peerTimeoutTable ) {

if ( peerTimeoutTable[id] == pevt.currentTarget ) {

_peerTimeoutTable[id].stop();

peerTimeoutTable[id].removeEventListener(TimerEvent.TIMERCOMPLETE,onPeerTimeout);

_peerTimeoutTable[id] = null ;

DebugUtil.debugTrace(" Peer to peer connection failed and timed out in Camera for user " + userManager.getUserDescriptor(userManager.myUserID).displayName);

if ( userDesc.isPeer ) {

userManager.setPeer(userManager.myUserID,false);

}

break ;

}

}

}

Make similar change in your AudioSubscriber.as too.

Hope this will help to fix your problem. Thanks for pointing this out and your patience. Let me know if you are still having any issue with your peer to peer streaming.

Thanks

Hironmay Basu

View solution in original post

32 Replies

Avatar

Former Community Member

Hi Hironmoy,

Any luck with this issue?? Were you able to try out the Publisher/Subscriber flex source?

Thanks,

Soumik

Avatar

Former Community Member

Hi,

I haven't got time to run it as we have a release in near future and that has kept me quite occupied. As I mentioned, I will do it sometimes this week or weekend. You can always use hub-spoke connection till then.

Thanks

Hironmay Basu

Avatar

Correct answer by
Former Community Member

Hi Soumik,

I got a chance to look and run your Publisher/Subscriber. I ran against your room. There is a fix I did on my side, you can put that on your source code , link your project to source and let me know if you still face the issue. I will put the fix in the next release coming in next few weeks so that you don’t need to link to source in future and can directly use the swc.

But there are some changes I want to suggest to your code also, specially the subscriber.

In the playPubStream function, you don't need to do

webCamSub.publisherIDs = [];

audioSub.publisherIDs = [];

as whenever you set the this property later in your function, it automatically will clean the previous streams.

Instead, you should do something like

var array:Array = new Array();

array.push(pubID);

webCamSub.publisherIDs = array ;

Also when you declare your rtc:WebcamSubscriber in mxml, it is automatically subscribed, you don't need to call webCamSub.subscribe() unless you are creating it in actionscript. Similarly for audioSub.subscribe().

Lastly if there are only two users in room, and one publishes and other subscribes, you don't need to set the publisherIDs property because by default, the stream goes to everyone in room who has a WebcamSubscriber.

My fix goes like this. You should modify your WebcamSubscriber's onPeerTimeout function to be the one below

protected function onPeerTimeout(p_evt:TimerEvent):void

{

// Peer to peer connection fails , and hence we switch back to the hub and spoke connection...

var userDesc:UserDescriptor = userManager.getUserDescriptor(userManager.myUserID) ;

for (var id:String in _peerTimeoutTable ) {

if ( peerTimeoutTable[id] == pevt.currentTarget ) {

_peerTimeoutTable[id].stop();

peerTimeoutTable[id].removeEventListener(TimerEvent.TIMERCOMPLETE,onPeerTimeout);

_peerTimeoutTable[id] = null ;

DebugUtil.debugTrace(" Peer to peer connection failed and timed out in Camera for user " + userManager.getUserDescriptor(userManager.myUserID).displayName);

if ( userDesc.isPeer ) {

userManager.setPeer(userManager.myUserID,false);

}

break ;

}

}

}

Make similar change in your AudioSubscriber.as too.

Hope this will help to fix your problem. Thanks for pointing this out and your patience. Let me know if you are still having any issue with your peer to peer streaming.

Thanks

Hironmay Basu

Avatar

Former Community Member

Hironmoy,

     The changes you suggested in the WebcamSubscriber/AudioSubscriber worked. Now I don't get the p2p failed message and the delay is minimal.

Really appreciate your co-operation and prompt replies to my queries, it was very helpful for me. I hope to dig deeper into LCCS and try out other stuff.

Thanks a lot,

Soumik

Avatar

Former Community Member

One more thing, more of a request really. It seems to me that right now the WebcamSubscriber/AudioSubscriber doesn't expose a callback function when the connection type changes - from RTMFP to RTMP.

I was wondering whether it was possible to have a hook to the Publisher/Subscriber objects so that we can attach a function to be executed whenever the connection type changes.

In my case, such a thing will help me alert users behind UDP restricted firewall/NATs to go set their firewall settings for better chat performance.

Thanks,

Soumik

Avatar

Former Community Member

Hi Soumik,

We do have an event called StreamEvent.CONNECTION_TYPE_CHANGE , that is fired from AudioSubscriber/WebcamSubscriber when the connection changes from RTMFP to RTMPS or vice versa.

You can take a look at the PeerToPeerRtmfp example in the sampleApps that has one use case for this event.

Hope this helps

Thanks

Hironmay Basu

Avatar

Former Community Member

Thanks that helped a lot.

Another quick question, it seems to me that the CameraPublisher object always has the capture aspect ratio of 1:1.

Is there a way to configure the aspect ratio of the Camera?? Better even, why not make the _camera attribute of WebcamPublisher a "writable" attribute rather than just a "read-only" attribute??

My attempts to configure the video stream using StreamManager to specific nativeheight and nativewidth didn't seem to make any difference.

Thanks,

Soumik

Avatar

Former Community Member

Hi Soumik,

We provide three different aspect ratios, portrait, standard and landscape, with default as standard with 1:1. You can use other aspect ratios( the widths and heights for them are there in StreamManager docs) and also use resolutionFactor. Resolution factor gets multiplied to aspect ratio values. If you want an event customized your own value, you can just override the updateCameraSettings function inside WebcamPublisher and use your own width and heights in _camera.setMode calls.

Hope this helps

Thanks

Hironmay Basu

Avatar

Former Community Member

Hironmoy,

Yes I noticed that the stream manager class supports 3 aspect ratios. And I could've used the landscape aspect ratio, but I didn't find any way(no set methods) to set the aspect ratio either in the StreamManager or the StreamDescriptor classes.

Also, the changeSizeStream() method in StreamManager class didn't seem to have any effect on the published aspect ratio.

Thanks,

Soumik

Avatar

Former Community Member

As I mentioned, you need to use resolution Factor, that multiplies with width and height you are using. Also, you need to look at the updateCameraSettings function inside WebcamPublisher if you want your own width and height.

Thanks

Hironmay Basu

Avatar

Former Community Member

I want to know how do I change the aspect ratio which is currently defaulted to standard to, say, landscape or portrait aspect ratio. What is the function call which does that?

Thanks,

Soumik

Avatar

Former Community Member

Actually, there is an API for aspectRatio in StreamManager, but somehow the doc isn't there. But you can use streamManager.aspectRatio = "one of the three ratios" .

Look inside StreamManager.as source, it will be clearer. Also as I mentioned, if you override the updateCameraSettings function in webcampublisher , you can use whatever value you want and not need the ratio values.

Thanks

Hironmay Basu

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----