Receiving new stream from my own device.

Ask questions about the iOS API here

Receiving new stream from my own device.

Postby markSci5 » Sun Jan 13, 2013 8:15 pm

Sometimes, whenever I start a video session, I receive a stream with a different connectionId from my own even though I'm pretty sure no one else is connecting to my video session. When this subscriber finally connects to my video session, it turns out it's streaming video from my own device but from seconds/minutes earlier.

Here's my session didReceiveStream code.

Code: Select all
- (void)session:(OTSession*)mySession didReceiveStream:(OTStream*)stream
{
    NSLog(@"session didReceiveStream (%@)", stream.streamId);
   
    // See the declaration of subscribeToSelf above.
    if (![stream.connection.connectionId isEqualToString: _session.connection.connectionId])
    {
        NSLog(@"stream name: %@", stream.name);
        NSLog(@"stream type: %@", stream.type);
        NSLog(@"stream date: %@", stream.creationTime);
        if (!_subscriber) {
            _subscriber = [[OTSubscriber alloc] initWithStream:stream delegate:self];
        }
    }
}


Is this a bug from tokbox? Or am I doing anything wrong?
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Mon Jan 14, 2013 10:26 am

What version of the SDK are you using and from what release date?

That is: are you using the Flash-compatible iOS SDK or the WebRTC (P2P only) SDK?
What is the release date of the SDK (noted in the banner that's printed when an OTSession object is initialized).

You can just copy/paste that entire banner here.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Mon Jan 14, 2013 8:44 pm

I'm using the flash-compatible version of the SDK

Here's the banner:

2013-01-15 09:39:06.053 SCI5video[132:907] OpenTok iOS Library
2013-01-15 09:39:06.054 SCI5video[132:907] Release version built on Nov 8 2012 at 17:40:53
2013-01-15 09:39:06.055 SCI5video[132:907] Copyright 2012 Tokbox, Inc.
2013-01-15 09:39:06.056 SCI5video[132:907] Licensed under the Apache License, Version 2.0
2013-01-15 09:39:06.057 SCI5video[132:907] ------------------------------------------------
2013-01-15 09:39:06.060 SCI5video[132:907] OpenTok API Server: api.opentok.com

If it helps, I'm testing connecting, disconnecting and then reconnecting to a session. Today I experienced it about once out of 30 times, but "session didDropStream" was quickly called afterwards.

I'm not sure if it's connected but I've posted other problems I'm experiencing during connection/reconnection http://www.tokbox.com/forums/ios/crashing-when-reconnecting-to-a-session-t14873. Don't know if it would help.

Thanks!
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Tue Jan 15, 2013 12:08 am

That's strange. I've never seen anything like that before. The next time you see this happen if you could please provide us with the ConnectionId/SessionId and time of the incident we can take a look at some logs and see what we find.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Tue Jan 15, 2013 2:17 am

Here are the logs of when I replicated the behavior again. These aren't the whole logs (since I was connecting and reconnecting for quite some time), but only the logs of the particular session where the bug appeared.


2013-01-15 16:49:47.132 SCI5video[714:907] sessionDidConnect (2_MX4yMTk1MzUyMn5-TW9uIEphbiAwNyAwMDozNDo1MSBQU1QgMjAxM34wLjAyOTIzNDM1fg) --> Session successfully connected

2013-01-15 16:49:47.133 SCI5video[714:907] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.

Jan 15 16:49:47 CaMP-iPad SCI5video[714] <Error>: CGContextDrawImage: invalid context 0x0

2013-01-15 16:49:52.072 SCI5video[714:907] session didReceiveStream (435246720) --> This is the stream that had a different connectionId but it came from my device

2013-01-15 16:49:52.782 SCI5video[714:907] stream name: CaMP iPad --> This is the name of the device I'm using, so the stream definitely came from the same source

2013-01-15 16:49:52.783 Lab2LabVideo[714:907] stream type: basic

2013-01-15 16:49:52.786 Lab2LabVideo[714:907] stream date: 2013-01-15 08:49:47 +0000 --> My timezone is GMT+8 so this stream was generated around the same time as my session.

2013-01-15 16:50:00.269 Lab2LabVideo[714:907] subscriberDidConnectToStream (80DCF797-A21E-44E2-8FCB-1F9842DEEC26)

2013-01-15 16:50:02.335 Lab2LabVideo[714:907] publisherDidStartStreaming: <OTPublisher: 0x1f27b930>

2013-01-15 16:50:02.336 Lab2LabVideo[714:907] - publisher.session: 2_MX4yMTk1MzUyMn5-TW9uIEphbiAwNyAwMDozNDo1MSBQU1QgMjAxM34wLjAyOTIzNDM1fg

2013-01-15 16:50:02.338 Lab2LabVideo[714:907] - publisher.name: CaMP iPad

2013-01-15 16:50:08.394 Lab2LabVideo[714:907] session didReceiveStream (1313155586) --> This is the stream that had the same connectionId as my session so it was ignored

2013-01-15 16:50:09.345 Lab2LabVideo[714:907] subscriberVideoDataReceived (435246720)

Jan 15 16:50:25 CaMP-iPad Lab2LabVideo[714] <Error>: CGContextDrawImage: invalid context 0x0

2013-01-15 16:52:40.125 Lab2LabVideo[714:907] session didDropStream (435246720) --> This is where the subscriber's stream was dropped after a few minutes

Again, the subscriber's stream was definitely showing a video stream probably seconds/minutes earlier, probably even before I started the particular video session. Weird.
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Tue Jan 15, 2013 9:24 pm

We're going to have to dive deeper into this one. I'll get back to you in the next day or so. If you come across any other details please add them to this thread.

Just to be clear:

This isn't happening very often, but when it does you're connecting with the same sessionId?

This line is concerning to me:

2013-01-15 16:49:52.072 SCI5video[714:907] session didReceiveStream (435246720) --> This is the stream that had a different connectionId but it came from my device


It sounds like you were publishing before on the same session, disconnected and came back to find your stream still present (but only occasionally?).

Can you try to reproduce while profiling with leaks and see how many OTPublisher and OTSubscriber objects you have laying around when you see it?

We'll look at the server logs and see what we can gather.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Wed Jan 16, 2013 12:28 am

This isn't happening very often, but when it does you're connecting with the same sessionId?


Yup.

I tried profiling using leaks and OTPublisher and OTSession was indeed leaking. By the time the bug happened, I had 2 instances each of OTPublisher and OTSession but only 1 instance of OTSubscriber.

I don't get it though, with ARC, shouldn't they be released when I allocate a new instance for the publisher? Or when I nil the previous session out?
Was this post helpful? (0)
Attachments
OTSubscriber.png
OTSession.png
OTPublisher.png
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Wed Jan 16, 2013 12:33 am

The 3 OTPublisher instances during this seems pretty suspect. Are you calling [OTSession disconnect] or just niling out the session?

This sounds like a dangling OTPublisher pointer issue. If you're not already doing it, try calling [OTSession disconnect] just before you set it to nil. That should be enough to get all the publishers and subscribers shutdown and cleaned up.

It's best practice to explicitly call the disconnect selector so that our internal cleanup mechanism gets triggered. I'll have to check the behavior for whether niling will always invoke the internal cleanup.

Let me know if you can reproduce after doing this.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Wed Jan 16, 2013 1:09 am

I'm actually already calling OTSession disconnect before I set it to nil. I'm setting it to nil on my sessionDidDisconnect method:

Code: Select all
- (void)sessionDidDisconnect:(OTSession*)session
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
   
    _session = nil;
   
    if(reconnectAfterDisconnecting){
        _session = [[OTSession alloc] initWithSessionId:self.videoSessionItem.sessionId
                                               delegate:self];
        [_session connectWithApiKey:self.videoSessionItem.apiKey token:self.videoSessionItem.token];
        reconnectAfterDisconnecting = NO;
    }
}


