Skip to content

Commit

Permalink
Log discovery and other files.
Browse files Browse the repository at this point in the history
HDHomeRun UPnP response is now more correct.
Added /videotest service to make it easier to troubleshoot encoding/transferring video related issues
  • Loading branch information
Craig Moksnes committed Mar 11, 2020
1 parent d6e9e30 commit 33d493b
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 288 deletions.
19 changes: 12 additions & 7 deletions LogUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ interface
uses
System.SysUtils;

const
cLogDefault = 'default';
cLogDiscovery = 'discovery';
cLogNames: Array[0..1] of String = (cLogDefault, cLogDiscovery);

type
ILogger = interface
['{772B05D3-D06A-4E0D-A259-929772F8704D}']
procedure Log(const aMessage: String);
procedure Log(const aLogName: String; const aMessage: String);
end;

TLogger = class abstract
private
class var
fLogger: ILogger;
public
class procedure Log(const aMessage: String); static;
class procedure LogFmt(const aMessage: String; const aArgs: array of const); static;
class procedure Log(const aLogName: String; const aMessage: String); static;
class procedure LogFmt(const aLogName: String; const aMessage: String; const aArgs: array of const); static;

class procedure SetLogger(const aLogger: ILogger); static;
end;
Expand All @@ -26,20 +31,20 @@ implementation

{ TLogger }

class procedure TLogger.Log(const aMessage: String);
class procedure TLogger.Log(const aLogName: String; const aMessage: String);
begin
if Assigned(fLogger) then
fLogger.Log(aMessage);
fLogger.Log(aLogName, aMessage);
end;

class procedure TLogger.SetLogger(const aLogger: ILogger);
begin
fLogger := aLogger;
end;

class procedure TLogger.LogFmt(const aMessage: String; const aArgs: array of const);
class procedure TLogger.LogFmt(const aLogName: String; const aMessage: String; const aArgs: array of const);
begin
Log(Format(aMessage, aArgs));
Log(aLogName, Format(aMessage, aArgs));
end;

end.
66 changes: 9 additions & 57 deletions ProxyFormUnit.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'Ceton HDHomeRun Proxy'
ClientHeight = 507
ClientHeight = 492
ClientWidth = 400
Fill.Kind = Solid
Position = ScreenCenter
Expand All @@ -12,20 +12,21 @@ object MainForm: TMainForm
FormFactor.Devices = [Desktop, iPhone, iPad]
OnCreate = FormCreate
OnDestroy = FormDestroy
OnMouseWheel = FormMouseWheel
OnShow = FormShow
DesignerMasterStyle = 0
object VertScrollBox1: TVertScrollBox
Align = Client
Size.Width = 400.000000000000000000
Size.Height = 507.000000000000000000
Size.Height = 492.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
Viewport.Width = 400.000000000000000000
Viewport.Height = 507.000000000000000000
Viewport.Height = 492.000000000000000000
object OuterPanelContainer: TLayout
Align = Top
Size.Width = 400.000000000000000000
Size.Height = 505.000000000000000000
Size.Height = 489.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object PanelContainer: TLayout
Expand Down Expand Up @@ -302,7 +303,7 @@ object MainForm: TMainForm
object Layout1: TLayout
Align = Bottom
Position.Y = 166.000000000000000000
Size.Width = 200.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 34.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Expand All @@ -318,7 +319,7 @@ object MainForm: TMainForm
end
object btnRefreshChannels: TButton
Anchors = [akTop, akRight]
Position.X = 69.000000000000000000
Position.X = 263.000000000000000000
Position.Y = 4.000000000000000000
Size.Width = 121.000000000000000000
Size.Height = 22.000000000000000000
Expand All @@ -342,7 +343,7 @@ object MainForm: TMainForm
Margins.Left = 10.000000000000000000
Margins.Top = 9.000000000000000000
Margins.Right = 10.000000000000000000
Size.Width = 180.000000000000000000
Size.Width = 374.000000000000000000
Size.Height = 157.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
Expand All @@ -352,7 +353,7 @@ object MainForm: TMainForm
DefaultItemStyles.GroupFooterStyle = ''
ShowCheckboxes = True
OnChangeCheck = lbChannelsChangeCheck
Viewport.Width = 176.000000000000000000
Viewport.Width = 370.000000000000000000
Viewport.Height = 153.000000000000000000
end
end
Expand All @@ -376,55 +377,6 @@ object MainForm: TMainForm
Size.Height = 6.000000000000000000
Size.PlatformDefault = False
end
object pnlDebug: TExpander
Align = Top
IsExpanded = False
Margins.Left = 3.000000000000000000
Margins.Right = 3.000000000000000000
Margins.Bottom = 3.000000000000000000
Position.X = 3.000000000000000000
Position.Y = 480.000000000000000000
ShowCheck = False
Size.Width = 394.000000000000000000
Size.Height = 20.000000000000000000
Size.PlatformDefault = False
Text = 'Debug'
TabOrder = 6
OnMouseDown = PanelMouseDown
OnResized = PanelResizing
ContentSize = '41'
object btnGetVideoSample: TButton
Position.X = 176.000000000000000000
Position.Y = 11.000000000000000000
Size.Width = 121.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Text = 'Get Video Sample'
OnClick = btnGetVideoSampleClick
end
object seChannel: TSpinBox
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 2
Cursor = crIBeam
Max = 10000.000000000000000000
RepeatClick = True
Position.X = 77.000000000000000000
Position.Y = 11.000000000000000000
Size.Width = 89.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
end
object Label8: TLabel
Position.X = 24.000000000000000000
Position.Y = 14.000000000000000000
Size.Width = 89.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
Text = 'Channel:'
TabOrder = 1
end
end
end
end
end
Expand Down
74 changes: 23 additions & 51 deletions ProxyFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface
FMX.ListView,
FMX.SpinBox,
FMX.Menus,
FMX.Platform,
REST.json,
REST.Client,

