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.
5 #ifndef MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_
6 #define MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_
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"
25 class AudioEncoder
: public base::RefCountedThreadSafe
<AudioEncoder
> {
27 typedef base::Callback
<void(scoped_ptr
<transport::EncodedAudioFrame
>,
28 const base::TimeTicks
&)> FrameEncodedCallback
;
30 AudioEncoder(const scoped_refptr
<CastEnvironment
>& cast_environment
,
31 const AudioSenderConfig
& audio_config
,
32 const FrameEncodedCallback
& frame_encoded_callback
);
34 CastInitializationStatus
InitializationResult() const;
36 // The |audio_bus| must be valid until the |done_callback| is called.
37 // The callback is called from the main cast thread as soon as the encoder is
38 // done with |audio_bus|; it does not mean that the encoded data has been
40 void InsertAudio(const AudioBus
* audio_bus
,
41 const base::TimeTicks
& recorded_time
,
42 const base::Closure
& done_callback
);
45 virtual ~AudioEncoder();
48 friend class base::RefCountedThreadSafe
<AudioEncoder
>;
54 // Invokes |impl_|'s encode method on the AUDIO_ENCODER thread while holding
55 // a ref-count on AudioEncoder.
56 void EncodeAudio(const AudioBus
* audio_bus
,
57 const base::TimeTicks
& recorded_time
,
58 const base::Closure
& done_callback
);
60 const scoped_refptr
<CastEnvironment
> cast_environment_
;
61 scoped_ptr
<ImplBase
> impl_
;
63 // Used to ensure only one thread invokes InsertAudio().
64 base::ThreadChecker insert_thread_checker_
;
66 DISALLOW_COPY_AND_ASSIGN(AudioEncoder
);
72 #endif // MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_