On my previous post, this was already the case.
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Wed Jan 16, 2013 1:11 am

Ah, yes you were - should have looked up to verify that. I'll dig more on this tomorrow and see what I find with our logs.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Wed Jan 16, 2013 1:30 am

Thanks! Actually, I only started setting the session to nil after you suggested it in another one of my posts. It solved the crashing issues from that post but this one still persists. :|
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby mjtitus » Wed Jan 16, 2013 12:28 pm

We haven't had problems with unexpectedly receiving our own streams, but we have experienced (and previously reported via email) leaks of OTSession and OTPublisher after disconnecting from a session.
Was this post helpful? (0)
mjtitus
 
Posts: 52
Joined: Tue Dec 06, 2011 3:27 pm
Thumbs Up: 0

Re: Receiving new stream from my own device.

Postby don » Wed Jan 16, 2013 1:43 pm

Based on server logs, it looks like you're not actually disconnecting from the session. You are potentially connecting to it twice, leaving a dangling OTPublisher instance laying around that is actually still streaming in the background.

This conclusion is based on your logs and what we're seeing:

Server Logs:

14:41:12,914 Controllers:0 Publishers:0 Subscribers:0 # New Session
14:41:15,176 Controllers:1 Publishers:0 Subscribers:0 # First Connection Joins Session
14:41:17,889 Controllers:1 Publishers:1 Subscribers:0 # First Connection Publishes
14:41:18,535 Controllers:2 Publishers:1 Subscribers:0 # Second Connection Joins Session <- I would think this is where your problem lays if this second connection is the same device
14:41:23,152 Controllers:2 Publishers:1 Subscribers:1 # Second Connection Subscribes to First Connection
14:41:23,796 Controllers:2 Publishers:2 Subscribers:1 # Someone publishes (Two Publishers now)
14:53:00,624 Controllers:2 Publishers:1 Subscribers:2 # Someone stops publishing, another subscribes
14:53:01,186 Controllers:2 Publishers:1 Subscribers:1 # Someone stops subscribing
14:53:05,930 Controllers:2 Publishers:1 Subscribers:0 # Someone stops subscribing
14:53:06,106 Controllers:2 Publishers:0 Subscribers:0 # Someone stops publishing
15:00:53,539 Controllers:1 Publishers:0 Subscribers:0 # Someone disconnects
15:22:31,985 Controllers:0 Publishers:0 Subscribers:0 # Last person disconnects
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Thu Jan 17, 2013 6:58 pm

