Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/dullahan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,34 @@ void dullahan::setOnOpenPopupCallback(std::function<void(const std::string url,
}

void dullahan::setOnPageChangedCallback(std::function<void(const unsigned char* pixels,
int x, int y,
int width, int height)> callback)
int x, int y,
int width, int height)> callback)
{
mImpl->getCallbackManager()->setOnPageChangedCallback(callback);
}

void dullahan::setOnAudioStreamStartedCallback(std::function<void(const dullahan_audio_stream_info& info)> callback)
{
mImpl->getCallbackManager()->setOnAudioStreamStartedCallback(callback);
}

void dullahan::setOnAudioStreamPacketCallback(std::function<void(const float** data,
int frames,
int64_t pts)> callback)
{
mImpl->getCallbackManager()->setOnAudioStreamPacketCallback(callback);
}

void dullahan::setOnAudioStreamStoppedCallback(std::function<void()> callback)
{
mImpl->getCallbackManager()->setOnAudioStreamStoppedCallback(callback);
}

void dullahan::setOnAudioStreamErrorCallback(std::function<void(const std::string message)> callback)
{
mImpl->getCallbackManager()->setOnAudioStreamErrorCallback(callback);
}

void dullahan::setOnRequestExitCallback(std::function<void()> callback)
{
mImpl->getCallbackManager()->setOnRequestExitCallback(callback);
Expand Down
22 changes: 22 additions & 0 deletions src/dullahan.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ class dullahan
FD_SAVE_FILE,
} EFileDialogType;

struct dullahan_audio_stream_info
{
int sample_rate = 0;
int channels = 0;
int channel_layout = 0;
int frames_per_buffer = 0;
};

public:
//////////// initialization settings ////////////
struct dullahan_settings
Expand Down Expand Up @@ -369,6 +377,20 @@ class dullahan
int x, int y,
int width, int height)> callback);

// browser audio stream starts
void setOnAudioStreamStartedCallback(std::function<void(const dullahan_audio_stream_info& info)> callback);

// browser audio PCM packet. Data is planar float PCM and valid only during the callback.
void setOnAudioStreamPacketCallback(std::function<void(const float** data,
int frames,
int64_t pts)> callback);

// browser audio stream stops
void setOnAudioStreamStoppedCallback(std::function<void()> callback);

// browser audio stream error
void setOnAudioStreamErrorCallback(std::function<void(const std::string message)> callback);

// exit app requested
void setOnRequestExitCallback(std::function<void()> callback);

Expand Down
40 changes: 40 additions & 0 deletions src/dullahan_browser_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,46 @@ bool dullahan_browser_client::OnBeforePopup(CefRefPtr<CefBrowser> browser,
return true;
}

bool dullahan_browser_client::GetAudioParameters(CefRefPtr<CefBrowser> browser,
CefAudioParameters& params)
{
params.channel_layout = CEF_CHANNEL_LAYOUT_7_1;
params.sample_rate = 48000;
params.frames_per_buffer = 1024;
return true;
}

void dullahan_browser_client::OnAudioStreamStarted(CefRefPtr<CefBrowser> browser,
const CefAudioParameters& params,
int channels)
{
dullahan::dullahan_audio_stream_info info;
info.sample_rate = params.sample_rate;
info.channels = channels;
info.channel_layout = static_cast<int>(params.channel_layout);
info.frames_per_buffer = params.frames_per_buffer;
mParent->getCallbackManager()->onAudioStreamStarted(info);
}

void dullahan_browser_client::OnAudioStreamPacket(CefRefPtr<CefBrowser> browser,
const float** data,
int frames,
int64_t pts)
{
mParent->getCallbackManager()->onAudioStreamPacket(data, frames, pts);
}

void dullahan_browser_client::OnAudioStreamStopped(CefRefPtr<CefBrowser> browser)
{
mParent->getCallbackManager()->onAudioStreamStopped();
}

void dullahan_browser_client::OnAudioStreamError(CefRefPtr<CefBrowser> browser,
const CefString& message)
{
mParent->getCallbackManager()->onAudioStreamError(std::string(message));
}

// CefLifeSpanHandler override
void dullahan_browser_client::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
Expand Down
22 changes: 21 additions & 1 deletion src/dullahan_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <list>

#include "cef_audio_handler.h"
#include "cef_client.h"

