Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / cast / net / rtp / rtp_sender.h
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.
4
5 // This file contains the interface to the cast RTP sender.
6
7 #ifndef MEDIA_CAST_NET_RTP_RTP_SENDER_H_
8 #define MEDIA_CAST_NET_RTP_RTP_SENDER_H_
9
10 #include <map>
11 #include <set>
12
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"
24
25 namespace media {
26 namespace cast {
27
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.
32 class RtpSender {
33  public:
34   RtpSender(
35       base::TickClock* clock,
36       const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner,
37       PacedSender* const transport);
38
39   ~RtpSender();
40
41   // This must be called before sending any frames. Returns false if
42   // configuration is invalid.
43   bool Initialize(const CastTransportRtpConfig& config);
44
45   void SendFrame(const EncodedFrame& frame);
46
47   void ResendPackets(const MissingFramesAndPacketsMap& missing_packets,
48                      bool cancel_rtx_if_not_in_list,
49                      const DedupInfo& dedup_info);
50
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
54   // partially.
55   int64 GetLastByteSentForFrame(uint32 frame_id);
56
57   void CancelSendingFrames(const std::vector<uint32>& frame_ids);
58
59   void ResendFrameForKickstart(uint32 frame_id, base::TimeDelta dedupe_window);
60
61   size_t send_packet_count() const {
62     return packetizer_ ? packetizer_->send_packet_count() : 0;
63   }
64   size_t send_octet_count() const {
65     return packetizer_ ? packetizer_->send_octet_count() : 0;
66   }
67   uint32 ssrc() const { return config_.ssrc; }
68
69  private:
70   void UpdateSequenceNumber(Packet* packet);
71
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_;
78
79   // NOTE: Weak pointers must be invalidated before all other member variables.
80   base::WeakPtrFactory<RtpSender> weak_factory_;
81
82   DISALLOW_COPY_AND_ASSIGN(RtpSender);
83 };
84
85 }  // namespace cast
86 }  // namespace media
87
88 #endif  // MEDIA_CAST_NET_RTP_SENDER_RTP_SENDER_H_