Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / media / cast / framer / frame_buffer.cc
blob2bfdeb5166907de08f323be1ee345dad937efcee
1 // Copyright 2013 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/framer/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 last_referenced_frame_id_ = rtp_header.reference_frame_id;
32 rtp_timestamp_ = rtp_header.rtp_timestamp;
34 // Is this the correct frame?
35 if (rtp_header.frame_id != frame_id_)
36 return;
38 // Insert every packet only once.
39 if (packets_.find(rtp_header.packet_id) != packets_.end()) {
40 return;
43 std::vector<uint8> data;
44 std::pair<PacketMap::iterator, bool> retval =
45 packets_.insert(make_pair(rtp_header.packet_id, data));
47 // Insert the packet.
48 retval.first->second.resize(payload_size);
49 std::copy(
50 payload_data, payload_data + payload_size, retval.first->second.begin());
52 ++num_packets_received_;
53 total_data_size_ += payload_size;
56 bool FrameBuffer::Complete() const {
57 return num_packets_received_ - 1 == max_packet_id_;
60 bool FrameBuffer::GetEncodedAudioFrame(
61 transport::EncodedAudioFrame* audio_frame) const {
62 if (!Complete())
63 return false;
65 // Frame is complete -> construct.
66 audio_frame->frame_id = frame_id_;
67 audio_frame->rtp_timestamp = rtp_timestamp_;
69 // Build the data vector.
70 audio_frame->data.clear();
71 audio_frame->data.reserve(total_data_size_);
72 PacketMap::const_iterator it;
73 for (it = packets_.begin(); it != packets_.end(); ++it) {
74 audio_frame->data.insert(
75 audio_frame->data.end(), it->second.begin(), it->second.end());
77 return true;
80 bool FrameBuffer::GetEncodedVideoFrame(
81 transport::EncodedVideoFrame* video_frame) const {
82 if (!Complete())
83 return false;
84 // Frame is complete -> construct.
85 video_frame->key_frame = is_key_frame_;
86 video_frame->frame_id = frame_id_;
87 video_frame->last_referenced_frame_id = last_referenced_frame_id_;
88 video_frame->rtp_timestamp = rtp_timestamp_;
90 // Build the data vector.
91 video_frame->data.clear();
92 video_frame->data.reserve(total_data_size_);
93 PacketMap::const_iterator it;
94 for (it = packets_.begin(); it != packets_.end(); ++it) {
95 video_frame->data.insert(
96 video_frame->data.end(), it->second.begin(), it->second.end());
98 return true;
101 } // namespace cast
102 } // namespace media