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 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_
6 #define MEDIA_CAST_SENDER_AUDIO_SENDER_H_
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/base/audio_bus.h"
16 #include "media/cast/cast_config.h"
17 #include "media/cast/sender/frame_sender.h"
24 // Not thread safe. Only called from the main cast thread.
25 // This class owns all objects related to sending audio, objects that create RTP
26 // packets, congestion control, audio encoder, parsing and sending of
28 // Additionally it posts a bunch of delayed tasks to the main thread for various
30 class AudioSender
: public FrameSender
,
31 public base::NonThreadSafe
,
32 public base::SupportsWeakPtr
<AudioSender
> {
34 AudioSender(scoped_refptr
<CastEnvironment
> cast_environment
,
35 const AudioSenderConfig
& audio_config
,
36 const StatusChangeCallback
& status_change_cb
,
37 CastTransportSender
* const transport_sender
);
41 // Note: It is not guaranteed that |audio_frame| will actually be encoded and
42 // sent, if AudioSender detects too many frames in flight. Therefore, clients
43 // should be careful about the rate at which this method is called.
44 void InsertAudio(scoped_ptr
<AudioBus
> audio_bus
,
45 const base::TimeTicks
& recorded_time
);
48 int GetNumberOfFramesInEncoder() const final
;
49 base::TimeDelta
GetInFlightMediaDuration() const final
;
50 void OnAck(uint32 frame_id
) final
;
53 // Called by the |audio_encoder_| with the next EncodedFrame to send.
54 void OnEncodedAudioFrame(int encoder_bitrate
,
55 scoped_ptr
<SenderEncodedFrame
> encoded_frame
,
58 // Encodes AudioBuses into EncodedFrames.
59 scoped_ptr
<AudioEncoder
> audio_encoder_
;
61 // The number of audio samples enqueued in |audio_encoder_|.
62 int samples_in_encoder_
;
64 // NOTE: Weak pointers must be invalidated before all other member variables.
65 base::WeakPtrFactory
<AudioSender
> weak_factory_
;
67 DISALLOW_COPY_AND_ASSIGN(AudioSender
);
73 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_