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_AUDIO_ENCODER_H_ 6 #define MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/threading/thread_checker.h" 11 #include "media/cast/cast_config.h" 12 #include "media/cast/cast_environment.h" 13 14 namespace base { 15 class TimeTicks; 16 } 17 18 namespace media { 19 class AudioBus; 20 } 21 22 namespace media { 23 namespace cast { 24 25 class AudioEncoder : public base::RefCountedThreadSafe<AudioEncoder> { 26 public: 27 typedef base::Callback<void(scoped_ptr<EncodedAudioFrame>, 28 const base::TimeTicks&)> FrameEncodedCallback; 29 30 AudioEncoder(const scoped_refptr<CastEnvironment>& cast_environment, 31 const AudioSenderConfig& audio_config, 32 const FrameEncodedCallback& frame_encoded_callback); 33 34 // The |audio_bus| must be valid until the |done_callback| is called. 35 // The callback is called from the main cast thread as soon as the encoder is 36 // done with |audio_bus|; it does not mean that the encoded data has been 37 // sent out. 38 void InsertAudio(const AudioBus* audio_bus, 39 const base::TimeTicks& recorded_time, 40 const base::Closure& done_callback); 41 42 protected: 43 virtual ~AudioEncoder(); 44 45 private: 46 friend class base::RefCountedThreadSafe<AudioEncoder>; 47 48 class ImplBase; 49 class OpusImpl; 50 class Pcm16Impl; 51 52 // Invokes |impl_|'s encode method on the AUDIO_ENCODER thread while holding 53 // a ref-count on AudioEncoder. 54 void EncodeAudio(const AudioBus* audio_bus, 55 const base::TimeTicks& recorded_time, 56 const base::Closure& done_callback); 57 58 const scoped_refptr<CastEnvironment> cast_environment_; 59 scoped_ptr<ImplBase> impl_; 60 61 // Used to ensure only one thread invokes InsertAudio(). 62 base::ThreadChecker insert_thread_checker_; 63 64 DISALLOW_COPY_AND_ASSIGN(AudioEncoder); 65 }; 66 67 } // namespace cast 68 } // namespace media 69 70 #endif // MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_ 71