Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / media / cast / net / cast_transport_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 is the main interface for the cast transport sender.  It accepts encoded
6 // frames (both audio and video), encrypts their encoded data, packetizes them
7 // and feeds them into a transport (e.g., UDP).
8
9 // Construction of the Cast Sender and the Cast Transport Sender should be done
10 // in the following order:
11 // 1. Create CastTransportSender.
12 // 2. Create CastSender (accepts CastTransportSender as an input).
13
14 // Destruction: The CastTransportSender is assumed to be valid as long as the
15 // CastSender is alive. Therefore the CastSender should be destructed before the
16 // CastTransportSender.
17
18 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
19 #define MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
20
21 #include "base/basictypes.h"
22 #include "base/callback.h"
23 #include "base/single_thread_task_runner.h"
24 #include "base/threading/non_thread_safe.h"
25 #include "base/time/tick_clock.h"
26 #include "media/cast/logging/logging_defines.h"
27 #include "media/cast/net/cast_transport_config.h"
28 #include "media/cast/net/cast_transport_defines.h"
29 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h"
30 #include "media/cast/net/rtcp/rtcp_defines.h"
31 #include "net/base/ip_endpoint.h"
32
33 namespace net {
34 class NetLog;
35 }  // namespace net
36
37 namespace media {
38 namespace cast {
39
40 // Following the initialization of either audio or video an initialization
41 // status will be sent via this callback.
42 typedef base::Callback<void(CastTransportStatus status)>
43     CastTransportStatusCallback;
44
45 typedef base::Callback<void(const std::vector<PacketEvent>&,
46                             const std::vector<FrameEvent>&)>
47     BulkRawEventsCallback;
48
49 // The application should only trigger this class from the transport thread.
50 class CastTransportSender : public base::NonThreadSafe {
51  public:
52   static scoped_ptr<CastTransportSender> Create(
53       net::NetLog* net_log,
54       base::TickClock* clock,
55       const net::IPEndPoint& remote_end_point,
56       const CastTransportStatusCallback& status_callback,
57       const BulkRawEventsCallback& raw_events_callback,
58       base::TimeDelta raw_events_callback_interval,
59       const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
60
61   virtual ~CastTransportSender() {}
62
63   // Audio/Video initialization.
64   // Encoded frames cannot be transmitted until the relevant initialize method
65   // is called.
66   virtual void InitializeAudio(const CastTransportRtpConfig& config,
67                                const RtcpCastMessageCallback& cast_message_cb,
68                                const RtcpRttCallback& rtt_cb) = 0;
69   virtual void InitializeVideo(const CastTransportRtpConfig& config,
70                                const RtcpCastMessageCallback& cast_message_cb,
71                                const RtcpRttCallback& rtt_cb) = 0;
72
73   // The following two functions handle the encoded media frames (audio and
74   // video) to be processed.
75   // Frames will be encrypted, packetized and transmitted to the network.
76   virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) = 0;
77   virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) = 0;
78
79   // Sends a RTCP sender report to the receiver.
80   // |ssrc| is the SSRC for this report.
81   // |current_time| is the current time reported by a tick clock.
82   // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
83   virtual void SendSenderReport(
84       uint32 ssrc,
85       base::TimeTicks current_time,
86       uint32 current_time_as_rtp_timestamp) = 0;
87
88   // Retransmission request.
89   // |missing_packets| includes the list of frames and packets in each
90   // frame to be re-transmitted.
91   // If |cancel_rtx_if_not_in_list| is used as an optimization to cancel
92   // pending re-transmission requests of packets not listed in
93   // |missing_packets|. If the requested packet(s) were sent recently
94   // (how long is specified by |dedupe_window|) then this re-transmit
95   // will be ignored.
96   virtual void ResendPackets(
97       bool is_audio,
98       const MissingFramesAndPacketsMap& missing_packets,
99       bool cancel_rtx_if_not_in_list,
100       base::TimeDelta dedupe_window) = 0;
101
102   // Returns a callback for receiving packets for testing purposes.
103   virtual PacketReceiverCallback PacketReceiverForTesting();
104 };
105
106 }  // namespace cast
107 }  // namespace media
108
109 #endif  // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_