Example #1
0
  void NiceConnection::updateIceState(IceState state) {
      { // New scope for our lock
          boost::unique_lock<boost::recursive_mutex> lock(stateMutex_);
          if(iceState_==state)
              return;

          ELOG_INFO("%s - NICE State Changing from %u to %u %p", transportName->c_str(), this->iceState_, state, this);
          this->iceState_ = state;
          switch( iceState_) {
          case NICE_FINISHED:
              return;
          case NICE_FAILED:
              this->running_=false;
              break;

          case NICE_READY:
              char ipaddr[NICE_ADDRESS_STRING_LEN];
              NiceCandidate* local, *remote;
              nice_agent_get_selected_pair(agent_, 1, 1, &local, &remote);
              nice_address_to_string(&local->addr, ipaddr);
              ELOG_INFO("Selected pair:\nlocal candidate addr: %s:%d",ipaddr, nice_address_get_port(&local->addr));
              nice_address_to_string(&remote->addr, ipaddr);
              ELOG_INFO("remote candidate addr: %s:%d",ipaddr, nice_address_get_port(&remote->addr));
              break;
          default:
              break;
          }
      }

      // Important: send this outside our state lock.  Otherwise, serious risk of deadlock.
      if (this->listener_ != NULL)
          this->listener_->updateIceState(state, this);
  }
Example #2
0
MediaStream::MediaStream(
  std::shared_ptr<WebRtcConnection> connection,
  const std::string& media_stream_id) :
    audio_enabled_{false}, video_enabled_{false},
    connection_{connection},
    stream_id_{media_stream_id},
    bundle_{false},
    pipeline_{Pipeline::create()}, audio_muted_{false}, video_muted_{false},
    pipeline_initialized_{false} {
  setVideoSinkSSRC(kDefaultVideoSinkSSRC);
  setAudioSinkSSRC(kDefaultAudioSinkSSRC);
  ELOG_INFO("%s message: constructor, id: %s",
      toLog(), media_stream_id.c_str());
  source_fb_sink_ = this;
  sink_fb_source_ = this;
  stats_ = connection->getStatsService();
  quality_manager_ = std::make_shared<QualityManager>();
  packet_buffer_ = std::make_shared<PacketBufferService>();
  worker_ = connection->getWorker();

  rtcp_processor_ = std::make_shared<RtcpForwarder>(static_cast<MediaSink*>(this), static_cast<MediaSource*>(this));

  should_send_feedback_ = true;
  slide_show_mode_ = false;

  mark_ = clock::now();

  rate_control_ = 0;
  sending_ = true;
}
Example #3
0
  CandidatePair NiceConnection::getSelectedPair(){
    char ipaddr[NICE_ADDRESS_STRING_LEN];
    CandidatePair selectedPair;
    NiceCandidate* local, *remote;
    nice_agent_get_selected_pair(agent_, 1, 1, &local, &remote);
    nice_address_to_string(&local->addr, ipaddr);
    selectedPair.erizoCandidateIp = std::string(ipaddr);
    selectedPair.erizoCandidatePort = nice_address_get_port(&local->addr);
    ELOG_INFO("Selected pair:\nlocal candidate addr: %s:%d",ipaddr, nice_address_get_port(&local->addr));
    nice_address_to_string(&remote->addr, ipaddr);
    selectedPair.clientCandidateIp = std::string(ipaddr);
    selectedPair.clientCandidatePort = nice_address_get_port(&remote->addr);
    ELOG_INFO("remote candidate addr: %s:%d",ipaddr, nice_address_get_port(&remote->addr));
    return selectedPair;

  }
Example #4
0
  void NiceConnection::updateIceState(IceState state) {

    if(iceState_==state)
      return;

    ELOG_INFO("%s - NICE State Changing from %u to %u %p", transportName->c_str(), this->iceState_, state, this);
    this->iceState_ = state;
    switch( iceState_) {
      case NICE_FINISHED:
        return;
      case NICE_FAILED:
        ELOG_ERROR("Nice Failed, stopping ICE");
        this->running_=false;
        break;

      case NICE_READY:
      case NICE_CANDIDATES_RECEIVED:
        break;
      default:
        break;
    }

    // Important: send this outside our state lock.  Otherwise, serious risk of deadlock.
    if (this->listener_ != NULL)
      this->listener_->updateIceState(state, this);
  }
