void AsioTcpSocket::Received(const boost::system::error_code& error, size_t transferred) { ptr<ReceiveHandler> receiveHandler; ptr<File> receiveFile; { CriticalCode cc(cs); receiveHandler = this->receiveHandler; receiveFile = this->receiveFile; if(error) { CloseNonSynced(); this->receiveHandler = nullptr; this->receiveFile = nullptr; } else StartReceiving(); } if(receiveHandler) { if(error) { // если корректный конец файла, это не ошибка if(error == boost::asio::error::eof) receiveHandler->FireData(nullptr); else receiveHandler->FireError(AsioService::ConvertError(error)); } else receiveHandler->FireData(NEW(PartFile(receiveFile, receiveFile->GetData(), transferred))); } }
void CTcpConn::RunL() { DEBUG_INFO("CTcpConn RunL (%p) iStatus=%d ts=%p tc=%p\n", this, iStatus.Int(), ts, tc); /* This happens after calling cancel functions in socket */ if (iStatus == KErrCancel || iStatus == KErrAbort) { iStatus = KErrNone; return; } else if (iStatus == KErrEof) { ; } else if (iStatus != KErrNone) { DEBUG_WARNING("RunL received iStatus %d\n", iStatus.Int()); } /* Outgoing CONNECT */ if (connecting) { connecting = false; if (iStatus == KErrNone) { int err = 0; DEBUG_INFO("TCP Conn ESTABLISHED\n"); struct le *le = list_head(&tc->helpers); while (le) { struct tcp_helper *th; th = (struct tcp_helper *)le->data; le = le->next; if (th->estabh(&err, tc->active, th->arg) || err) { if (err) tc->conn_close(err); return; } } if (tc->estabh) tc->estabh(tc->arg); StartReceiving(); } else { DEBUG_WARNING("RunL: connecting (%d)\n", iStatus.Int()); tc->conn_close(ECONNREFUSED); } } /* Incoming DATA */ else if (receiving) { if (iStatus == KErrEof) tc->conn_close(0); else tc->recv(); } else { DEBUG_WARNING("CTcpConn RunL: bogus state\n"); } }
void AsioTcpSocket::SetReceiveHandler(ptr<ReceiveHandler> receiveHandler) { CriticalCode cc(cs); bool firstTime = !this->receiveHandler; this->receiveHandler = receiveHandler; if(firstTime) // запустить приём StartReceiving(); }
void FileTransfer::Start() { emit StartReceiving(); QFile file(path_); file.open(QIODevice::WriteOnly); QDataStream stream(&file); while (!sock_->atEnd()) { QByteArray data = sock_->read(buf_size_); if (data.size() <= 0) { break; } bytes_read_ += data.size(); stream.writeRawData(data.data(), data.size()); emit Percent(bytes_read_/total_); } emit EndReceiving(); }
MediaConduitErrorCode WebrtcVideoConduit::ConfigureRecvMediaCodecs( const std::vector<VideoCodecConfig* >& codecConfigList) { CSFLogDebug(logTag, "%s ", __FUNCTION__); MediaConduitErrorCode condError = kMediaConduitNoError; bool success = false; std::string payloadName; condError = StopReceiving(); if (condError != kMediaConduitNoError) { return condError; } if(codecConfigList.empty()) { CSFLogError(logTag, "%s Zero number of codecs to configure", __FUNCTION__); return kMediaConduitMalformedArgument; } webrtc::ViEKeyFrameRequestMethod kf_request = webrtc::kViEKeyFrameRequestNone; bool use_nack_basic = false; //Try Applying the codecs in the list // we treat as success if atleast one codec was applied and reception was // started successfully. for(std::vector<VideoCodecConfig*>::size_type i=0;i < codecConfigList.size();i++) { //if the codec param is invalid or diplicate, return error if((condError = ValidateCodecConfig(codecConfigList[i],false)) != kMediaConduitNoError) { return condError; } // Check for the keyframe request type: PLI is preferred // over FIR, and FIR is preferred over none. if (codecConfigList[i]->RtcpFbNackIsSet("pli")) { kf_request = webrtc::kViEKeyFrameRequestPliRtcp; } else if(kf_request == webrtc::kViEKeyFrameRequestNone && codecConfigList[i]->RtcpFbCcmIsSet("fir")) { kf_request = webrtc::kViEKeyFrameRequestFirRtcp; } // Check whether NACK is requested if(codecConfigList[i]->RtcpFbNackIsSet("")) { use_nack_basic = true; } webrtc::VideoCodec video_codec; memset(&video_codec, 0, sizeof(webrtc::VideoCodec)); if (mExternalRecvCodec && codecConfigList[i]->mType == mExternalRecvCodec->mType) { CSFLogError(logTag, "%s Configuring External H264 Receive Codec", __FUNCTION__); // XXX Do we need a separate setting for receive maxbitrate? Is it // different for hardware codecs? For now assume symmetry. CodecConfigToWebRTCCodec(codecConfigList[i], video_codec); // values SetReceiveCodec() cares about are name, type, maxbitrate if(mPtrViECodec->SetReceiveCodec(mChannel,video_codec) == -1) { CSFLogError(logTag, "%s Invalid Receive Codec %d ", __FUNCTION__, mPtrViEBase->LastError()); } else { CSFLogError(logTag, "%s Successfully Set the codec %s", __FUNCTION__, codecConfigList[i]->mName.c_str()); if(CopyCodecToDB(codecConfigList[i])) { success = true; } else { CSFLogError(logTag,"%s Unable to update Codec Database", __FUNCTION__); return kMediaConduitUnknownError; } } } else { //Retrieve pre-populated codec structure for our codec. for(int idx=0; idx < mPtrViECodec->NumberOfCodecs(); idx++) { if(mPtrViECodec->GetCodec(idx, video_codec) == 0) { payloadName = video_codec.plName; if(codecConfigList[i]->mName.compare(payloadName) == 0) { CodecConfigToWebRTCCodec(codecConfigList[i], video_codec); if(mPtrViECodec->SetReceiveCodec(mChannel,video_codec) == -1) { CSFLogError(logTag, "%s Invalid Receive Codec %d ", __FUNCTION__, mPtrViEBase->LastError()); } else { CSFLogError(logTag, "%s Successfully Set the codec %s", __FUNCTION__, codecConfigList[i]->mName.c_str()); if(CopyCodecToDB(codecConfigList[i])) { success = true; } else { CSFLogError(logTag,"%s Unable to update Codec Database", __FUNCTION__); return kMediaConduitUnknownError; } } break; //we found a match } } }//end for codeclist } }//end for if(!success) { CSFLogError(logTag, "%s Setting Receive Codec Failed ", __FUNCTION__); return kMediaConduitInvalidReceiveCodec; } if (!mVideoCodecStat) { mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec); } mVideoCodecStat->Register(false); // XXX Currently, we gather up all of the feedback types that the remote // party indicated it supports for all video codecs and configure the entire // conduit based on those capabilities. This is technically out of spec, // as these values should be configured on a per-codec basis. However, // the video engine only provides this API on a per-conduit basis, so that's // how we have to do it. The approach of considering the remote capablities // for the entire conduit to be a union of all remote codec capabilities // (rather than the more conservative approach of using an intersection) // is made to provide as many feedback mechanisms as are likely to be // processed by the remote party (and should be relatively safe, since the // remote party is required to ignore feedback types that it does not // understand). // // Note that our configuration uses this union of remote capabilites as // input to the configuration. It is not isomorphic to the configuration. // For example, it only makes sense to have one frame request mechanism // active at a time; so, if the remote party indicates more than one // supported mechanism, we're only configuring the one we most prefer. // // See http://code.google.com/p/webrtc/issues/detail?id=2331 if (kf_request != webrtc::kViEKeyFrameRequestNone) { CSFLogDebug(logTag, "Enabling %s frame requests for video stream\n", (kf_request == webrtc::kViEKeyFrameRequestPliRtcp ? "PLI" : "FIR")); if(mPtrRTP->SetKeyFrameRequestMethod(mChannel, kf_request) != 0) { CSFLogError(logTag, "%s KeyFrameRequest Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitKeyFrameRequestError; } } switch (kf_request) { case webrtc::kViEKeyFrameRequestNone: mFrameRequestMethod = FrameRequestNone; break; case webrtc::kViEKeyFrameRequestPliRtcp: mFrameRequestMethod = FrameRequestPli; break; case webrtc::kViEKeyFrameRequestFirRtcp: mFrameRequestMethod = FrameRequestFir; break; default: MOZ_ASSERT(PR_FALSE); mFrameRequestMethod = FrameRequestUnknown; } if(use_nack_basic) { CSFLogDebug(logTag, "Enabling NACK (recv) for video stream\n"); if (mPtrRTP->SetNACKStatus(mChannel, true) != 0) { CSFLogError(logTag, "%s NACKStatus Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitNACKStatusError; } } mUsingNackBasic = use_nack_basic; condError = StartReceiving(); if (condError != kMediaConduitNoError) { return condError; } // by now we should be successfully started the reception mPtrRTP->SetRembStatus(mChannel, false, true); DumpCodecDB(); return kMediaConduitNoError; }
MediaConduitErrorCode WebrtcAudioConduit::ConfigureRecvMediaCodecs( const std::vector<AudioCodecConfig*>& codecConfigList) { CSFLogDebug(logTag, "%s ", __FUNCTION__); MediaConduitErrorCode condError = kMediaConduitNoError; int error = 0; //webrtc engine errors bool success = false; // Are we receiving already? If so, stop receiving and playout // since we can't apply new recv codec when the engine is playing. condError = StopReceiving(); if (condError != kMediaConduitNoError) { return condError; } if(codecConfigList.empty()) { CSFLogError(logTag, "%s Zero number of codecs to configure", __FUNCTION__); return kMediaConduitMalformedArgument; } // Try Applying the codecs in the list. // We succeed if at least one codec was applied and reception was // started successfully. for(std::vector<AudioCodecConfig*>::size_type i=0 ;i<codecConfigList.size();i++) { //if the codec param is invalid or diplicate, return error if((condError = ValidateCodecConfig(codecConfigList[i],false)) != kMediaConduitNoError) { return condError; } webrtc::CodecInst cinst; if(!CodecConfigToWebRTCCodec(codecConfigList[i],cinst)) { CSFLogError(logTag,"%s CodecConfig to WebRTC Codec Failed ",__FUNCTION__); continue; } if(mPtrVoECodec->SetRecPayloadType(mChannel,cinst) == -1) { error = mPtrVoEBase->LastError(); CSFLogError(logTag, "%s SetRecvCodec Failed %d ",__FUNCTION__, error); continue; } else { CSFLogDebug(logTag, "%s Successfully Set RecvCodec %s", __FUNCTION__, codecConfigList[i]->mName.c_str()); //copy this to local database if(CopyCodecToDB(codecConfigList[i])) { success = true; } else { CSFLogError(logTag,"%s Unable to updated Codec Database", __FUNCTION__); return kMediaConduitUnknownError; } } } //end for if(!success) { CSFLogError(logTag, "%s Setting Receive Codec Failed ", __FUNCTION__); return kMediaConduitInvalidReceiveCodec; } //If we are here, atleast one codec should have been set condError = StartReceiving(); if (condError != kMediaConduitNoError) { return condError; } DumpCodecDB(); return kMediaConduitNoError; }