- add sources.
[platform/framework/web/crosswalk.git] / src / media / cast / audio_sender / audio_encoder.h
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 "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/rtp_sender/rtp_sender.h"
13
14 namespace webrtc {
15 class AudioCodingModule;
16 }
17
18 namespace media {
19 namespace cast {
20
21 class WebrtEncodedDataCallback;
22
23 // Thread safe class.
24 // It should be called from the main cast thread; however that is not required.
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(scoped_refptr<CastEnvironment> cast_environment,
31                const AudioSenderConfig& audio_config);
32
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
36   // has been sent out.
37   void InsertRawAudioFrame(const PcmAudioFrame* audio_frame,
38                            const base::TimeTicks& recorded_time,
39                            const FrameEncodedCallback& frame_encoded_callback,
40                            const base::Closure callback);
41
42  protected:
43   virtual ~AudioEncoder();
44
45  private:
46   friend class base::RefCountedThreadSafe<AudioEncoder>;
47
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);
53
54   scoped_refptr<CastEnvironment> cast_environment_;
55   scoped_ptr<webrtc::AudioCodingModule> audio_encoder_;
56   scoped_ptr<WebrtEncodedDataCallback> webrtc_encoder_callback_;
57   uint32 timestamp_;
58
59   DISALLOW_COPY_AND_ASSIGN(AudioEncoder);
60 };
61
62 }  // namespace cast
63 }  // namespace media
64
65 #endif  // MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_