/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include namespace Swift { VP8RTPPacketizer::VP8RTPPacketizer() { } void VP8RTPPacketizer::packetizeFrame(const vpx_codec_cx_pkt_t* pkt, int pictureID) { 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(pkt->data.frame.buf); size_t sent = 0; bool firstPacket = true; while (sent < size) { payloadBuffer.clear(); // Payload descriptor uint8_t req = XBit; if (firstPacket) req |= SBit; uint8_t optX = IBit; uint8_t optI = (pictureID & 127); // pictureID payloadBuffer.push_back(req); payloadBuffer.push_back(optX); payloadBuffer.push_back(optI); // 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(size >> 3)); // Size1 payloadBuffer.push_back(static_cast(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); } } }