diff options
author | dknn <yoann.blein@free.fr> | 2012-06-26 14:05:35 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 08:53:12 (GMT) |
commit | 39ac2af90938aec4f4e43b81a6e043e0ebcdd798 (patch) | |
tree | add99f9eb287778191ebde47917adbaa96a39b8a /Swiften/ScreenSharing/VP8RTPPacketizer.cpp | |
parent | f374887e7a27831771304a09a74d6cd54f8ef4e4 (diff) | |
download | swift-contrib-39ac2af90938aec4f4e43b81a6e043e0ebcdd798.zip swift-contrib-39ac2af90938aec4f4e43b81a6e043e0ebcdd798.tar.bz2 |
Single threaded codec
Diffstat (limited to 'Swiften/ScreenSharing/VP8RTPPacketizer.cpp')
-rw-r--r-- | Swiften/ScreenSharing/VP8RTPPacketizer.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Swiften/ScreenSharing/VP8RTPPacketizer.cpp b/Swiften/ScreenSharing/VP8RTPPacketizer.cpp new file mode 100644 index 0000000..4c1e8e9 --- /dev/null +++ b/Swiften/ScreenSharing/VP8RTPPacketizer.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/ScreenSharing/VP8RTPPacketizer.h> + + +namespace Swift { + +VP8RTPPacketizer::VP8RTPPacketizer() +{ +} + +void VP8RTPPacketizer::packetizeFrame(const vpx_codec_cx_pkt_t* pkt) +{ + if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) + return; + + // only case there is no partitions is handle (TODO: implement partitions) + if (pkt->data.frame.partition_id != -1) + return; + + size_t size = pkt->data.frame.sz; + uint8_t* buf = static_cast<uint8_t*>(pkt->data.frame.buf); + size_t sent = 0; + bool firstPacket = true; + + while (sent < size) { + payloadBuffer.clear(); + + // Payload descriptor + uint8_t req = 0; + if (firstPacket) + req |= SBit; + payloadBuffer.push_back(req); + + // Payload header + if (firstPacket) { + firstPacket = false; + + uint8_t o1 = (size & Size0BitMask) << Size0BitShift; // Size0 + o1 |= HBit; // H (show frame) + if (!(pkt->data.frame.flags & VPX_FRAME_IS_KEY)) + o1 |= 1; // P (Inverse key frame) + payloadBuffer.push_back(o1); + payloadBuffer.push_back(static_cast<uint8_t>(size >> 3)); // Size1 + payloadBuffer.push_back(static_cast<uint8_t>(size >> 11)); // Size2 + } + + // Payload content + size_t toSend = std::min(size - sent, MaxRTPPayloadSize - payloadBuffer.size()); + payloadBuffer.insert(payloadBuffer.end(), buf, buf + toSend); + + sent += toSend; + buf += toSend; + + // Mark rtp packet if last of the curr frame + bool lastPacket = (sent >= size); + + // TODO: send packet + //parser.newPayloadReceived(&payloadBuffer[0], payloadBuffer.size(), lastPacket); + onNewPayloadReady(payloadBuffer, lastPacket); + } +} + +} |