Example #5
0
void NicerConnection::startGathering() {
  UINT4 r = nicer_->IceGather(ctx_, &NicerConnection::gather_callback, this);
  if (r && r != R_WOULDBLOCK) {
    ELOG_WARN("%s message: Couldn't start ICE gathering", toLog());
    assert(false);
  }
  ELOG_INFO("%s message: start gathering", toLog());
}
Example #6
0
void DtlsTransport::updateIceState(IceState state, NiceConnection* conn)
{
    ELOG_DEBUG("%s - New NICE state state: %d - Media: %d - is Bundle: %d", transport_name.c_str(), state, mediaType, bundle_);
    if (state == NICE_INITIAL && this->getTransportState() != TRANSPORT_STARTED) {
        updateTransportState(TRANSPORT_STARTED);
    } else if (state == NICE_CANDIDATES_RECEIVED && this->getTransportState() != TRANSPORT_GATHERED) {
        updateTransportState(TRANSPORT_GATHERED);
    } else if (state == NICE_FAILED) {
        ELOG_DEBUG("Nice Failed, no more reading packets");
        running_ = false;
        updateTransportState(TRANSPORT_FAILED);
    } else if (state == NICE_READY) {
        ELOG_INFO("%s - Nice ready", transport_name.c_str());
        if (dtlsRtp_ && !dtlsRtp_->started) {
            ELOG_INFO("%s - DTLSRTP Start", transport_name.c_str());
            dtlsRtp_->start();
        }
        if (dtlsRtcp_ != NULL && (!dtlsRtcp_->started || rtcpResender_->getStatus() < 0)) {
            ELOG_DEBUG("%s - DTLSRTCP Start", transport_name.c_str());
            dtlsRtcp_->start();
        }
    }
}
Example #7
0
void RtpPacketQueue::pushPacket(const char *data, int length)
{
    const RTPHeader *currentHeader = reinterpret_cast<const RTPHeader*>(data);
    uint16_t currentSequenceNumber = currentHeader->getSeqNumber();

    if(lastSequenceNumberGiven_ >= 0 && (rtpSequenceLessThan(currentSequenceNumber, (uint16_t)lastSequenceNumberGiven_) || currentSequenceNumber == lastSequenceNumberGiven_)) {
        // this sequence number is less than the stuff we've already handed out, which means it's too late to be of any value.
        // TODO adaptive depth?
        ELOG_WARN("SSRC:%u, Payload: %u, discarding very late sample %d that is <= %d.  Current queue depth is %d",currentHeader->getSSRC(),currentHeader->getPayloadType(), currentSequenceNumber, lastSequenceNumberGiven_, this->getSize());
        return;
    }

    // TODO this should be a secret of the dataPacket class.  It should maintain its own memory
    // and copy stuff as necessary.
    boost::shared_ptr<dataPacket> packet(new dataPacket());
    memcpy(packet->data, data, length);
    packet->length = length;

    // let's insert this packet where it belongs in the queue.
    boost::mutex::scoped_lock lock(queueMutex_);

    std::list<boost::shared_ptr<dataPacket> >::iterator it;
    for (it=queue_.begin(); it != queue_.end(); ++it) {
        const RTPHeader *header = reinterpret_cast<const RTPHeader*>((*it)->data);
        uint16_t sequenceNumber = header->getSeqNumber();

        if (sequenceNumber == currentSequenceNumber) {
            // We already have this sequence number in the queue.
            ELOG_INFO("discarding duplicate sample %d", currentSequenceNumber);
            break;
        }

        if (this->rtpSequenceLessThan(sequenceNumber, currentSequenceNumber)) {
            queue_.insert(it, packet);
            break;
        }
    }

    if (it == queue_.end()) {
        // something old, or queue is empty.
        queue_.push_back(packet);
    }

    // Enforce our max queue size.
    while(queue_.size() > max_) {
        ELOG_DEBUG("RtpPacketQueue - Discarding a sample due to hitting MAX_SIZE");
        queue_.pop_back();  // remove oldest samples.
    }
}
Example #8
0
 WebRtcConnection::~WebRtcConnection() {
   ELOG_INFO("WebRtcConnection Destructor");
   sending_ = false;
   cond_.notify_one();
   send_Thread_.join();
   globalState_ = CONN_FINISHED;
   if (connEventListener_ != NULL){
     connEventListener_->notifyEvent(globalState_);
     connEventListener_ = NULL;
   }
   globalState_ = CONN_FINISHED;
   videoSink_ = NULL;
   audioSink_ = NULL;
   fbSink_ = NULL;
   delete videoTransport_;
   videoTransport_=NULL;
   delete audioTransport_;
   audioTransport_= NULL;
 }
