Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
ISO 8601 string value are now processed as TimeSpan by the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
xpouyat committed Mar 22, 2024
1 parent ff80e69 commit c1b2b0c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
42 changes: 39 additions & 3 deletions MK.IO/ConverterLE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Newtonsoft.Json;
using System.Xml;

namespace MK.IO
{
Expand All @@ -11,10 +12,11 @@ internal static class ConverterLE
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented,
Formatting = Newtonsoft.Json.Formatting.Indented,
Converters =
{
new CustomDateTimeConverter()
new CustomDateTimeConverter(),
new CustomTimeSpanConverter()
},
};
}
Expand All @@ -28,7 +30,7 @@ public override bool CanConvert(Type objectType)

public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
if (objectType == typeof(DateTime?))
if (objectType == typeof(DateTime?))
{
if (reader.Value == null)
{
Expand All @@ -54,4 +56,38 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
}
}
}

internal class CustomTimeSpanConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(TimeSpan)) || (objectType == typeof(TimeSpan?));
}

public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
if (objectType == typeof(TimeSpan?))
{
if (reader.Value == null)
{
return (TimeSpan?)null;
}
return XmlConvert.ToTimeSpan(reader.Value.ToString());
}
else if (objectType == typeof(TimeSpan))
{
return XmlConvert.ToTimeSpan(reader.Value.ToString());
}
return XmlConvert.ToTimeSpan(reader.Value.ToString());
}

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is not null and TimeSpan)
{
// convert TimeSpan to ISO 8601 format
writer.WriteValue(XmlConvert.ToString((TimeSpan)value));
}
}
}
}
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/LiveEventEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LiveEventEncoding
/// <value>Use an ISO 8601 time value between 1 and 10 seconds to specify the output fragment length for the video and audio tracks of an encoding live event. For example, use PT2S to indicate 2 seconds. For the video track it also defines the key frame interval, or the length of a GoP (group of pictures). If this value is not set for an encoding live event, the fragment duration defaults to 2 seconds. The value cannot be set for pass-through live events.</value>
[DataMember(Name = "keyFrameInterval", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "keyFrameInterval")]
public string KeyFrameInterval { get; set; }
public TimeSpan KeyFrameInterval { get; set; }

/// <summary>
/// Defaults to either Default720p or Default1080p depending on encoding type. May be used to specify alternative encoding templates - contact support for assistance if your needs are complex.
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/CsharpDotNet2/Model/LiveEventInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LiveEventInput
/// <value>ISO 8601 time duration of the key frame interval duration of the input. This value sets the EXT-X-TARGETDURATION property in the HLS output. For example, use PT2S to indicate 2 seconds. Leave the value empty for encoding live events.</value>
[DataMember(Name = "keyFrameIntervalDuration", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "keyFrameIntervalDuration")]
public string KeyFrameIntervalDuration { get; set; }
public TimeSpan KeyFrameIntervalDuration { get; set; }

/// <summary>
/// The input protocol for the live event. This is specified at creation time and cannot be updated. Must be one of RTMP or SRT. fmp4 smooth input is not supported.
Expand Down
4 changes: 2 additions & 2 deletions MK.IO/CsharpDotNet2/Model/LiveOutputProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LiveOutputProperties
/// <value>ISO 8601 timespan duration of the archive window length. This is duration that customer want to retain the recorded content.</value>
[DataMember(Name = "archiveWindowLength", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "archiveWindowLength")]
public string ArchiveWindowLength { get; set; }
public TimeSpan ArchiveWindowLength { get; set; }

/// <summary>
/// The name of the asset that the live output will write to.
Expand Down Expand Up @@ -98,7 +98,7 @@ public class LiveOutputProperties
/// <value>Not supported. ISO 8601 timespan duration of the rewind window length during live playback. This is the amount of time that the live output will be able to rewind.</value>
[DataMember(Name = "rewindWindowLength", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "rewindWindowLength")]
public string RewindWindowLength { get; set; }
public TimeSpan RewindWindowLength { get; set; }


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SampleLiveOperations.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var liveOutputAsset = client.Assets.CreateOrUpdate(nameOutputAsset, "asset-" + n

var lo = client.LiveOutputs.Create(liveEvent.Name, MKIOClient.GenerateUniqueName("liveOutput"), new LiveOutputProperties
{
ArchiveWindowLength = "PT5M",
ArchiveWindowLength = new TimeSpan(0,5,0),
AssetName = nameOutputAsset
});

Expand Down
2 changes: 1 addition & 1 deletion SampleNet7.0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static async Task MainAsync()

var lo = client.LiveOutputs.Create(le.Name, MKIOClient.GenerateUniqueName("liveOutput"), new LiveOutputProperties
{
ArchiveWindowLength = "PT5M",
ArchiveWindowLength = new TimeSpan(0,5,0),
AssetName = nameasset
});

Expand Down

0 comments on commit c1b2b0c

Please sign in to comment.