2020-03-29 17:31:42 +02:00
|
|
|
unit uCEFMediaObserver;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2020-03-29 17:31:42 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TCefMediaObserverOwn = class(TCefBaseRefCountedOwn, ICefMediaObserver)
|
|
|
|
protected
|
|
|
|
procedure OnSinks(const sinks: TCefMediaSinkArray); virtual;
|
|
|
|
procedure OnRoutes(const routes: TCefMediaRouteArray); virtual;
|
|
|
|
procedure OnRouteStateChanged(const route: ICefMediaRoute; state: TCefMediaRouteConnectionState); virtual;
|
2020-04-19 22:47:20 +02:00
|
|
|
procedure OnRouteMessageReceived(const route: ICefMediaRoute; const message_: ustring); virtual;
|
2020-03-29 17:31:42 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomMediaObserver = class(TCefMediaObserverOwn)
|
|
|
|
protected
|
|
|
|
FEvents : Pointer;
|
|
|
|
|
|
|
|
procedure OnSinks(const sinks: TCefMediaSinkArray); override;
|
|
|
|
procedure OnRoutes(const routes: TCefMediaRouteArray); override;
|
|
|
|
procedure OnRouteStateChanged(const route: ICefMediaRoute; state: TCefMediaRouteConnectionState); override;
|
2020-04-19 22:47:20 +02:00
|
|
|
procedure OnRouteMessageReceived(const route: ICefMediaRoute; const message_: ustring); override;
|
2020-03-29 17:31:42 +02:00
|
|
|
|
|
|
|
public
|
2020-04-19 22:47:20 +02:00
|
|
|
constructor Create(const events: IChromiumEvents); reintroduce;
|
2020-03-29 17:31:42 +02:00
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFMediaSource, uCEFMediaSink,
|
|
|
|
uCEFMediaRoute;
|
|
|
|
|
|
|
|
// **************************************************
|
|
|
|
// ************** TCefMediaObserverOwn **************
|
|
|
|
// **************************************************
|
|
|
|
|
|
|
|
procedure cef_media_observer_on_sinks( self : PCefMediaObserver;
|
|
|
|
sinksCount : NativeUInt;
|
|
|
|
const sinks : PPCefMediaSink); stdcall;
|
2020-04-19 22:47:20 +02:00
|
|
|
type
|
|
|
|
TSinkArray = array of PCefMediaSink;
|
2020-03-29 17:31:42 +02:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
TempArray : TCefMediaSinkArray;
|
|
|
|
i : NativeUInt;
|
|
|
|
begin
|
|
|
|
TempArray := nil;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefMediaObserverOwn) then
|
|
|
|
try
|
2020-04-19 22:47:20 +02:00
|
|
|
if (sinksCount > 0) and (sinks <> nil) then
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
2020-04-19 22:47:20 +02:00
|
|
|
SetLength(TempArray, sinksCount);
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
while (i < sinksCount) do
|
|
|
|
begin
|
|
|
|
TempArray[i] := TCefMediaSinkRef.UnWrap(TSinkArray(sinks)[i]);
|
|
|
|
inc(i);
|
|
|
|
end;
|
2020-03-29 17:31:42 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
TCefMediaObserverOwn(TempObject).OnSinks(TempArray);
|
|
|
|
finally
|
|
|
|
if (TempArray <> nil) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
while (i < sinksCount) do
|
|
|
|
begin
|
|
|
|
TempArray[i] := nil;
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Finalize(TempArray);
|
|
|
|
TempArray := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_media_observer_on_routes( self : PCefMediaObserver;
|
|
|
|
routesCount : NativeUInt;
|
|
|
|
const routes : PPCefMediaRoute); stdcall;
|
2020-04-19 22:47:20 +02:00
|
|
|
type
|
|
|
|
TRouteArray = array of PCefMediaRoute;
|
2020-03-29 17:31:42 +02:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
TempArray : TCefMediaRouteArray;
|
|
|
|
i : NativeUInt;
|
|
|
|
begin
|
|
|
|
TempArray := nil;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefMediaObserverOwn) then
|
|
|
|
try
|
2020-04-19 22:47:20 +02:00
|
|
|
if (routesCount > 0) and (routes <> nil) then
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
2020-04-19 22:47:20 +02:00
|
|
|
SetLength(TempArray, routesCount);
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
while (i < routesCount) do
|
|
|
|
begin
|
|
|
|
TempArray[i] := TCefMediaRouteRef.UnWrap(TRouteArray(routes)[i]);
|
|
|
|
inc(i);
|
|
|
|
end;
|
2020-03-29 17:31:42 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
TCefMediaObserverOwn(TempObject).OnRoutes(TempArray);
|
|
|
|
finally
|
|
|
|
if (TempArray <> nil) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
while (i < routesCount) do
|
|
|
|
begin
|
|
|
|
TempArray[i] := nil;
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Finalize(TempArray);
|
|
|
|
TempArray := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_media_observer_on_route_state_changed(self : PCefMediaObserver;
|
|
|
|
route : PCefMediaRoute;
|
|
|
|
state : TCefMediaRouteConnectionState); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefMediaObserverOwn) then
|
|
|
|
TCefMediaObserverOwn(TempObject).OnRouteStateChanged(TCefMediaRouteRef.UnWrap(route), state);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_media_observer_on_route_message_received( self : PCefMediaObserver;
|
|
|
|
route : PCefMediaRoute;
|
|
|
|
const message_ : Pointer;
|
|
|
|
message_size : NativeUInt); stdcall;
|
|
|
|
var
|
2020-04-19 22:47:20 +02:00
|
|
|
TempObject : TObject;
|
2020-04-21 13:27:34 +02:00
|
|
|
TempAnsiMsg : Ansistring;
|
|
|
|
TempMsg : ustring;
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefMediaObserverOwn) then
|
2020-04-19 22:47:20 +02:00
|
|
|
begin
|
|
|
|
if (message_size > 0) and (message_ <> nil) then
|
2020-04-21 13:27:34 +02:00
|
|
|
begin
|
|
|
|
SetString(TempAnsiMsg, PAnsiChar(message_), message_size);
|
|
|
|
{$IFDEF DELPHI12_UP}
|
|
|
|
TempMsg := Utf8ToString(TempAnsiMsg);
|
|
|
|
{$ELSE}
|
|
|
|
TempMsg := Utf8Decode(TempAnsiMsg);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
2020-04-19 22:47:20 +02:00
|
|
|
|
|
|
|
TCefMediaObserverOwn(TempObject).OnRouteMessageReceived(TCefMediaRouteRef.UnWrap(route),
|
2020-04-21 13:27:34 +02:00
|
|
|
TempMsg);
|
2020-04-19 22:47:20 +02:00
|
|
|
end;
|
2020-03-29 17:31:42 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefMediaObserverOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefMediaObserver));
|
|
|
|
|
|
|
|
with PCefMediaObserver(FData)^ do
|
|
|
|
begin
|
|
|
|
on_sinks := {$IFDEF FPC}@{$ENDIF}cef_media_observer_on_sinks;
|
|
|
|
on_routes := {$IFDEF FPC}@{$ENDIF}cef_media_observer_on_routes;
|
|
|
|
on_route_state_changed := {$IFDEF FPC}@{$ENDIF}cef_media_observer_on_route_state_changed;
|
|
|
|
on_route_message_received := {$IFDEF FPC}@{$ENDIF}cef_media_observer_on_route_message_received;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefMediaObserverOwn.OnSinks(const sinks: TCefMediaSinkArray);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefMediaObserverOwn.OnRoutes(const routes: TCefMediaRouteArray);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefMediaObserverOwn.OnRouteStateChanged(const route: ICefMediaRoute; state: TCefMediaRouteConnectionState);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2020-04-19 22:47:20 +02:00
|
|
|
procedure TCefMediaObserverOwn.OnRouteMessageReceived(const route: ICefMediaRoute; const message_: ustring);
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
// **************************************************
|
|
|
|
// ************** TCustomMediaObserver **************
|
|
|
|
// **************************************************
|
|
|
|
|
2020-04-19 22:47:20 +02:00
|
|
|
constructor TCustomMediaObserver.Create(const events: IChromiumEvents);
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FEvents := Pointer(events);
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCustomMediaObserver.Destroy;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomMediaObserver.OnSinks(const sinks: TCefMediaSinkArray);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2020-04-19 22:47:20 +02:00
|
|
|
IChromiumEvents(FEvents).doOnSinks(sinks);
|
2020-03-29 17:31:42 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomMediaObserver.OnSinks', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomMediaObserver.OnRoutes(const routes: TCefMediaRouteArray);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2020-04-19 22:47:20 +02:00
|
|
|
IChromiumEvents(FEvents).doOnRoutes(routes);
|
2020-03-29 17:31:42 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomMediaObserver.OnRoutes', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomMediaObserver.OnRouteStateChanged(const route: ICefMediaRoute; state: TCefMediaRouteConnectionState);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2020-04-19 22:47:20 +02:00
|
|
|
IChromiumEvents(FEvents).doOnRouteStateChanged(route, state);
|
2020-03-29 17:31:42 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomMediaObserver.OnRouteStateChanged', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-04-19 22:47:20 +02:00
|
|
|
procedure TCustomMediaObserver.OnRouteMessageReceived(const route: ICefMediaRoute; const message_: ustring);
|
2020-03-29 17:31:42 +02:00
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2020-04-19 22:47:20 +02:00
|
|
|
IChromiumEvents(FEvents).doOnRouteMessageReceived(route, message_);
|
2020-03-29 17:31:42 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomMediaObserver.OnRouteMessageReceived', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|