Example #9
0
void NiceConnection::gatheringDone(uint stream_id) {
    int currentCompId = 1;
    lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++);
    NiceCandidate *cand;
    GSList* iterator;
    gchar *ufrag = NULL, *upass = NULL;
    nice_agent_get_local_credentials(agent_, stream_id, &ufrag, &upass);
    //////False candidate for testing when there is no network (like in the train) :)
    /*
    	NiceCandidate* thecandidate = nice_candidate_new(NICE_CANDIDATE_TYPE_HOST);
    	NiceAddress* naddr = nice_address_new();
    	nice_address_set_from_string(naddr, "127.0.0.1");
    	nice_address_set_port(naddr, 50000);
    	thecandidate->addr = *naddr;
    	char* uname = (char*) malloc(50);
    	char* pass = (char*) malloc(50);
    	sprintf(thecandidate->foundation, "%s", "1");
    	sprintf(uname, "%s", "Pedro");
    	sprintf(pass, "%s", "oooo");

    	thecandidate->username = uname;
    	thecandidate->password = pass;
    	thecandidate->stream_id = (guint) 1;
    	thecandidate->component_id = 1;
    	thecandidate->priority = 1000;
    	thecandidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
    	lcands = g_slist_append(lcands, thecandidate);
    */

    //	ELOG_DEBUG("gathering done %u",stream_id);
    //ELOG_DEBUG("Candidates---------------------------------------------------->");
    while (lcands != NULL) {
        for (iterator = lcands; iterator; iterator = iterator->next) {
            char address[40], baseAddress[40];
            cand = (NiceCandidate*) iterator->data;
            nice_address_to_string(&cand->addr, address);
            nice_address_to_string(&cand->base_addr, baseAddress);
            if (strstr(address, ":") != NULL) {
                ELOG_DEBUG("Ignoring IPV6 candidate %s", address);
                continue;
            }
//			ELOG_DEBUG("foundation %s", cand->foundation);
//			ELOG_DEBUG("compid %u", cand->component_id);
//			ELOG_DEBUG("stream_id %u", cand->stream_id);
//			ELOG_DEBUG("priority %u", cand->priority);
//			ELOG_DEBUG("username %s", cand->username);
//			ELOG_DEBUG("password %s", cand->password);
            CandidateInfo cand_info;
            cand_info.componentId = cand->component_id;
            cand_info.foundation = cand->foundation;
            cand_info.priority = cand->priority;
            cand_info.hostAddress = std::string(address);
            cand_info.hostPort = nice_address_get_port(&cand->addr);
            cand_info.mediaType = mediaType;

            /*
             *   NICE_CANDIDATE_TYPE_HOST,
             * 	  NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE,
             *	  NICE_CANDIDATE_TYPE_PEER_REFLEXIVE,
             * 	  NICE_CANDIDATE_TYPE_RELAYED,
             */
            switch (cand->type) {
            case NICE_CANDIDATE_TYPE_HOST:
                cand_info.hostType = HOST;
                break;
            case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
                cand_info.hostType = SRLFX;
                cand_info.baseAddress = std::string(baseAddress);
                cand_info.basePort = nice_address_get_port(&cand->base_addr);
                break;
            case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
                cand_info.hostType = PRFLX;
                break;
            case NICE_CANDIDATE_TYPE_RELAYED:
                ELOG_DEBUG("WARNING TURN NOT IMPLEMENTED YET");
                cand_info.hostType = RELAY;
                break;
            default:
                break;
            }
            cand_info.netProtocol = "udp";
            cand_info.transProtocol = std::string(*transportName);

            cand_info.username = std::string(ufrag);

            cand_info.password = std::string(upass);
            /*
            if (cand->username)
            	cand_info.username = std::string(cand->username);
            else
            	cand_info.username = std::string("(null)");

            if (cand->password)
            	cand_info.password = std::string(cand->password);
            else
            	cand_info.password = std::string("(null)");
            */

            localCandidates->push_back(cand_info);
        }
        lcands = nice_agent_get_local_candidates(agent_, stream_id,
                 currentCompId++);
    }
    ELOG_INFO("candidate_gathering done with %d candidates", localCandidates->size());

    if (localCandidates->size()==0) {
        ELOG_WARN("No local candidates found, check your network connection");
        exit(0);
    }
    updateIceState(NICE_CANDIDATES_GATHERED);
}
Example #10
0
  void NiceConnection::gatheringDone(uint stream_id) {
    if (this->checkIceState() >= NICE_FINISHED) {
      ELOG_DEBUG("gathering Done after FINISHED");
      nice_agent_remove_stream (agent_,1);
      return;
    }
    ELOG_DEBUG("Gathering Done %p", this);
    int currentCompId = 1;
    GSList* lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++);
    gchar *ufrag = NULL, *upass = NULL;
    nice_agent_get_local_credentials(agent_, stream_id, &ufrag, &upass);
    while (lcands != NULL) {
      for (GSList* iterator = lcands; iterator; iterator = iterator->next) {
        char address[NICE_ADDRESS_STRING_LEN], baseAddress[NICE_ADDRESS_STRING_LEN];
        NiceCandidate *cand = (NiceCandidate*) iterator->data;
        nice_address_to_string(&cand->addr, address);
        nice_address_to_string(&cand->base_addr, baseAddress);
        if (strstr(address, ":") != NULL) {
          ELOG_DEBUG("Ignoring IPV6 candidate %s %p", address, this);
          continue;
        }

        CandidateInfo cand_info;
        cand_info.componentId = cand->component_id;
        cand_info.foundation = cand->foundation;
        cand_info.priority = cand->priority;
        cand_info.hostAddress = std::string(address);
        cand_info.hostPort = nice_address_get_port(&cand->addr);
        cand_info.mediaType = mediaType;

        /*
         *   NICE_CANDIDATE_TYPE_HOST,
         * 	  NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE,
         *	  NICE_CANDIDATE_TYPE_PEER_REFLEXIVE,
         * 	  NICE_CANDIDATE_TYPE_RELAYED,
         */
        switch (cand->type) {
          case NICE_CANDIDATE_TYPE_HOST:
            cand_info.hostType = HOST;
            break;
          case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
            cand_info.hostType = SRFLX;
            cand_info.rAddress = std::string(baseAddress);
            cand_info.rPort = nice_address_get_port(&cand->base_addr);
            break;
          case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
            cand_info.hostType = PRFLX;
            break;
          case NICE_CANDIDATE_TYPE_RELAYED:
            char turnAddres[NICE_ADDRESS_STRING_LEN];
            ELOG_DEBUG("TURN LOCAL CANDIDATE");
            nice_address_to_string(&cand->turn->server,turnAddres);
        		ELOG_DEBUG("address %s", address);
        		ELOG_DEBUG("baseAddress %s", baseAddress);
        		ELOG_DEBUG("stream_id %u", cand->stream_id);
        		ELOG_DEBUG("priority %u", cand->priority);
        		ELOG_DEBUG("TURN ADDRESS %s", turnAddres);
           
            cand_info.hostType = RELAY;
            cand_info.rAddress = std::string(baseAddress);
            cand_info.rPort = nice_address_get_port(&cand->base_addr);
            break;
          default:
            break;
        }
        cand_info.netProtocol = "udp";
        cand_info.transProtocol = std::string(*transportName.get());
        cand_info.username = std::string(ufrag);
        cand_info.password = std::string(upass);
        localCandidates->push_back(cand_info);
      }
      // for nice_agent_get_local_candidates,  the caller owns the returned GSList as well as the candidates contained within it.
      // let's free everything in the list, as well as the list.
      g_slist_free_full(lcands, (GDestroyNotify)&nice_candidate_free);
      lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++);
    }
    // According to libnice, this is how these must be free'd
    g_free(ufrag);
    g_free(upass);

    ELOG_INFO("candidate_gathering done with %lu candidates %p", localCandidates->size(), this);

    if (localCandidates->size()==0){
      ELOG_WARN("No local candidates found, check your network connection");
      exit(0);
    }
    updateIceState(NICE_CANDIDATES_GATHERED);
  }