So the previous OTSession and publisher was still remaining even though I thought I disconnected it properly. hmmmmmm

I've got a question, regarding sessionDidFail. I was assuming that if it was called, the session was already disconnected. Should I still call [session disconnect] after a session connection failure before reconnecting to that session? I haven't tested it yet, but perhaps this could be the reason?

@mjtitus

What were the scenarios were you found out that OTSession and OTPublisher were leaking? How did you fix it?

Thanks. I would appreciate any help.
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby markSci5 » Thu Jan 17, 2013 8:22 pm

Also, I wanted to make sure I wasn't doing anything special that created retain cycles, so I tested the sample OpenTokBasic iOS app and I've found that it too was leaking instances of OTSession and OTPublisher, even after I disconnected. Although, I didn't receive any stream from my own device, I'm guessing the leaking OTSessions and OTPublishers are issues that haven't been fully resolved yet?
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby markSci5 » Fri Jan 18, 2013 1:58 am

Ok, this is what I found out.

I think this bug happens if I automatically connect during the sessionDidDisconnect callback.

Code: Select all
- (void)sessionDidDisconnect:(OTSession*)session
{
    ...
    _session = nil;
    [self doConnect];
}



I've tried it out on the OpenTokBasic sample app and I could replicate the bug there which means I wasn't doing anything else weird in my code aside from immediately connecting after the session was disconnected. I added this automatic reconnection function because I wanted the user to be able to immediately connect to a different session if he wanted to, without having to go through the hassle of tapping a disconnect button.

I don't know if this is a matter of timing issues, but intuitively, the session should be completely disconnected already by the time sessionDidDisconnect is called or even after I've set my OTSession instance to false. I guess this bug happening just proves this isn't the case as of now.

@don or @mjtitus

Just wanted to know your opinion on this and if I'm on the right track. If this is the case, then I may need to create a separate disconnect button on my app.
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Tue Jan 22, 2013 10:18 am

Sorry for the delay on this one, long weekend got in the way there. I'll be digging into this one today. I'll report back with my findings.
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby don » Tue Jan 22, 2013 4:14 pm

I am still unable to reproduce this issue.

I just did a git clone of the OpenTokHelloWorld project and changed the following two methods:

