Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BTRemoteControl] Reinstate IVoiceHandler support #867

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BluetoothRemoteControl/4ModDecoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ADPCM : public Decoders::IDecoder {
};

public:
static constexpr Exchange::IBluetoothRemoteControl::codectype DecoderType = Exchange::IBluetoothRemoteControl::codectype::IMA_ADPCM;
static constexpr Exchange::IAudioStream::codectype DecoderType = Exchange::IAudioStream::codectype::IMA_ADPCM;
static const TCHAR* Name;

public:
Expand Down Expand Up @@ -166,7 +166,7 @@ static Decoders::DecoderFactory<ADPCM> _adpcmFactory;

class PCM : public ADPCM {
public:
static constexpr Exchange::IBluetoothRemoteControl::codectype DecoderType = Exchange::IBluetoothRemoteControl::codectype::PCM;
static constexpr Exchange::IAudioStream::codectype DecoderType = Exchange::IAudioStream::codectype::PCM;

public:
PCM() = delete;
Expand Down
8 changes: 4 additions & 4 deletions BluetoothRemoteControl/Administrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Key {
Key(const Key&) = delete;
Key& operator= (const Key&) = delete;

Key(const TCHAR name[], const Exchange::IBluetoothRemoteControl::codectype codec)
Key(const TCHAR name[], const Exchange::IAudioStream::codectype codec)
: _name(name)
, _codec(codec) {
}
Expand All @@ -48,12 +48,12 @@ class Key {

private:
const string _name;
Exchange::IBluetoothRemoteControl::codectype _codec;
Exchange::IAudioStream::codectype _codec;
};

static std::map<Key, IDecoder::IFactory*> _factories;

/* static */ IDecoder* IDecoder::Instance(const TCHAR name[], Exchange::IBluetoothRemoteControl::codectype codec, const string& configuration)
/* static */ IDecoder* IDecoder::Instance(const TCHAR name[], Exchange::IAudioStream::codectype codec, const string& configuration)
{
IDecoder* result = nullptr;
std::map<Key, IDecoder::IFactory*>::iterator index = _factories.find(Key(name, codec));
Expand All @@ -63,7 +63,7 @@ static std::map<Key, IDecoder::IFactory*> _factories;
return (result);
}

/* static */ void IDecoder::Announce(const TCHAR name[], Exchange::IBluetoothRemoteControl::codectype codec, IDecoder::IFactory* factory)
/* static */ void IDecoder::Announce(const TCHAR name[], Exchange::IAudioStream::codectype codec, IDecoder::IFactory* factory)
{
// uses pair's piecewise constructor
_factories.emplace(std::piecewise_construct,
Expand Down
6 changes: 3 additions & 3 deletions BluetoothRemoteControl/Administrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "Module.h"

#include <interfaces/IBluetoothRemoteControl.h>
#include <interfaces/IVoiceHandler.h>

namespace Thunder {

Expand All @@ -35,8 +35,8 @@ namespace Decoders {
virtual IDecoder* Factory(const string& configuration) = 0;
};

static void Announce(const TCHAR name[], Exchange::IBluetoothRemoteControl::codectype, IFactory* factory);
static IDecoder* Instance(const TCHAR name[], Exchange::IBluetoothRemoteControl::codectype codec, const string& configuration);
static void Announce(const TCHAR name[], Exchange::IAudioStream::codectype, IFactory* factory);
static IDecoder* Instance(const TCHAR name[], Exchange::IAudioStream::codectype codec, const string& configuration);

virtual uint32_t Frames() const = 0;
virtual uint32_t Dropped() const = 0;
Expand Down
67 changes: 50 additions & 17 deletions BluetoothRemoteControl/BluetoothRemoteControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ namespace Plugin {
std::vector<Entry> _lut;
};

static const LUT<Exchange::IBluetoothRemoteControl::codectype, WAV::Recorder::codec> CodecTable({
static const LUT<Exchange::IAudioStream::codectype, WAV::Recorder::codec> CodecTable({

{ Exchange::IBluetoothRemoteControl::codectype::PCM, WAV::Recorder::codec::PCM },
{ Exchange::IBluetoothRemoteControl::codectype::IMA_ADPCM, WAV::Recorder::codec::ADPCM }
{ Exchange::IAudioStream::codectype::PCM, WAV::Recorder::codec::PCM },
{ Exchange::IAudioStream::codectype::IMA_ADPCM, WAV::Recorder::codec::ADPCM }

});

Expand Down Expand Up @@ -181,8 +181,8 @@ namespace Plugin {
}
}

Exchange::JAudioStream::Register(*this, this, this);
Exchange::JBluetoothRemoteControl::Register(*this, this, this);
Exchange::JSONRPC::JBluetoothRemoteControlLegacy::Register(*this, this);

return (string());
}
Expand All @@ -192,8 +192,8 @@ namespace Plugin {
ASSERT(service != nullptr);
ASSERT(_service = service);

Exchange::JAudioStream::Unregister(*this);
Exchange::JBluetoothRemoteControl::Unregister(*this);
Exchange::JSONRPC::JBluetoothRemoteControlLegacy::Unregister(*this);

if (_recorder.IsOpen() == true) {
_recorder.Close();
Expand All @@ -204,10 +204,17 @@ namespace Plugin {
_gattRemote = nullptr;
}

if (_audioHandler != nullptr) {
_audioHandler->Release();
_audioHandler = nullptr;
}

#ifdef USE_VOICE_API
if (_voiceHandler != nullptr) {
_voiceHandler->Release();
_voiceHandler = nullptr;
}
#endif

if (_buffer != nullptr) {
delete _buffer;
Expand Down Expand Up @@ -338,6 +345,8 @@ namespace Plugin {
_buffer = nullptr;

_adminLock.Unlock();

Exchange::JAudioStream::Event::StateChanged(*this, Exchange::IAudioStream::UNAVAILABLE, {});
}

void BluetoothRemoteControl::Operational(const GATTRemote::Data& settings)
Expand All @@ -347,7 +356,7 @@ namespace Plugin {
ASSERT (_gattRemote != nullptr);

if (settings.VoiceCommandHandle != 0) {
_gattRemote->Decoder(_configLine);
_gattRemote->DecoderFromConfigLine(_configLine);

if (_buffer != nullptr) {
delete _buffer;
Expand Down Expand Up @@ -410,23 +419,35 @@ namespace Plugin {
}

_adminLock.Unlock();

Exchange::JAudioStream::Event::StateChanged(*this, Exchange::IAudioStream::IDLE, {});
}

void BluetoothRemoteControl::VoiceData(const Exchange::IBluetoothRemoteControl::audioprofile& profile)
void BluetoothRemoteControl::VoiceData(const Exchange::IAudioStream::audioprofile& profile)
{
_adminLock.Lock();

if (_transmission == true) {
// This should not happen, but let's be prepared
TRACE(Trace::Error, (_T("Missing end of transmission event from the unit`")));
TRACE(Trace::Error, (_T("Missing end of transmission event from the unit")));
VoiceData();
}

if (_voiceHandler != nullptr) {
_voiceHandler->StateChanged(Exchange::IBluetoothRemoteControl::IAudioTransmissionCallback::STARTED);
ASSERT(_gattRemote != nullptr);
ASSERT(_gattRemote->SelectedProfile().IsSet() == true);

if (_audioHandler != nullptr) {
for (auto& observer : _streamObservers) {
observer->StateChanged(Exchange::IAudioStream::STARTED, _gattRemote->SelectedProfile());
}
}
#ifdef USE_VOICE_API
else if (_voiceHandler != nullptr) {
_voiceHandler->Start(_gattRemote->SelectedAudioProfile());
}
#endif
else {
Exchange::JBluetoothRemoteControl::Event::StateChanged(*this, Exchange::IBluetoothRemoteControl::IAudioTransmissionCallback::STARTED);
Exchange::JAudioStream::Event::StateChanged(*this, Exchange::IAudioStream::STARTED, _gattRemote->SelectedProfile());
}

_sequence = 0;
Expand Down Expand Up @@ -476,11 +497,18 @@ namespace Plugin {

_transmission = false;

if (_voiceHandler != nullptr) {
_voiceHandler->StateChanged(Exchange::IBluetoothRemoteControl::IAudioTransmissionCallback::STOPPED);
if (_audioHandler != nullptr) {
for (auto& observer : _streamObservers) {
observer->StateChanged(Exchange::IAudioStream::IDLE, {});
}
}
#ifdef USE_VOICE_API
else if (_voiceHandler != nullptr) {
_voiceHandler->Stop();
}
#endif
else {
Exchange::JBluetoothRemoteControl::Event::StateChanged(*this, Exchange::IBluetoothRemoteControl::IAudioTransmissionCallback::STOPPED);
Exchange::JAudioStream::Event::StateChanged(*this, Exchange::IAudioStream::IDLE, {});
}

_adminLock.Unlock();
Expand Down Expand Up @@ -543,13 +571,18 @@ namespace Plugin {
ASSERT(length != 0);
ASSERT(dataBuffer != nullptr);

if (_voiceHandler != nullptr) {
_voiceHandler->Data(seq, length, dataBuffer);
if (_audioHandler != nullptr) {
_audioHandler->Data(seq, {}, length, dataBuffer);
}
#ifdef USE_VOICE_API
else if (_voiceHandler != nullptr) {
_voiceHandler->Data(seq, dataBuffer, length);
}
#endif
else {
string frame;
Core::ToString(dataBuffer, length, true, frame);
Exchange::JBluetoothRemoteControl::Event::Data(*this, seq, length, frame);
Exchange::JAudioStream::Event::Data(*this, seq, {}, length, frame);
}
}

Expand Down
Loading