[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / mojo_audio_encoder_service.h
1 // Copyright 2021 The Chromium Authors
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_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11
12 #include "base/memory/weak_ptr.h"
13 #include "media/base/audio_encoder.h"
14 #include "media/base/status.h"
15 #include "media/mojo/mojom/audio_encoder.mojom.h"
16 #include "media/mojo/services/media_mojo_export.h"
17 #include "mojo/public/cpp/bindings/associated_remote.h"
18 #include "mojo/public/cpp/bindings/pending_associated_remote.h"
19 #include "third_party/abseil-cpp/absl/types/optional.h"
20
21 namespace media {
22
23 class MEDIA_MOJO_EXPORT MojoAudioEncoderService final
24     : public mojom::AudioEncoder {
25  public:
26   explicit MojoAudioEncoderService(
27       std::unique_ptr<media::AudioEncoder> encoder);
28
29   MojoAudioEncoderService(const MojoAudioEncoderService&) = delete;
30   MojoAudioEncoderService& operator=(const MojoAudioEncoderService&) = delete;
31
32   ~MojoAudioEncoderService() final;
33
34   // mojom::AudioEncoder implementation
35   void Initialize(
36       mojo::PendingAssociatedRemote<mojom::AudioEncoderClient> client,
37       const AudioEncoderConfig& config,
38       InitializeCallback callback) final;
39
40   void Encode(mojom::AudioBufferPtr buffer, EncodeCallback callback) final;
41
42   void Flush(FlushCallback callback) final;
43
44  private:
45   using MojoDoneCallback =
46       base::OnceCallback<void(const media::EncoderStatus&)>;
47   void OnDone(MojoDoneCallback callback, EncoderStatus error);
48   void OnOutput(EncodedAudioBuffer output,
49                 absl::optional<media::AudioEncoder::CodecDescription> desc);
50
51   std::unique_ptr<media::AudioEncoder> encoder_;
52   mojo::AssociatedRemote<mojom::AudioEncoderClient> client_;
53
54   base::WeakPtr<MojoAudioEncoderService> weak_this_;
55   base::WeakPtrFactory<MojoAudioEncoderService> weak_factory_{this};
56 };
57
58 }  // namespace media
59
60 #endif  // MEDIA_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_