Code: Select all
- (void)sessionDidDisconnect:(OTSession*)session
{
    NSString* alertMessage = [NSString stringWithFormat:@"Session disconnected: (%@)", session.sessionId];
    NSLog(@"sessionDidDisconnect (%@)", alertMessage);
    [self showAlert:alertMessage];
   
    _session = nil;
    _session = [[OTSession alloc] initWithSessionId:kSessionId
                                           delegate:self];
    [self doConnect];
}


I'm automatically disconnecting after 10 seconds of being connected to a session (to invoke the sessionDidDisconnect: selector):

Code: Select all
- (void)sessionDidConnect:(OTSession*)session
{
    NSLog(@"sessionDidConnect (%@)", session.sessionId);
    [self doPublish];
   
    int64_t delayInSeconds = 10.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [_session disconnect];
    });
}


I followed up by running it through the Leaks profiler for about 20 cycles and I'm not seeing any of my OTPublisher or OTSession objects getting leaked (albeit there are a few minor leaks that should be cleaned up in the next release). Are you sure you don't have a strong reference to one of these objects (OTSession or OTPublisher) somewhere in your code?

If you want, please attach the HelloWorld project you modified to reproduce this behavior and I'll see what I can find from that.

To be clear:

I'm using the OpenTok iOS SDK from our GitHub page: https://github.com/opentok/opentok-ios-sdk
with the OpenTokHelloWorld example: https://github.com/opentok/OpenTok-iOS-Hello-World

You can download them both at the same time by running:

Code: Select all
git clone git@github.com:opentok/OpenTok-iOS-Hello-World.git --recursive
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Thu Jan 24, 2013 2:16 am

Ok, I don't know what I happened but I can't replicate the bug anymore on the sample app (I was using opentok-basic-tutorial rather than opentok-helloworld project). Perhaps I was too hasty in posting my findings or I just messed up my previous testing. I have implemented a manual disconnect button on my app though and I haven't experienced any problems again so far. I'll have to wait and see.

BUT, I can replicate the memory leaks of OTSession and OTPublisher on the opentok-helloworld project. Although I guess "abandoned memory" is the correct term since they won't show up on the leaks instruments but you can see multiple living instances on the allocations list.

I've posted a screenshot after running opentok-helloworld for a minute with your modifications and its clear that the OTSession and OTPublisher instances won't die even after disconnection. Now, I'm not sure if this is supposed to be normal, but I'm guessing it's not supposed to work this way ?

I've also done some heapshot analysis using the opentok-basic project. I marked a heapshot after everytime I connected and disconnected and I found 1 instance each of OTSession and OTPublisher on every heapshot meaning they weren't destroyed after disconnecting. I think this a clearer sign of memory leaking rather than the leaks instrument.

As of now, I'm not having any problems, but I am worried about any weird behavior this may cause in the future. And I can't be sure that any bug I experience with tokbox from now on may or may not be related to these "memory leaks". Is it alright for me to just ignore this for now?
Was this post helpful? (0)
Attachments
Screen Shot 2013-01-24 at 5.05.17 PM.png
Screen Shot 2013-01-24 at 4.54.26 PM.png
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2

Re: Receiving new stream from my own device.

Postby don » Thu Jan 24, 2013 11:06 am

Glad your original problem seems to have cleared up. As for the object leaks, I'm in the process of going through all of those right now and they should be cleaned up for our next release (sometime in the next couple weeks). You can safely ignore these for now, assuming you're not connecting/disconnecting to sessions more than a reasonable amount of times, the leaks you're seeing are pretty small (though annoying I do agree).

Keep an eye on the GitHub page for updates to the SDK :)
Was this post helpful? (0)
don
 
Posts: 148
Joined: Wed Dec 14, 2011 1:45 pm
Thumbs Up: 11

Re: Receiving new stream from my own device.

Postby markSci5 » Thu Jan 24, 2013 6:14 pm

Thanks don!

BTW, any chance for the tokbox iOS sdk to have its own cocoa pod ?
Was this post helpful? (0)
markSci5
 
Posts: 24
Joined: Sun Jan 13, 2013 7:59 pm
Thumbs Up: 2


Return to iOS (Native)



Who is online

Users browsing this forum: No registered users and 1 guest

cron