Example #11
0
  void WebRtcConnection::updateState(TransportState state, Transport * transport) {
    boost::mutex::scoped_lock lock(updateStateMutex_);
    WebRTCState temp = globalState_;
    ELOG_DEBUG("Update Transport State %d", state);
    if (audioTransport_ == NULL && videoTransport_ == NULL) {
      return;
    }

    if (state == TRANSPORT_FAILED) {
      temp = FAILED;
      ELOG_INFO("WebRtcConnection failed.");
    }

    
    if (globalState_ == FAILED) {
      // if current state is failed we don't use
      return;
    }

    if (state == TRANSPORT_STARTED &&
        (!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_STARTED)) &&
        (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_STARTED))) {
      if (remoteSdp_.hasVideo) {
        videoTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
      }
      if (!bundle_ && remoteSdp_.hasAudio) {
        audioTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
      }
      temp = STARTED;
    }

    if (state == TRANSPORT_READY &&
        (!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_READY)) &&
        (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_READY))) {
        temp = READY;
    }

    if (transport != NULL && transport == videoTransport_ && bundle_) {
      if (state == TRANSPORT_STARTED) {
        videoTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
        temp = STARTED;
      }
      if (state == TRANSPORT_READY) {
        temp = READY;
      }
    }

    if (temp == READY && globalState_ != temp) {
      ELOG_INFO("Ready to send and receive media");
    }
    if (audioTransport_ != NULL && videoTransport_ != NULL) {
      ELOG_INFO("Update Transport State end, %d - %d, %d - %d, %d - %d, %d - %d", 
        audioTransport_->getTransportState(), 
        videoTransport_->getTransportState(), 
        this->getAudioSourceSSRC(),
        this->getVideoSourceSSRC(),
        temp, globalState_);
    }
    if (temp < 0) {
      return;
    }

    if (temp == globalState_ || (temp == STARTED && globalState_ == READY))
      return;

    globalState_ = temp;
    if (connStateListener_ != NULL)
      connStateListener_->connectionStateChanged(globalState_);
  }
