Ejemplo n.º 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);
    }
}
Ejemplo n.º 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);
    }
}
Ejemplo n.º 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);
  }
}
Ejemplo n.º 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);
    }
}
Ejemplo n.º 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);
    }
}
Ejemplo n.º 6
0
void SdesTransport::write(char* data, int len) {
   //boost::mutex::scoped_lock lock(writeMutex_);
    int length = len;
    SrtpChannel *srtp = srtp_;

    int comp = 1;
    if (this->getTransportState() == TRANSPORT_READY) {
      memset(protectBuf_, 0, len);
      memcpy(protectBuf_, data, len);

      rtcpheader *chead = reinterpret_cast<rtcpheader*> (protectBuf_);
      if (chead->packettype == RTCP_Sender_PT || chead->packettype == RTCP_Receiver_PT || chead->packettype == RTCP_PS_Feedback_PT
          || chead->packettype == RTCP_RTP_Feedback_PT) {
        if (!rtcp_mux_) {
          comp = 2;
        }
        if (srtcp_ != NULL) {
          srtp = srtcp_;
        }
        if (srtp && nice_->iceState == NICE_READY) {
          if(srtp->protectRtcp(protectBuf_, &length)<0) {
            return;
          }
        }
      }
      else{
        comp = 1;

        if (srtp && nice_->iceState == NICE_READY) {
          if(srtp->protectRtp(protectBuf_, &length)<0) {
            return;
          }
        }
      }
      if (length <= 10) {
        return;
      }
      if (nice_->iceState == NICE_READY) {
          //getTransportListener()->queueData(comp, protectBuf_, length, this);
          this->writeOnNice(comp, protectBuf_, length);
      }
    }
}
Ejemplo n.º 7
0
void DtlsTransport::write(char* data, int len) {
  boost::mutex::scoped_lock lock(writeMutex_);
  if (nice_==NULL)
    return;
  int length = len;
  SrtpChannel *srtp = srtp_.get();

  if (this->getTransportState() == TRANSPORT_READY) {
    memcpy(protectBuf_, data, len);
    int comp = 1;
    RtcpHeader *chead = reinterpret_cast<RtcpHeader*> (protectBuf_);
    if (chead->isRtcp()) {
      if (!rtcp_mux_) {
        comp = 2;
      }
      if (dtlsRtcp != NULL) {
        srtp = srtcp_.get();
      }
      if (srtp && nice_->checkIceState() == NICE_READY) {
        if(srtp->protectRtcp(protectBuf_, &length)<0) {
          return;
        }
      }
    }
    else{
      comp = 1;

      if (srtp && nice_->checkIceState() == NICE_READY) {
        if(srtp->protectRtp(protectBuf_, &length)<0) {
          return;
        }
      }
    }
    if (length <= 10) {
      return;
    }
    if (nice_->checkIceState() == NICE_READY) {
      this->writeOnNice(comp, protectBuf_, length);
    }
  }
}