Report errors from ChromiumEnv::GetChildren in Posix.
[chromium-blink-merge.git] / media / cast / pacing / paced_sender.h
blobeb466a1c2c3ea49096cc7beea908884d8982c0c7
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 #ifndef MEDIA_CAST_PACING_PACED_SENDER_H_
6 #define MEDIA_CAST_PACING_PACED_SENDER_H_
8 #include <list>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/time/default_tick_clock.h"
16 #include "base/time/tick_clock.h"
17 #include "base/time/time.h"
18 #include "media/cast/cast_config.h"
19 #include "media/cast/cast_environment.h"
21 namespace media {
22 namespace cast {
24 // We have this pure virtual class to enable mocking.
25 class PacedPacketSender {
26 public:
27 // Inform the pacer / sender of the total number of packets.
28 virtual bool SendPackets(const PacketList& packets) = 0;
30 virtual bool ResendPackets(const PacketList& packets) = 0;
32 virtual bool SendRtcpPacket(const Packet& packet) = 0;
34 virtual ~PacedPacketSender() {}
37 class PacedSender : public PacedPacketSender,
38 public base::NonThreadSafe,
39 public base::SupportsWeakPtr<PacedSender> {
40 public:
41 PacedSender(scoped_refptr<CastEnvironment> cast_environment,
42 PacketSender* transport);
43 virtual ~PacedSender();
45 virtual bool SendPackets(const PacketList& packets) OVERRIDE;
47 virtual bool ResendPackets(const PacketList& packets) OVERRIDE;
49 virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE;
51 protected:
52 // Schedule a delayed task on the main cast thread when it's time to send the
53 // next packet burst.
54 void ScheduleNextSend();
56 // Process any pending packets in the queue(s).
57 void SendNextPacketBurst();
59 private:
60 bool SendPacketsToTransport(const PacketList& packets,
61 PacketList* packets_not_sent);
62 void SendStoredPackets();
63 void UpdateBurstSize(size_t num_of_packets);
65 scoped_refptr<CastEnvironment> cast_environment_;
66 size_t burst_size_;
67 size_t packets_sent_in_burst_;
68 base::TimeTicks time_last_process_;
69 // Note: We can't combine the |packet_list_| and the |resend_packet_list_|
70 // since then we might get reordering of the retransmitted packets.
71 PacketList packet_list_;
72 PacketList resend_packet_list_;
73 PacketSender* transport_;
75 base::WeakPtrFactory<PacedSender> weak_factory_;
77 DISALLOW_COPY_AND_ASSIGN(PacedSender);
80 } // namespace cast
81 } // namespace media
83 #endif // MEDIA_CAST_PACING_PACED_SENDER_H_