Skip to content

Commit

Permalink
Clean up compile conditionals for microphone (youtube#2771)
Browse files Browse the repository at this point in the history
Microphone is universally enabled on all platforms, the #ifdefs are a
no-op.

b/150410605
  • Loading branch information
kaidokert authored Mar 29, 2024
1 parent 44b58d2 commit d9978e9
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 46 deletions.
6 changes: 0 additions & 6 deletions cobalt/media_capture/media_devices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
namespace cobalt {
namespace media_capture {

#if SB_USE_SB_MICROPHONE && !defined(DISABLE_MICROPHONE_IDL)
#define ENABLE_MICROPHONE_IDL
#endif

namespace {

using speech::Microphone;
Expand All @@ -56,13 +52,11 @@ std::unique_ptr<Microphone> CreateMicrophone(

std::unique_ptr<Microphone> mic;

#if defined(ENABLE_MICROPHONE_IDL)
mic.reset(new speech::MicrophoneStarboard(
speech::MicrophoneStarboard::kDefaultSampleRate,
/* Buffer for one second. */
speech::MicrophoneStarboard::kDefaultSampleRate *
speech::MicrophoneStarboard::kSbMicrophoneSampleSizeInBytes));
#endif // defined(ENABLE_MICROPHONE_IDL)

return mic;
}
Expand Down
9 changes: 0 additions & 9 deletions cobalt/media_stream/microphone_audio_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "cobalt/speech/microphone_fake.h"
#include "cobalt/speech/microphone_starboard.h"

#if SB_USE_SB_MICROPHONE && !defined(DISABLE_MICROPHONE_IDL)
#define ENABLE_MICROPHONE_IDL
#endif

namespace cobalt {
namespace media_stream {

Expand All @@ -43,16 +39,12 @@ void MicrophoneAudioSource::EnsureSourceIsStopped() {
std::unique_ptr<cobalt::speech::Microphone>
MicrophoneAudioSource::CreateMicrophone(
const cobalt::speech::Microphone::Options& options, int buffer_size_bytes) {
#if !defined(ENABLE_MICROPHONE_IDL)
return std::unique_ptr<speech::Microphone>();
#else
std::unique_ptr<speech::Microphone> mic;

#if defined(ENABLE_FAKE_MICROPHONE)
if (options.enable_fake_microphone) {
mic.reset(new speech::MicrophoneFake(options));
}
#else
#endif // defined(ENABLE_FAKE_MICROPHONE)

if (!mic) {
Expand All @@ -68,7 +60,6 @@ MicrophoneAudioSource::CreateMicrophone(
}

return mic;
#endif // defined(ENABLE_MICROPHONE_IDL)
}

MicrophoneAudioSource::MicrophoneAudioSource(
Expand Down
12 changes: 1 addition & 11 deletions cobalt/speech/cobalt_speech_recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#include "cobalt/speech/url_fetcher_fake.h"
#endif // defined(ENABLE_FAKE_MICROPHONE)
#include "cobalt/speech/microphone_manager.h"
#include "cobalt/speech/speech_recognition_error.h"
#if defined(SB_USE_SB_MICROPHONE)
#include "cobalt/speech/microphone_starboard.h"
#endif // defined(SB_USE_SB_MICROPHONE)
#include "cobalt/speech/speech_recognition_error.h"
#include "net/url_request/url_fetcher.h"

namespace cobalt {
Expand All @@ -45,15 +43,10 @@ std::unique_ptr<net::URLFetcher> CreateURLFetcher(
}

std::unique_ptr<Microphone> CreateMicrophone(int buffer_size_bytes) {
#if defined(SB_USE_SB_MICROPHONE)
return std::unique_ptr<Microphone>(
new MicrophoneStarboard(kSampleRate, buffer_size_bytes));
#else
return std::unique_ptr<Microphone>();
#endif // defined(SB_USE_SB_MICROPHONE)
}

#if defined(SB_USE_SB_MICROPHONE)
#if defined(ENABLE_FAKE_MICROPHONE)
std::unique_ptr<net::URLFetcher> CreateFakeURLFetcher(
const GURL& url, net::URLFetcher::RequestType request_type,
Expand All @@ -67,7 +60,6 @@ std::unique_ptr<Microphone> CreateFakeMicrophone(
return std::unique_ptr<Microphone>(new MicrophoneFake(options));
}
#endif // defined(ENABLE_FAKE_MICROPHONE)
#endif // defined(SB_USE_SB_MICROPHONE)
} // namespace

CobaltSpeechRecognizer::CobaltSpeechRecognizer(
Expand All @@ -80,7 +72,6 @@ CobaltSpeechRecognizer::CobaltSpeechRecognizer(
MicrophoneManager::MicrophoneCreator microphone_creator =
base::Bind(&CreateMicrophone);

#if defined(SB_USE_SB_MICROPHONE)
#if defined(ENABLE_FAKE_MICROPHONE)
if (microphone_options.enable_fake_microphone) {
// If fake microphone is enabled, fake URL fetchers should be enabled as
Expand All @@ -89,7 +80,6 @@ CobaltSpeechRecognizer::CobaltSpeechRecognizer(
microphone_creator = base::Bind(&CreateFakeMicrophone, microphone_options);
}
#endif // defined(ENABLE_FAKE_MICROPHONE)
#endif // defined(SB_USE_SB_MICROPHONE)

service_.reset(new GoogleSpeechService(
network_module,
Expand Down
3 changes: 0 additions & 3 deletions cobalt/speech/google_speech_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
#include "cobalt/speech/speech_recognition_error.h"
#include "net/base/escape.h"
#include "net/url_request/url_fetcher.h"

#if defined(SB_USE_SB_MICROPHONE)
#include "starboard/system.h"
#endif // defined(SB_USE_SB_MICROPHONE)

namespace cobalt {
namespace speech {
Expand Down
4 changes: 0 additions & 4 deletions cobalt/speech/microphone_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include "cobalt/speech/microphone_starboard.h"

#if defined(SB_USE_SB_MICROPHONE)

#include "starboard/common/log.h"

namespace cobalt {
Expand Down Expand Up @@ -89,5 +87,3 @@ bool MicrophoneStarboard::Close() {

} // namespace speech
} // namespace cobalt

#endif // defined(SB_USE_SB_MICROPHONE)
6 changes: 1 addition & 5 deletions cobalt/speech/microphone_starboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
#ifndef COBALT_SPEECH_MICROPHONE_STARBOARD_H_
#define COBALT_SPEECH_MICROPHONE_STARBOARD_H_

#include "cobalt/speech/speech_configuration.h"

#if defined(SB_USE_SB_MICROPHONE)

#include <string>

#include "cobalt/speech/microphone.h"
#include "cobalt/speech/speech_configuration.h"
#include "starboard/microphone.h"

namespace cobalt {
Expand Down Expand Up @@ -55,5 +52,4 @@ class MicrophoneStarboard : public Microphone {
} // namespace speech
} // namespace cobalt

#endif // defined(SB_USE_SB_MICROPHONE)
#endif // COBALT_SPEECH_MICROPHONE_STARBOARD_H_
2 changes: 0 additions & 2 deletions cobalt/speech/speech_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
#include "build/build_config.h"
#include "starboard/configuration.h"

#define SB_USE_SB_MICROPHONE 1

#endif // COBALT_SPEECH_SPEECH_CONFIGURATION_H_
3 changes: 0 additions & 3 deletions starboard/evergreen/arm/softfp/configuration_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@

// --- I/O Configuration -----------------------------------------------------

// Whether the current platform has microphone supported.
#define SB_HAS_MICROPHONE 0

// Whether the current platform implements the on screen keyboard interface.
#define SB_HAS_ON_SCREEN_KEYBOARD 0

Expand Down
3 changes: 0 additions & 3 deletions starboard/evergreen/arm64/configuration_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@

// --- I/O Configuration -----------------------------------------------------

// Whether the current platform has microphone supported.
#define SB_HAS_MICROPHONE 1

// Whether the current platform implements the on screen keyboard interface.
#define SB_HAS_ON_SCREEN_KEYBOARD 0

Expand Down

0 comments on commit d9978e9

Please sign in to comment.