本文整理汇总了C++中PacketStream类的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream类的具体用法?C++ PacketStream怎么用?C++ PacketStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PacketStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runAVInputReaderRecorderTest
// ---------------------------------------------------------------------
// Audio CaptureRecorder Test
//
void runAVInputReaderRecorderTest()
{
PacketStream stream;
// Create the Encoder Options
av::EncoderOptions options;
options.ofile = "audio_test.mp4";
options.duration = 5; //time(0) +
options.oformat = av::Format("AAC", "aac",
av::AudioCodec("AAC", "aac", 2, 44100, 96000, "fltp"));
//av::AudioCodec("MP3", "libmp3lame", 2, 44100, 128000, "s16p"));
// Attach the Audio Capture
av::AVInputReader::Ptr reader(new av::AVInputReader());
reader->openAudioDevice(0,
options.oformat.audio.channels,
options.oformat.audio.sampleRate);
reader->getEncoderFormat(options.iformat);
// Attach the Audio Capture
stream.attachSource<av::AVInputReader>(reader, true);
// Attach the Audio Encoder
auto encoder = new av::AVPacketEncoder(options);
encoder->initialize();
stream.attach(encoder, 5, true);
stream.start();
scy::pause();
stream.stop();
}
示例2:
STDMETHODIMP
BasicPacketFlow::HandleSubscribe(INT32 lRuleNumber, UINT16 unStreamNumber)
{
PacketStream* pStream = &m_pStreams[unStreamNumber];
HX_ASSERT(pStream->m_bStreamRegistered);
INT32 ret = pStream->SubscribeRule(lRuleNumber,
m_bInitialSubscriptionDone,
m_bIsMulticast,
m_pFlowMgr);
if (ret >= 0)
{
m_bSubscribed = TRUE;
if (m_pRateManager)
{
IHXPacketFlowControl* pRateMgrFlowControl = NULL;
if (HXR_OK == m_pRateManager->QueryInterface(IID_IHXPacketFlowControl,
(void**)&pRateMgrFlowControl))
{
pRateMgrFlowControl->HandleSubscribe(lRuleNumber, unStreamNumber);
HX_RELEASE(pRateMgrFlowControl);
}
}
}
return HXR_OK;
}
示例3: runAudioStreamRecorderTest
// ---------------------------------------------------------------------
// Audio CaptureRecorder Test
//
void runAudioStreamRecorderTest()
{
PacketStream stream;
// Create the Encoder Options
av::EncoderOptions options;
options.ofile = "audio_test.mp3";
//options.stopAt = time(0) + 5;
options.oformat = av::Format("MP3", "mp3",
av::AudioCodec("MP3", "libmp3lame", 2, 44100, 128000, "s16p"));
// Create the Audio Capture
av::Device dev;
auto& media = av::MediaFactory::instance();
media.devices().getDefaultAudioInputDevice(dev);
InfoL << "Default audio capture " << dev.id << endl;
av::AudioCapture::Ptr audioCapture = media.createAudioCapture(0, //dev.id
options.oformat.audio.channels,
options.oformat.audio.sampleRate);
audioCapture->getEncoderFormat(options.iformat);
// Attach the Audio Capture
stream.attachSource<av::AudioCapture>(audioCapture, true);
// Attach the Audio Encoder
//auto encoder = new av::AVPacketEncoder(options);
//encoder->initialize();
//stream.attach(encoder, 5, true);
//CaptureRecorder enc(audioCapture, options);
stream.start();
scy::pause();
stream.stop();
}
示例4: SendFinishRace
void Game::SendFinishRace()
{
PacketStream PS;
ENUM_Event e = FINISHEDRACE;
PS.writeInt(e);
e = ENDOFMESSAGE;
PS.writeInt(e);
// get the data from the stream
char data[100];
PS.toCharArray(data);
// send the data
Net::GetInstance()->SendData(data,"127.0.0.1",m_sendToPort);
// increment num packets sent
m_numPacketsSent++;
m_raceFinished = true;
if(m_host)
{
m_hostWon = true;
}
else
{
m_hostWon = false;
}
}
示例5: sendQuery
void GameNetInterface::sendQuery(const Address &theAddress, const Nonce &clientNonce, U32 identityToken)
{
PacketStream packet;
packet.write(U8(Query));
clientNonce.write(&packet);
packet.write(identityToken);
packet.sendto(mSocket, theAddress);
}
示例6: sendPing
// Send ping to the server. If server has different PROTOCOL_VERSION, the packet will be ignored. This prevents players
// from seeing servers they are incompatible with.
void GameNetInterface::sendPing(const Address &theAddress, const Nonce &clientNonce)
{
PacketStream packet;
packet.write(U8(Ping));
clientNonce.write(&packet);
packet.write(CS_PROTOCOL_VERSION);
packet.sendto(mSocket, theAddress);
}
示例7: routingPacket
void* routingPacket(void* buffin)
{
PacketBufferV* buff = (PacketBufferV*) buffin;
int npix_idx = 0;
int nsamp_idx = 0;
// load packet type (once per thread)
PacketStream* ps;
pthread_mutex_lock(&lockp);
try {
ps = new PacketStream(configFileName.c_str());
} catch (PacketException* e)
{
cout << "Error during routingPacket: ";
cout << e->geterror() << endl;
}
pthread_mutex_unlock(&lockp);
ByteStreamPtr localBuffer[PACKET_NUM];
int npix[PACKET_NUM];
int nsamp[PACKET_NUM];
for(int n=0; n<NTIMES; n++)
{
// copy PACKET_NUM packets data locally
pthread_mutex_lock(&lockp);
for(int m=0; m<PACKET_NUM; m++)
{
ByteStreamPtr rawPacket = buff->getNext();
localBuffer[m] = rawPacket;
}
pthread_mutex_unlock(&lockp);
for(int m=0; m<PACKET_NUM; m++)
{
ByteStreamPtr rawPacket = localBuffer[m];
Packet *p = ps->getPacket(rawPacket);
// get npixel and nsamples
if(p->getPacketID() > 0) {
sizeMB += (p->size() / 1000000.0);
//do something with the packet
;
}
#ifdef DEBUG
else {
cout << "Warning: no packet recognized" << endl;
}
#endif
#ifdef DEBUG
std::cout << "tot size (MB) " << sizeMB << std::endl;
#endif
}
}
delete ps;
return 0;
}
示例8: while
void LoginServerSession::parseInputPacket()
{
PacketStream * ps = NULL;
int msg_length = 0;
// try
{
msg_length = m_input_msg_block.length();
while(true)
{
if (m_input_msg_block.length() < sizeof(Header))
{
break;
}
ps = new PacketStream();
memcpy(ps->re_head(), m_input_msg_block.rd_ptr(), ps->head_size());
if (m_input_msg_block.length() >= ps->head_size() + ps->body_size())
{
m_input_msg_block.rd_ptr(ps->head_size());
if (ps->body_size() > 0)
{
memcpy(ps->re_body(), m_input_msg_block.rd_ptr(), ps->body_size());
m_input_msg_block.rd_ptr(ps->body_size());
}
else
{
// do nothing
}
// ManageStat::instance()->statClientInputTraffic(ps->stream_size(), 1);
ManageClientValidation::instance()->handlePackage(ps);
msg_length = m_input_msg_block.length();
}
else
{
delete ps;
break;
}
}
if (m_input_msg_block.rd_ptr() != m_input_msg_block.base())
{
msg_length = m_input_msg_block.length();
if (msg_length > 0)
{
memcpy(m_input_msg_block.base(), m_input_msg_block.rd_ptr(), msg_length);
}
m_input_msg_block.rd_ptr(m_input_msg_block.base());
m_input_msg_block.wr_ptr(m_input_msg_block.base() + msg_length);
}
}
//catch (...)
//{
// GATE_LOG_ERROR(ACE_TEXT("Raise unknown exception in LoginServerSession::parseInputPacket, last error is <%d>\n"), ACE_OS::last_error());
//}
}
示例9: sendConnectChallengeResponse
void NetInterface::sendConnectChallengeResponse(const Address &addr, Nonce &clientNonce, bool wantsKeyExchange, bool wantsCertificate)
{
PacketStream out;
out.write(U8(ConnectChallengeResponse));
clientNonce.write(&out);
U32 identityToken = computeClientIdentityToken(addr, clientNonce);
out.write(identityToken);
// write out a client puzzle
Nonce serverNonce = mPuzzleManager.getCurrentNonce();
U32 difficulty = mPuzzleManager.getCurrentDifficulty();
serverNonce.write(&out);
out.write(difficulty);
if(out.writeFlag(mRequiresKeyExchange || (wantsKeyExchange && !mPrivateKey.isNull())))
{
if(out.writeFlag(wantsCertificate && !mCertificate.isNull()))
out.write(mCertificate);
else
out.write(mPrivateKey->getPublicKey());
}
TNLLogMessageV(LogNetInterface, ("Sending Challenge Response: %8x", identityToken));
out.sendto(mSocket, addr);
}
示例10: main
int main(int argc, char** argv)
{
Logger::instance().add(new ConsoleChannel("debug", Level::Trace)); // Debug
{
// Create a PacketStream to pass packets
// from device captures to the encoder
PacketStream stream;
av::EncoderOptions options;
options.ofile = OUTPUT_FILENAME;
options.oformat = OUTPUT_FORMAT;
options.iformat.audio.enabled = false; // enabled if available
options.iformat.video.enabled = false; // enabled if available
// Create a device manager instance to enumerate system devices
av::Device device;
av::DeviceManager devman;
// Create and attach the default video capture
av::VideoCapture video;
if (devman.getDefaultCamera(device)) {
LInfo("Using video device: ", device.name)
video.openVideo(device.id, { 640, 480 });
video.getEncoderFormat(options.iformat);
stream.attachSource(&video, false, true);
}
// Create and attach the default audio capture
av::AudioCapture audio;
if (devman.getDefaultMicrophone(device)) {
LInfo("Using audio device: ", device.name)
audio.openAudio(device.id, { 2, 44100 });
audio.getEncoderFormat(options.iformat);
stream.attachSource(&audio, false, true);
}
// Create and attach the multiplex encoder
av::MultiplexPacketEncoder encoder(options);
encoder.init();
stream.attach(&encoder, 5, false);
// Start the stream
stream.start();
// Keep recording until Ctrl-C is pressed
LInfo("Recording video: ", OUTPUT_FILENAME)
waitForShutdown([](void* opaque) {
reinterpret_cast<PacketStream*>(opaque)->stop();
}, &stream);
}
// Logger::destroy();
return 0;
}
示例11: checkIncomingPackets
void NetInterface::checkIncomingPackets()
{
PacketStream stream;
NetError error;
Address sourceAddress;
mCurrentTime = Platform::getRealMilliseconds();
// read out all the available packets:
while((error = stream.recvfrom(mSocket, &sourceAddress)) == NoError)
processPacket(sourceAddress, &stream);
}
示例12: sendConnectReject
void NetInterface::sendConnectReject(ConnectionParameters *conn, const Address &theAddress, const char *reason)
{
if(!reason)
return; // if the stream is NULL, we reject silently
PacketStream out;
out.write(U8(ConnectReject));
conn->mNonce.write(&out);
conn->mServerNonce.write(&out);
out.writeString(reason);
out.sendto(mSocket, theAddress);
}
示例13: assert
bool StreamManager::closeStream(const std::string& name, bool whiny)
{
assert(!name.empty());
DebugL << "Close stream: " << name << endl;
PacketStream* stream = get(name, whiny);
if (stream) {
stream->close();
return true;
}
return false;
}
示例14: sendConnectReject
void NetInterface::sendConnectReject(ConnectionParameters *conn, const Address &theAddress, NetConnection::TerminationReason reason)
{
//if(!reason)
// return; // if the stream is NULL, we reject silently
PacketStream out;
out.write(U8(ConnectReject));
conn->mNonce.write(&out);
conn->mServerNonce.write(&out);
out.writeEnum(reason, NetConnection::TerminationReasons);
out.writeString("");
out.sendto(mSocket, theAddress);
}
示例15: SubmitQuestion
bool AskService::SubmitQuestion(IAnswer *answerCB, char16* nickname, char16* password, char16* questionText, int32 numberOfPhotos, int32 responseType, ArrayOfString *customResponses, int32 durationType, bool isPrivate)
{
if (!StartRequest(answerCB, AskService::EPS_SUBMITQUESTION))
{
return false;
}
PacketStream *str = pServer->GetStream();
bool isOk = true;
isOk = isOk && str->WriteInt32(16);//request id
isOk = isOk && str->WriteWString(nickname);
isOk = isOk && str->WriteWString(password);
isOk = isOk && str->WriteWString(questionText);
isOk = isOk && str->WriteInt32(numberOfPhotos);
isOk = isOk && str->WriteInt32(responseType);
isOk = isOk && customResponses->WriteToStream(str);
isOk = isOk && str->WriteInt32(durationType);
isOk = isOk && str->WriteInt8((int8)isPrivate);
return isOk && EndRequest();
}