Upstream version 5.34.104.0
[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 "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<transport::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   CastInitializationStatus InitializationResult() const;
35
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
39   // sent out.
40   void InsertAudio(const AudioBus* audio_bus,
41                    const base::TimeTicks& recorded_time,
42                    const base::Closure& done_callback);
43
44  protected:
45   virtual ~AudioEncoder();
46
47  private:
48   friend class base::RefCountedThreadSafe<AudioEncoder>;
49
50   class ImplBase;
51   class OpusImpl;
52   class Pcm16Impl;
53
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);
59
60   const scoped_refptr<CastEnvironment> cast_environment_;
61   scoped_ptr<ImplBase> impl_;
62
63   // Used to ensure only one thread invokes InsertAudio().
64   base::ThreadChecker insert_thread_checker_;
65
66   DISALLOW_COPY_AND_ASSIGN(AudioEncoder);
67 };
68
69 }  // namespace cast
70 }  // namespace media
71
72 #endif  // MEDIA_CAST_AUDIO_SENDER_AUDIO_ENCODER_H_