From 852f684d82206ffc66566d16e6b4caf8dc339057 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 16 Nov 2026 17:21:38 +0000 Subject: [PATCH] =?UTF-8?q?Porter=20l'=C3=A9diteur=20du=20replay=20sur=20A?= =?UTF-8?q?ndroid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En portrait, le panneau des marques et des plages passe sous la vidéo native. La barre native du replay affiche l'image pendant le glissement (dernière position, au plus toutes les 60 ms). Les miniatures des marques sont copiées depuis la surface native avec PixelCopy via la nouvelle interface IVideoFrameCapture, l'instantané LibVLC ne lisant pas le décodage matériel. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 + doc/video-edition.md | 21 +++++-- .../Services/AndroidVideoSurface.cs | 57 +++++++++++++++++-- src/PostIt/PostIt.Tests/ReplayEditorTests.cs | 37 ++++++++++++ .../PostIt/Services/IVideoFrameCapture.cs | 15 +++++ .../PostIt/Views/Video/ReplayEditorPage.axaml | 12 ++-- .../Views/Video/ReplayEditorPage.axaml.cs | 29 +++++++++- 7 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 src/PostIt/PostIt/Services/IVideoFrameCapture.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9732594a8..d06589982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Added +* [PostIt/Android] Port the replay draft editor to Android: the page stacks the mark and range panel under the native video in portrait, the native replay seek bar previews the dragged position (latest position only, at most every 60 ms, shared `ReplayControlsState`), and mark thumbnails are copied from the native surface with `PixelCopy` through the new `IVideoFrameCapture`, since the LibVLC snapshot cannot read hardware-decoded output. + * [Podcasts] Publish named marks as replay chapters: the draft stores optional mark titles (`Chapters`, at most 120 characters, a title's time is also a mark, titles of removed marks are dropped). Publication converts their times to the published timeline, embeds them in the MP4 with an FFmpeg stream copy (titles only go through an escaped metadata file) and exposes them in `PodcastResponse.Chapters`. The PostIt editor names marks, and the PostIt replay player and the web podcasts page list the chapters as buttons that seek the replay. * [PostIt/Podcasts] Add the desktop replay draft editor: from the refinement panel, the owner plays the private draft source, steps frame by frame, adds marks at the current time (Ctrl+M) with local thumbnails, picks start and end marks to remove ranges, restores ranges, then saves with the read revision (a conflict keeps local edits and asks for a reload) or publishes after saving pending edits. `ReplayEditPlan` moves to `Yavsc.Abstract` so the editor merges and validates ranges like the server. diff --git a/doc/video-edition.md b/doc/video-edition.md index e7e2f600f..1a40864cf 100644 --- a/doc/video-edition.md +++ b/doc/video-edition.md @@ -65,8 +65,8 @@ Le lecteur de direct utilise les segments et rejoint le flux près du direct. Sur ordinateur, les contrôles du lecteur sont des contrôles Avalonia. Sur Android, la surface vidéo et ses commandes sont natives. Sur desktop, le curseur de replay met à jour l'image pendant son déplacement (voir le résultat -du prototype ci-dessous) ; sur Android, la recherche n'est encore validée qu'au -relâchement. +du prototype ci-dessous) ; la barre native Android fait de même, avec la même +coalescence des positions (voir « Éditeur Android »). Les captures PostIt desktop et Android n'utilisent pas le même pipeline média. @@ -308,9 +308,20 @@ Le brouillon privé est implémenté côté serveur, et son éditeur sur PostIt copie de la source. `PodcastResponse.Chapters` expose les chapitres publiés à tous les auditeurs ; le site web les affiche en boutons sous le lecteur du MP4 et PostIt dans le lecteur du replay, chacun positionnant la lecture. +- **Éditeur Android** : la même page et le même modèle de vue s'ouvrent + depuis les podcasts Android, sur la surface vidéo native. En portrait, le + panneau des marques et des plages passe sous la vidéo et défile seul (la + surface native reste hors du défilement) ; en paysage, il reste à droite. + Pendant le glissement, la barre native n'envoie au lecteur que la dernière + position demandée, au plus toutes les 60 ms (`ReplayControlsState`, partagé + avec desktop), et applique la position finale au relâchement. L'instantané + LibVLC ne lit pas la sortie du décodage matériel : la surface Android + implémente `IVideoFrameCapture` et copie l'image affichée avec `PixelCopy` + (Android 7 et plus ; sans miniature avant), directement en mémoire. - **Reste à faire** : miniatures des marques rechargées depuis le serveur - (elles ne sont créées qu'à la pose), éditeur Android et validation sur de - vrais médias. + (elles ne sont créées qu'à la pose), validation sur de vrais médias et + essais de l'éditeur Android sur appareil (réactivité du glissement sur un + long replay distant, précision du pas image par image). Une émission interrompue doit rester récupérable par son auteur. Lorsqu'un direct programmé s'arrête après le délai « Direct interrompu », ou qu'un @@ -414,7 +425,7 @@ différent de celui annoncé à l'auteur. 4. Valider la finalisation sur de vrais médias synthétiques et conserver le comportement existant pour les émissions sans raffinage. 5. Porter l'éditeur sur Android (surface native), en réutilisant l'API et le - traitement serveur. + traitement serveur (fait, essais sur appareil à mener). 6. Étudier la composition live, d'abord sur desktop puis sur Android, avant d'engager les génériques et les incrustations. diff --git a/src/PostIt/PostIt.Android/Services/AndroidVideoSurface.cs b/src/PostIt/PostIt.Android/Services/AndroidVideoSurface.cs index 215883a44..937d05e70 100644 --- a/src/PostIt/PostIt.Android/Services/AndroidVideoSurface.cs +++ b/src/PostIt/PostIt.Android/Services/AndroidVideoSurface.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Threading; using System.Threading.Tasks; using Avalonia.Android; using Avalonia.Controls; @@ -14,7 +16,8 @@ using Button = Android.Widget.Button; namespace PostIt.Android.Services; -internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool showControls = false, Action? playbackFailed = null) : NativeControlHost, IDisposable +internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool showControls = false, Action? playbackFailed = null) + : NativeControlHost, IDisposable, IVideoFrameCapture { private VideoView? _video; private ReplayLayout? _layout; @@ -71,6 +74,30 @@ internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool if (_video is not null) _video.MediaPlayer = null; } + /// Copies the displayed frame with , which also reads hardware-decoded video. + public async Task CaptureFrameAsync(int width, CancellationToken ct) + { + if (!OperatingSystem.IsAndroidVersionAtLeast(24) || _disposed + || _video is not { Width: > 0, Height: > 0, Holder.Surface.IsValid: true } video) return null; + var height = Math.Max(1, (int)Math.Round(width * (double)video.Height / video.Width)); + using var bitmap = global::Android.Graphics.Bitmap.CreateBitmap(width, height, global::Android.Graphics.Bitmap.Config.Argb8888!); + using var listener = new PixelCopyListener(); + using var registration = ct.Register(() => listener.Result.TrySetCanceled(ct)); + using var handler = new Handler(Looper.MainLooper!); + PixelCopy.Request(video, bitmap, listener, handler); + if (await listener.Result.Task != (int)PixelCopyResult.Success) return null; + using var png = new MemoryStream(); + if (!bitmap.Compress(global::Android.Graphics.Bitmap.CompressFormat.Png!, 100, png)) return null; + png.Position = 0; + return new Avalonia.Media.Imaging.Bitmap(png); + } + + private sealed class PixelCopyListener : Java.Lang.Object, PixelCopy.IOnPixelCopyFinishedListener + { + public TaskCompletionSource Result { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously); + public void OnPixelCopyFinished(int copyResult) => Result.TrySetResult(copyResult); + } + private void OnPlaybackChanged(object? sender, EventArgs e) => Avalonia.Threading.Dispatcher.UIThread.Post(UpdateScreenAwake); @@ -106,6 +133,7 @@ internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool private readonly ReplayControlsState _state = new(); private readonly Handler _handler = new(Looper.MainLooper!); private readonly Java.Lang.Runnable _tick; + private readonly Java.Lang.Runnable _preview; private readonly LinearLayout _bar; private readonly Button _toggle; private readonly SeekBar _seek; @@ -137,6 +165,7 @@ internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool _seek.StopTrackingTouch += EndSeek; _seek.ProgressChanged += ProgressChanged; _tick = new Java.Lang.Runnable(Update); + _preview = new Java.Lang.Runnable(ApplyPreview); _handler.Post(_tick); } @@ -168,19 +197,37 @@ internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool _state.Show(); } - private void BeginSeek(object? sender, SeekBar.StartTrackingTouchEventArgs e) => _state.IsInteracting = true; + private void BeginSeek(object? sender, SeekBar.StartTrackingTouchEventArgs e) + { + _state.IsInteracting = true; + _handler.PostDelayed(_preview, 60); + } private void EndSeek(object? sender, SeekBar.StopTrackingTouchEventArgs e) { + _handler.RemoveCallbacks(_preview); + _state.EndPreview(); Seek(); _state.IsInteracting = false; } private void ProgressChanged(object? sender, SeekBar.ProgressChangedEventArgs e) { - if (e.FromUser && !_state.IsInteracting) Seek(); + if (!e.FromUser) return; + if (_state.IsInteracting) _state.RequestPreview(PositionOf(_seek.Progress)); + else Seek(); } + + /// Shows the frame under the thumb while dragging: only the latest position is sent, at most every 60 ms. + private void ApplyPreview() + { + if (_stopped || !_state.IsInteracting) return; + if (_player.IsSeekable && _state.TryTakePreview(out var time)) _player.Time = time; + _handler.PostDelayed(_preview, 60); + } + + private long PositionOf(int progress) => (long)(_player.Length * (progress / 10000d)); private void Seek() { - if (_player.IsSeekable) _player.Time = (long)(_player.Length * (_seek.Progress / 10000d)); + if (_player.IsSeekable) _player.Time = PositionOf(_seek.Progress); _state.Show(); } @@ -189,11 +236,13 @@ internal sealed class AndroidVideoSurface(MediaPlayer player, bool replay, bool if (_stopped) return; _stopped = true; _handler.RemoveCallbacks(_tick); + _handler.RemoveCallbacks(_preview); _toggle.Click -= Toggle; _seek.StartTrackingTouch -= BeginSeek; _seek.StopTrackingTouch -= EndSeek; _seek.ProgressChanged -= ProgressChanged; _tick.Dispose(); + _preview.Dispose(); _handler.Dispose(); } } diff --git a/src/PostIt/PostIt.Tests/ReplayEditorTests.cs b/src/PostIt/PostIt.Tests/ReplayEditorTests.cs index 7cdd81d91..f0a532b30 100644 --- a/src/PostIt/PostIt.Tests/ReplayEditorTests.cs +++ b/src/PostIt/PostIt.Tests/ReplayEditorTests.cs @@ -1,5 +1,8 @@ using System.Net; +using Avalonia.Controls; +using Avalonia.Threading; using PostIt.ViewModels; +using PostIt.Views.Blogs; using Yavsc.Abstract.Streaming; using Yavsc.Api.Client; @@ -178,6 +181,40 @@ public sealed class ReplayEditorTests(AvaloniaUiFixture ui) return Task.CompletedTask; }, TestContext.Current.CancellationToken); + [Fact] + public Task The_editor_stacks_its_panel_under_the_video_in_portrait() + => ui.RunAsync(async () => + { + var api = new DraftApi(); + // Without a draft source the page skips the native player. + api.Podcast = api.Podcast with { Draft = api.Podcast.Draft! with { SourceBytes = 0 } }; + var page = new ReplayEditorPage { DataContext = Editor(api) }; + var nav = new NavigationPage(); + await nav.PushAsync(page); + var window = new Window { Width = 360, Height = 800, Content = nav }; + try + { + window.Show(); + foreach (var (width, height) in new[] { (360, 800), (1000, 500), (360, 800) }) + { + window.Width = width; + window.Height = height; + Dispatcher.UIThread.RunJobs(); + window.UpdateLayout(); + + var wide = width >= height; + var grid = page.FindControl("EditorGrid")!; + var panel = page.FindControl("EditPanel")!; + Assert.Equal(wide ? 2 : 1, grid.ColumnDefinitions.Count); + Assert.Equal(wide ? 1 : 0, Grid.GetColumn(panel)); + Assert.Equal(wide ? 1 : 4, Grid.GetRow(panel)); + Assert.True(panel.Bounds.Top >= (wide ? 0 : page.FindControl("VideoBorder")!.Bounds.Bottom)); + } + Assert.Contains("source du brouillon", page.FindControl("PlaybackStatus")!.Text); + } + finally { window.Close(); } + }, TestContext.Current.CancellationToken); + private static ReplayEditorPageViewModel Editor(DraftApi api) => new(new PodcastApiClient(api, () => "https://api.example/"), api.Podcast); diff --git a/src/PostIt/PostIt/Services/IVideoFrameCapture.cs b/src/PostIt/PostIt/Services/IVideoFrameCapture.cs new file mode 100644 index 000000000..4a7430624 --- /dev/null +++ b/src/PostIt/PostIt/Services/IVideoFrameCapture.cs @@ -0,0 +1,15 @@ +using System.Threading; +using System.Threading.Tasks; +using Avalonia.Media.Imaging; + +namespace PostIt.Services; + +/// +/// Copies the frame displayed by a native video surface, for platforms where the LibVLC snapshot cannot read +/// hardware-decoded output. The image stays in memory. +/// +public interface IVideoFrameCapture +{ + /// Returns the displayed frame scaled to pixels, or null when no frame is available. + Task CaptureFrameAsync(int width, CancellationToken ct); +} diff --git a/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml b/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml index eb642fc43..19ee99cff 100644 --- a/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml +++ b/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml @@ -5,21 +5,21 @@ xmlns:vm="using:PostIt.ViewModels" xmlns:abs="using:Yavsc.Abstract.Streaming" x:DataType="vm:ReplayEditorPageViewModel"> - - - + + + - +