class dullahan_impl;
Expand All @@ -42,7 +43,8 @@ class dullahan_browser_client :
public CefRequestHandler,
public CefDownloadHandler,
public CefDialogHandler,
public CefJSDialogHandler
public CefJSDialogHandler,
public CefAudioHandler
{
public:
dullahan_browser_client(dullahan_impl* parent,
Expand All @@ -51,6 +53,10 @@ class dullahan_browser_client :

// CefClient override
CefRefPtr<CefRenderHandler> GetRenderHandler() override;
CefRefPtr<CefAudioHandler> GetAudioHandler() override
{
return this;
}

// CefLifeSpanHandler overrides
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override
Expand Down Expand Up @@ -166,6 +172,20 @@ class dullahan_browser_client :
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) override;

// CefAudioHandler overrides
bool GetAudioParameters(CefRefPtr<CefBrowser> browser,
CefAudioParameters& params) override;
void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser,
const CefAudioParameters& params,
int channels) override;
void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser,
const float** data,
int frames,
int64_t pts) override;
void OnAudioStreamStopped(CefRefPtr<CefBrowser> browser) override;
void OnAudioStreamError(CefRefPtr<CefBrowser> browser,
const CefString& message) override;
private:
dullahan_impl* mParent;
CefRefPtr<CefRenderHandler> mRenderHandler;
Expand Down
55 changes: 54 additions & 1 deletion src/dullahan_callback_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,60 @@ void dullahan_callback_manager::onPageChanged(const unsigned char* pixels, int x
}
}

void dullahan_callback_manager::setOnAudioStreamStartedCallback(
std::function<void(const dullahan::dullahan_audio_stream_info& info)> callback)
{
mOnAudioStreamStartedCallbackFunc = callback;
}

void dullahan_callback_manager::onAudioStreamStarted(const dullahan::dullahan_audio_stream_info& info)
{
if (mOnAudioStreamStartedCallbackFunc)
{
mOnAudioStreamStartedCallbackFunc(info);
}
}

void dullahan_callback_manager::setOnAudioStreamPacketCallback(
std::function<void(const float** data, int frames, int64_t pts)> callback)
{
mOnAudioStreamPacketCallbackFunc = callback;
}

void dullahan_callback_manager::onAudioStreamPacket(const float** data, int frames, int64_t pts)
{
if (mOnAudioStreamPacketCallbackFunc)
{
mOnAudioStreamPacketCallbackFunc(data, frames, pts);
}
}

void dullahan_callback_manager::setOnAudioStreamStoppedCallback(std::function<void()> callback)
{
mOnAudioStreamStoppedCallbackFunc = callback;
}

void dullahan_callback_manager::onAudioStreamStopped()
{
if (mOnAudioStreamStoppedCallbackFunc)
{
mOnAudioStreamStoppedCallbackFunc();
}
}

void dullahan_callback_manager::setOnAudioStreamErrorCallback(std::function<void(const std::string message)> callback)
{
mOnAudioStreamErrorCallbackFunc = callback;
}

void dullahan_callback_manager::onAudioStreamError(const std::string message)
{
if (mOnAudioStreamErrorCallbackFunc)
{
mOnAudioStreamErrorCallbackFunc(message);
}
}

void dullahan_callback_manager::setOnStatusMessageCallback(std::function<void(const std::string message)> callback)
{
mOnStatusMessageCallbackFunc = callback;
Expand Down Expand Up @@ -291,4 +345,3 @@ bool dullahan_callback_manager::onJSBeforeUnloadCallback()
// default to cancel request if no callback set up
return false;
}

16 changes: 16 additions & 0 deletions src/dullahan_callback_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ class dullahan_callback_manager
void setOnPageChangedCallback(std::function<void(const unsigned char* pixels, int x, int y, int width, int height)> callback);
void onPageChanged(const unsigned char* pixels, int x, int y, int width, int height);

void setOnAudioStreamStartedCallback(std::function<void(const dullahan::dullahan_audio_stream_info& info)> callback);
void onAudioStreamStarted(const dullahan::dullahan_audio_stream_info& info);

void setOnAudioStreamPacketCallback(std::function<void(const float** data, int frames, int64_t pts)> callback);
void onAudioStreamPacket(const float** data, int frames, int64_t pts);

void setOnAudioStreamStoppedCallback(std::function<void()> callback);
void onAudioStreamStopped();

void setOnAudioStreamErrorCallback(std::function<void(const std::string message)> callback);
void onAudioStreamError(const std::string message);

void setOnStatusMessageCallback(std::function<void(const std::string message)> callback);
void onStatusMessage(const std::string message);

Expand Down Expand Up @@ -102,6 +114,10 @@ class dullahan_callback_manager
std::function<void()> mOnLoadStartCallbackFunc;
std::function<void(const std::string, const std::string)> mOnOpenPopupCallbackFunc;
std::function<void(const unsigned char*, int, int, int, int)> mOnPageChangedCallbackFunc;
std::function<void(const dullahan::dullahan_audio_stream_info&)> mOnAudioStreamStartedCallbackFunc;
std::function<void(const float**, int, int64_t)> mOnAudioStreamPacketCallbackFunc;
std::function<void()> mOnAudioStreamStoppedCallbackFunc;
std::function<void(const std::string)> mOnAudioStreamErrorCallbackFunc;
std::function<void(const std::string)> mOnStatusMessageCallbackFunc;
std::function<void()> mOnRequestExitCallbackFunc;
std::function<void(const std::string)> mOnTitleChangeCallbackFunc;
Expand Down