Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / cast / transport / rtp_sender / rtp_sender.h
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 // This file contains the interface to the cast RTP sender.
6
7 #ifndef MEDIA_CAST_TRANSPORT_RTP_SENDER_RTP_SENDER_H_
8 #define MEDIA_CAST_TRANSPORT_RTP_SENDER_RTP_SENDER_H_
9
10 #include <map>
11 #include <set>
12
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/tick_clock.h"
15 #include "base/time/time.h"
16 #include "base/memory/weak_ptr.h"
17 #include "media/cast/cast_config.h"
18 #include "media/cast/cast_environment.h"
19 #include "media/cast/transport/cast_transport_defines.h"
20 #include "media/cast/transport/cast_transport_sender.h"
21 #include "media/cast/transport/pacing/paced_sender.h"
22 #include "media/cast/transport/rtp_sender/packet_storage/packet_storage.h"
23 #include "media/cast/transport/rtp_sender/rtp_packetizer/rtp_packetizer.h"
24
25 namespace media {
26 namespace cast {
27 namespace transport {
28
29 // This object is only called from the main cast thread.
30 // This class handles splitting encoded audio and video frames into packets and
31 // add an RTP header to each packet. The sent packets are stored until they are
32 // acknowledged by the remote peer or timed out.
33 class RtpSender : public base::SupportsWeakPtr<RtpSender>{
34  public:
35   RtpSender(base::TickClock* clock,
36             const CastTransportConfig& config,
37             bool is_audio,
38             const scoped_refptr<base::TaskRunner>& transport_task_runner,
39             PacedSender* const transport);
40
41   ~RtpSender();
42
43   // The video_frame objects ownership is handled by the main cast thread.
44   void IncomingEncodedVideoFrame(const EncodedVideoFrame* video_frame,
45                                  const base::TimeTicks& capture_time);
46
47   // The audio_frame objects ownership is handled by the main cast thread.
48   void IncomingEncodedAudioFrame(const EncodedAudioFrame* audio_frame,
49                                  const base::TimeTicks& recorded_time);
50
51   void ResendPackets(const MissingFramesAndPacketsMap& missing_packets);
52
53   // Set the callback on which RTP statistics data will be returned. Calling
54   // this function would start a timer that would schedule the callback in
55   // a constant interval.
56   void SubscribeRtpStatsCallback(const CastTransportRtpStatistics& callback);
57
58  private:
59   void ScheduleNextStatsReport();
60   void RtpStatistics();
61   void UpdateSequenceNumber(Packet* packet);
62
63   RtpPacketizerConfig config_;
64   scoped_ptr<RtpPacketizer> packetizer_;
65   scoped_ptr<PacketStorage> storage_;
66   PacedSender* const transport_;
67   CastTransportRtpStatistics stats_callback_;
68   scoped_refptr<base::TaskRunner> transport_task_runner_;
69
70   DISALLOW_COPY_AND_ASSIGN(RtpSender);
71 };
72
73 }  // namespace transport
74 }  // namespace cast
75 }  // namespace media
76
77 #endif  // MEDIA_CAST_TRANSPORT_RTP_SENDER_RTP_SENDER_H_