void CMainDlg::updateSetting() { for (int i = 0;i<BLM_CHANNEL_MAX;i++) { if (m_channelHandle[i] != INVALID_HANDLE_VALUE) { if (m_settingDlg->m_encodeSetting[i].audio) { SetStreamType(m_channelHandle[i],STREAM_TYPE_AVSYNC); }else{ SetStreamType(m_channelHandle[i],STREAM_TYPE_VIDEO); } } } for (int i = 0;i<BLM_CHANNEL_MAX;i++) { if (m_channelHandle[i] != INVALID_HANDLE_VALUE) { //取值范围:12~30 //系统默认:16 int quant[5]={12,16,20,24,30}; SetDefaultQuant(m_channelHandle[i],quant[m_settingDlg->m_encodeSetting[i].quality],NULL,NULL); int format[4] = {1,2,5,6}; SetEncoderPictureFormat(m_channelHandle[i],(PictureFormat_t)format[m_settingDlg->m_encodeSetting[i].format]); //N 制:1,2,3,4,5,6,7,10,15,30; //P 制:1,2,3,4,5,6,8,12,25。 int frameRateP[10] ={1,2,3,4,5,6,7,10,15,30}; int frameRateN[9] ={1,2,3,4,5,6,8,12,25}; VideoStandard_t vs; int a,b,c,d;//useless GetVideoPara(m_channelHandle[i],&vs,&a,&b,&c,&d); if (vs==STANDARD_PAL) { SetIBPMode(m_channelHandle[i],25,0,0,frameRateP[m_settingDlg->m_encodeSetting[i].frameRate]); }else{ SetIBPMode(m_channelHandle[i],25,0,0,frameRateN[m_settingDlg->m_encodeSetting[i].frameRate]); } //todo int maxBits[5]; SetupBitrateControl(m_channelHandle[i],5*1024*1024); if (m_settingDlg->m_encodeSetting[i].sub) { SetSubEncoderPictureFormat(m_channelHandle[i],(PictureFormat_t)format[m_settingDlg->m_encodeSetting[i].format_sub]); SetupSubChannel(m_channelHandle[i],1); SetDefaultQuant(m_channelHandle[i],quant[m_settingDlg->m_encodeSetting[i].quality_sub],NULL,NULL); if (vs==STANDARD_PAL) { SetIBPMode(m_channelHandle[i],25,0,0,frameRateP[m_settingDlg->m_encodeSetting[i].frameRate_sub]); }else{ SetIBPMode(m_channelHandle[i],25,0,0,frameRateN[m_settingDlg->m_encodeSetting[i].frameRate_sub]); } SetupBitrateControl(m_channelHandle[i],5*1024*1024); SetupSubChannel(m_channelHandle[i],0); } } } }
nsresult nsNPAPIPluginStreamListener::OnStartBinding(nsPluginStreamListenerPeer* streamPeer) { if (!mInst || !mInst->CanFireNotifications() || mStreamCleanedUp) return NS_ERROR_FAILURE; PluginDestructionGuard guard(mInst); nsNPAPIPlugin* plugin = mInst->GetPlugin(); if (!plugin || !plugin->GetLibrary()) return NS_ERROR_FAILURE; NPPluginFuncs* pluginFunctions = plugin->PluginFuncs(); if (!pluginFunctions->newstream) return NS_ERROR_FAILURE; NPP npp; mInst->GetNPP(&npp); bool seekable; char* contentType; uint16_t streamType = NP_NORMAL; NPError error; streamPeer->GetURL(&mNPStreamWrapper->mNPStream.url); streamPeer->GetLength((uint32_t*)&(mNPStreamWrapper->mNPStream.end)); streamPeer->GetLastModified((uint32_t*)&(mNPStreamWrapper->mNPStream.lastmodified)); streamPeer->IsSeekable(&seekable); streamPeer->GetContentType(&contentType); if (!mResponseHeaders.IsEmpty()) { mResponseHeaderBuf = PL_strdup(mResponseHeaders.get()); mNPStreamWrapper->mNPStream.headers = mResponseHeaderBuf; } mStreamListenerPeer = streamPeer; NPPAutoPusher nppPusher(npp); NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->newstream)(npp, (char*)contentType, &mNPStreamWrapper->mNPStream, seekable, &streamType), mInst, NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO); NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPP NewStream called: this=%p, npp=%p, mime=%s, seek=%d, type=%d, return=%d, url=%s\n", this, npp, (char *)contentType, seekable, streamType, error, mNPStreamWrapper->mNPStream.url)); if (error != NPERR_NO_ERROR) return NS_ERROR_FAILURE; if (streamType == nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN) { SuspendRequest(); } else if (!SetStreamType(streamType, false)) { return NS_ERROR_FAILURE; } return NS_OK; }
// CONSTRUCTOR OSndStreamWAV::OSndStreamWAV() :OSndStream() { SetStreamType( SNDSTREAM_WAV ); m_pSndFile=NULL; SetFileExtention( _T( "wav" ) ); m_OutputFormat = SF_FORMAT_PCM_16; SetSampleRate( 44100 ); SetChannels( 2 ); }
MediaPacket::MediaPacket(IN const AVStream& _avStream, IN const AVPacket* _pAvPacket) { // save codec pointer pAvCodecPar_ = _avStream.codecpar; enum AVMediaType stream = pAvCodecPar_->codec_type; if (stream != AVMEDIA_TYPE_AUDIO && stream != AVMEDIA_TYPE_VIDEO) { stream = AVMEDIA_TYPE_DATA; } SetStreamType(stream); SetCodec(pAvCodecPar_->codec_id); Width(pAvCodecPar_->width); Height(pAvCodecPar_->height); SampleRate(pAvCodecPar_->sample_rate); Channels(pAvCodecPar_->channels); // copy packet pAvPacket_ = const_cast<AVPacket*>(_pAvPacket); }
// CONSTRUCTOR ISndStreamMPEG::ISndStreamMPEG() :ISndStream() { SetFileExtention("mp3"); SetStreamType( SNDSTREAM_MPEG ); m_pFile=NULL; m_hDLL=NULL; m_pOpenStream=NULL; m_pDecode=NULL; m_pCloseStream=NULL; m_pVersion=NULL; m_hStream=NULL; m_pGetBitRate=NULL; m_dwTotalFileSize=0; m_dwCurrentFilePos=0; m_dwBytesToDo=0; m_dwSkipBytes=0; }
void EncodedStream::start(){ if (m_channel_id >= 0){ if (m_g_real_handler != NULL || m_g_real_handler_ext != NULL){ SetStreamPackType(m_channel_handle, 3);//2:hikvision pack, 3:ps pack SetEncoderPictureFormat(m_channel_handle, ENC_DCIF_FORMAT); SetStreamType(m_channel_handle, STREAM_TYPE_VIDEO); SetDefaultQuant(m_channel_handle, 18, 18, 23);//use the default, the less the better (range:12-30) SetIBPMode(m_channel_handle, 100, 2, 0, FPS);//the last is framerate SetupBitrateControl(m_channel_handle, 2000000);//unit:bps SetBitrateControlMode(m_channel_handle, brCBR);//use cbr, or brVBR StartVideoCapture(m_channel_handle); } if (m_g_real_ori_handler != NULL){ m_yuv_buf_size = WIDTH * HEIGHT * 3 / 2; m_yuv_buf = new unsigned char[m_yuv_buf_size]; SetImageStream(m_channel_handle, true, 25, WIDTH, HEIGHT, m_yuv_buf); } } }
void EQStream::ProcessPacket(EQProtocolPacket *p) { uint32 processed=0,subpacket_length=0; if (p == NULL) return; // Raw Application packet if (p->opcode > 0xff) { p->opcode = htons(p->opcode); //byte order is backwards in the protocol packet EQRawApplicationPacket *ap=MakeApplicationPacket(p); if (ap) InboundQueuePush(ap); return; } if (!Session && p->opcode!=OP_SessionRequest && p->opcode!=OP_SessionResponse) { _log(NET__DEBUG, _L "Session not initialized, packet ignored" __L); _raw(NET__DEBUG, 0xFFFF, p); return; } switch (p->opcode) { case OP_Combined: { processed=0; while(processed < p->size) { subpacket_length=*(p->pBuffer+processed); EQProtocolPacket *subp=MakeProtocolPacket(p->pBuffer+processed+1,subpacket_length); _log(NET__NET_CREATE, _L "Extracting combined packet of length %d" __L, subpacket_length); _raw(NET__NET_CREATE_HEX, 0xFFFF, subp); subp->copyInfo(p); ProcessPacket(subp); delete subp; processed+=subpacket_length+1; } } break; case OP_AppCombined: { processed=0; while(processed<p->size) { EQRawApplicationPacket *ap=NULL; if ((subpacket_length=(unsigned char)*(p->pBuffer+processed))!=0xff) { _log(NET__NET_CREATE, _L "Extracting combined app packet of length %d, short len" __L, subpacket_length); ap=MakeApplicationPacket(p->pBuffer+processed+1,subpacket_length); processed+=subpacket_length+1; } else { subpacket_length=ntohs(*(uint16 *)(p->pBuffer+processed+1)); _log(NET__NET_CREATE, _L "Extracting combined app packet of length %d, short len" __L, subpacket_length); ap=MakeApplicationPacket(p->pBuffer+processed+3,subpacket_length); processed+=subpacket_length+3; } if (ap) { ap->copyInfo(p); InboundQueuePush(ap); } } } break; case OP_Packet: { if(!p->pBuffer || (p->Size() < 4)) { _log(NET__ERROR, _L "Received OP_Packet that was of malformed size" __L); break; } uint16 seq=ntohs(*(uint16 *)(p->pBuffer)); SeqOrder check=CompareSequence(NextInSeq,seq); if (check == SeqFuture) { _log(NET__DEBUG, _L "Future OP_Packet: Expecting Seq=%d, but got Seq=%d" __L, NextInSeq, seq); _raw(NET__DEBUG, seq, p); PacketQueue[seq]=p->Copy(); _log(NET__APP_TRACE, _L "OP_Packet Queue size=%d" __L, PacketQueue.size()); //SendOutOfOrderAck(seq); } else if (check == SeqPast) { _log(NET__DEBUG, _L "Duplicate OP_Packet: Expecting Seq=%d, but got Seq=%d" __L, NextInSeq, seq); _raw(NET__DEBUG, seq, p); SendOutOfOrderAck(seq); //we already got this packet but it was out of order } else { // In case we did queue one before as well. EQProtocolPacket *qp=RemoveQueue(seq); if (qp) { _log(NET__NET_TRACE, "OP_Packet: Removing older queued packet with sequence %d", seq); delete qp; } SetNextAckToSend(seq); NextInSeq++; // Check for an embedded OP_AppCombinded (protocol level 0x19) if (*(p->pBuffer+2)==0x00 && *(p->pBuffer+3)==0x19) { EQProtocolPacket *subp=MakeProtocolPacket(p->pBuffer+2,p->size-2); _log(NET__NET_CREATE, _L "seq %d, Extracting combined packet of length %d" __L, seq, subp->size); _raw(NET__NET_CREATE_HEX, seq, subp); subp->copyInfo(p); ProcessPacket(subp); delete subp; } else { EQRawApplicationPacket *ap=MakeApplicationPacket(p->pBuffer+2,p->size-2); if (ap) { ap->copyInfo(p); InboundQueuePush(ap); } } } } break; case OP_Fragment: { if(!p->pBuffer || (p->Size() < 4)) { _log(NET__ERROR, _L "Received OP_Fragment that was of malformed size" __L); break; } uint16 seq=ntohs(*(uint16 *)(p->pBuffer)); SeqOrder check=CompareSequence(NextInSeq,seq); if (check == SeqFuture) { _log(NET__DEBUG, _L "Future OP_Fragment: Expecting Seq=%d, but got Seq=%d" __L, NextInSeq, seq); _raw(NET__DEBUG, seq, p); PacketQueue[seq]=p->Copy(); _log(NET__APP_TRACE, _L "OP_Fragment Queue size=%d" __L, PacketQueue.size()); //SendOutOfOrderAck(seq); } else if (check == SeqPast) { _log(NET__DEBUG, _L "Duplicate OP_Fragment: Expecting Seq=%d, but got Seq=%d" __L, NextInSeq, seq); _raw(NET__DEBUG, seq, p); SendOutOfOrderAck(seq); } else { // In case we did queue one before as well. EQProtocolPacket *qp=RemoveQueue(seq); if (qp) { _log(NET__NET_TRACE, "OP_Fragment: Removing older queued packet with sequence %d", seq); delete qp; } SetNextAckToSend(seq); NextInSeq++; if (oversize_buffer) { memcpy(oversize_buffer+oversize_offset,p->pBuffer+2,p->size-2); oversize_offset+=p->size-2; _log(NET__NET_TRACE, _L "Fragment of oversized of length %d, seq %d: now at %d/%d" __L, p->size-2, seq, oversize_offset, oversize_length); if (oversize_offset==oversize_length) { if (*(p->pBuffer+2)==0x00 && *(p->pBuffer+3)==0x19) { EQProtocolPacket *subp=MakeProtocolPacket(oversize_buffer,oversize_offset); _log(NET__NET_CREATE, _L "seq %d, Extracting combined oversize packet of length %d" __L, seq, subp->size); //_raw(NET__NET_CREATE_HEX, subp); subp->copyInfo(p); ProcessPacket(subp); delete subp; } else { EQRawApplicationPacket *ap=MakeApplicationPacket(oversize_buffer,oversize_offset); _log(NET__NET_CREATE, _L "seq %d, completed combined oversize packet of length %d" __L, seq, ap->size); if (ap) { ap->copyInfo(p); InboundQueuePush(ap); } } delete[] oversize_buffer; oversize_buffer=NULL; oversize_offset=0; } } else { oversize_length=ntohl(*(uint32 *)(p->pBuffer+2)); oversize_buffer=new unsigned char[oversize_length]; memcpy(oversize_buffer,p->pBuffer+6,p->size-6); oversize_offset=p->size-6; _log(NET__NET_TRACE, _L "First fragment of oversized of seq %d: now at %d/%d" __L, seq, oversize_offset, oversize_length); } } } break; case OP_KeepAlive: { #ifndef COLLECTOR NonSequencedPush(new EQProtocolPacket(p->opcode,p->pBuffer,p->size)); _log(NET__NET_TRACE, _L "Received and queued reply to keep alive" __L); #endif } break; case OP_Ack: { if(!p->pBuffer || (p->Size() < 4)) { _log(NET__ERROR, _L "Received OP_Ack that was of malformed size" __L); break; } #ifndef COLLECTOR uint16 seq=ntohs(*(uint16 *)(p->pBuffer)); AckPackets(seq); #ifdef RETRANSMITS retransmittimer = Timer::GetCurrentTime(); #endif #endif } break; case OP_SessionRequest: { if(p->Size() < sizeof(SessionRequest)) { _log(NET__ERROR, _L "Received OP_SessionRequest that was of malformed size" __L); break; } #ifndef COLLECTOR if (GetState()==ESTABLISHED) { _log(NET__ERROR, _L "Received OP_SessionRequest in ESTABLISHED state (%d)" __L, GetState()); /*RemoveData(); init(); State=UNESTABLISHED;*/ _SendDisconnect(); SetState(CLOSED); break; } #endif //cout << "Got OP_SessionRequest" << endl; init(); OutboundQueueClear(); SessionRequest *Request=(SessionRequest *)p->pBuffer; Session=ntohl(Request->Session); SetMaxLen(ntohl(Request->MaxLength)); _log(NET__NET_TRACE, _L "Received OP_SessionRequest: session %lu, maxlen %d" __L, (unsigned long)Session, MaxLen); SetState(ESTABLISHED); #ifndef COLLECTOR Key=0x11223344; SendSessionResponse(); #endif } break; case OP_SessionResponse: { if(p->Size() < sizeof(SessionResponse)) { _log(NET__ERROR, _L "Received OP_SessionResponse that was of malformed size" __L); break; } init(); OutboundQueueClear(); SessionResponse *Response=(SessionResponse *)p->pBuffer; SetMaxLen(ntohl(Response->MaxLength)); Key=ntohl(Response->Key); NextInSeq=0; SetState(ESTABLISHED); if (!Session) Session=ntohl(Response->Session); compressed=(Response->Format&FLAG_COMPRESSED); encoded=(Response->Format&FLAG_ENCODED); _log(NET__NET_TRACE, _L "Received OP_SessionResponse: session %lu, maxlen %d, key %lu, compressed? %s, encoded? %s" __L, (unsigned long)Session, MaxLen, (unsigned long)Key, compressed?"yes":"no", encoded?"yes":"no"); // Kinda kludgy, but trie for now if (StreamType==UnknownStream) { if (compressed) { if (remote_port==9000 || (remote_port==0 && p->src_port==9000)) { SetStreamType(WorldStream); } else { SetStreamType(ZoneStream); } } else if (encoded) { SetStreamType(ChatOrMailStream); } else { SetStreamType(LoginStream); } } } break; case OP_SessionDisconnect: { //NextInSeq=0; EQStreamState state = GetState(); if(state == ESTABLISHED) { //client initiated disconnect? _log(NET__NET_TRACE, _L "Received unsolicited OP_SessionDisconnect. Treating like a client-initiated disconnect." __L); _SendDisconnect(); SetState(CLOSED); } else if(state == CLOSING) { //we were waiting for this anyways, ignore pending messages, send the reply and be closed. _log(NET__NET_TRACE, _L "Received OP_SessionDisconnect when we have a pending close, they beat us to it. Were happy though." __L); _SendDisconnect(); SetState(CLOSED); } else { //we are expecting this (or have already gotten it, but dont care either way) _log(NET__NET_TRACE, _L "Received expected OP_SessionDisconnect. Moving to closed state." __L); SetState(CLOSED); } } break; case OP_OutOfOrderAck: { if(!p->pBuffer || (p->Size() < 4)) { _log(NET__ERROR, _L "Received OP_OutOfOrderAck that was of malformed size" __L); break; } #ifndef COLLECTOR uint16 seq=ntohs(*(uint16 *)(p->pBuffer)); MOutboundQueue.lock(); if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) { _log(NET__ERROR, _L "Pre-OOA Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq); } if(NextSequencedSend > SequencedQueue.size()) { _log(NET__ERROR, _L "Pre-OOA Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size()); } //if the packet they got out of order is between our last acked packet and the last sent packet, then its valid. if (CompareSequence(SequencedBase,seq) != SeqPast && CompareSequence(NextOutSeq,seq) == SeqPast) { _log(NET__NET_TRACE, _L "Received OP_OutOfOrderAck for sequence %d, starting retransmit at the start of our unacked buffer (seq %d, was %d)." __L, seq, SequencedBase, SequencedBase+NextSequencedSend); #ifdef RETRANSMITS if (!RuleB(EQStream, RetransmitAckedPackets)) { #endif uint16 sqsize = SequencedQueue.size(); uint16 index = seq - SequencedBase; _log(NET__NET_TRACE, _L " OP_OutOfOrderAck marking packet acked in queue (queue index = %d, queue size = %d)." __L, index, sqsize); if (index < sqsize) { deque<EQProtocolPacket *>::iterator sitr; sitr = SequencedQueue.begin(); sitr += index; (*sitr)->acked = true; } #ifdef RETRANSMITS } if (RuleR(EQStream, RetransmitTimeoutMult)) { // only choose new behavior if multiplier is set retransmittimer = Timer::GetCurrentTime(); } #endif NextSequencedSend = 0; } else { _log(NET__NET_TRACE, _L "Received OP_OutOfOrderAck for out-of-window %d. Window (%d->%d)." __L, seq, SequencedBase, NextOutSeq); } if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) { _log(NET__ERROR, _L "Post-OOA Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq); } if(NextSequencedSend > SequencedQueue.size()) { _log(NET__ERROR, _L "Post-OOA Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size()); } MOutboundQueue.unlock(); #endif } break; case OP_SessionStatRequest: { if(p->Size() < sizeof(SessionStats)) { _log(NET__ERROR, _L "Received OP_SessionStatRequest that was of malformed size" __L); break; } #ifndef COLLECTOR SessionStats *Stats=(SessionStats *)p->pBuffer; _log(NET__NET_TRACE, _L "Received Stats: %lu packets received, %lu packets sent, Deltas: local %lu, (%lu <- %lu -> %lu) remote %lu" __L, (unsigned long)ntohl(Stats->packets_received), (unsigned long)ntohl(Stats->packets_sent), (unsigned long)ntohl(Stats->last_local_delta), (unsigned long)ntohl(Stats->low_delta), (unsigned long)ntohl(Stats->average_delta), (unsigned long)ntohl(Stats->high_delta), (unsigned long)ntohl(Stats->last_remote_delta)); uint64 x=Stats->packets_received; Stats->packets_received=Stats->packets_sent; Stats->packets_sent=x; NonSequencedPush(new EQProtocolPacket(OP_SessionStatResponse,p->pBuffer,p->size)); AdjustRates(ntohl(Stats->average_delta)); #ifdef RETRANSMITS if (RuleR(EQStream, RetransmitTimeoutMult) && ntohl(Stats->average_delta)) { //recalculate retransmittimeout using the larger of the last rtt or average rtt, which is multiplied by the rule value if((ntohl(Stats->last_local_delta) + ntohl(Stats->last_remote_delta)) > (ntohl(Stats->average_delta) * 2)) { retransmittimeout = (ntohl(Stats->last_local_delta) + ntohl(Stats->last_remote_delta)) * RuleR(EQStream, RetransmitTimeoutMult); } else { retransmittimeout = ntohl(Stats->average_delta) * 2 * RuleR(EQStream, RetransmitTimeoutMult); } if(retransmittimeout > RuleI(EQStream, RetransmitTimeoutMax)) retransmittimeout = RuleI(EQStream, RetransmitTimeoutMax); _log(NET__NET_TRACE, _L "Retransmit timeout recalculated to %dms" __L, retransmittimeout); } #endif #endif } break; case OP_SessionStatResponse: { _log(NET__NET_TRACE, _L "Received OP_SessionStatResponse. Ignoring." __L); } break; case OP_OutOfSession: { _log(NET__NET_TRACE, _L "Received OP_OutOfSession. Ignoring." __L); } break; default: EQRawApplicationPacket *ap = MakeApplicationPacket(p); if (ap) InboundQueuePush(ap); break; } }