chromium/third_party/blink/renderer/modules/speech/speech_recognition_media_stream_audio_sink.h

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_RECOGNITION_MEDIA_STREAM_AUDIO_SINK_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_RECOGNITION_MEDIA_STREAM_AUDIO_SINK_H_

#include <memory>

#include "base/functional/callback.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_parameters.h"
#include "media/base/channel_mixer.h"
#include "media/mojo/mojom/speech_recognition.mojom-blink.h"
#include "media/mojo/mojom/speech_recognition_audio_forwarder.mojom-blink.h"
#include "media/mojo/mojom/speech_recognizer.mojom-blink.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_audio_sink.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/platform_export.h"

namespace base {
class SingleThreadTaskRunner;
}

namespace blink {

class ExecutionContext;

// Class used to extract the raw audio from the media stream for use with the
// Web Speech API. Raw audio is extracted from the MediaStreamAudioSink and
// forwarded via the SpeechRecognitionAudioForwarder interface for speech
// recognition. `OnData()` is called on the real-time audio thread, but audio is
// forwarded on the main thread.
class MODULES_EXPORT SpeechRecognitionMediaStreamAudioSink final
    : public GarbageCollected<SpeechRecognitionMediaStreamAudioSink>,
      public WebMediaStreamAudioSink {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_RECOGNITION_MEDIA_STREAM_AUDIO_SINK_H_