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.
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_
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"
23 class MEDIA_MOJO_EXPORT MojoAudioEncoderService final
24 : public mojom::AudioEncoder {
26 explicit MojoAudioEncoderService(
27 std::unique_ptr<media::AudioEncoder> encoder);
29 MojoAudioEncoderService(const MojoAudioEncoderService&) = delete;
30 MojoAudioEncoderService& operator=(const MojoAudioEncoderService&) = delete;
32 ~MojoAudioEncoderService() final;
34 // mojom::AudioEncoder implementation
36 mojo::PendingAssociatedRemote<mojom::AudioEncoderClient> client,
37 const AudioEncoderConfig& config,
38 InitializeCallback callback) final;
40 void Encode(mojom::AudioBufferPtr buffer, EncodeCallback callback) final;
42 void Flush(FlushCallback callback) final;
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);
51 std::unique_ptr<media::AudioEncoder> encoder_;
52 mojo::AssociatedRemote<mojom::AudioEncoderClient> client_;
54 base::WeakPtr<MojoAudioEncoderService> weak_this_;
55 base::WeakPtrFactory<MojoAudioEncoderService> weak_factory_{this};
60 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_ENCODER_SERVICE_H_