EricssonResearch / openwebrtc-ios-sdk

SDK for adding OpenWebRTC to your iOS apps using CocoaPods
BSD 2-Clause "Simplified" License
69 stars 37 forks source link

[iOS] after hangup the call once (terminateCall function) the background still running #40

Open xelven opened 8 years ago

xelven commented 8 years ago

I not sure it is a issue or something I done wrong, I found if I getting a call once then hangup, meaning call terminateCall function for reset, then press home button enter background, the app still running like this: photo 15-11-13 15 14 52

I think may there something need to reset too.

is there any suggestion for this, thanks

stefanalund commented 8 years ago

I'm not sure but I think this is connected to the AVSession. This does not happen in Bowser so there should be another way to use the OpenWebRTC API to avoid this. Sorry that I don't have a better explanation right now :disappointed:

superdump commented 8 years ago

Which application? Can you describe the steps so that we can try to reproduce?

stefanalund commented 8 years ago

terminateCall is part of the iOS SDK, my guess is that @xelven has built his own app. The behaviour should however be the same for our NativeDemo app (I guess).

https://github.com/EricssonResearch/openwebrtc-ios-sdk/blob/master/SDK/OpenWebRTCNativeHandler.h#L62

xelven commented 8 years ago

@superdump yes yes, just @stefanalund said, it is test app almost same with NativeDemo, it has same issue: photo 15-11-16 11 02 13 after you enable the Background Modes like this: screenshot

xelven commented 8 years ago

I think is works, after I added the code [AudioSession setActive:NO error:&error] when finish the call terminateCall() and then enter background will not running anymore. and remember reactive [AudioSession setActive:YES error:&error] before the call or connected. thanks @superdump @stefanalund for the help and show me the way.

stefanalund commented 8 years ago

Good! This looks like something that should be part of the SDK. Could you please submit a Pull Request with your change? Thanks.

xelven commented 8 years ago

okay just give me more time for test this, then will do that. give me some time to take look : )

stefanalund commented 8 years ago

No problem, thanks a lot!

xelven commented 8 years ago

@stefanalund @superdump I got need to update recently what I doing, after I take look the source code of openwebrtc, I drop [AudioSession setActive:NO error:&error] solution, because this will have chance to happen this:

2015-11-23 17:45:44.874 testWebRTC[8887:1864070] 17:45:44.874 WARNING:  [owr_main_loop] 1251:  [owr_main_loop] 1251: AURemoteIO::Stop: error 0x10000004 calling TerminateOwnIOThread
2015-11-23 17:45:44.877 testWebRTC[8887:1864439] 17:45:44.877 ERROR:    [AURemoteIO::IOThread] >aurioc> 1503: AURemoteIO@0x1729a020: IOThread exiting with error 0x10004002

and then I take look the more deep the for owr_media_session_set_send_source I believe the reason in that, because if there no call connected then won't show the red status bar, then I found the method: owr_media_session_finalize, I can't call it so I copy it out then put into reset() OpenWebRTCNativeHandler, then I think conflict between g_object_unref(transport_agent); and

static void owr_media_session_finalize(GObject *object)
{
    OwrMediaSession *media_session = OWR_MEDIA_SESSION(object);
    OwrMediaSessionPrivate *priv = media_session->priv;
//    _owr_media_session_clear_closures(media_session);
    NSLog(@"*** *** media session object %d",media_session);
    if (priv->incoming_srtp_key)
        g_free(priv->incoming_srtp_key);
    if (priv->outgoing_srtp_key)
        g_free(priv->outgoing_srtp_key);
    if (priv->cname)
        g_free(priv->cname);
//
    if (priv->remote_sources) {
        g_mutex_lock(&priv->remote_source_lock);
        g_slist_free_full(priv->remote_sources, g_object_unref);
        priv->remote_sources = NULL;
        g_mutex_unlock(&priv->remote_source_lock);
    }
    g_mutex_clear(&priv->remote_source_lock);
    if (priv->send_source)
        owr_media_session_set_send_source(media_session, NULL);
//    if (priv->send_payload)
//        g_object_unref(priv->send_payload);
//    g_ptr_array_unref(priv->receive_payloads);
    g_rw_lock_clear(&priv->rw_lock);
//    G_OBJECT_CLASS(owr_media_session_parent_class)->finalize(object);
}

so I comment it first, and make sure it really works finish the call the red status will gone, and in the call the background status will running, may have memory leak a little bit. please discuss with me, if I am doing wrong.