- add sources.
[platform/framework/web/crosswalk.git] / src / media / cast / audio_sender / audio_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 #ifndef MEDIA_CAST_AUDIO_SENDER_H_
6 #define MEDIA_CAST_AUDIO_SENDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/tick_clock.h"
14 #include "base/time/time.h"
15 #include "media/cast/cast_config.h"
16 #include "media/cast/cast_environment.h"
17 #include "media/cast/rtcp/rtcp.h"
18 #include "media/cast/rtp_sender/rtp_sender.h"
19
20 namespace media {
21 namespace cast {
22
23 class AudioEncoder;
24 class LocalRtcpAudioSenderFeedback;
25 class LocalRtpSenderStatistics;
26 class PacedPacketSender;
27
28 // This class is not thread safe.
29 // It's only called from the main cast thread.
30 class AudioSender : public base::NonThreadSafe,
31                     public base::SupportsWeakPtr<AudioSender> {
32  public:
33   AudioSender(scoped_refptr<CastEnvironment> cast_environment,
34               const AudioSenderConfig& audio_config,
35               PacedPacketSender* const paced_packet_sender);
36
37   virtual ~AudioSender();
38
39   // The audio_frame must be valid until the closure callback is called.
40   // The closure callback is called from the main cast thread as soon as
41   // the encoder is done with the frame; it does not mean that the encoded frame
42   // has been sent out.
43   void InsertRawAudioFrame(const PcmAudioFrame* audio_frame,
44                            const base::TimeTicks& recorded_time,
45                            const base::Closure callback);
46
47   // The audio_frame must be valid until the closure callback is called.
48   // The closure callback is called from the main cast thread as soon as
49   // the cast sender is done with the frame; it does not mean that the encoded
50   // frame has been sent out.
51   void InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame,
52                              const base::TimeTicks& recorded_time,
53                              const base::Closure callback);
54
55   // Only called from the main cast thread.
56   void IncomingRtcpPacket(const uint8* packet, size_t length,
57                           const base::Closure callback);
58
59  protected:
60   void SendEncodedAudioFrame(scoped_ptr<EncodedAudioFrame> audio_frame,
61                              const base::TimeTicks& recorded_time);
62
63  private:
64   friend class LocalRtcpAudioSenderFeedback;
65
66   void ResendPackets(
67       const MissingFramesAndPacketsMap& missing_frames_and_packets);
68
69   void ScheduleNextRtcpReport();
70   void SendRtcpReport();
71
72   base::WeakPtrFactory<AudioSender> weak_factory_;
73
74   const uint32 incoming_feedback_ssrc_;
75   scoped_refptr<CastEnvironment> cast_environment_;
76   scoped_refptr<AudioEncoder> audio_encoder_;
77   RtpSender rtp_sender_;
78   scoped_ptr<LocalRtpSenderStatistics> rtp_audio_sender_statistics_;
79   scoped_ptr<LocalRtcpAudioSenderFeedback> rtcp_feedback_;
80   Rtcp rtcp_;
81
82   DISALLOW_COPY_AND_ASSIGN(AudioSender);
83 };
84
85 }  // namespace cast
86 }  // namespace media
87
88 #endif  // MEDIA_CAST_AUDIO_SENDER_H_
89