void WebRtcConnection::queueData(int comp, const char* buf, int length, Transport *transport, packetType type) { if ((audioSink_ == NULL && videoSink_ == NULL && fbSink_==NULL) || !sending_) //we don't enqueue data if there is nothing to receive it return; boost::mutex::scoped_lock lock(receiveVideoMutex_); if (!sending_) return; if (comp == -1){ sending_ = false; std::queue<dataPacket> empty; std::swap( sendQueue_, empty); dataPacket p_; p_.comp = -1; sendQueue_.push(p_); cond_.notify_one(); return; } if (sendQueue_.size() < 1000) { dataPacket p_; memcpy(p_.data, buf, length); p_.comp = comp; // p_.type = (transport->mediaType == VIDEO_TYPE) ? VIDEO_PACKET : AUDIO_PACKET; p_.type = type; p_.length = length; changeDeliverPayloadType(&p_, type); sendQueue_.push(p_); }else{ ELOG_DEBUG("Discarding Packets"); } cond_.notify_one(); }
// changes the outgoing payload type for in the given data packet void MediaStream::sendPacketAsync(std::shared_ptr<DataPacket> packet) { if (!sending_) { return; } auto stream_ptr = shared_from_this(); if (packet->comp == -1) { sending_ = false; auto p = std::make_shared<DataPacket>(); p->comp = -1; worker_->task([stream_ptr, p]{ stream_ptr->sendPacket(p); }); return; } changeDeliverPayloadType(packet.get(), packet->type); worker_->task([stream_ptr, packet]{ stream_ptr->sendPacket(packet); }); }