From 1c52e4f51b1a9732264203fb0d987cf9752ef45b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 28 Nov 2016 14:26:48 -0500 Subject: [PATCH 1/7] update transaction modes --- .../Activity/ActivityRepository.cs | 2 +- .../Data/BaseSqliteRepository.cs | 5 +++++ .../Data/SqliteDisplayPreferencesRepository.cs | 4 ++-- .../Data/SqliteFileOrganizationRepository.cs | 6 +++--- .../Data/SqliteItemRepository.cs | 8 ++++---- .../Data/SqliteUserDataRepository.cs | 10 +++++----- .../Data/SqliteUserRepository.cs | 4 ++-- .../SqliteNotificationsRepository.cs | 6 +++--- .../Security/AuthenticationRepository.cs | 18 ++++++++++-------- .../Social/SharingRepository.cs | 2 +- .../Sync/SyncRepository.cs | 8 ++++---- 11 files changed, 40 insertions(+), 33 deletions(-) diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index ba81992acb..f7419de808 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Activity statement.MoveNext(); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index 308b8356f9..af8de0e84f 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -30,6 +30,11 @@ namespace Emby.Server.Implementations.Data get { return false; } } + protected TransactionMode TransactionMode + { + get { return TransactionMode.Immediate; } + } + static BaseSqliteRepository() { SQLite3.EnableSharedCache = false; diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs index 1bd64b21dc..743186db24 100644 --- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs @@ -100,7 +100,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveDisplayPreferences(displayPreferences, userId, client, db); - }); + }, TransactionMode); } } } @@ -147,7 +147,7 @@ namespace Emby.Server.Implementations.Data { SaveDisplayPreferences(displayPreference, userId, displayPreference.Client, db); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs index 23bab883e2..448d38c8cb 100644 --- a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs @@ -85,7 +85,7 @@ namespace Emby.Server.Implementations.Data statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -108,7 +108,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@ResultId", id.ToGuidParamValue()); statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -124,7 +124,7 @@ namespace Emby.Server.Implementations.Data var commandText = "delete from FileOrganizerResults"; db.Execute(commandText); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 29aacc0592..54820ab536 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -316,7 +316,7 @@ namespace Emby.Server.Implementations.Data AddColumn(db, "MediaStreams", "RefFrames", "INT", existingColumnNames); AddColumn(db, "MediaStreams", "KeyFrames", "TEXT", existingColumnNames); AddColumn(db, "MediaStreams", "IsAnamorphic", "BIT", existingColumnNames); - }); + }, TransactionMode); string[] postQueries = @@ -697,7 +697,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveItemsInTranscation(db, tuples); - }); + }, TransactionMode); } } } @@ -2211,7 +2211,7 @@ namespace Emby.Server.Implementations.Data index++; } } - }); + }, TransactionMode); } } } @@ -4531,7 +4531,7 @@ namespace Emby.Server.Implementations.Data // Delete the item ExecuteWithSingleParam(db, "delete from TypedBaseItems where guid=@Id", id.ToGuidParamValue()); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index b01f215e0b..f7184540a6 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Data AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); - }); + }, TransactionMode); ImportUserDataIfNeeded(connection); } @@ -116,7 +116,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@IsUserDataImported", true); statement.MoveNext(); } - }); + }, TransactionMode); } private void ImportUserData(IDatabaseConnection connection, string file) @@ -128,7 +128,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { db.Execute("REPLACE INTO userdata(" + columns + ") SELECT " + columns + " FROM UserDataBackup.userdata;"); - }); + }, TransactionMode); } /// @@ -197,7 +197,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveUserData(db, userId, key, userData); - }); + }, TransactionMode); } } } @@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.Data { SaveUserData(db, userId, userItemData.Key, userItemData); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs index f902d981fe..5fb27d0812 100644 --- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs @@ -102,7 +102,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@data", serialized); statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -164,7 +164,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@id", user.Id.ToGuidParamValue()); statement.MoveNext(); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index 66ef5d5d18..5f0d4d29a8 100644 --- a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -249,7 +249,7 @@ namespace Emby.Server.Implementations.Notifications statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -304,7 +304,7 @@ namespace Emby.Server.Implementations.Notifications statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -334,7 +334,7 @@ namespace Emby.Server.Implementations.Notifications } } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs index 2632b9666a..e498253c30 100644 --- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs +++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs @@ -50,7 +50,8 @@ namespace Emby.Server.Implementations.Security var existingColumnNames = GetColumnNames(db, "AccessTokens"); AddColumn(db, "AccessTokens", "AppVersion", "TEXT", existingColumnNames); - }); + + }, TransactionMode); } } @@ -70,9 +71,9 @@ namespace Emby.Server.Implementations.Security cancellationToken.ThrowIfCancellationRequested(); - using (WriteLock.Write()) + using (var connection = CreateConnection()) { - using (var connection = CreateConnection()) + using (WriteLock.Write()) { connection.RunInTransaction(db => { @@ -100,7 +101,8 @@ namespace Emby.Server.Implementations.Security statement.MoveNext(); } - }); + + }, TransactionMode); } } } @@ -137,9 +139,9 @@ namespace Emby.Server.Implementations.Security throw new ArgumentNullException("query"); } - using (WriteLock.Read()) + using (var connection = CreateConnection(true)) { - using (var connection = CreateConnection(true)) + using (WriteLock.Read()) { var commandText = BaseSelectText; @@ -244,9 +246,9 @@ namespace Emby.Server.Implementations.Security throw new ArgumentNullException("id"); } - using (WriteLock.Read()) + using (var connection = CreateConnection(true)) { - using (var connection = CreateConnection(true)) + using (WriteLock.Read()) { var commandText = BaseSelectText + " where Id=@Id"; diff --git a/Emby.Server.Implementations/Social/SharingRepository.cs b/Emby.Server.Implementations/Social/SharingRepository.cs index 6dab54bc6b..71f80a5752 100644 --- a/Emby.Server.Implementations/Social/SharingRepository.cs +++ b/Emby.Server.Implementations/Social/SharingRepository.cs @@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.Social info.ItemId, info.UserId, info.ExpirationDate.ToDateTimeParamValue()); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index b2d9fbcc9d..caf98e6663 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Sync existingColumnNames = GetColumnNames(db, "SyncJobItems"); AddColumn(db, "SyncJobItems", "ItemDateModifiedTicks", "BIGINT", existingColumnNames); - }); + }, TransactionMode); } } @@ -268,7 +268,7 @@ namespace Emby.Server.Implementations.Sync connection.RunInTransaction(conn => { conn.Execute(commandText, paramList.ToArray()); - }); + }, TransactionMode); } } } @@ -290,7 +290,7 @@ namespace Emby.Server.Implementations.Sync { conn.Execute("delete from SyncJobs where Id=?", id.ToGuidParamValue()); conn.Execute("delete from SyncJobItems where JobId=?", id); - }); + }, TransactionMode); } } } @@ -743,7 +743,7 @@ namespace Emby.Server.Implementations.Sync connection.RunInTransaction(conn => { conn.Execute(commandText, paramList.ToArray()); - }); + }, TransactionMode); } } } From 2748bc2e1c29fbbb1a4904b9a5176612c32876ee Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 28 Nov 2016 14:27:06 -0500 Subject: [PATCH 2/7] sync timer settings with series --- .../LiveTv/EmbyTV/EmbyTV.cs | 7 ++++ .../LiveTv/EmbyTV/RecordingHelper.cs | 35 ++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 36a4dc6084..d74cf41e81 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -2064,6 +2064,13 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV enabledTimersForSeries.Add(existingTimer); } + existingTimer.KeepUntil = seriesTimer.KeepUntil; + existingTimer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired; + existingTimer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired; + existingTimer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds; + existingTimer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds; + existingTimer.Priority = seriesTimer.Priority; + existingTimer.SeriesTimerId = seriesTimer.Id; _timerProvider.Update(existingTimer); } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs index 1b6ddc73f9..881aaaf0d6 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs @@ -15,23 +15,24 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public static TimerInfo CreateTimer(ProgramInfo parent, SeriesTimerInfo seriesTimer) { - var timer = new TimerInfo(); - - timer.ChannelId = parent.ChannelId; - timer.Id = (seriesTimer.Id + parent.Id).GetMD5().ToString("N"); - timer.StartDate = parent.StartDate; - timer.EndDate = parent.EndDate; - timer.ProgramId = parent.Id; - timer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds; - timer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds; - timer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired; - timer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired; - timer.KeepUntil = seriesTimer.KeepUntil; - timer.Priority = seriesTimer.Priority; - timer.Name = parent.Name; - timer.Overview = parent.Overview; - timer.SeriesTimerId = seriesTimer.Id; - timer.ShowId = parent.ShowId; + var timer = new TimerInfo + { + ChannelId = parent.ChannelId, + Id = (seriesTimer.Id + parent.Id).GetMD5().ToString("N"), + StartDate = parent.StartDate, + EndDate = parent.EndDate, + ProgramId = parent.Id, + PrePaddingSeconds = seriesTimer.PrePaddingSeconds, + PostPaddingSeconds = seriesTimer.PostPaddingSeconds, + IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired, + IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired, + KeepUntil = seriesTimer.KeepUntil, + Priority = seriesTimer.Priority, + Name = parent.Name, + Overview = parent.Overview, + SeriesTimerId = seriesTimer.Id, + ShowId = parent.ShowId + }; CopyProgramInfoToTimerInfo(parent, timer); From 9ecfb4fd823be8fbca8e9bbc242fc8a025c6d3a5 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 28 Nov 2016 14:42:13 -0500 Subject: [PATCH 3/7] update mac project --- .../Emby.Server.Mac.csproj | 24 ++++++++++++++++--- MediaBrowser.Server.Mac/MacAppHost.cs | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj index 494b89149b..38f693dc55 100644 --- a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj @@ -1001,9 +1001,6 @@ Resources\dashboard-ui\bower_components\emby-webcomponents\README.md - - Resources\dashboard-ui\bower_components\emby-webcomponents\animations.css - Resources\dashboard-ui\bower_components\emby-webcomponents\appsettings.js @@ -1433,6 +1430,9 @@ Resources\dashboard-ui\bower_components\emby-webcomponents\guide\tvguide.template.html + + Resources\dashboard-ui\bower_components\emby-webcomponents\imageeditor\imageeditor.css + Resources\dashboard-ui\bower_components\emby-webcomponents\imageeditor\imageeditor.js @@ -1589,6 +1589,9 @@ Resources\dashboard-ui\bower_components\emby-webcomponents\recordingcreator\recordingeditor.template.html + + Resources\dashboard-ui\bower_components\emby-webcomponents\recordingcreator\recordingfields.css + Resources\dashboard-ui\bower_components\emby-webcomponents\recordingcreator\recordingfields.js @@ -1973,6 +1976,12 @@ Resources\dashboard-ui\bower_components\hlsjs\API.md + + Resources\dashboard-ui\bower_components\hlsjs\CONTRIBUTING.md + + + Resources\dashboard-ui\bower_components\hlsjs\ISSUE_TEMPLATE.md + Resources\dashboard-ui\bower_components\hlsjs\LICENSE @@ -3428,6 +3437,9 @@ Resources\dashboard-ui\strings\da.json + + Resources\dashboard-ui\strings\de-DE.json + Resources\dashboard-ui\strings\de.json @@ -3443,6 +3455,9 @@ Resources\dashboard-ui\strings\es-AR.json + + Resources\dashboard-ui\strings\es-ES.json + Resources\dashboard-ui\strings\es-MX.json @@ -3485,6 +3500,9 @@ Resources\dashboard-ui\strings\ko.json + + Resources\dashboard-ui\strings\lt-LT.json + Resources\dashboard-ui\strings\ms.json diff --git a/MediaBrowser.Server.Mac/MacAppHost.cs b/MediaBrowser.Server.Mac/MacAppHost.cs index 11a1ff59dd..d73a8fbbda 100644 --- a/MediaBrowser.Server.Mac/MacAppHost.cs +++ b/MediaBrowser.Server.Mac/MacAppHost.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Mac { get { - return false; + return true; } } From 61e195c096dfc2c5713bbbcbc0be73ddff99cb55 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 29 Nov 2016 14:12:37 -0500 Subject: [PATCH 4/7] update repositories --- .../Activity/ActivityRepository.cs | 20 ++- .../Data/BaseSqliteRepository.cs | 42 ++++--- .../SqliteDisplayPreferencesRepository.cs | 7 +- .../Data/SqliteFileOrganizationRepository.cs | 7 +- .../Data/SqliteItemRepository.cs | 11 +- .../Data/SqliteUserDataRepository.cs | 2 - .../Data/SqliteUserRepository.cs | 7 +- .../SqliteNotificationsRepository.cs | 11 +- .../Security/AuthenticationRepository.cs | 119 +++++++++--------- .../Social/SharingRepository.cs | 7 +- .../Sync/SyncRepository.cs | 7 +- 11 files changed, 101 insertions(+), 139 deletions(-) diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index f7419de808..9513c224f8 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -27,17 +27,11 @@ namespace Emby.Server.Implementations.Activity { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { - - "create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)", - "create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)" + "create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)", + "create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)" }; connection.RunQueries(queries); @@ -58,9 +52,9 @@ namespace Emby.Server.Implementations.Activity throw new ArgumentNullException("entry"); } - using (WriteLock.Write()) + using (var connection = CreateConnection()) { - using (var connection = CreateConnection()) + using (WriteLock.Write()) { connection.RunInTransaction(db => { @@ -86,9 +80,9 @@ namespace Emby.Server.Implementations.Activity public QueryResult GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit) { - using (WriteLock.Read()) + using (var connection = CreateConnection(true)) { - using (var connection = CreateConnection(true)) + using (WriteLock.Read()) { var commandText = BaseActivitySelectText; var whereClauses = new List(); diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index af8de0e84f..e066d02d35 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -67,20 +67,8 @@ namespace Emby.Server.Implementations.Data //Logger.Info("Opening write connection"); } - isReadOnly = false; - - if (isReadOnly) - { - connectionFlags = ConnectionFlags.ReadOnly; - //connectionFlags = ConnectionFlags.Create; - //connectionFlags |= ConnectionFlags.ReadWrite; - } - else - { - connectionFlags = ConnectionFlags.Create; - connectionFlags |= ConnectionFlags.ReadWrite; - } - + connectionFlags = ConnectionFlags.Create; + connectionFlags |= ConnectionFlags.ReadWrite; connectionFlags |= ConnectionFlags.SharedCached; connectionFlags |= ConnectionFlags.NoMutex; @@ -89,6 +77,8 @@ namespace Emby.Server.Implementations.Data if (string.IsNullOrWhiteSpace(_defaultWal)) { _defaultWal = db.Query("PRAGMA journal_mode").SelectScalarString().First(); + + Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal); } var queries = new List @@ -115,7 +105,7 @@ namespace Emby.Server.Implementations.Data //Logger.Info("synchronous: " + db.Query("PRAGMA synchronous").SelectScalarString().First()); //Logger.Info("temp_store: " + db.Query("PRAGMA temp_store").SelectScalarString().First()); - if (!string.Equals(_defaultWal, "wal", StringComparison.OrdinalIgnoreCase)) + /*if (!string.Equals(_defaultWal, "wal", StringComparison.OrdinalIgnoreCase)) { queries.Add("PRAGMA journal_mode=WAL"); @@ -124,7 +114,7 @@ namespace Emby.Server.Implementations.Data db.ExecuteAll(string.Join(";", queries.ToArray())); } } - else if (queries.Count > 0) + else*/ if (queries.Count > 0) { db.ExecuteAll(string.Join(";", queries.ToArray())); } @@ -132,6 +122,26 @@ namespace Emby.Server.Implementations.Data return db; } + protected void RunDefaultInitialization(IDatabaseConnection db) + { + var queries = new List + { + "PRAGMA journal_mode=WAL", + "PRAGMA page_size=4096", + }; + + if (EnableTempStoreMemory) + { + queries.AddRange(new List + { + "pragma default_temp_store = memory", + "pragma temp_store = memory" + }); + } + + db.ExecuteAll(string.Join(";", queries.ToArray())); + } + protected virtual bool EnableTempStoreMemory { get diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs index 743186db24..0197efb510 100644 --- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs @@ -54,12 +54,7 @@ namespace Emby.Server.Implementations.Data { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { diff --git a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs index 448d38c8cb..6034371206 100644 --- a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs @@ -31,12 +31,7 @@ namespace Emby.Server.Implementations.Data { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 54820ab536..9c096916f7 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -157,12 +157,7 @@ namespace Emby.Server.Implementations.Data { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "PRAGMA default_temp_store=memory", - "PRAGMA temp_store=memory" - })); + RunDefaultInitialization(connection); var createMediaStreamsTableCommand = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; @@ -396,9 +391,9 @@ namespace Emby.Server.Implementations.Data { try { - using (WriteLock.Write()) + using (var connection = CreateConnection()) { - using (var connection = CreateConnection()) + using (WriteLock.Write()) { connection.RunQueries(new string[] { diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index f7184540a6..b65e5d1b36 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -51,8 +51,6 @@ namespace Emby.Server.Implementations.Data { string[] queries = { - "pragma temp_store = memory", - "create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", "create table if not exists DataSettings (IsUserDataImported bit)", diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs index 5fb27d0812..99d7563c7e 100644 --- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs @@ -50,12 +50,7 @@ namespace Emby.Server.Implementations.Data { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { diff --git a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index 5f0d4d29a8..767ba55049 100644 --- a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -29,12 +29,7 @@ namespace Emby.Server.Implementations.Notifications { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { @@ -58,7 +53,7 @@ namespace Emby.Server.Implementations.Notifications using (var connection = CreateConnection(true)) { - //using (WriteLock.Read()) + using (WriteLock.Read()) { var clauses = new List(); var paramList = new List(); @@ -113,7 +108,7 @@ namespace Emby.Server.Implementations.Notifications using (var connection = CreateConnection(true)) { - //using (WriteLock.Read()) + using (WriteLock.Read()) { using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead")) { diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs index e498253c30..dbda4a4607 100644 --- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs +++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs @@ -30,12 +30,7 @@ namespace Emby.Server.Implementations.Security { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { @@ -139,78 +134,78 @@ namespace Emby.Server.Implementations.Security throw new ArgumentNullException("query"); } - using (var connection = CreateConnection(true)) - { - using (WriteLock.Read()) - { - var commandText = BaseSelectText; + var commandText = BaseSelectText; - var whereClauses = new List(); + var whereClauses = new List(); - var startIndex = query.StartIndex ?? 0; + var startIndex = query.StartIndex ?? 0; - if (!string.IsNullOrWhiteSpace(query.AccessToken)) - { - whereClauses.Add("AccessToken=@AccessToken"); - } + if (!string.IsNullOrWhiteSpace(query.AccessToken)) + { + whereClauses.Add("AccessToken=@AccessToken"); + } - if (!string.IsNullOrWhiteSpace(query.UserId)) - { - whereClauses.Add("UserId=@UserId"); - } + if (!string.IsNullOrWhiteSpace(query.UserId)) + { + whereClauses.Add("UserId=@UserId"); + } - if (!string.IsNullOrWhiteSpace(query.DeviceId)) - { - whereClauses.Add("DeviceId=@DeviceId"); - } + if (!string.IsNullOrWhiteSpace(query.DeviceId)) + { + whereClauses.Add("DeviceId=@DeviceId"); + } - if (query.IsActive.HasValue) - { - whereClauses.Add("IsActive=@IsActive"); - } + if (query.IsActive.HasValue) + { + whereClauses.Add("IsActive=@IsActive"); + } - if (query.HasUser.HasValue) - { - if (query.HasUser.Value) - { - whereClauses.Add("UserId not null"); - } - else - { - whereClauses.Add("UserId is null"); - } - } + if (query.HasUser.HasValue) + { + if (query.HasUser.Value) + { + whereClauses.Add("UserId not null"); + } + else + { + whereClauses.Add("UserId is null"); + } + } - var whereTextWithoutPaging = whereClauses.Count == 0 ? - string.Empty : - " where " + string.Join(" AND ", whereClauses.ToArray()); + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); - if (startIndex > 0) - { - var pagingWhereText = whereClauses.Count == 0 ? - string.Empty : - " where " + string.Join(" AND ", whereClauses.ToArray()); + if (startIndex > 0) + { + var pagingWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); - whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM AccessTokens {0} ORDER BY DateCreated LIMIT {1})", - pagingWhereText, - startIndex.ToString(_usCulture))); - } + whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM AccessTokens {0} ORDER BY DateCreated LIMIT {1})", + pagingWhereText, + startIndex.ToString(_usCulture))); + } - var whereText = whereClauses.Count == 0 ? - string.Empty : - " where " + string.Join(" AND ", whereClauses.ToArray()); + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); - commandText += whereText; + commandText += whereText; - commandText += " ORDER BY DateCreated"; + commandText += " ORDER BY DateCreated"; - if (query.Limit.HasValue) - { - commandText += " LIMIT " + query.Limit.Value.ToString(_usCulture); - } + if (query.Limit.HasValue) + { + commandText += " LIMIT " + query.Limit.Value.ToString(_usCulture); + } - var list = new List(); + var list = new List(); + using (var connection = CreateConnection(true)) + { + using (WriteLock.Read()) + { using (var statement = connection.PrepareStatement(commandText)) { BindAuthenticationQueryParams(query, statement); diff --git a/Emby.Server.Implementations/Social/SharingRepository.cs b/Emby.Server.Implementations/Social/SharingRepository.cs index 71f80a5752..12d846e813 100644 --- a/Emby.Server.Implementations/Social/SharingRepository.cs +++ b/Emby.Server.Implementations/Social/SharingRepository.cs @@ -27,12 +27,7 @@ namespace Emby.Server.Implementations.Social { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index caf98e6663..037507872f 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -43,12 +43,7 @@ namespace Emby.Server.Implementations.Sync { using (var connection = CreateConnection()) { - connection.ExecuteAll(string.Join(";", new[] - { - "PRAGMA page_size=4096", - "pragma default_temp_store = memory", - "pragma temp_store = memory" - })); + RunDefaultInitialization(connection); string[] queries = { From c80ac9b823d4f128c232d4a69e051af1fd4ea3f4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 29 Nov 2016 14:13:01 -0500 Subject: [PATCH 5/7] update artist lists --- .../Localization/TextLocalizer.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Core/Localization/TextLocalizer.cs b/Emby.Server.Core/Localization/TextLocalizer.cs index 016d596590..6690c62638 100644 --- a/Emby.Server.Core/Localization/TextLocalizer.cs +++ b/Emby.Server.Core/Localization/TextLocalizer.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Emby.Server.Implementations.Localization; namespace Emby.Server.Core.Localization @@ -10,11 +11,41 @@ namespace Emby.Server.Core.Localization { public string RemoveDiacritics(string text) { - return String.Concat( - text.Normalize(NormalizationForm.FormD) - .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != - UnicodeCategory.NonSpacingMark) - ).Normalize(NormalizationForm.FormC); + if (text == null) + { + throw new ArgumentNullException("text"); + } + + var chars = Normalize(text, NormalizationForm.FormD) + .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark); + + return Normalize(String.Concat(chars), NormalizationForm.FormC); + } + + private static string Normalize(string text, NormalizationForm form, bool stripStringOnFailure = true) + { + if (stripStringOnFailure) + { + try + { + return text.Normalize(form); + } + catch (ArgumentException) + { + // will throw if input contains invalid unicode chars + // https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/ + text = StripInvalidUnicodeCharacters(text); + return Normalize(text, form, false); + } + } + + return text.Normalize(form); + } + + private static string StripInvalidUnicodeCharacters(string str) + { + var invalidCharactersRegex = new Regex("([\ud800-\udbff](?![\udc00-\udfff]))|((? Date: Tue, 29 Nov 2016 14:13:20 -0500 Subject: [PATCH 6/7] update recording encoder --- .../EnvironmentInfo/EnvironmentInfo.cs | 5 ++ Emby.Server.Core/ApplicationHost.cs | 3 +- .../LiveTv/EmbyTV/EncodedRecorder.cs | 83 ++++--------------- .../MediaEncoding/IMediaEncoder.cs | 3 + .../Encoder/MediaEncoder.cs | 59 ++++++++++++- MediaBrowser.Model/System/IEnvironmentInfo.cs | 8 +- 6 files changed, 88 insertions(+), 73 deletions(-) diff --git a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs index ebd596dc41..6cc4626eaf 100644 --- a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -110,5 +110,10 @@ namespace Emby.Common.Implementations.EnvironmentInfo { get { return Environment.StackTrace; } } + + public void SetProcessEnvironmentVariable(string name, string value) + { + Environment.SetEnvironmentVariable(name, value); + } } } diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index 90848d930e..f7fe02fbaa 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -789,7 +789,8 @@ namespace Emby.Server.Core MemoryStreamFactory, ProcessFactory, (Environment.ProcessorCount > 2 ? 14000 : 40000), - EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows); + EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows, + EnvironmentInfo); MediaEncoder = mediaEncoder; RegisterSingleInstance(MediaEncoder); diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index 5e55b893f3..5bb65b6506 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs @@ -31,7 +31,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private readonly IServerApplicationPaths _appPaths; private readonly LiveTvOptions _liveTvOptions; private bool _hasExited; - private Stream _logFileStream; private string _targetPath; private IProcess _process; private readonly IProcessFactory _processFactory; @@ -85,22 +84,26 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _targetPath = targetFile; _fileSystem.CreateDirectory(Path.GetDirectoryName(targetFile)); + var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "record-transcode-" + Guid.NewGuid().ToString("N") + ".txt"); + _fileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath)); + var process = _processFactory.Create(new ProcessOptions { CreateNoWindow = true, - UseShellExecute = false, + UseShellExecute = true, // Must consume both stdout and stderr or deadlocks may occur //RedirectStandardOutput = true, - RedirectStandardError = true, - RedirectStandardInput = true, + RedirectStandardError = false, + RedirectStandardInput = false, FileName = _mediaEncoder.EncoderPath, Arguments = GetCommandLineArgs(mediaSource, inputFile, targetFile, duration), IsHidden = true, ErrorDialog = false, - EnableRaisingEvents = true + EnableRaisingEvents = true, + WorkingDirectory = Path.GetDirectoryName(logFilePath) }); _process = process; @@ -108,14 +111,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV var commandLineLogMessage = process.StartInfo.FileName + " " + process.StartInfo.Arguments; _logger.Info(commandLineLogMessage); - var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "record-transcode-" + Guid.NewGuid() + ".txt"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath)); + _mediaEncoder.SetLogFilename(Path.GetFileName(logFilePath)); - // FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory. - _logFileStream = _fileSystem.GetFileStream(logFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true); - - var commandLineLogMessageBytes = Encoding.UTF8.GetBytes(_json.SerializeToString(mediaSource) + Environment.NewLine + Environment.NewLine + commandLineLogMessage + Environment.NewLine + Environment.NewLine); - _logFileStream.Write(commandLineLogMessageBytes, 0, commandLineLogMessageBytes.Length); + //var commandLineLogMessageBytes = Encoding.UTF8.GetBytes(_json.SerializeToString(mediaSource) + Environment.NewLine + Environment.NewLine + commandLineLogMessage + Environment.NewLine + Environment.NewLine); process.Exited += (sender, args) => OnFfMpegProcessExited(process, inputFile); @@ -128,10 +126,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV onStarted(); - // Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback - StartStreamingLog(process.StandardError.BaseStream, _logFileStream); - _logger.Info("ffmpeg recording process started for {0}", _targetPath); + _mediaEncoder.ClearLogFilename(); return _taskCompletionSource.Task; } @@ -154,7 +150,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV var durationParam = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks); var inputModifiers = "-fflags +genpts -async 1 -vsync -1"; - var commandLineArgs = "-i \"{0}\"{4} -sn {2} -map_metadata -1 -threads 0 {3} -y \"{1}\""; + var commandLineArgs = "-i \"{0}\"{4} -sn {2} -map_metadata -1 -threads 0 {3} -loglevel info -y \"{1}\""; long startTimeTicks = 0; //if (mediaSource.DateLiveStreamOpened.HasValue) @@ -234,16 +230,19 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV return output; } + private bool _isCancelled; private void Stop() { if (!_hasExited) { try { + _isCancelled = true; + _logger.Info("Killing ffmpeg recording process for {0}", _targetPath); - //process.Kill(); - _process.StandardInput.WriteLine("q"); + _process.Kill(); + //_process.StandardInput.WriteLine("q"); } catch (Exception ex) { @@ -259,11 +258,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { _hasExited = true; - DisposeLogStream(); - try { - var exitCode = process.ExitCode; + var exitCode = _isCancelled ? 0 : process.ExitCode; _logger.Info("FFMpeg recording exited with code {0} for {1}", exitCode, _targetPath); @@ -282,49 +279,5 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _taskCompletionSource.TrySetException(new Exception(string.Format("Recording for {0} failed", _targetPath))); } } - - private void DisposeLogStream() - { - if (_logFileStream != null) - { - try - { - _logFileStream.Dispose(); - } - catch (Exception ex) - { - _logger.ErrorException("Error disposing recording log stream", ex); - } - - _logFileStream = null; - } - } - - private async void StartStreamingLog(Stream source, Stream target) - { - try - { - using (var reader = new StreamReader(source)) - { - while (!reader.EndOfStream) - { - var line = await reader.ReadLineAsync().ConfigureAwait(false); - - var bytes = Encoding.UTF8.GetBytes(Environment.NewLine + line); - - await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); - await target.FlushAsync().ConfigureAwait(false); - } - } - } - catch (ObjectDisposedException) - { - // Don't spam the log. This doesn't seem to throw in windows, but sometimes under linux - } - catch (Exception ex) - { - _logger.ErrorException("Error reading ffmpeg recording log", ex); - } - } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 866a08aa1f..45aaa8e8e6 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -135,5 +135,8 @@ namespace MediaBrowser.Controller.MediaEncoding Task UpdateEncoderPath(string path, string pathType); bool SupportsEncoder(string encoder); bool IsDefaultEncoderPath { get; } + + void SetLogFilename(string name); + void ClearLogFilename(); } } diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 719083e732..a8ab1a4c0e 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -24,6 +24,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Model.Diagnostics; +using MediaBrowser.Model.System; namespace MediaBrowser.MediaEncoding.Encoder { @@ -88,9 +89,11 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly int DefaultImageExtractionTimeoutMs; private readonly bool EnableEncoderFontFile; + private readonly IEnvironmentInfo _environmentInfo; + public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, bool hasExternalEncoder, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILiveTvManager liveTvManager, IIsoManager isoManager, ILibraryManager libraryManager, IChannelManager channelManager, ISessionManager sessionManager, Func subtitleEncoder, Func mediaSourceManager, IHttpClient httpClient, IZipClient zipClient, IMemoryStreamFactory memoryStreamProvider, IProcessFactory processFactory, int defaultImageExtractionTimeoutMs, - bool enableEncoderFontFile) + bool enableEncoderFontFile, IEnvironmentInfo environmentInfo) { _logger = logger; _jsonSerializer = jsonSerializer; @@ -109,12 +112,66 @@ namespace MediaBrowser.MediaEncoding.Encoder _processFactory = processFactory; DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs; EnableEncoderFontFile = enableEncoderFontFile; + _environmentInfo = environmentInfo; FFProbePath = ffProbePath; FFMpegPath = ffMpegPath; _originalFFProbePath = ffProbePath; _originalFFMpegPath = ffMpegPath; _hasExternalEncoder = hasExternalEncoder; + + SetEnvironmentVariable(); + } + + private readonly object _logLock = new object(); + public void SetLogFilename(string name) + { + lock (_logLock) + { + try + { + _environmentInfo.SetProcessEnvironmentVariable("FFREPORT", "file=" + name + ":level=32"); + } + catch (Exception ex) + { + _logger.ErrorException("Error setting FFREPORT environment variable", ex); + } + } + } + + public void ClearLogFilename() + { + lock (_logLock) + { + try + { + _environmentInfo.SetProcessEnvironmentVariable("FFREPORT", null); + } + catch (Exception ex) + { + //_logger.ErrorException("Error setting FFREPORT environment variable", ex); + } + } + } + + private void SetEnvironmentVariable() + { + try + { + //_environmentInfo.SetProcessEnvironmentVariable("FFREPORT", "file=program-YYYYMMDD-HHMMSS.txt:level=32"); + } + catch (Exception ex) + { + _logger.ErrorException("Error setting FFREPORT environment variable", ex); + } + try + { + //_environmentInfo.SetUserEnvironmentVariable("FFREPORT", "file=program-YYYYMMDD-HHMMSS.txt:level=32"); + } + catch (Exception ex) + { + _logger.ErrorException("Error setting FFREPORT environment variable", ex); + } } public string EncoderLocationType diff --git a/MediaBrowser.Model/System/IEnvironmentInfo.cs b/MediaBrowser.Model/System/IEnvironmentInfo.cs index f9795a5684..abe39fa03d 100644 --- a/MediaBrowser.Model/System/IEnvironmentInfo.cs +++ b/MediaBrowser.Model/System/IEnvironmentInfo.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace MediaBrowser.Model.System { public interface IEnvironmentInfo @@ -13,6 +8,7 @@ namespace MediaBrowser.Model.System string OperatingSystemVersion { get; } Architecture SystemArchitecture { get; } string GetEnvironmentVariable(string name); + void SetProcessEnvironmentVariable(string name, string value); string GetUserId(); string StackTrace { get; } } From 456d5e5b760abe46c8dedf08b2465d2bd3ced4af Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 29 Nov 2016 14:39:23 -0500 Subject: [PATCH 7/7] update responses --- SocketHttpListener.Portable/Net/HttpConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SocketHttpListener.Portable/Net/HttpConnection.cs b/SocketHttpListener.Portable/Net/HttpConnection.cs index 4b54fc0139..bc4286dc8c 100644 --- a/SocketHttpListener.Portable/Net/HttpConnection.cs +++ b/SocketHttpListener.Portable/Net/HttpConnection.cs @@ -211,7 +211,7 @@ namespace SocketHttpListener.Net { context.Response.DetermineIfChunked(); - if (context.Response.SendChunked || isExpect100Continue || context.Request.IsWebSocketRequest) + if (context.Response.SendChunked || isExpect100Continue || context.Request.IsWebSocketRequest || true) { o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding); }