diff options
author | dknn <yoann.blein@free.fr> | 2012-07-08 20:27:27 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:00:01 (GMT) |
commit | 1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4 (patch) | |
tree | 94c9884d7746786568d0da2d6e122dd0f0b5ca9c /Swiften/ScreenSharing/OutgoingScreenSharing.cpp | |
parent | 4e0236b08d3914d24af32f45bc99663a73c6d83a (diff) | |
download | swift-contrib-1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4.zip swift-contrib-1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4.tar.bz2 |
Screen sharing managing
Diffstat (limited to 'Swiften/ScreenSharing/OutgoingScreenSharing.cpp')
-rw-r--r-- | Swiften/ScreenSharing/OutgoingScreenSharing.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Swiften/ScreenSharing/OutgoingScreenSharing.cpp b/Swiften/ScreenSharing/OutgoingScreenSharing.cpp new file mode 100644 index 0000000..3aa460c --- /dev/null +++ b/Swiften/ScreenSharing/OutgoingScreenSharing.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/ScreenSharing/OutgoingScreenSharing.h> + +#include <Swiften/Elements/JinglePayload.h> +#include <Swiften/Elements/JingleRawUDPTransportPayload.h> +#include <Swiften/Elements/JingleRTPDescription.h> +#include <Swiften/Jingle/JingleSession.h> +#include <Swiften/Network/UDPSocket.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/Timer.h> + +#include <boost/bind.hpp> + +namespace Swift { + +OutgoingScreenSharing::OutgoingScreenSharing(boost::shared_ptr<JingleSession> session, UDPSocketFactory* udpSocketFactory, TimerFactory* timerFactory) + : ScreenSharing(session, udpSocketFactory), + contentID(JingleContentID(idGenerator.generateID(), JingleContentPayload::InitiatorCreator)), canceled(false), + sessionAccepted(false), socketConnected(false), timerFactory(timerFactory) +{ +} + +OutgoingScreenSharing::~OutgoingScreenSharing() +{ +} + +void OutgoingScreenSharing::cancel() +{ + canceled = true; + session->sendTerminate(JinglePayload::Reason::Cancel); + + onStateChange(ScreenSharing::Canceled); +} + +void OutgoingScreenSharing::start() +{ + //onStateChange(ScreenSharing::WaitingForStart); + SWIFT_LOG(debug) << "Screen sharing: start" << std::endl; + + JingleRTPDescription::ref desc = boost::make_shared<JingleRTPDescription>(JingleRTPDescription::Video); + desc->addPayloadType(RTPPayloadType(98, "VP8", 90000)); + + JingleRawUDPTransportPayload::ref transport = boost::make_shared<JingleRawUDPTransportPayload>(); + addBestCandidate(transport); + + session->sendInitiate(contentID, desc, transport); + onStateChange(ScreenSharing::WaitingForAccept); + + serverSocket->onConnected.connect(boost::bind(&OutgoingScreenSharing::handleSocketConnected, this)); + serverSocket->connectToFirstIncoming(); +} + +void OutgoingScreenSharing::handleSocketConnected() +{ + SWIFT_LOG(debug) << "Screen sharing: UDP socket connected" << std::endl; + + if (canceled) + return; + + socketConnected = true; + if (sessionAccepted) + startRTPSession(); +} + +void OutgoingScreenSharing::handleSessionAcceptReceived(const JingleContentID& /*id*/, boost::shared_ptr<JingleDescription> /*desc*/, boost::shared_ptr<JingleTransportPayload> /*transport*/) +{ + SWIFT_LOG(debug) << "Screen sharing: accepted" << std::endl; + + if (canceled) + return; + + sessionAccepted = true; + if (socketConnected) { + startRTPSession(); + } else { + connectionTimer = timerFactory->createTimer(1000); + connectionTimer->onTick.connect(boost::bind(&OutgoingScreenSharing::handleConnectionFailed, this)); + connectionTimer->start(); + onStateChange(ScreenSharing::Connecting); + } +} + +void OutgoingScreenSharing::handleConnectionFailed() +{ + SWIFT_LOG(debug) << "Screen sharing: unable to connect" << std::endl; + + session->sendTerminate(JinglePayload::Reason::ConnectivityError); + canceled = true; + + onStateChange(ScreenSharing::Failed); +} + +void OutgoingScreenSharing::startRTPSession() +{ + SWIFT_LOG(debug) << "Screen sharing: accepted and connect, start screen sharing" << std::endl; + + // Session accepted and socket connected, we can start the rtp session +} + +} |