adding feature sendUserState and voice target for whisper.

This commit is contained in:
Auzan 2018-03-20 11:09:25 +07:00
parent b7720cc7f3
commit 24e8ec4964
5 changed files with 90 additions and 3 deletions

3
.gitignore vendored
View File

@ -32,3 +32,6 @@ build/
# IntelliJ # IntelliJ
*.iml *.iml
.idea/ .idea/
# Boost
include/boost/

View File

@ -50,10 +50,18 @@ namespace mumlib {
void sendAudioData(int16_t *pcmData, int pcmLength); void sendAudioData(int16_t *pcmData, int pcmLength);
void sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength);
void sendTextMessage(std::string message); void sendTextMessage(std::string message);
void joinChannel(int channelId); void joinChannel(int channelId);
void sendVoiceTarget(int targetId, int channelId);
void sendUserState(mumlib::UserState state, bool val);
void sendUserState(mumlib::UserState state, std::string value);
private: private:
_Mumlib_Private *impl; _Mumlib_Private *impl;
}; };

View File

@ -45,4 +45,14 @@ namespace mumlib {
OPUS OPUS
}; };
enum class UserState {
MUTE,
DEAF,
SUPPRESS,
SELF_MUTE,
SELF_DEAF,
COMMENT,
PRIORITY_SPEAKER,
RECORDING
};
} }

View File

@ -181,7 +181,8 @@ bool mumlib::CryptState::decrypt(const unsigned char *source, unsigned char *dst
#define SHIFTBITS 63 #define SHIFTBITS 63
typedef uint64_t subblock; typedef uint64_t subblock;
#define SWAP64(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;}) // #define SWAP64(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;})
#define SWAP64(x) (__builtin_bswap64(x))
#define SWAPPED(x) SWAP64(x) #define SWAPPED(x) SWAP64(x)
typedef subblock keyblock[BLOCKSIZE]; typedef subblock keyblock[BLOCKSIZE];

View File

@ -152,7 +152,7 @@ namespace mumlib {
links_remove.push_back(channelState.links_remove(i)); links_remove.push_back(channelState.links_remove(i));
} }
this->channelId = channel_id; // this->channelId = channel_id;
callback.channelState( callback.channelState(
channelState.name(), channelState.name(),
@ -369,7 +369,7 @@ namespace mumlib {
void Mumlib::disconnect() { void Mumlib::disconnect() {
if (not impl->externalIoService) { if (not impl->externalIoService) {
impl->ioService.reset(); impl->ioService.stop();
} }
if (impl->transport.getConnectionState() != ConnectionState::NOT_CONNECTED) { if (impl->transport.getConnectionState() != ConnectionState::NOT_CONNECTED) {
impl->transport.disconnect(); impl->transport.disconnect();
@ -390,6 +390,12 @@ namespace mumlib {
impl->transport.sendEncodedAudioPacket(encodedData, length); impl->transport.sendEncodedAudioPacket(encodedData, length);
} }
void Mumlib::sendAudioDataTarget(int targetId, int16_t *pcmData, int pcmLength) {
uint8_t encodedData[5000];
int length = impl->audio.encodeAudioPacket(targetId, pcmData, pcmLength, encodedData, 5000);
impl->transport.sendEncodedAudioPacket(encodedData, length);
}
void Mumlib::sendTextMessage(string message) { void Mumlib::sendTextMessage(string message) {
MumbleProto::TextMessage textMessage; MumbleProto::TextMessage textMessage;
textMessage.set_actor(impl->sessionId); textMessage.set_actor(impl->sessionId);
@ -404,4 +410,63 @@ namespace mumlib {
impl->transport.sendControlMessage(MessageType::USERSTATE, userState); impl->transport.sendControlMessage(MessageType::USERSTATE, userState);
impl->channelId = channelId; impl->channelId = channelId;
} }
void Mumlib::sendVoiceTarget(int targetId, int channelId) {
MumbleProto::VoiceTarget voiceTarget;
MumbleProto::VoiceTarget_Target voiceTargetTarget;
voiceTargetTarget.set_channel_id(channelId);
voiceTargetTarget.set_children(true);
voiceTarget.set_id(targetId);
voiceTarget.add_targets()->CopyFrom(voiceTargetTarget);
impl->transport.sendControlMessage(MessageType::VOICETARGET, voiceTarget);
}
void Mumlib::sendUserState(mumlib::UserState field, bool val) {
MumbleProto::UserState userState;
switch (field) {
case UserState::MUTE:
userState.set_mute(val);
break;
case UserState::DEAF:
userState.set_deaf(val);
break;
case UserState::SUPPRESS:
userState.set_suppress(val);
break;
case UserState::SELF_MUTE:
userState.set_self_mute(val);
break;
case UserState::SELF_DEAF:
userState.set_self_deaf(val);
break;
case UserState::PRIORITY_SPEAKER:
userState.set_priority_speaker(val);
break;
case UserState::RECORDING:
userState.set_recording(val);
break;
default:
// in any other case, just ignore the command
return;
}
impl->transport.sendControlMessage(MessageType::USERSTATE, userState);
}
void Mumlib::sendUserState(mumlib::UserState field, std::string val) {
MumbleProto::UserState userState;
switch (field) {
case UserState::COMMENT:
// TODO: if comment longer than 128 bytes, we need to set the SHA1 hash
userState.set_comment(val);
break;
default:
// in any other case, just ignore the command
return;
}
impl->transport.sendControlMessage(MessageType::USERSTATE, userState);
}
} }