[SyncFS] Initialize SyncWorker when sync is enabled.
[chromium-blink-merge.git] / media / cast / sender / audio_sender.h
blobbef042a24246154d6b3df9a70c3f0db9afa620e7
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"
19 namespace media {
20 namespace cast {
22 class AudioEncoder;
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
27 // RTCP packets.
28 // Additionally it posts a bunch of delayed tasks to the main thread for various
29 // timeouts.
30 class AudioSender : public FrameSender,
31 public base::NonThreadSafe,
32 public base::SupportsWeakPtr<AudioSender> {
33 public:
34 AudioSender(scoped_refptr<CastEnvironment> cast_environment,
35 const AudioSenderConfig& audio_config,
36 CastTransportSender* const transport_sender);
38 virtual ~AudioSender();
40 CastInitializationStatus InitializationResult() const {
41 return cast_initialization_status_;
44 // Note: It is not guaranteed that |audio_frame| will actually be encoded and
45 // sent, if AudioSender detects too many frames in flight. Therefore, clients
46 // should be careful about the rate at which this method is called.
48 // Note: It is invalid to call this method if InitializationResult() returns
49 // anything but STATUS_AUDIO_INITIALIZED.
50 void InsertAudio(scoped_ptr<AudioBus> audio_bus,
51 const base::TimeTicks& recorded_time);
53 protected:
54 // Protected for testability.
55 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback);
57 private:
58 // Returns true if there are too many frames in flight, or if the media
59 // duration of the frames in flight would be too high by sending the next
60 // frame. The latter metric is determined from the given |capture_time|
61 // for the next frame to be encoded and sent.
62 bool ShouldDropNextFrame(base::TimeTicks capture_time) const;
64 // Called by the |audio_encoder_| with the next EncodedFrame to send.
65 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame);
67 // Encodes AudioBuses into EncodedFrames.
68 scoped_ptr<AudioEncoder> audio_encoder_;
69 const int configured_encoder_bitrate_;
71 // NOTE: Weak pointers must be invalidated before all other member variables.
72 base::WeakPtrFactory<AudioSender> weak_factory_;
74 DISALLOW_COPY_AND_ASSIGN(AudioSender);
77 } // namespace cast
78 } // namespace media
80 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_