OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "media/cast/framer/frame_buffer.h" | |
6 | |
7 namespace media { | |
8 namespace cast { | |
9 | |
10 FrameBuffer::FrameBuffer() | |
11 : frame_id_(0), | |
12 max_packet_id_(0), | |
13 num_packets_received_(0), | |
14 is_key_frame_(false), | |
15 total_data_size_(0), | |
16 last_referenced_frame_id_(0), | |
17 packets_() {} | |
18 | |
19 FrameBuffer::~FrameBuffer() { | |
20 std::map<uint16, std::vector<uint8> >::iterator it; | |
Alpha Left Google
2013/08/28 00:27:31
There's no need to do this, STL will cleanup.
pwestin
2013/08/28 16:40:44
Done.
| |
21 for (it = packets_.begin(); it != packets_.end(); ++it) { | |
22 it->second.clear(); | |
23 } | |
24 } | |
25 | |
26 void FrameBuffer::InsertPacket(const uint8* payload_data, | |
27 int payload_size, | |
28 const RtpCastHeader& rtp_header) { | |
29 // Is this the first packet in the frame? | |
30 if (packets_.empty()) { | |
31 frame_id_ = rtp_header.frame_id; | |
32 max_packet_id_ = rtp_header.max_packet_id; | |
33 is_key_frame_ = rtp_header.is_key_frame; | |
34 if (rtp_header.is_reference) { | |
35 last_referenced_frame_id_ = rtp_header.reference_frame_id; | |
36 } else { | |
37 last_referenced_frame_id_ = static_cast<uint8>(rtp_header.frame_id - 1); | |
38 } | |
39 | |
40 rtp_timestamp_ = rtp_header.webrtc.header.timestamp; | |
41 } | |
42 // Is this the correct frame? | |
43 if (rtp_header.frame_id != frame_id_) return; | |
44 | |
45 // Insert every packet only once. | |
46 if (packets_.find(rtp_header.packet_id) != packets_.end()) return; | |
47 | |
48 // Insert the packet. | |
49 std::vector<uint8> data; | |
50 data.resize(payload_size); | |
51 std::copy(&payload_data[0], &payload_data[payload_size], data.begin()); | |
Alpha Left Google
2013/08/28 00:27:31
It's cleaner to be: std::copy(payload_data, payloa
pwestin
2013/08/28 16:40:44
Done.
| |
52 packets_.insert(std::pair<uint16, std::vector<uint8> >( | |
Alpha Left Google
2013/08/28 00:27:31
std::make_pair() would be perfect for this. This a
pwestin
2013/08/28 16:40:44
Done.
| |
53 rtp_header.packet_id, data)); | |
54 | |
55 ++num_packets_received_; | |
56 total_data_size_ += payload_size; | |
57 } | |
58 | |
59 bool FrameBuffer::Complete() const { | |
60 return num_packets_received_ - 1 == max_packet_id_; | |
61 } | |
62 | |
63 bool FrameBuffer::GetEncodedAudioFrame(EncodedAudioFrame* audio_frame, | |
64 uint32* rtp_timestamp) const { | |
65 if (!Complete()) return false; | |
Alpha Left Google
2013/08/28 00:27:31
nit: One space before return.
pwestin
2013/08/28 16:40:44
Done.
| |
66 | |
67 *rtp_timestamp = rtp_timestamp_; | |
68 | |
69 // Frame is complete -> construct. | |
70 audio_frame->frame_id = frame_id_; | |
71 | |
72 // Build the data vector. | |
73 audio_frame->data.clear(); | |
74 audio_frame->data.reserve(total_data_size_); | |
75 std::map<uint16, std::vector<uint8> >::const_iterator it; | |
76 for (it = packets_.begin(); it != packets_.end(); ++it) { | |
77 audio_frame->data.insert(audio_frame->data.end(), | |
78 it->second.begin(), it->second.end()); | |
79 } | |
80 return true; | |
81 } | |
82 | |
83 bool FrameBuffer::GetEncodedVideoFrame(EncodedVideoFrame* video_frame, | |
84 uint32* rtp_timestamp) const { | |
85 if (!Complete()) return false; | |
Alpha Left Google
2013/08/28 00:27:31
nit: One space before return.
pwestin
2013/08/28 16:40:44
Done.
| |
86 | |
87 *rtp_timestamp = rtp_timestamp_; | |
88 | |
89 // Frame is complete -> construct. | |
90 video_frame->key_frame = is_key_frame_; | |
91 video_frame->frame_id = frame_id_; | |
92 video_frame->last_referenced_frame_id = last_referenced_frame_id_; | |
93 | |
94 // Build the data vector. | |
95 video_frame->data.clear(); | |
96 video_frame->data.reserve(total_data_size_); | |
97 std::map<uint16, std::vector<uint8> >::const_iterator it; | |
Alpha Left Google
2013/08/28 00:27:31
Use the typedef. That should be PacketMap.
pwestin
2013/08/28 16:40:44
Done.
| |
98 for (it = packets_.begin(); it != packets_.end(); ++it) { | |
99 video_frame->data.insert(video_frame->data.end(), | |
100 it->second.begin(), it->second.end()); | |
101 } | |
102 return true; | |
103 } | |
104 | |
105 } // namespace cast | |
106 } // namespace media | |
OLD | NEW |