diff options
author | dknn <yoann.blein@free.fr> | 2012-07-14 08:00:24 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:01:48 (GMT) |
commit | 51958a50e31b483aa932aac8d696b229ba66b5cb (patch) | |
tree | 559c19451c2d53a1ee72113154aa187060680f3c /Swiften/ScreenSharing/OutgoingScreenSharing.cpp | |
parent | ce9a3d75677f08af0a226bb3d2bf02c28c938c33 (diff) | |
download | swift-contrib-51958a50e31b483aa932aac8d696b229ba66b5cb.zip swift-contrib-51958a50e31b483aa932aac8d696b229ba66b5cb.tar.bz2 |
Fixes to make classes working together
Diffstat (limited to 'Swiften/ScreenSharing/OutgoingScreenSharing.cpp')
-rw-r--r-- | Swiften/ScreenSharing/OutgoingScreenSharing.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/Swiften/ScreenSharing/OutgoingScreenSharing.cpp b/Swiften/ScreenSharing/OutgoingScreenSharing.cpp index da7eb3e..77226c5 100644 --- a/Swiften/ScreenSharing/OutgoingScreenSharing.cpp +++ b/Swiften/ScreenSharing/OutgoingScreenSharing.cpp @@ -6,6 +6,7 @@ #include <Swiften/ScreenSharing/OutgoingScreenSharing.h> +#include <Swiften/Base/Algorithm.h> #include <Swiften/Elements/JinglePayload.h> #include <Swiften/Elements/JingleRawUDPTransportPayload.h> #include <Swiften/Elements/JingleRTPDescription.h> @@ -14,6 +15,9 @@ #include <Swiften/Network/TimerFactory.h> #include <Swiften/Network/Timer.h> #include <Swiften/ScreenSharing/RTPSessionImpl.h> +#include <Swiften/ScreenSharing/VP8Encoder.h> +#include <Swiften/ScreenSharing/VP8RTPPacketizer.h> +#include <Swiften/ScreenSharing/Image.h> #include <boost/bind.hpp> @@ -21,29 +25,35 @@ 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), rtpSession(0), timerFactory(timerFactory) + timerFactory(timerFactory), contentID(JingleContentID(idGenerator.generateID(), JingleContentPayload::InitiatorCreator)), + canceled(false), sessionAccepted(false), socketConnected(false), encoder(0), packetizer(0) { session->onSessionAcceptReceived.connect(boost::bind(&OutgoingScreenSharing::handleSessionAcceptReceived, this, _1, _2, _3)); } OutgoingScreenSharing::~OutgoingScreenSharing() { + delete rtpSession; + delete encoder; + delete packetizer; } void OutgoingScreenSharing::cancel() { canceled = true; - session->sendTerminate(JinglePayload::Reason::Cancel); + jingleSession->sendTerminate(JinglePayload::Reason::Cancel); onStateChange(ScreenSharing::Canceled); } -void OutgoingScreenSharing::start() +void OutgoingScreenSharing::start(unsigned int width, unsigned int height) { //onStateChange(ScreenSharing::WaitingForStart); SWIFT_LOG(debug) << "Screen sharing: start" << std::endl; + this->width = width; + this->height = height; + JingleRTPDescription::ref desc = boost::make_shared<JingleRTPDescription>(JingleRTPDescription::Video); payloadTypeUsed = RTPPayloadType(98, "VP8", 90000); desc->addPayloadType(payloadTypeUsed); @@ -51,13 +61,18 @@ void OutgoingScreenSharing::start() JingleRawUDPTransportPayload::ref transport = boost::make_shared<JingleRawUDPTransportPayload>(); addBestCandidate(transport); - session->sendInitiate(contentID, desc, transport); + jingleSession->sendInitiate(contentID, desc, transport); onStateChange(ScreenSharing::WaitingForAccept); serverSocket->onConnected.connect(boost::bind(&OutgoingScreenSharing::handleSocketConnected, this)); serverSocket->connectToFirstIncoming(); } +void OutgoingScreenSharing::addImage(const Image &image) +{ + encoder->encodeImage(image); +} + void OutgoingScreenSharing::handleSocketConnected() { if (canceled) @@ -92,7 +107,7 @@ void OutgoingScreenSharing::handleConnectionFailed() { SWIFT_LOG(debug) << "Screen sharing: unable to connect" << std::endl; - session->sendTerminate(JinglePayload::Reason::ConnectivityError); + jingleSession->sendTerminate(JinglePayload::Reason::ConnectivityError); canceled = true; onStateChange(ScreenSharing::Failed); @@ -104,6 +119,19 @@ void OutgoingScreenSharing::startRTPSession() // Session accepted and socket connected, we can start the rtp session rtpSession = new RTPSessionImpl(serverSocket, payloadTypeUsed); + + if (payloadTypeUsed.getID() == 98 && payloadTypeUsed.getName() == "VP8") { + packetizer = new VP8RTPPacketizer; + encoder = new VP8Encoder(packetizer, width, height); + packetizer->onNewPayloadReady.connect(boost::bind(&OutgoingScreenSharing::handleNewPayloadReady, this, _1, _2)); + onReady(); + } +} + +void OutgoingScreenSharing::handleNewPayloadReady(const std::vector<uint8_t>& data, bool marker) +{ + SafeByteArray sba(data.begin(), data.end()); + rtpSession->sendPacket(sba, 500, marker); } } |