Changeset 5986


Ignore:
Timestamp:
May 10, 2019 8:27:22 AM (5 months ago)
Author:
ming
Message:

Re #2189: Fixing various bugs:

  • assertion: !Endpoint::instance().mediaExists(*this) in Media::registerMediaPort() when using AudioMedia?

Sound device is already registered in the conference bridge, while AudioMediaPlayer/Recorder? creation function, i.e. pjsua_player_create(), pjsua_playlist_create(), and pjsua_recorder_create() already call pjmedia_conf_add_port(), so mediaExists() will always return TRUE.

  • Endpoint.mediaAdd() should check in its own internal list if the media exists, rather than querying pjsua.
  • Calling Endpoint::libDestroy() first, then deleting Endpoint will cause crash, since the mutex to remove the medias has been deleted in libDestroy().

The introduction of the mutex is in r5964.

  • DevAudioMedia? never removes itself from mediaList, potentially causing infinite loop/crash.
Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/pjsua2_demo.cpp

    r5899 r5986  
    3131private: 
    3232    MyAccount *myAcc; 
     33    AudioMediaPlayer *wav_player; 
    3334 
    3435public: 
     
    3637    : Call(acc, call_id) 
    3738    { 
     39        wav_player = NULL; 
    3840        myAcc = (MyAccount *)&acc; 
     41    } 
     42     
     43    ~MyCall() 
     44    { 
     45        if (wav_player) 
     46            delete wav_player; 
    3947    } 
    4048     
     
    4250    virtual void onCallTransferRequest(OnCallTransferRequestParam &prm); 
    4351    virtual void onCallReplaced(OnCallReplacedParam &prm); 
     52    virtual void onCallMediaState(OnCallMediaStateParam &prm); 
    4453}; 
    4554 
     
    115124} 
    116125 
     126void MyCall::onCallMediaState(OnCallMediaStateParam &prm) 
     127{ 
     128    PJ_UNUSED_ARG(prm); 
     129 
     130    unsigned i; 
     131    CallInfo ci = getInfo(); 
     132    AudioMedia aud_med; 
     133    AudioMedia& play_dev_med = 
     134        Endpoint::instance().audDevManager().getPlaybackDevMedia(); 
     135 
     136    try { 
     137        // Get the first audio media 
     138        aud_med = getAudioMedia(-1); 
     139    } catch(...) { 
     140        std::cout << "Failed to get audio media" << std::endl; 
     141        return; 
     142    } 
     143 
     144    if (!wav_player) { 
     145        wav_player = new AudioMediaPlayer(); 
     146        try { 
     147            wav_player->createPlayer( 
     148                "../../../../tests/pjsua/wavs/input.16.wav", 0); 
     149        } catch (...) { 
     150            std::cout << "Failed opening wav file" << std::endl; 
     151            delete wav_player; 
     152            wav_player = NULL; 
     153        } 
     154    } 
     155 
     156    // This will connect the wav file to the call audio media 
     157    if (wav_player) 
     158        wav_player->startTransmit(aud_med); 
     159 
     160    // And this will connect the call audio media to the sound device/speaker 
     161    aud_med.startTransmit(play_dev_med); 
     162} 
     163 
    117164void MyCall::onCallTransferRequest(OnCallTransferRequestParam &prm) 
    118165{ 
     
    164211     
    165212    // Hangup all calls 
    166     pj_thread_sleep(8000); 
     213    pj_thread_sleep(4000); 
    167214    ep.hangupAllCalls(); 
    168215    pj_thread_sleep(4000); 
  • pjproject/trunk/pjsip/src/pjsua2/call.cpp

    r5985 r5986  
    861861            /* Clear medias. */ 
    862862            for (mi = 0; mi < medias.size(); mi++) { 
    863                 if (medias[mi]) 
     863                if (medias[mi]) { 
     864                    Endpoint::instance().mediaRemove((AudioMedia&)*medias[mi]); 
    864865                    delete medias[mi]; 
     866                } 
    865867            } 
    866868            medias.clear();      
     
    923925        /* Clear medias. */ 
    924926        for (mi = 0; mi < medias.size(); mi++) { 
    925             if (medias[mi]) 
     927            if (medias[mi]) { 
     928                Endpoint::instance().mediaRemove((AudioMedia &)*medias[mi]); 
    926929                delete medias[mi]; 
     930            } 
    927931        } 
    928932        medias.clear(); 
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r5976 r5986  
    503503        delete pendingJobs.front(); 
    504504        pendingJobs.pop_front(); 
    505     } 
    506  
    507     while(mediaList.size() > 0) { 
    508         AudioMedia *cur_media = mediaList[0]; 
    509         delete cur_media; /* this will remove itself from the list */ 
    510505    } 
    511506 
     
    17881783    } 
    17891784 
     1785    while(mediaList.size() > 0) { 
     1786        AudioMedia *cur_media = mediaList[0]; 
     1787        delete cur_media; /* this will remove itself from the list */ 
     1788    } 
     1789 
    17901790    if (mediaListMutex) { 
    17911791        pj_mutex_destroy(mediaListMutex); 
     
    20892089    pj_mutex_lock(mediaListMutex); 
    20902090 
    2091     if (mediaExists(media)) { 
    2092         pj_mutex_unlock(mediaListMutex); 
    2093         return; 
    2094     } 
    2095  
    2096     mediaList.push_back(&media); 
     2091    AudioMediaVector::iterator it = std::find(mediaList.begin(), 
     2092                                              mediaList.end(), 
     2093                                              &media); 
     2094 
     2095    if (it == mediaList.end()) 
     2096        mediaList.push_back(&media); 
    20972097    pj_mutex_unlock(mediaListMutex); 
    20982098} 
  • pjproject/trunk/pjsip/src/pjsua2/media.cpp

    r5972 r5986  
    132132{ 
    133133    /* Check if media already added to Conf bridge. */ 
    134     pj_assert(!Endpoint::instance().mediaExists(*this)); 
    135  
    136     if (port != NULL) { 
     134    if (!Endpoint::instance().mediaExists(*this) && port != NULL) { 
    137135        pj_assert(id == PJSUA_INVALID_ID); 
    138136 
     
    664662    /* Avoid removing this port (conf port id=0) from conference */ 
    665663    this->id = PJSUA_INVALID_ID; 
     664    unregisterMediaPort(); 
    666665} 
    667666 
Note: See TracChangeset for help on using the changeset viewer.