示例#1
0
func (c *Client) handleCodecVersion(buffer []byte) error {
	var packet MumbleProto.CodecVersion
	if err := proto.Unmarshal(buffer, &packet); err != nil {
		return err
	}
	event := ServerConfigEvent{
		Client: c,
	}
	event.CodecAlpha = packet.Alpha
	event.CodecBeta = packet.Beta
	{
		val := packet.GetPreferAlpha()
		event.CodecPreferAlpha = &val
	}
	{
		val := packet.GetOpus()
		event.CodecOpus = &val
	}

	var codec AudioCodec
	switch {
	case *event.CodecOpus:
		codec = audioCodecs[audioCodecIDOpus]
	}
	if codec != nil {
		c.audioCodec = codec
		c.AudioEncoder = codec.NewEncoder()
		for _, user := range c.Users {
			user.decoder = codec.NewDecoder()
		}
	}

	c.listeners.OnServerConfig(&event)
	return nil
}
示例#2
0
func (c *Client) handleCodecVersion(buffer []byte) error {
	var packet MumbleProto.CodecVersion
	if err := proto.Unmarshal(buffer, &packet); err != nil {
		return err
	}
	event := ServerConfigEvent{
		Client: c,
	}
	event.CodecAlpha = packet.Alpha
	event.CodecBeta = packet.Beta
	{
		val := packet.GetPreferAlpha()
		event.CodecPreferAlpha = &val
	}
	{
		val := packet.GetOpus()
		event.CodecOpus = &val
	}

	var codec AudioCodec
	switch {
	case *event.CodecOpus:
		codec = getAudioCodec(audioCodecIDOpus)
	}
	if codec != nil {
		c.audioCodec = codec

		{
			c.volatileLock.Lock()
			c.volatileWg.Wait()

			c.AudioEncoder = codec.NewEncoder()

			c.volatileLock.Unlock()
		}
	}

	c.Config.Listeners.onServerConfig(&event)
	return nil
}