Expand my Community achievements bar.

SOLVED

Webcam Subscribers with a publisherIDs array of length 1 picking up multiple streams

Avatar

Level 2

Hi folks,

We are having an issue where we are seeing a webcam subscriber with streamCount = 2 (and indeed, displaying multiple camera streams) even though its publisherIDs.length = 1.

This seems to be occurring when we try to change the publisherIDs array of a webcam subscriber while the publishing user to which the webcam subscriber's publisherIDs are currently set is temporarily out of the room (for example, if they have refreshed their browser). Once this initial publisher re-enters the room and resumes publishing his camera stream, our webcam subscriber picks up the stream and displays it alongside the new stream.

Examining the the source code provided here (http://forums.adobe.com/message/3718199#3718199), this seems to be a consequence of the way that webcam subscribers handle new STREAM_RECEIVE events.

Please have a look at the following excerpt from WebcamSubscriber.as (relevant code in bold for emphasis):

It would appear that _publisherIDs and _publisherIDTable are getting out of sync. The _publisherIDTable object is only removing stream publisher IDs from itself if the stream still exists in the room. When STREAM_RECEIVE events are fired, the webcam subscriber checks against _publisherIDTable, rather than _publisherIDs, to determine whether or not to play the stream. As the _publisherIDTable is retaining certain ID's that do not exist in _publisherIDs, we are seeing this issue of multiple streams displayed on a webcam subscriber even when we have set the publisherIDs array for that webcam subscriber to a single element array.

public function set publisherIDs(p_publishers:Array):void

     {

          var tempNewPublisherTable:Object = new Object();

          var i:int = 0 ;

          // comparing the old list to the new list ...

          if ( _streamManager == null ) {

               _publisherIDs = p_publishers;

               var l:int = _publisherIDs.length;

               for (i=0; i<l; i++) {

                    _publisherIDTable[_publisherIDs[i]] = true;

               }

          }else {

               for ( i= 0 ; i < p_publishers.length ; i++ ) {

                    if ( _publisherIDTable[p_publishers[i]] == null ) {

                         _publisherIDTable[p_publishers[i]] = true ;

                         if ( _streamManager.getStreamDescriptor(StreamManager.CAMERA_STREAM,p_publishers[i]) != null ){

                              // we need to play only those that exists...

                              playStream(p_publishers[i]);

                         }

                    }

                    tempNewPublisherTable[p_publishers[i]] = true ;

               }

               for ( var id:String in _streamDescriptorTable ) {

                    var remainingPublisher:String = (_streamDescriptorTable[id] as StreamDescriptor).streamPublisherID ;

                    if ( tempNewPublisherTable[remainingPublisher] == null ) {

                         deleteStream(_streamDescriptorTable[id]);

                         delete _publisherIDTable[remainingPublisher] ;

                    }

               }

               if ( _publisherIDs.length != p_publishers.length ) {

                    dispatchEvent(new Event("numberOfStreamsChange"));

               }

               _publisherIDs = p_publishers ;

               displayInvalidator.invalidate();

          }

     }

protected function shouldDisplayStream(p_desc:StreamDescriptor):Boolean
{
     return (_publisherIDs.length==0 || _publisherIDTable[p_desc.streamPublisherID]==true);
}
protected function onStreamReceive (p_evt:StreamEvent):void
{
     var streamDescriptor:StreamDescriptor;
     streamDescriptor = p_evt.streamDescriptor ;
     if (streamDescriptor==null || (streamDescriptor.groupName && streamDescriptor.groupName != _groupName) ) {
          return ;
     }
     if (!shouldDisplayStream(streamDescriptor)) {
          // Don't display the stream if it is not in the list.
          return;
     }
     if (streamDescriptor.finishPublishing && streamDescriptor.type == StreamManager.CAMERA_STREAM ){
          if ( streamDescriptor.nativeWidth!=0 && streamDescriptor.nativeHeight!=0){       
               playStream(streamDescriptor.streamPublisherID);
          }
          dispatchEvent(new Event("numberOfStreamsChange"));
          dispatchEvent(p_evt);
          displayInvalidator.invalidate();
     }
       
}
Thanks for your help,
Davis

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Davis,

Sorry about the confusion, ended up zipping the wrong path

I have attached the updated zip. (I would unzip and double check this time )

Thanks

Arun

View solution in original post

10 Replies

Avatar

Former Community Member

Hi there,

Can you confirm specific repro steps? I'm guessing it's

A) User A is publishing and user B has a subscriber with a publisherIDs

