Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: webrtc/modules/audio_coding/neteq/packet_buffer.h

Issue 2425223002: NetEq now works with packets as values, rather than pointers. (Closed)
Patch Set: Compare packets better in test. One more const. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // Flushes the buffer and deletes all packets in it. 44 // Flushes the buffer and deletes all packets in it.
45 virtual void Flush(); 45 virtual void Flush();
46 46
47 // Returns true for an empty buffer. 47 // Returns true for an empty buffer.
48 virtual bool Empty() const; 48 virtual bool Empty() const;
49 49
50 // Inserts |packet| into the buffer. The buffer will take over ownership of 50 // Inserts |packet| into the buffer. The buffer will take over ownership of
51 // the packet object. 51 // the packet object.
52 // Returns PacketBuffer::kOK on success, PacketBuffer::kFlushed if the buffer 52 // Returns PacketBuffer::kOK on success, PacketBuffer::kFlushed if the buffer
53 // was flushed due to overfilling. 53 // was flushed due to overfilling.
54 virtual int InsertPacket(Packet* packet); 54 virtual int InsertPacket(Packet&& packet);
55 55
56 // Inserts a list of packets into the buffer. The buffer will take over 56 // Inserts a list of packets into the buffer. The buffer will take over
57 // ownership of the packet objects. 57 // ownership of the packet objects.
58 // Returns PacketBuffer::kOK if all packets were inserted successfully. 58 // Returns PacketBuffer::kOK if all packets were inserted successfully.
59 // If the buffer was flushed due to overfilling, only a subset of the list is 59 // If the buffer was flushed due to overfilling, only a subset of the list is
60 // inserted, and PacketBuffer::kFlushed is returned. 60 // inserted, and PacketBuffer::kFlushed is returned.
61 // The last three parameters are included for legacy compatibility. 61 // The last three parameters are included for legacy compatibility.
62 // TODO(hlundin): Redesign to not use current_*_payload_type and 62 // TODO(hlundin): Redesign to not use current_*_payload_type and
63 // decoder_database. 63 // decoder_database.
64 virtual int InsertPacketList( 64 virtual int InsertPacketList(
(...skipping 13 matching lines...) Expand all
78 // variable |next_timestamp|. 78 // variable |next_timestamp|.
79 // Returns PacketBuffer::kBufferEmpty if the buffer is empty, 79 // Returns PacketBuffer::kBufferEmpty if the buffer is empty,
80 // PacketBuffer::kOK otherwise. 80 // PacketBuffer::kOK otherwise.
81 virtual int NextHigherTimestamp(uint32_t timestamp, 81 virtual int NextHigherTimestamp(uint32_t timestamp,
82 uint32_t* next_timestamp) const; 82 uint32_t* next_timestamp) const;
83 83
84 // Returns a (constant) pointer to the first packet in the buffer. Returns 84 // Returns a (constant) pointer to the first packet in the buffer. Returns
85 // NULL if the buffer is empty. 85 // NULL if the buffer is empty.
86 virtual const Packet* PeekNextPacket() const; 86 virtual const Packet* PeekNextPacket() const;
87 87
88 // Extracts the first packet in the buffer and returns a pointer to it. 88 // Extracts the first packet in the buffer and returns it.
89 // Returns NULL if the buffer is empty. The caller is responsible for deleting 89 // Returns an empty optional if the buffer is empty.
90 // the packet. 90 virtual rtc::Optional<Packet> GetNextPacket();
91 // Subsequent packets with the same timestamp as the one extracted will be
92 // discarded and properly deleted. The number of discarded packets will be
93 // written to the output variable |discard_count|.
94 virtual Packet* GetNextPacket(size_t* discard_count);
95 91
96 // Discards the first packet in the buffer. The packet is deleted. 92 // Discards the first packet in the buffer. The packet is deleted.
97 // Returns PacketBuffer::kBufferEmpty if the buffer is empty, 93 // Returns PacketBuffer::kBufferEmpty if the buffer is empty,
98 // PacketBuffer::kOK otherwise. 94 // PacketBuffer::kOK otherwise.
99 virtual int DiscardNextPacket(); 95 virtual int DiscardNextPacket();
100 96
101 // Discards all packets that are (strictly) older than timestamp_limit, 97 // Discards all packets that are (strictly) older than timestamp_limit,
102 // but newer than timestamp_limit - horizon_samples. Setting horizon_samples 98 // but newer than timestamp_limit - horizon_samples. Setting horizon_samples
103 // to zero implies that the horizon is set to half the timestamp range. That 99 // to zero implies that the horizon is set to half the timestamp range. That
104 // is, if a packet is more than 2^31 timestamps into the future compared with 100 // is, if a packet is more than 2^31 timestamps into the future compared with
(...skipping 11 matching lines...) Expand all
116 // Returns the number of packets in the buffer, including duplicates and 112 // Returns the number of packets in the buffer, including duplicates and
117 // redundant packets. 113 // redundant packets.
118 virtual size_t NumPacketsInBuffer() const; 114 virtual size_t NumPacketsInBuffer() const;
119 115
120 // Returns the number of samples in the buffer, including samples carried in 116 // Returns the number of samples in the buffer, including samples carried in
121 // duplicate and redundant packets. 117 // duplicate and redundant packets.
122 virtual size_t NumSamplesInBuffer(size_t last_decoded_length) const; 118 virtual size_t NumSamplesInBuffer(size_t last_decoded_length) const;
123 119
124 virtual void BufferStat(int* num_packets, int* max_num_packets) const; 120 virtual void BufferStat(int* num_packets, int* max_num_packets) const;
125 121
126 // Static method that properly deletes the first packet, and its payload
127 // array, in |packet_list|. Returns false if |packet_list| already was empty,
128 // otherwise true.
129 static bool DeleteFirstPacket(PacketList* packet_list);
130
131 // Static method that properly deletes all packets, and their payload arrays,
132 // in |packet_list|.
133 static void DeleteAllPackets(PacketList* packet_list);
134
135 // Static method returning true if |timestamp| is older than |timestamp_limit| 122 // Static method returning true if |timestamp| is older than |timestamp_limit|
136 // but less than |horizon_samples| behind |timestamp_limit|. For instance, 123 // but less than |horizon_samples| behind |timestamp_limit|. For instance,
137 // with timestamp_limit = 100 and horizon_samples = 10, a timestamp in the 124 // with timestamp_limit = 100 and horizon_samples = 10, a timestamp in the
138 // range (90, 100) is considered obsolete, and will yield true. 125 // range (90, 100) is considered obsolete, and will yield true.
139 // Setting |horizon_samples| to 0 is the same as setting it to 2^31, i.e., 126 // Setting |horizon_samples| to 0 is the same as setting it to 2^31, i.e.,
140 // half the 32-bit timestamp range. 127 // half the 32-bit timestamp range.
141 static bool IsObsoleteTimestamp(uint32_t timestamp, 128 static bool IsObsoleteTimestamp(uint32_t timestamp,
142 uint32_t timestamp_limit, 129 uint32_t timestamp_limit,
143 uint32_t horizon_samples) { 130 uint32_t horizon_samples) {
144 return IsNewerTimestamp(timestamp_limit, timestamp) && 131 return IsNewerTimestamp(timestamp_limit, timestamp) &&
145 (horizon_samples == 0 || 132 (horizon_samples == 0 ||
146 IsNewerTimestamp(timestamp, timestamp_limit - horizon_samples)); 133 IsNewerTimestamp(timestamp, timestamp_limit - horizon_samples));
147 } 134 }
148 135
149 private: 136 private:
150 size_t max_number_of_packets_; 137 size_t max_number_of_packets_;
151 PacketList buffer_; 138 PacketList buffer_;
152 const TickTimer* tick_timer_; 139 const TickTimer* tick_timer_;
153 RTC_DISALLOW_COPY_AND_ASSIGN(PacketBuffer); 140 RTC_DISALLOW_COPY_AND_ASSIGN(PacketBuffer);
154 }; 141 };
155 142
156 } // namespace webrtc 143 } // namespace webrtc
157 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_ 144 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/packet.cc ('k') | webrtc/modules/audio_coding/neteq/packet_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698