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 "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/rtp_sender/rtp_sender.h"
15 class AudioCodingModule;
21 class WebrtEncodedDataCallback;
24 // It should be called from the main cast thread; however that is not required.
25 class AudioEncoder : public base::RefCountedThreadSafe<AudioEncoder> {
27 typedef base::Callback<void(scoped_ptr<EncodedAudioFrame>,
28 const base::TimeTicks&)> FrameEncodedCallback;
30 AudioEncoder(scoped_refptr<CastEnvironment> cast_environment,
31 const AudioSenderConfig& audio_config);
33 // The audio_frame must be valid until the closure callback is called.
34 // The closure callback is called from the main cast thread as soon as
35 // the encoder is done with the frame; it does not mean that the encoded frame
37 void InsertRawAudioFrame(const PcmAudioFrame* audio_frame,
38 const base::TimeTicks& recorded_time,
39 const FrameEncodedCallback& frame_encoded_callback,
40 const base::Closure callback);
43 virtual ~AudioEncoder();
46 friend class base::RefCountedThreadSafe<AudioEncoder>;
48 void EncodeAudioFrameThread(
49 const PcmAudioFrame* audio_frame,
50 const base::TimeTicks& recorded_time,
51 const FrameEncodedCallback& frame_encoded_callback,
52 const base::Closure release_callback);
54 scoped_refptr<CastEnvironment> cast_environment_;
55 scoped_ptr<webrtc::AudioCodingModule> audio_encoder_;
56 scoped_ptr<WebrtEncodedDataCallback> webrtc_encoder_callback_;
59 DISALLOW_COPY_AND_ASSIGN(AudioEncoder);
65 #endif // MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_