Example #12
0
  void WebRtcConnection::updateState(TransportState state, Transport * transport) {
    boost::mutex::scoped_lock lock(updateStateMutex_);
    WebRTCEvent temp = globalState_;
    ELOG_INFO("Update Transport State %s to %d", transport->transport_name.c_str(), state);
    if (audioTransport_ == NULL && videoTransport_ == NULL) {
      return;
    }

    if (state == TRANSPORT_FAILED) {
      temp = CONN_FAILED;
      //globalState_ = CONN_FAILED;
      sending_ = false;
      ELOG_INFO("WebRtcConnection failed, stopping sending");
      cond_.notify_one();
      ELOG_INFO("WebRtcConnection failed, stopped sending");
    }

    
    if (globalState_ == CONN_FAILED) {
      // if current state is failed we don't use
      return;
    }

    if (state == TRANSPORT_STARTED &&
        (!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_STARTED)) &&
        (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_STARTED))) {
      if (remoteSdp_.hasVideo) {
        videoTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
      }
      if (!bundle_ && remoteSdp_.hasAudio) {
        audioTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
      }
      temp = CONN_STARTED;
    }

    if (state == TRANSPORT_READY &&
        (!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_READY)) &&
        (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_READY))) {
        // WebRTCConnection will be ready only when all channels are ready.
        temp = CONN_READY;
    }

    if (transport != NULL && transport == videoTransport_ && bundle_) {
      if (state == TRANSPORT_STARTED) {
        videoTransport_->setRemoteCandidates(remoteSdp_.getCandidateInfos());
        temp = CONN_STARTED;
      }
      if (state == TRANSPORT_READY) {
        temp = CONN_READY;
      }
    }

    if (temp == CONN_READY && globalState_ != temp) {
      ELOG_INFO("Ready to send and receive media");
    }

    if (audioTransport_ != NULL && videoTransport_ != NULL) {
      ELOG_INFO("%s - Update Transport State end, %d - %d, %d - %d, %d - %d", 
        transport->transport_name.c_str(),
        (int)audioTransport_->getTransportState(), 
        (int)videoTransport_->getTransportState(), 
        this->getAudioSourceSSRC(),
        this->getVideoSourceSSRC(),
        (int)temp, 
        (int)globalState_);
    }
    
    if (temp < 0) {
      return;
    }

    if (temp == globalState_ || (temp == CONN_STARTED && globalState_ == CONN_READY))
      return;

    globalState_ = temp;
    if (connEventListener_ != NULL)
      connEventListener_->notifyEvent(globalState_);
  }
