Video Call
  • iOS : Objective-C
  • Android
  • Web
  • Flutter
  • React Native
  • Electron
  • Unity3D
  • Cocos Creator
  • Windows
  • macOS
  • Linux
  • Overview
  • Develop your app
    • Integrate the SDK
    • Implement a basic video call
    • Enhance basic feature
      • Use Tokens for authentication
      • Config your video based on scenes
      • Check the room connection status
      • Set up common video config
      • Set up common audio config
  • Best practices
    • Implement a video call for multiple users
  • Upgrade using advanced features
    • Advanced features
      • Configure the video
        • Watermark the video/Take snapshots
        • Improve your appearance in the video
        • Beautify & Change the voice
        • Configure video codec
        • Output the video in H.265
      • Improve video quality
        • Configure bandwidth management
        • Test network and devices in advance
        • Visualize the sound level
        • Monitor streaming quality
      • Message signaling
        • Convey extra information using SEI
        • Broadcast real-time messages to a room
        • Quotas and limits
      • Play media files
        • Play media files
        • Play sound effects
      • Share the screen
      • Mix the video streams
      • Publish multiple video streams
      • Encrypt the video streams
      • Record video media data
    • Distincitve features
      • Join multiple rooms
      • Customize the video and audio
      • Set the voice hearing range
      • Use the bit mask
      • Play streams via URL
      • Play a transparent gift special effect
  • Upgrade using Add-on
  • Resources & Reference
    • SDK
    • Sample codes
    • API reference
      • Client APIs
      • Server APIs
    • Debugging
      • Error codes
      • Logging/Version number
    • FAQs
    • Key concepts
  • Documentation
  • Video Call
  • Upgrade using advanced features
  • Distincitve features
  • Use the bit mask

Using bit mask

Last updated:2022-04-01 15:34

All numbers in the program are stored in binary form in the computer memory, and bit operations are directly operated on the binary bits of the integer in the memory.

Symbols Meaning Operation Rules Examples
& And When both bits are 1, the result is 1. 0&1=0, 1&1=1.
| Or When both bits are 0, the result is 0. 0
^ XOR If two bits are the same, it is 0, and if they are different, it is 11. 1^1=0, 0^1=1.
~ Inverted 0 becomes 1, and 1 becomes 0. ~1=0, ~0=1.
<< Shift left Shift all the numbers to the left by the corresponding number of digits in binary form, shift out the high position (discard), and fill in the low vacancy with zero. For example, the binary of the integer 3 is 00000011, and 3 << 2 means that the binary bit of the number 3 is shifted to the left by 2 bits, and the binary bit after the shift is 00001100.
>> Signed right shift According to the binary form, move all the numbers to the right by the corresponding number of bits, shift out (discard) the low, and fill the sign bit with the high space, that is, add zero for positive numbers and add 1 for negative numbers. For example, the binary of the integer 3 is 00000011, and 3 >> 1 means that the binary bit of the number 3 is signed to the right by 1 bit, and the shifted binary is 00000001.
>>> Unsigned right shift Shift all the numbers to the right by the corresponding number of bits in binary form, shift out (discard) the low bits, and fill in zeros in the high vacancies. For positive numbers, the rules are the same as for signed right shifting, but for negative numbers it is different. For example, the binary of the integer 3 is 00000011, and 3 >> 1 means that the binary bit of the number 3 is signed to the right by 1 bit, and the shifted binary is 00000001.

The SDK mainly uses the bitmask principle to implement multiple switch operations, that is, when multiple selections of module switches are required in the API, the developer needs to pass in the bitmask result to the SDK.

Take the function of obtaining original audio and video data as an example. Examples of using bit masks in different languages ​​are as follows:

  • C++
enum ZegoAudioDataCallbackBitMask
{
    /** This property controls whether the SDK calls back the [onCapturedAudioData] method */
    ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_CAPTURED = 1 << 0,

    /** This attribute controls whether the SDK will call back the [onPlaybackAudioData] method */
    ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYBACK = 1 << 1,

    /** This attribute controls whether the SDK calls back the [onMixedAudioData] method */
    ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_MIXED = 1 << 2,

    /** This attribute controls whether the SDK will call back the [onPlayerAudioData] method */
    ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYER = 1 << 3
};

// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
unsigned int bitmask = ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_CAPTURED | ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYBACK;
engine->startAudioDataObserver(bitmask, param);
  • Objective-C
typedef NS_OPTIONS(NSUInteger, ZegoAudioDataCallbackBitMask) {
    /// This property controls whether the SDK calls back the [onCapturedAudioData] method
    ZegoAudioDataCallbackBitMaskCaptured = 1 << 0,
    /// This property controls whether the SDK will call back the [onPlaybackAudioData] method
    ZegoAudioDataCallbackBitMaskPlayback = 1 << 1,
    /// This attribute controls whether the SDK calls back the [onMixedAudioData] method
    ZegoAudioDataCallbackBitMaskMixed = 1 << 2,
    /// This property controls whether the SDK will call back the [onPlayerAudioData] method
    ZegoAudioDataCallbackBitMaskPlayer = 1 << 3
};

// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
ZegoAudioDataCallbackBitMask bitmask = ZegoAudioDataCallbackBitMaskCaptured | ZegoAudioDataCallbackBitMaskPlayback;
[[ZegoExpressEngine sharedEngine] startAudioDataObserver:bitmask param:param];
  • Java
public enum ZegoAudioDataCallbackBitMask {
    /** This property controls whether the SDK calls back the [onCapturedAudioData] method */
    CAPTURED(1 << 0),
    /** This attribute controls whether the SDK will call back the [onPlaybackAudioData] method */
    PLAYBACK(1 << 1),
    /** This attribute controls whether the SDK calls back the [onMixedAudioData] method */
    MIXED(1 << 2),
    /** This attribute controls whether the SDK will call back the [onPlayerAudioData] method */
    PLAYER(1 << 3);
}

// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
int bitmask = 0;
bitmask |= ZegoAudioDataCallbackBitMask.CAPTURED.value();
bitmask |= ZegoAudioDataCallbackBitMask.PLAYBACK.value();
engine.startAudioDataObserver(bitmask, param);
Page Directory