Beispiel #1
0
void SdesTransport::onNiceData(unsigned int component_id, char* data, int len, NiceConnection* nice) {
    //boost::mutex::scoped_lock lock(readMutex_);
    int length = len;
    SrtpChannel *srtp = srtp_;

    if (this->getTransportState() == TRANSPORT_READY) {
      memset(unprotectBuf_, 0, len);
      memcpy(unprotectBuf_, data, len);

      if (component_id == 2) {
        srtp = srtcp_;
      }

      rtcpheader *chead = reinterpret_cast<rtcpheader*> (unprotectBuf_);
      if (chead->packettype == RTCP_Sender_PT ||
          chead->packettype == RTCP_Receiver_PT ||
          chead->packettype == RTCP_PS_Feedback_PT||
          chead->packettype == RTCP_RTP_Feedback_PT){
        if(srtp->unprotectRtcp(unprotectBuf_, &length)<0)
          return;
      } else {
        if(srtp->unprotectRtp(unprotectBuf_, &length)<0)
          return;
      }

      if (length <= 0)
          return;

      getTransportListener()->onTransportData(unprotectBuf_, length, this);
    }
}
Beispiel #2
0
void SdesTransport::onNiceData(unsigned int component_id, char* data, int len, NiceConnection* nice) {
    //boost::mutex::scoped_lock lock(readMutex_);
    int length = len;
    SrtpChannel *srtp = srtp_;

    if (this->getTransportState() == TRANSPORT_READY) {
      memcpy(unprotectBuf_, data, len);

      if (component_id == 2) {
        srtp = srtcp_;
      }

      RtcpHeader *chead = reinterpret_cast<RtcpHeader*> (unprotectBuf_);
      if (chead->isRtcp()){
        if(srtp->unprotectRtcp(unprotectBuf_, &length)<0)
          return;
      } else {
        if(srtp->unprotectRtp(unprotectBuf_, &length)<0)
          return;
      }

      if (length <= 0)
          return;

      getTransportListener()->onTransportData(unprotectBuf_, length, this);
    }
}
Beispiel #3
0
void DtlsTransport::onNiceData(packetPtr packet) {
  int len = packet->length;
  char *data = packet->data;
  unsigned int component_id = packet->comp;

  int length = len;
  SrtpChannel *srtp = srtp_.get();
  if (DtlsTransport::isDtlsPacket(data, len)) {
    ELOG_DEBUG("%s message: Received DTLS message, transportName: %s, componentId: %u",
               toLog(), transport_name.c_str(), component_id);
    if (component_id == 1) {
      if (rtp_resender_.get() != NULL) {
        rtp_resender_->cancel();
      }
      dtlsRtp->read(reinterpret_cast<unsigned char*>(data), len);
    } else {
      if (rtcp_resender_.get() != NULL) {
        rtcp_resender_->cancel();
      }
      dtlsRtcp->read(reinterpret_cast<unsigned char*>(data), len);
    }
    return;
  } else if (this->getTransportState() == TRANSPORT_READY) {
    unprotect_packet_->length = len;
    unprotect_packet_->received_time_ms = packet->received_time_ms;
    memcpy(unprotect_packet_->data, data, len);

    if (dtlsRtcp != NULL && component_id == 2) {
      srtp = srtcp_.get();
    }
    if (srtp != NULL) {
      RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(unprotect_packet_->data);
      if (chead->isRtcp()) {
        if (srtp->unprotectRtcp(unprotect_packet_->data, &unprotect_packet_->length) < 0) {
          return;
        }
      } else {
        if (srtp->unprotectRtp(unprotect_packet_->data, &unprotect_packet_->length) < 0) {
          return;
        }
      }
    } else {
      return;
    }

    if (length <= 0) {
      return;
    }
    getTransportListener()->onTransportData(unprotect_packet_, this);
  }
}
Beispiel #4
0
void DtlsTransport::onNiceData(unsigned int component_id, char* data, int len, NiceConnection* nice) {
    boost::mutex::scoped_lock lock(readMutex_);
    int length = len;
    SrtpChannel *srtp = srtp_;

    if (DtlsTransport::isDtlsPacket(data, len)) {
      printf("Received DTLS message from %u\n", component_id);
      if (component_id == 1) {
        dtlsRtp->read(reinterpret_cast<unsigned char*>(data), len);
      } else {
        dtlsRtcp->read(reinterpret_cast<unsigned char*>(data), len);
      }

      return;
    } else if (this->getTransportState() == TRANSPORT_READY) {
      memset(unprotectBuf_, 0, len);
      memcpy(unprotectBuf_, data, len);

      if (dtlsRtcp != NULL && component_id == 2) {
        srtp = srtcp_;
      }

      if (srtp != NULL){
          rtcpheader *chead = reinterpret_cast<rtcpheader*> (unprotectBuf_);
          if (chead->packettype == RTCP_Sender_PT || 
              chead->packettype == RTCP_Receiver_PT || 
              chead->packettype == RTCP_Feedback_PT){
            if (chead->packettype == RTCP_Feedback_PT) {
              printf("NACK received\n");
            }

            if(srtp->unprotectRtcp(unprotectBuf_, &length)<0)
              return;
         } else {
            if(srtp->unprotectRtp(unprotectBuf_, &length)<0)
              return;
          }
      } else {
        return;
      }

      if (length <= 0)
          return;

      getTransportListener()->onTransportData(unprotectBuf_, length, this);
    }
}
Beispiel #5
0
void DtlsTransport::onNiceData(unsigned int component_id, char* data, int len, NiceConnection* nice)
{
    int length = len;
    SrtpChannel* srtp = srtp_.get();
    if (DtlsTransport::isDtlsPacket(data, len)) {
        ELOG_DEBUG("%s - Received DTLS message from %u", transport_name.c_str(), component_id);
        if (component_id == 1) {
            if (rtpResender_.get() != NULL) {
                rtpResender_->cancel();
            }
            dtlsRtp_->read(reinterpret_cast<unsigned char*>(data), len);
        } else {
            if (rtcpResender_.get() != NULL) {
                rtcpResender_->cancel();
            }
            dtlsRtcp_->read(reinterpret_cast<unsigned char*>(data), len);
        }
        return;
    } else if (this->getTransportState() == TRANSPORT_READY) {
        memcpy(unprotectBuf_, data, len);

        if (dtlsRtcp_ != NULL && component_id == 2) {
            srtp = srtcp_.get();
        }
        if (srtp != NULL) {
            RtcpHeader* chead = reinterpret_cast<RtcpHeader*>(unprotectBuf_);
            if (chead->isRtcp()) {
                if (srtp->unprotectRtcp(unprotectBuf_, &length) < 0) {
                    return;
                }
            } else {
                if (srtp->unprotectRtp(unprotectBuf_, &length) < 0) {
                    return;
                }
            }
        } else {
            return;
        }

        if (length <= 0) {
            return;
        }

        getTransportListener()->onTransportData(unprotectBuf_, length, this);
    }
}