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 // This file contains the interface to the cast RTP sender.
7 #ifndef MEDIA_CAST_NET_RTP_RTP_SENDER_H_
8 #define MEDIA_CAST_NET_RTP_RTP_SENDER_H_
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/tick_clock.h"
16 #include "base/time/time.h"
17 #include "media/cast/cast_config.h"
18 #include "media/cast/cast_environment.h"
19 #include "media/cast/net/cast_transport_defines.h"
20 #include "media/cast/net/cast_transport_sender.h"
21 #include "media/cast/net/pacing/paced_sender.h"
22 #include "media/cast/net/rtp/packet_storage.h"
23 #include "media/cast/net/rtp/rtp_packetizer.h"
28 // This object is only called from the main cast thread.
29 // This class handles splitting encoded audio and video frames into packets and
30 // add an RTP header to each packet. The sent packets are stored until they are
31 // acknowledged by the remote peer or timed out.
35 base::TickClock* clock,
36 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner,
37 PacedSender* const transport);
41 // This must be called before sending any frames. Returns false if
42 // configuration is invalid.
43 bool Initialize(const CastTransportRtpConfig& config);
45 void SendFrame(const EncodedFrame& frame);
47 void ResendPackets(const MissingFramesAndPacketsMap& missing_packets,
48 bool cancel_rtx_if_not_in_list,
49 const DedupInfo& dedup_info);
51 // Returns the total number of bytes sent to the socket when the specified
52 // frame was just sent.
53 // Returns 0 if the frame cannot be found or the frame was only sent
55 int64 GetLastByteSentForFrame(uint32 frame_id);
57 void CancelSendingFrames(const std::vector<uint32>& frame_ids);
59 void ResendFrameForKickstart(uint32 frame_id, base::TimeDelta dedupe_window);
61 size_t send_packet_count() const {
62 return packetizer_ ? packetizer_->send_packet_count() : 0;
64 size_t send_octet_count() const {
65 return packetizer_ ? packetizer_->send_octet_count() : 0;
67 uint32 ssrc() const { return config_.ssrc; }
70 void UpdateSequenceNumber(Packet* packet);
72 base::TickClock* clock_; // Not owned by this class.
73 RtpPacketizerConfig config_;
74 PacketStorage storage_;
75 scoped_ptr<RtpPacketizer> packetizer_;
76 PacedSender* const transport_;
77 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_;
79 // NOTE: Weak pointers must be invalidated before all other member variables.
80 base::WeakPtrFactory<RtpSender> weak_factory_;
82 DISALLOW_COPY_AND_ASSIGN(RtpSender);
88 #endif // MEDIA_CAST_NET_RTP_SENDER_RTP_SENDER_H_