summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/rtp_video_writer.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 01:53:07 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 01:53:07 +0000
commit6357e609331c79bda865ac4ec9301a3f0f59d9c7 (patch)
tree9008d83ee315f5ed9422e6b3cbe10e715707f5a7 /remoting/protocol/rtp_video_writer.cc
parentb1081e5dde10ee027a3fc9dfa3781380fb9b49c1 (diff)
downloadchromium_src-6357e609331c79bda865ac4ec9301a3f0f59d9c7.zip
chromium_src-6357e609331c79bda865ac4ec9301a3f0f59d9c7.tar.gz
chromium_src-6357e609331c79bda865ac4ec9301a3f0f59d9c7.tar.bz2
Packetizer/Depacketizer for RTP.
BUG=None TEST=None Review URL: http://codereview.chromium.org/4925001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/rtp_video_writer.cc')
-rw-r--r--remoting/protocol/rtp_video_writer.cc56
1 files changed, 54 insertions, 2 deletions
diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc
index 1aefbe8..146752c 100644
--- a/remoting/protocol/rtp_video_writer.cc
+++ b/remoting/protocol/rtp_video_writer.cc
@@ -13,6 +13,10 @@
namespace remoting {
namespace protocol {
+namespace {
+const int kMtu = 1200;
+} // namespace
+
RtpVideoWriter::RtpVideoWriter() { }
RtpVideoWriter::~RtpVideoWriter() { }
@@ -22,17 +26,65 @@ void RtpVideoWriter::Init(protocol::Session* session) {
}
void RtpVideoWriter::SendPacket(const VideoPacket& packet) {
+ CHECK(packet.format().encoding() == VideoPacketFormat::ENCODING_VP8)
+ << "Only VP8 is supported in RTP.";
+
CompoundBuffer payload;
+ // TODO(sergeyu): This copy would not be necessary CompoundBuffer was used
+ // inside of VideoPacket.
payload.AppendCopyOf(packet.data().data(), packet.data().size());
- rtp_writer_.SendPacket(payload, packet.timestamp());
+ Vp8Descriptor vp8_desriptor;
+ // TODO(sergeyu): Add a flag in VideoPacket that indicates whether this is a
+ // key frame or not.
+ vp8_desriptor.non_reference_frame = false;
+ vp8_desriptor.picture_id = kuint32max;
+
+ int position = 0;
+ while (position < payload.total_bytes()) {
+ int size = std::min(kMtu, payload.total_bytes() - position);
+
+ // Frame beginning flag is set only for the first packet in the first
+ // partition.
+ vp8_desriptor.frame_beginning =
+ (packet.flags() & VideoPacket::FIRST_PACKET) != 0 && position == 0;
+
+ // Marker bit is set only for the last packet in the last partition.
+ bool marker = (position + size) == payload.total_bytes() &&
+ (packet.flags() & VideoPacket::LAST_PACKET) != 0;
+
+ // Set fragmentation flag appropriately.
+ if (position == 0) {
+ if (size == payload.total_bytes()) {
+ vp8_desriptor.fragmentation_info = Vp8Descriptor::NOT_FRAGMENTED;
+ } else {
+ vp8_desriptor.fragmentation_info = Vp8Descriptor::FIRST_FRAGMENT;
+ }
+ } else {
+ if (position + size == payload.total_bytes()) {
+ vp8_desriptor.fragmentation_info = Vp8Descriptor::LAST_FRAGMENT;
+ } else {
+ vp8_desriptor.fragmentation_info = Vp8Descriptor::MIDDLE_FRAGMENT;
+ }
+ }
+
+ // Create CompoundBuffer for the chunk.
+ CompoundBuffer chunk;
+ chunk.CopyFrom(payload, position, position + size);
+
+ // And send it.
+ rtp_writer_.SendPacket(packet.timestamp(), marker, vp8_desriptor, chunk);
+
+ position += size;
+ }
+
+ DCHECK_EQ(position, payload.total_bytes());
}
int RtpVideoWriter::GetPendingPackets() {
return rtp_writer_.GetPendingPackets();
}
-
void RtpVideoWriter::Close() {
rtp_writer_.Close();
}