Example #13
0
void NicerConnection::gatheringDone(uint stream_id) {
  ELOG_INFO("%s message: gathering done, stream_id: %u", toLog(), stream_id);
  updateIceState(IceState::CANDIDATES_RECEIVED);
}
Example #14
0
void elog::init(int _argc, const char** _argv) {
	ELOG_INFO("E-log system init (BEGIN)");
	// retrive application Name:
	std::string applName = _argv[0];
	int lastSlash = applName.rfind('/');
	applName = &applName[lastSlash+1];
	// get name: applName
	bool userSpecifyLogFile = false;
	for (int32_t iii=0; iii<_argc ; ++iii) {
		std::string data = _argv[iii];
		if (startWith(data, "--elog-level=")) {
			ELOG_INFO("Change global level at " << getLogLevel(std::string(data.begin()+13, data.end())));
			elog::setLevel(getLogLevel(std::string(data.begin()+13, data.end())));
		} else if (data == "--elog-color") {
			elog::setColor(true);
		} else if (data == "--elog-no-color") {
			elog::setColor(false);
		} else if (data == "--elog-back-trace") {
			elog::setBackTrace(true);
		} else if (startWith(data, "--elog-file=")) {
			std::string value(data.begin()+12, data.end());
			if (value.size() == 0) {
				elog::unsetLogInFile();
			} else {
				elog::setLogInFile(value);
			}
			userSpecifyLogFile = true;
		} else if (startWith(data, "--elog-config=")) {
			std::string value(data.begin()+14, data.end());
			elog::setTime(false);
			elog::setLine(false);
			elog::setFunction(false);
			elog::setLibName(false);
			elog::setThreadId(false);
			elog::setThreadNameEnable(false);
			for (size_t iii=0; iii<value.size(); ++iii) {
				if (value[iii] == 't') {
					elog::setTime(true);
				} else if (value[iii] == 'T') {
					elog::setThreadId(true);
				} else if (value[iii] == 'N') {
					elog::setThreadNameEnable(true);
				} else if (value[iii] == 'L') {
					elog::setLine(true);
				} else if (value[iii] == 'l') {
					elog::setLibName(true);
				} else if (value[iii] == 'f') {
					elog::setFunction(true);
				} else {
					ELOG_ERROR("In program argument: --elog-config= , the value '" << value[iii] << "' is not supported");
				}
			}
		} else if (startWith(data, "--elog-lib=")) {
			std::string value(data.begin()+11, data.end());
			std::vector<std::string> list = split(value, '/');
			if (list.size() != 2) {
				list = split(value, ':');
				if (list.size() != 2) {
					list = split(value, '+');
					if (list.size() != 2) {
						ELOG_ERROR("Can not set the --elog-lib= with value='" << value << "' not formated name:X or name/X or name+X");
						continue;
					}
				}
			}
			ELOG_INFO("Change level of '" << list[0] << "' at " << getLogLevel(list[1]));
			elog::setLevel(list[0], getLogLevel(list[1]));
		} else if (    data == "-h"
		            || data == "--help") {
			ELOG_PRINT("elog - help : ");
			ELOG_PRINT("    " << _argv[0] << " [options]");
			ELOG_PRINT("        --elog-level=            Change the default log level (set all Log level):");
			ELOG_PRINT("            0: debug None (default in release)");
			ELOG_PRINT("            1: debug Critical");
			ELOG_PRINT("            2: debug Error");
			ELOG_PRINT("            3: debug Warning");
			ELOG_PRINT("            4: debug Info (default in debug)");
			ELOG_PRINT("            5: debug Debug");
			ELOG_PRINT("            6: debug Verbose");
			ELOG_PRINT("        --elog-lib=name:X  Set a library specific level:");
			ELOG_PRINT("            name  Name of the library");
			ELOG_PRINT("            X     Log level to set [0..6]");
			ELOG_PRINT("            note: ':' can be replace with '/' or '+'");
			ELOG_PRINT("        --elog-file=pathToFile   File to store the logs: (disable console logs)");
			ELOG_PRINT("        --elog-color             Enable color in log (default in Linux/debug)");
			ELOG_PRINT("        --elog-no-color          Disable color in log (default in Linux/release and Other)");
			ELOG_PRINT("        --elog-back-trace        Enable back-trace when an error log level is generated (to get a fast debug)");
			ELOG_PRINT("        --elog-config=           Configure the Log interface");
			ELOG_PRINT("            t: diplay time");
			#ifdef ELOG_BUILD_ETHREAD
				ELOG_PRINT("            T: diplay thread id");
				ELOG_PRINT("            N: diplay thread name");
			#endif
			ELOG_PRINT("            L: diplay line number");
			ELOG_PRINT("            l: diplay lib name");
			ELOG_PRINT("            f: diplay function name");
			ELOG_PRINT("        -h/--help:               Dispplay this help");
			ELOG_PRINT("    example:");
			ELOG_PRINT("        " << _argv[0] << " --elog-color --elog-level=2 --elog-lib=etk:5 --elog-lib=appl:6 --elog-config=NLlf");
		} else if (startWith(data, "--elog") == true) {
			ELOG_ERROR("Can not parse the argument : '" << data << "'");
		}
	}
	if (userSpecifyLogFile == false) {
		#ifdef DEBUG
			#if defined(__TARGET_OS__Windows)
				elog::setLogInFile("log.txt");
			#endif
		#else
			#if defined(__TARGET_OS__Linux)
				//elog::setLogInFile("/var/log/elog_" +applName + ".log");
				elog::setLogInFile("/tmp/elog_" +applName + ".log");
			#elif defined(__TARGET_OS__MacOs)
				elog::setLogInFile(applName + ".log");
			#elif defined(__TARGET_OS__Windows)
				elog::setLogInFile(applName + ".log");
			#endif
		#endif
	}
	
	ELOG_INFO("E-LOG system init (END)");
}
Example #15
0
  void WebRtcConnection::updateState(TransportState state, Transport * transport) {
    boost::mutex::scoped_lock lock(updateStateMutex_);
    WebRTCEvent temp = globalState_;
    std::string msg = "";
    ELOG_INFO("Update Transport State %s to %d", transport->transport_name.c_str(), state);
    if (videoTransport_ == NULL && audioTransport_ == NULL) {
      ELOG_ERROR("Update Transport State with Transport NULL, this should not happen!");
      return;
    }
    

    if (globalState_ == CONN_FAILED) {
      // if current state is failed -> noop
      return;
    }

    switch (state){
      case TRANSPORT_STARTED:
        if (bundle_){
          temp = CONN_STARTED;
        }else{
          if ((!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_STARTED)) &&
            (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_STARTED))) {
              // WebRTCConnection will be ready only when all channels are ready.
              temp = CONN_STARTED;
            }
        }
        break;
      case TRANSPORT_GATHERED:
        if (bundle_){
          if(!trickleEnabled_){
            temp = CONN_GATHERED;
            msg = this->getLocalSdp();
          }
        }else{
          if ((!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_GATHERED)) &&
            (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_GATHERED))) {
              // WebRTCConnection will be ready only when all channels are ready.
              if(!trickleEnabled_){
                temp = CONN_GATHERED;
                msg = this->getLocalSdp();
              }
            }
        }
        break;
      case TRANSPORT_READY:
        if (bundle_){
          temp = CONN_READY;

        }else{
          if ((!remoteSdp_.hasAudio || (audioTransport_ != NULL && audioTransport_->getTransportState() == TRANSPORT_READY)) &&
            (!remoteSdp_.hasVideo || (videoTransport_ != NULL && videoTransport_->getTransportState() == TRANSPORT_READY))) {
              // WebRTCConnection will be ready only when all channels are ready.
              temp = CONN_READY;            
            }
        }
        break;
      case TRANSPORT_FAILED:
        temp = CONN_FAILED;
        sending_ = false;
        msg = remoteSdp_.getSdp();
        ELOG_INFO("WebRtcConnection failed, stopping sending");
        cond_.notify_one();
        break;
      default:
        ELOG_DEBUG("New state %d", state);
        break;
    }

    if (audioTransport_ != NULL && videoTransport_ != NULL) {
      ELOG_INFO("%s - Update Transport State end, %d - %d, %d - %d, %d - %d", 
        transport->transport_name.c_str(),
        (int)audioTransport_->getTransportState(), 
        (int)videoTransport_->getTransportState(), 
        this->getAudioSourceSSRC(),
        this->getVideoSourceSSRC(),
        (int)temp, 
        (int)globalState_);
    }
    
    if (globalState_ == temp)
      return;

    globalState_ = temp;

    if (connEventListener_ != NULL) {
      connEventListener_->notifyEvent(globalState_, msg);
    }
  }