array including A's ID.

B) User A leaves the room

C) You remove user A's ID and reset the publisherIDs for user B

D) User A returns and is somehow still displayed in user B's subscriber.

Does that sound about right? If you can confirm concrete steps, we'll work

to resolve.

nigel

Avatar

Employee

Hi Davis,

I analyzed the code you highlighted, and I dont see an issue. Infact, _publisherIDTable has only id's that are in both publisherIDs and _streamDescriptorTable

We did run a few tests around setting of publisherIDs when trying to optimize the WebcamSubscriber, and didnt hit any issue. So could you share your code if you are hitting this issue.

Thanks

Arun

Avatar

Employee

Hi Davis,

Sorry about the previous post, we do see an issue. We'll fix the issue, and update it in the next release (which is pretty soon). In the mean time, I can post you a custom src & swc that is patched.

Thanks again for notifying us about the bug.

Thanks

Arun

Avatar

Level 2

Nigel,

Those are indeed the steps. To elaborate a little more:

Users A and B, both with WebcamPublishers and WebcamSubscribers.

1) UserAWebcamPublisher.publish()

2) UserBWebcamPublisher.publish()

3) UserBWebcamSubscriber.publisherIDs = [UserAID]

4) User A leaves room (User A's camera stream dies)

5) UserBWebcamSubscriber.publisherIDs = [UserBID]

6) User A re-enters room

7) UserAWebcamPublisher.publish()

User B now sees both streams in his WebcamSubscriber (i.e. UserBWebcamSubscriber.streamCount = 2; UserBWebcamSubscriber.publisherIDs.length = 1)

Arun,

The issue seems to be how elements are removed from _publisherIDTable:

public function set publisherIDs(p_publishers:Array):void

.

.

.

     for ( var id:String in _streamDescriptorTable ) {

          var remainingPublisher:String = (_streamDescriptorTable[id] as StreamDescriptor).streamPublisherID ;

          if ( tempNewPublisherTable[remainingPublisher] == null ) {

               deleteStream(_streamDescriptorTable[id]);

               delete _publisherIDTable[remainingPublisher] ;

          }

     }

}

This bit of code is the only thing that seems to remove elements from _publisherIDTable. As you will notice, it will only remove an ID from _publisherIDTable if the ID belongs to a currently stream-publishing User (that is, it is called within a for loop through _streamDescriptorTable). So if the User ID that is sitting in the _publisherIDTable (when publisherIDs gets set to something else) belongs to a User that is no longer in the room, and thus is no longer streaming, it will not be removed from _publisherIDTable (I believe).

Anyway, please let me know if this is sufficient to go on to look into the issue further.

Thanks again,

Davis

Avatar

Level 2

Whoops, sorry,

Was writing this up and didn't see your previous post.

Good to hear that the next release will include a fix; a custom patched src and swc with whichever fix you guys choose would be great in the meantime (don't want our code to diverge).

Also, just out of curiosity, was it a similar issue to this (with the publisherIDs array) that was causing that ratcheting we were seeing before? It just seemed kinda funky that Webcam Publishers were holding onto streams even after having their publisherID's reset.

Anyway, thanks again for your help.

Cheers,

Davis

Avatar

Former Community Member

Hi Davis,

Nope, the ratcheting was a separate problem (I want to say, player bug that

we found a workaround for, but maybe that's not charitable enough...).

nigel

Avatar

Employee

Hi Davis,

I have attached a new & patched 10.3 src & swc. It took me some time, as I had to write test case to reproduce the issue, and then later ensure that my fix - fixes the issue.

Thanks again for reporting the bug and your patience.

Thanks

Arun

Avatar

Level 2

Hi Arun,

So, the swc you posted here doesn't seem to fix the issue. Is this the correct swc?

Cheers,

Davis

Avatar

Correct answer by
Employee

Hi Davis,

Sorry about the confusion, ended up zipping the wrong path

I have attached the updated zip. (I would unzip and double check this time )

Thanks

Arun