Expand Down Expand Up @@ -92,10 +93,6 @@ TMainForm = class(TForm, IServiceConfigEvents)
Splitter1: TSplitter;
Splitter2: TSplitter;
OuterPanelContainer: TLayout;
pnlDebug: TExpander;
btnGetVideoSample: TButton;
seChannel: TSpinBox;
Label8: TLabel;
HelpCallout: TCalloutRectangle;
lblHelp: TLabel;
eCetonTunerAddress: TComboEdit;
Expand All @@ -110,7 +107,6 @@ TMainForm = class(TForm, IServiceConfigEvents)
procedure btnRefreshChannelsClick(Sender: TObject);
procedure eHDHRListenHTTPPortChangeTracking(Sender: TObject);
procedure ceHDHRListenIPChangeTracking(Sender: TObject);
procedure btnGetVideoSampleClick(Sender: TObject);
procedure btnShowConfigFolderClick(Sender: TObject);
procedure PanelResizing(Sender: TObject);
procedure eHDHRExternalAddressChangeTracking(Sender: TObject);
Expand All @@ -119,6 +115,8 @@ TMainForm = class(TForm, IServiceConfigEvents)
procedure EditMouseLeave(Sender: TObject);
procedure PanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
private
{ Private declarations }
fConfigManager: IServiceConfigManager;
Expand Down Expand Up @@ -151,7 +149,7 @@ TMainForm = class(TForm, IServiceConfigEvents)
protected
// IServiceConfigEvents
procedure Changed(const aSender: TObject; const aSections: TServiceConfigSections);
procedure Log(const aMessage: String);
procedure Log(const aLogName: String; const aMessage: String);
procedure DiscoveredCetonDevicesChanged;
public
{ Public declarations }
Expand Down Expand Up @@ -644,50 +642,7 @@ function TMainForm.ExtractIP(const aComboEdit: TComboEdit): String;
end;
end;

procedure TMainForm.btnGetVideoSampleClick(Sender: TObject);
var
lStream: TCetonVideoStream;
lStopWatch: TStopWatch;
lBuffer: array[0..8191] of Byte;
lSize: Integer;
lFS: TFileStream;
lChannel: TChannelMapItem;
lFilename: String;
begin
lFilename := 'Sample.ts';

lChannel := TChannelMapItem.Create;
try
if Client.TryGetChannel(Round(seChannel.Value), lChannel) then
begin
lFilename := Format('SampleCh%dP%d.ts', [lChannel.Channel, lChannel.ItemProgram]);
end;
finally
lChannel.Free;
end;

lFS := TFile.Create(ExtractFilePath(ParamStr(0))+lFilename);
try
lStream := TCetonVideoStream.Create(Client, -1, Round(seChannel.Value), False);
try
lStopWatch := TStopWatch.StartNew;
while lStopWatch.ElapsedMilliseconds <= 6000 do
begin
lSize := lStream.Read(lBuffer, SizeOf(lBuffer));
if lSize = 0 then
Break;

lFS.WriteBuffer(lBuffer, lSize);
end;
finally
lStream.Free;
end;
finally
lFS.Free;
end;
end;

procedure TMainForm.Log(const aMessage: String);
procedure TMainForm.Log(const aLogName: String; const aMessage: String);
begin
// TODO
end;
Expand All @@ -700,7 +655,7 @@ procedure TMainForm.btnShowConfigFolderClick(Sender: TObject);
procedure TMainForm.PanelResizing(Sender: TObject);
begin
// Always keep the outer panel container at content size so the scrolling matches the content
OuterPanelContainer.Height := pnlDebug.Position.Y + pnlDebug.Height + pnlDebug.Margins.Bottom;
OuterPanelContainer.Height := Splitter2.Position.Y + Splitter2.Height;
// But make the panel container much larger so that splitters have lots of room to work with
PanelContainer.Height := OuterPanelContainer.Height + 1000;
end;
Expand Down Expand Up @@ -793,4 +748,21 @@ procedure TMainForm.DiscoveredCetonDevicesChanged;
end);
end;

type
TCustomScrollBox_Access = class(TCustomScrollBox);

procedure TMainForm.FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
var
lControl: IControl;
begin
lControl := ObjectAtPoint(Screen.MousePos);
if Assigned(lControl) and (not (lControl.GetObject is TListBox)) then
begin
// Force all mouse wheel handling to go to scrollbox. There's probably a better way to do this.
TCustomScrollBox_Access(VertScrollBox1).MouseWheel(Shift, WheelDelta, Handled);
Handled := True;
end;
end;

end.
Loading

0 comments on commit 33d493b

Please sign in to comment.