Skip to content

CefAudioHandler

Header: cef_audio_handler.h
Category: Browser Handlers

Overview

User-implemented handler interfaces returned from CefClient and registered with CefBrowserHost.

CefAudioHandler

Source File: include/cef_audio_handler.h

Process / Thread Context: Browser Process. Per-method:

Purpose: User-implemented interface to receive raw PCM audio packets

Methods

bool GetAudioParameters(CefRefPtr<CefBrowser> browser, CefAudioParameters& params)

Parameters:

  • browser: The browser whose audio stream errored.
  • message: Human-readable error description.

Return Value: None.

Usage Instruction: Log the error and tear down any per-stream state. The stream will be stopped immediately.

Threading Constraint: Called on the UI thread during stream creation, or the audio stream thread during the capturing phase.

Usage Example

cpp
#include "include/cef_audio_handler.h"
#include "include/cef_client.h"

class MyAudioHandler : public CefAudioHandler {
 public:
  bool GetAudioParameters(CefRefPtr<CefBrowser> browser,
                          CefAudioParameters& params) override {
    // Accept defaults (or override params.sample_rate, params.channel_layout,
    // params.frames_per_buffer). Return true to proceed.
    return true;
  }

  void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser,
                            const CefAudioParameters& params,
                            int channels) override {
    // Allocate an output sink/encoder for this stream.
    // (Will run on the browser audio capture thread.)
  }

  void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser,
                           const float** data,
                           int frames,
                           int64_t pts) override {
    // Consume |frames| float samples per channel from |data|.
    // (Will run on the audio stream thread — do not block.)
  }

  void OnAudioStreamStopped(CefRefPtr<CefBrowser> browser) override {
    // Free per-stream state. (Will run on the UI thread.)
  }

  void OnAudioStreamError(CefRefPtr<CefBrowser> browser,
                          const CefString& message) override {
    // Log error, tear down state.
  }

  IMPLEMENT_REFCOUNTING(MyAudioHandler);
};

class MyClient : public CefClient {
 public:
  CefRefPtr<CefAudioHandler> GetAudioHandler() override {
    return new MyAudioHandler();
  }
};

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.