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 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).
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).
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.
18 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
19 #define MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
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"
34 class DictionaryValue
;
44 // Following the initialization of either audio or video an initialization
45 // status will be sent via this callback.
46 typedef base::Callback
<void(CastTransportStatus status
)>
47 CastTransportStatusCallback
;
49 typedef base::Callback
<void(const std::vector
<PacketEvent
>&,
50 const std::vector
<FrameEvent
>&)>
51 BulkRawEventsCallback
;
53 // The application should only trigger this class from the transport thread.
54 class CastTransportSender
: public base::NonThreadSafe
{
56 static scoped_ptr
<CastTransportSender
> Create(
58 base::TickClock
* clock
,
59 const net::IPEndPoint
& remote_end_point
,
60 scoped_ptr
<base::DictionaryValue
> options
,
61 const CastTransportStatusCallback
& status_callback
,
62 const BulkRawEventsCallback
& raw_events_callback
,
63 base::TimeDelta raw_events_callback_interval
,
64 const scoped_refptr
<base::SingleThreadTaskRunner
>& transport_task_runner
);
66 virtual ~CastTransportSender() {}
68 // Audio/Video initialization.
69 // Encoded frames cannot be transmitted until the relevant initialize method
71 virtual void InitializeAudio(const CastTransportRtpConfig
& config
,
72 const RtcpCastMessageCallback
& cast_message_cb
,
73 const RtcpRttCallback
& rtt_cb
) = 0;
74 virtual void InitializeVideo(const CastTransportRtpConfig
& config
,
75 const RtcpCastMessageCallback
& cast_message_cb
,
76 const RtcpRttCallback
& rtt_cb
) = 0;
78 // Encrypt, packetize and transmit |frame|. |ssrc| must refer to a
79 // a channel already established with InitializeAudio / InitializeVideo.
80 virtual void InsertFrame(uint32 ssrc
, const EncodedFrame
& frame
) = 0;
82 // Sends a RTCP sender report to the receiver.
83 // |ssrc| is the SSRC for this report.
84 // |current_time| is the current time reported by a tick clock.
85 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
86 virtual void SendSenderReport(
88 base::TimeTicks current_time
,
89 uint32 current_time_as_rtp_timestamp
) = 0;
91 // Cancels sending packets for the frames in the set.
92 // |ssrc| is the SSRC for the stream.
93 // |frame_ids| contains the IDs of the frames that will be cancelled.
94 virtual void CancelSendingFrames(uint32 ssrc
,
95 const std::vector
<uint32
>& frame_ids
) = 0;
97 // Resends a frame or part of a frame to kickstart. This is used when the
98 // stream appears to be stalled.
99 virtual void ResendFrameForKickstart(uint32 ssrc
, uint32 frame_id
) = 0;
101 // Returns a callback for receiving packets for testing purposes.
102 virtual PacketReceiverCallback
PacketReceiverForTesting();
108 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_