Skip to content

Commit

Permalink
Allow to play more than 1 segment
Browse files Browse the repository at this point in the history
  • Loading branch information
spektor56 committed May 3, 2022
1 parent d8ddab4 commit 9386a3f
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 93 deletions.
14 changes: 6 additions & 8 deletions OpenpilotSdk/Hardware/OpenpilotDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public async Task<Bitmap> GetThumbnailAsync(DriveSegment driveSegment)
await ConnectAsync();

Bitmap thumbnail = null;
var drive = new DirectoryInfo(Path.GetDirectoryName(driveSegment.FrontVideo.File.FullName)).Name;
var videoFile = driveSegment.FrontVideoQuick ?? driveSegment.FrontVideo;
var drive = new DirectoryInfo(Path.GetDirectoryName(videoFile.File.FullName)).Name;
var cachedThumbnail = Path.Combine(TempDirectory, drive + ".jpg");


Expand All @@ -389,7 +390,6 @@ public async Task<Bitmap> GetThumbnailAsync(DriveSegment driveSegment)
bool quickVideo = driveSegment.FrontVideoQuick != null;
var offset = 0;

var videoFile = driveSegment.FrontVideoQuick ?? driveSegment.FrontVideo;
var imageBuffer = quickVideo ? new byte[10000] : new byte[200000];

await using (var sftpFileStream = SftpClient.OpenRead(videoFile.File.FullName))
Expand All @@ -407,7 +407,7 @@ public async Task<Bitmap> GetThumbnailAsync(DriveSegment driveSegment)
try
{
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(msInput), options => options.WithFramerate(20).ForceFormat(quickVideo ? "mpegts" : "rawvideo"))
.FromPipeInput(new StreamPipeSource(msInput), options => options.WithFramerate(20))
.OutputToPipe(new StreamPipeSink(msOutput), options =>
options.WithVideoCodec(VideoCodec.Png)
.WithFrameOutputCount(1)
Expand Down Expand Up @@ -591,9 +591,7 @@ public async Task<IEnumerable<Firmware>> GetFirmwareVersions(IProgress<int> prog

var firmwares = new List<Firmware>();

var drives = GetDrives();

foreach (var drive in drives)
await foreach (var drive in GetDrivesAsync())
{
foreach (var driveSegment in drive.Segments.OrderBy(segment => segment.Index))
{
Expand Down Expand Up @@ -668,7 +666,7 @@ public async Task<GpxFile> GenerateGpxFileAsync(Drive drive, IProgress<int> prog

public async IAsyncEnumerable<Drive> GetDrivesAsync([EnumeratorCancellation]CancellationToken cancellationToken = default(CancellationToken))
{
await ConnectAsync();
await ConnectAsync(cancellationToken);

IOrderedEnumerable<IGrouping<DateTime, SftpFile>> directoryListing;

Expand All @@ -680,7 +678,7 @@ public async Task<GpxFile> GenerateGpxFileAsync(Drive drive, IProgress<int> prog
{
return DateTime.ParseExact(dir.Name.AsSpan().Slice(0, 20), "yyyy-MM-dd--HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
})
.OrderBy(dir =>
.OrderByDescending(dir =>
{
var date = dir.Key;
return date;
Expand Down
2 changes: 1 addition & 1 deletion OpenpilotSdk/OpenpilotSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="NetTopologySuite" Version="2.4.0" />
<PackageReference Include="NetTopologySuite.IO.GPX" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
Expand Down
166 changes: 145 additions & 21 deletions OpenpilotToolkit/Controls/Media/VideoPlayer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9386a3f

Please sign in to comment.