Meet Media API: C++ reference client quickstart

This page explains how to set up and run a sample using the C++ reference client implementation. To learn about the TypeScript client instead, see the TypeScript reference client quickstart.

Prerequisites

To run this quickstart, you need the following prerequisites:

Build the C++ client

  1. The C++ implementation is built with Bazel. However, the C++ WebRTC library (libwebrtc) doesn't have a working Bazel build, so you must build that library first by following the instructions at WebRTC docs.

    The following is an abbreviated version of what's explained in the WebRTC docs:

    $ cd ~
    $ mkdir src
    $ cd src
    $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    $ export PATH=~/src/depot_tools:$PATH
    $ mkdir webrtc-checkout
    $ cd webrtc-checkout
    $ fetch --nohooks webrtc
    $ cd src
    $ # Latest known version to work with our builds
    $ git checkout b00c469cad3f8c926fcf81ded90b90b6e1e62b9c
    $ cd ..
    $ gclient sync
    $ mv src webrtc
    $ cd webrtc
    $ ./build/install-build-deps.sh
    $ gn gen out/Default --args='is_debug=false use_custom_libcxx=false rtc_include_tests=false rtc_build_examples=false dcheck_always_on=true rtc_use_x11=false use_rtti=true'
    $ ninja -C out/Default
    

    Note: Commit b00c469cad3f8c926fcf81ded90b90b6e1e62b9c is the latest known version to work with our builds due to toolchain and abseil updates. This might change in the future. This set of commands works now, but the provided link should be referred to in case the underlying tooling changes. If you're building for a non-x64 Debian or Ubuntu Linux variant, your prerequisite setup might be different.

  2. After building libwebrtc, update your WORKSPACE file to point to your webrtc-checkout directory. Update the webrtc_path path near the top of that file:

    webrtc_path = "/usr/local/myuser/webrtc-checkout/" 
    
  3. Use Bazel to build the C++ client:

    $ bazel build //cpp/...
    

Note: You should be using Bazel 7.4.1. If you have newer versions of Bazel installed, you can run it by using bazel-7.4.1 build/run/test ...

  1. Optionally, run the tests:

    $ bazel test //cpp/...
    

Generate OAuth tokens

To connect to the Meet Media API, your app must use OAuth to generate access tokens. To learn more about accessing Google APIs with OAuth, see Using OAuth 2.0 to Access Google APIs.

You can use the OAuth 2.0 Playground to generate tokens. When using the playground, make sure to:

  • Use your client ID and secret credentials from your cloud project.
  • Request the correct scopes.
  • Sign in to a Google Account and accept access.

Once complete, click the Exchange authorization code for tokens button and copy the generated access token.

Start a meeting

Start a meeting using the same user account that you used to generate the OAuth token. Copy the meeting code. You're now ready to run the samples.

Sample apps

The GitHub repository offers samples for receiving media and participant metadata from a meeting.

These samples collect data for a specified amount of time (default is 3 seconds) and write the collected data to files.

Audio files are in PCM16 format. Video files are in YUV420p format. These files can be played by using a library such as FFmpeg.

Because video resolutions might change during a meeting, samples include the resolution in video file names.

Participant metadata files will be human-readable text files.

Single User Media Sample

The single user media sample is a basic app that focuses on collecting audio and video. The sample doesn't determine which participant created the audio and video data. Therefore, using this sample in a meeting with more than one participant might result in corrupted output.

To run the single user media sample, run:

Linux

$ bazel run cpp/samples:single_user_media_sample -- \
    --meeting_space_id MEETING_SPACE_ID \
    --oauth_token OAUTH_TOKEN

By default, a single audio file is saved to /tmp/test_output_audio.pcm.

Because video streams might change resolutions during a meeting, multiple video files might be created. Video file names will include an incrementing counter and the resolution for that file. For example, if the video stream resolution changed from 320x180 to 240x135 and then back to 320x180, the following video files would be created:

  • /tmp/test_output_video_0_320x180.pcm
  • /tmp/test_output_video_1_240x135.pcm
  • /tmp/test_output_video_2_320x180.pcm

(Optional) Use FFmpeg to Play Output Files on Linux and Mac

FFmpeg can be used to play created audio and video files. Example commands:

Linux & Mac

# Audio
$ ffplay -f s16le -ar 48k -af aformat=channel_layouts=mono \
    /tmp/test_output_audio.pcm

# Video
#
# `video_size` must match the resolution in the video filename (320x180 in
# this example).
$ ffplay -f rawvideo -pixel_format yuv420p -video_size 320x180 \
    /tmp/test_output_video_0_320x180.yuv

Options

You can specify these options when running the samples:

Option Description
--output_file_prefix PREFIX Specify the prefix for output files. Defaults to /tmp_test_output_.
--collection_duration DURATION Specify how long to collect media. Defaults to 30s.
--join_timeout TIMEOUT Specify how long to wait for the app to join the conference. Defaults to 2m.
--meet_api_url URL Specify the URL for the Meet Media API API. Defaults to https://meet.googleapis.com/v2alpha/.