/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include #include #include #include #include #include namespace Swift { IncomingScreenSharing::IncomingScreenSharing(boost::shared_ptr session, UDPSocketFactory* udpSocketFactory, boost::shared_ptr content) : ScreenSharing(session, udpSocketFactory), initialContent(content), parser(0), decoder(0) { onStateChange(ScreenSharing::WaitingForAccept); } IncomingScreenSharing::~IncomingScreenSharing() { delete rtpSession; delete parser; delete decoder; } void IncomingScreenSharing::cancel() { jingleSession->sendTerminate(JinglePayload::Reason::Cancel); if (rtpSession) rtpSession->stop(); onStateChange(ScreenSharing::Canceled); } void IncomingScreenSharing::accept() { JingleRawUDPTransportPayload::ref transport = boost::make_shared(); addBestCandidate(transport); JingleRTPDescription::ref desc = initialContent->getDescription(); if (!desc->getPayloadTypes().empty()) payloadTypeUsed = desc->getPayloadTypes().front(); // TODO: create a valid description instead of copying the initator's one jingleSession->sendAccept(getContentID(), desc, transport); JingleRawUDPTransportPayload::ref initialTransport = initialContent->getTransport(); clientSocket = udpSocketFactory->createUDPSocket(); clientSocket->connect(initialTransport->getCandidates().front().hostAddressPort); // Send a empty packet to let the server know about us SafeByteArray data(1, 0); clientSocket->send(data); rtpSession = new RTPSessionImpl(clientSocket, payloadTypeUsed); if (payloadTypeUsed.getID() == 98 && payloadTypeUsed.getName() == "VP8") { decoder = new VP8Decoder; parser = new VP8RTPParser(decoder); rtpSession->onIncomingPacket.connect(boost::bind(&VP8RTPParser::newPayloadReceived, parser, _1, _2, _3)); decoder->onNewImageDecoded.connect(boost::bind(&IncomingScreenSharing::hangleNewImageDecoded, this, _1)); } onStateChange(ScreenSharing::Connecting); } JingleContentID IncomingScreenSharing::getContentID() const { return JingleContentID(initialContent->getName(), initialContent->getCreator()); } void IncomingScreenSharing::hangleNewImageDecoded(const Image& image) { onNewImageReceived(image); } }