Disable accessible touch exploration by default.
[chromium-blink-merge.git] / media / cast / net / rtp / frame_buffer.cc
bloba419ab6a4667585c9866866fc1a6698811e2484a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/net/rtp/frame_buffer.h"
7 #include "base/logging.h"
9 namespace media {
10 namespace cast {
12 FrameBuffer::FrameBuffer()
13 : frame_id_(0),
14 max_packet_id_(0),
15 num_packets_received_(0),
16 is_key_frame_(false),
17 total_data_size_(0),
18 last_referenced_frame_id_(0),
19 packets_() {}
21 FrameBuffer::~FrameBuffer() {}
23 void FrameBuffer::InsertPacket(const uint8* payload_data,
24 size_t payload_size,
25 const RtpCastHeader& rtp_header) {
26 // Is this the first packet in the frame?
27 if (packets_.empty()) {
28 frame_id_ = rtp_header.frame_id;
29 max_packet_id_ = rtp_header.max_packet_id;
30 is_key_frame_ = rtp_header.is_key_frame;
31 if (is_key_frame_)
32 DCHECK_EQ(rtp_header.frame_id, rtp_header.reference_frame_id);
33 last_referenced_frame_id_ = rtp_header.reference_frame_id;
34 rtp_timestamp_ = rtp_header.rtp_timestamp;
36 // Is this the correct frame?
37 if (rtp_header.frame_id != frame_id_)
38 return;
40 // Insert every packet only once.
41 if (packets_.find(rtp_header.packet_id) != packets_.end()) {
42 return;
45 std::vector<uint8> data;
46 std::pair<PacketMap::iterator, bool> retval =
47 packets_.insert(make_pair(rtp_header.packet_id, data));
49 // Insert the packet.
50 retval.first->second.resize(payload_size);
51 std::copy(
52 payload_data, payload_data + payload_size, retval.first->second.begin());
54 ++num_packets_received_;
55 total_data_size_ += payload_size;
58 bool FrameBuffer::Complete() const {
59 return num_packets_received_ - 1 == max_packet_id_;
62 bool FrameBuffer::AssembleEncodedFrame(EncodedFrame* frame) const {
63 if (!Complete())
64 return false;
66 // Frame is complete -> construct.
67 if (is_key_frame_)
68 frame->dependency = EncodedFrame::KEY;
69 else if (frame_id_ == last_referenced_frame_id_)
70 frame->dependency = EncodedFrame::INDEPENDENT;
71 else
72 frame->dependency = EncodedFrame::DEPENDENT;
73 frame->frame_id = frame_id_;
74 frame->referenced_frame_id = last_referenced_frame_id_;
75 frame->rtp_timestamp = rtp_timestamp_;
77 // Build the data vector.
78 frame->data.clear();
79 frame->data.reserve(total_data_size_);
80 PacketMap::const_iterator it;
81 for (it = packets_.begin(); it != packets_.end(); ++it)
82 frame->data.insert(frame->data.end(), it->second.begin(), it->second.end());
83 return true;
86 } // namespace cast
87 } // namespace media