OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 5 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
6 #define MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 6 #define MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace cast { | 23 namespace cast { |
24 | 24 |
25 class AudioEncoder; | 25 class AudioEncoder; |
26 | 26 |
27 // Not thread safe. Only called from the main cast thread. | 27 // Not thread safe. Only called from the main cast thread. |
28 // This class owns all objects related to sending audio, objects that create RTP | 28 // This class owns all objects related to sending audio, objects that create RTP |
29 // packets, congestion control, audio encoder, parsing and sending of | 29 // packets, congestion control, audio encoder, parsing and sending of |
30 // RTCP packets. | 30 // RTCP packets. |
31 // Additionally it posts a bunch of delayed tasks to the main thread for various | 31 // Additionally it posts a bunch of delayed tasks to the main thread for various |
32 // timeouts. | 32 // timeouts. |
33 class AudioSender : public FrameSender, | 33 class AudioSender : public FrameSender, public base::NonThreadSafe { |
34 public base::NonThreadSafe, | |
35 public base::SupportsWeakPtr<AudioSender> { | |
36 public: | 34 public: |
37 AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 35 AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
38 const FrameSenderConfig& audio_config, | 36 const FrameSenderConfig& audio_config, |
39 const StatusChangeCallback& status_change_cb, | 37 const StatusChangeCallback& status_change_cb, |
40 CastTransport* const transport_sender); | 38 CastTransport* const transport_sender); |
41 | 39 |
42 ~AudioSender() final; | 40 ~AudioSender() final; |
43 | 41 |
44 // Note: It is not guaranteed that |audio_frame| will actually be encoded and | 42 // 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 | 43 // sent, if AudioSender detects too many frames in flight. Therefore, clients |
46 // should be careful about the rate at which this method is called. | 44 // should be careful about the rate at which this method is called. |
47 void InsertAudio(std::unique_ptr<AudioBus> audio_bus, | 45 void InsertAudio(std::unique_ptr<AudioBus> audio_bus, |
48 const base::TimeTicks& recorded_time); | 46 const base::TimeTicks& recorded_time); |
49 | 47 |
| 48 base::WeakPtr<AudioSender> AsWeakPtr(); |
| 49 |
50 protected: | 50 protected: |
51 int GetNumberOfFramesInEncoder() const final; | 51 int GetNumberOfFramesInEncoder() const final; |
52 base::TimeDelta GetInFlightMediaDuration() const final; | 52 base::TimeDelta GetInFlightMediaDuration() const final; |
53 | 53 |
54 private: | 54 private: |
55 // Called by the |audio_encoder_| with the next EncodedFrame to send. | 55 // Called by the |audio_encoder_| with the next EncodedFrame to send. |
56 void OnEncodedAudioFrame(int encoder_bitrate, | 56 void OnEncodedAudioFrame(int encoder_bitrate, |
57 std::unique_ptr<SenderEncodedFrame> encoded_frame, | 57 std::unique_ptr<SenderEncodedFrame> encoded_frame, |
58 int samples_skipped); | 58 int samples_skipped); |
59 | 59 |
60 // Encodes AudioBuses into EncodedFrames. | 60 // Encodes AudioBuses into EncodedFrames. |
61 std::unique_ptr<AudioEncoder> audio_encoder_; | 61 std::unique_ptr<AudioEncoder> audio_encoder_; |
62 | 62 |
63 // The number of audio samples enqueued in |audio_encoder_|. | 63 // The number of audio samples enqueued in |audio_encoder_|. |
64 int samples_in_encoder_; | 64 int samples_in_encoder_; |
65 | 65 |
66 // NOTE: Weak pointers must be invalidated before all other member variables. | 66 // NOTE: Weak pointers must be invalidated before all other member variables. |
67 base::WeakPtrFactory<AudioSender> weak_factory_; | 67 base::WeakPtrFactory<AudioSender> weak_factory_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(AudioSender); | 69 DISALLOW_COPY_AND_ASSIGN(AudioSender); |
70 }; | 70 }; |
71 | 71 |
72 } // namespace cast | 72 } // namespace cast |
73 } // namespace media | 73 } // namespace media |
74 | 74 |
75 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 75 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
OLD | NEW |