[longomatch] Adapt Video Encoder API to add ROI.
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Adapt Video Encoder API to add ROI.
- Date: Mon, 27 Apr 2015 22:23:13 +0000 (UTC)
commit be2bbef5fafe2d572f56375ceb76db40dc8ea638
Author: Julien Moutte <julien fluendo com>
Date: Mon Apr 27 15:28:18 2015 +0200
Adapt Video Encoder API to add ROI.
.../Interfaces/Multimedia/IVideoEditor.cs | 16 ++--
LongoMatch.Multimedia/Editor/GstVideoSplitter.cs | 93 ++++++++++---------
LongoMatch.Services/RenderingJobsManager.cs | 13 ++-
Tests/Services/TestRenderingJobsManager.cs | 6 +-
libcesarplayer/gst-video-editor.c | 6 +-
libcesarplayer/gst-video-editor.h | 6 +-
6 files changed, 76 insertions(+), 64 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Multimedia/IVideoEditor.cs
b/LongoMatch.Core/Interfaces/Multimedia/IVideoEditor.cs
index c8e952b..c813fac 100644
--- a/LongoMatch.Core/Interfaces/Multimedia/IVideoEditor.cs
+++ b/LongoMatch.Core/Interfaces/Multimedia/IVideoEditor.cs
@@ -31,23 +31,23 @@ namespace LongoMatch.Core.Interfaces.Multimedia
event ProgressHandler Progress;
event ErrorHandler Error;
- EncodingSettings EncodingSettings{
+ EncodingSettings EncodingSettings {
set;
}
-
+
string TempDir {
set;
}
- void AddSegment(string filePath, long start, long duration, double rate, string title, bool
hasAudio) ;
-
- void AddImageSegment(string filePath, long start, long duration, string title) ;
+ void AddSegment (string filePath, long start, long duration, double rate, string title, bool
hasAudio, Area roi) ;
+
+ void AddImageSegment (string filePath, long start, long duration, string title, Area roi) ;
- void ClearList();
+ void ClearList ();
- void Start();
+ void Start ();
- void Cancel();
+ void Cancel ();
}
}
diff --git a/LongoMatch.Multimedia/Editor/GstVideoSplitter.cs
b/LongoMatch.Multimedia/Editor/GstVideoSplitter.cs
index c5630b6..2ce40e2 100644
--- a/LongoMatch.Multimedia/Editor/GstVideoSplitter.cs
+++ b/LongoMatch.Multimedia/Editor/GstVideoSplitter.cs
@@ -30,13 +30,13 @@ namespace LongoMatch.Video.Editor
public class GstVideoSplitter : GLib.Object, IVideoEditor
{
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern unsafe IntPtr gst_video_editor_new (out IntPtr err);
public event LongoMatch.Core.Handlers.ProgressHandler Progress;
public event LongoMatch.Core.Handlers.ErrorHandler Error;
- public unsafe GstVideoSplitter () : base(IntPtr.Zero)
+ public unsafe GstVideoSplitter () : base (IntPtr.Zero)
{
if (GetType () != typeof(GstVideoSplitter)) {
throw new InvalidOperationException ("Can't override this constructor.");
@@ -80,7 +80,7 @@ namespace LongoMatch.Video.Editor
OverrideVirtualMethod (gtype, "error", ErrorVMCallback);
}
- [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.Video.Editor.GstVideoSplitter),
ConnectionMethod="OverrideError")]
+ [GLib.DefaultSignalHandler (Type = typeof(LongoMatch.Video.Editor.GstVideoSplitter),
ConnectionMethod = "OverrideError")]
protected virtual void OnError (string message)
{
GLib.Value ret = GLib.Value.Empty;
@@ -95,7 +95,7 @@ namespace LongoMatch.Video.Editor
v.Dispose ();
}
- [GLib.Signal("error")]
+ [GLib.Signal ("error")]
public event GlibErrorHandler InternalError {
add {
GLib.Signal sig = GLib.Signal.Lookup (this, "error", typeof(ErrorArgs));
@@ -129,7 +129,7 @@ namespace LongoMatch.Video.Editor
OverrideVirtualMethod (gtype, "percent_completed", PercentCompletedVMCallback);
}
- [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.Video.Editor.GstVideoSplitter),
ConnectionMethod="OverridePercentCompleted")]
+ [GLib.DefaultSignalHandler (Type = typeof(LongoMatch.Video.Editor.GstVideoSplitter),
ConnectionMethod = "OverridePercentCompleted")]
protected virtual void OnPercentCompleted (float percent)
{
GLib.Value ret = GLib.Value.Empty;
@@ -144,7 +144,7 @@ namespace LongoMatch.Video.Editor
v.Dispose ();
}
- [GLib.Signal("percent_completed")]
+ [GLib.Signal ("percent_completed")]
public event GlibPercentCompletedHandler PercentCompleted {
add {
GLib.Signal sig = GLib.Signal.Lookup (this, "percent_completed",
typeof(PercentCompletedArgs));
@@ -157,8 +157,10 @@ namespace LongoMatch.Video.Editor
}
#pragma warning disable 0169
#endregion
+
#region Public Methods
- [DllImport("libcesarplayer.dll")]
+
+ [DllImport ("libcesarplayer.dll")]
static extern IntPtr gst_video_editor_get_type ();
public static new GLib.GType GType {
@@ -169,7 +171,7 @@ namespace LongoMatch.Video.Editor
}
}
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern void gst_video_editor_clear_segments_list (IntPtr raw);
public void ClearList ()
@@ -177,23 +179,25 @@ namespace LongoMatch.Video.Editor
gst_video_editor_clear_segments_list (Handle);
}
- [DllImport("libcesarplayer.dll")]
- static extern void gst_video_editor_add_segment (IntPtr raw, string file_path, long start,
long duration, double rate, IntPtr title, bool hasAudio);
+ [DllImport ("libcesarplayer.dll")]
+ static extern void gst_video_editor_add_segment (IntPtr raw, string file_path, long start,
long duration, double rate, IntPtr title, bool hasAudio,
+ uint roi_x, uint roi_y, uint roi_w, uint
roi_h);
- public void AddSegment (string filePath, long start, long duration, double rate, string
title, bool hasAudio)
+ public void AddSegment (string filePath, long start, long duration, double rate, string
title, bool hasAudio, Area roi)
{
- gst_video_editor_add_segment (Handle, filePath, start, duration, rate,
GLib.Marshaller.StringToPtrGStrdup (title), true);
+ gst_video_editor_add_segment (Handle, filePath, start, duration, rate,
GLib.Marshaller.StringToPtrGStrdup (title), true, (uint)roi.Start.X, (uint)roi.Start.Y, (uint)roi.Width,
(uint)roi.Height);
}
- [DllImport("libcesarplayer.dll")]
- static extern void gst_video_editor_add_image_segment (IntPtr raw, string file_path, long
start, long duration, IntPtr title);
+ [DllImport ("libcesarplayer.dll")]
+ static extern void gst_video_editor_add_image_segment (IntPtr raw, string file_path, long
start, long duration, IntPtr title,
+ uint roi_x, uint roi_y, uint roi_w,
uint roi_h);
- public void AddImageSegment (string filePath, long start, long duration, string title)
+ public void AddImageSegment (string filePath, long start, long duration, string title, Area
roi)
{
- gst_video_editor_add_image_segment (Handle, filePath, start, duration,
GLib.Marshaller.StringToPtrGStrdup (title));
+ gst_video_editor_add_image_segment (Handle, filePath, start, duration,
GLib.Marshaller.StringToPtrGStrdup (title), (uint)roi.Start.X, (uint)roi.Start.Y, (uint)roi.Width,
(uint)roi.Height);
}
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern void gst_video_editor_start (IntPtr raw);
public void Start ()
@@ -201,7 +205,7 @@ namespace LongoMatch.Video.Editor
gst_video_editor_start (Handle);
}
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern void gst_video_editor_cancel (IntPtr raw);
public void Cancel ()
@@ -213,7 +217,7 @@ namespace LongoMatch.Video.Editor
}
}
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern void gst_video_editor_init_backend (out int argc, IntPtr argv);
public static int InitBackend (string argv)
@@ -223,36 +227,36 @@ namespace LongoMatch.Video.Editor
return argc;
}
- [DllImport("libcesarplayer.dll")]
+ [DllImport ("libcesarplayer.dll")]
static extern bool gst_video_editor_set_encoding_format (IntPtr raw,
- string output_file,
- VideoEncoderType video_codec,
- AudioEncoderType audio_codec,
- VideoMuxerType muxer,
- uint video_quality,
- uint audio_quality,
- uint width,
- uint height,
- uint fps_n,
- uint fps_d,
- bool enable_audio,
- bool enable_video);
+ string output_file,
+ VideoEncoderType video_codec,
+ AudioEncoderType audio_codec,
+ VideoMuxerType muxer,
+ uint video_quality,
+ uint audio_quality,
+ uint width,
+ uint height,
+ uint fps_n,
+ uint fps_d,
+ bool enable_audio,
+ bool enable_video);
public EncodingSettings EncodingSettings {
set {
gst_video_editor_set_encoding_format (Handle,
- value.OutputFile,
- value.EncodingProfile.VideoEncoder,
- value.EncodingProfile.AudioEncoder,
- value.EncodingProfile.Muxer,
- value.EncodingQuality.VideoQuality,
- value.EncodingQuality.AudioQuality,
- value.VideoStandard.Width,
- value.VideoStandard.Height,
- value.Framerate_n,
- value.Framerate_d,
- value.EnableAudio,
- value.EnableTitle);
+ value.OutputFile,
+ value.EncodingProfile.VideoEncoder,
+ value.EncodingProfile.AudioEncoder,
+ value.EncodingProfile.Muxer,
+ value.EncodingQuality.VideoQuality,
+ value.EncodingQuality.AudioQuality,
+ value.VideoStandard.Width,
+ value.VideoStandard.Height,
+ value.Framerate_n,
+ value.Framerate_d,
+ value.EnableAudio,
+ value.EnableTitle);
}
}
@@ -261,6 +265,7 @@ namespace LongoMatch.Video.Editor
;
}
}
+
#endregion
}
}
diff --git a/LongoMatch.Services/RenderingJobsManager.cs b/LongoMatch.Services/RenderingJobsManager.cs
index c79893c..fbc7518 100644
--- a/LongoMatch.Services/RenderingJobsManager.cs
+++ b/LongoMatch.Services/RenderingJobsManager.cs
@@ -204,7 +204,7 @@ namespace LongoMatch.Services
{
string path = System.IO.Path.GetTempFileName ().Replace (@"\", @"\\");
image.Save (path);
- videoEditor.AddImageSegment (path, 0, duration.MSeconds, "");
+ videoEditor.AddImageSegment (path, 0, duration.MSeconds, "", new Area ());
}
void ProcessImage (PlaylistImage image)
@@ -218,7 +218,7 @@ namespace LongoMatch.Services
{
Log.Debug ("Adding external video " + video.File.FilePath);
videoEditor.AddSegment (video.File.FilePath, 0, video.File.Duration.MSeconds,
- 1, "", video.File.HasAudio);
+ 1, "", video.File.HasAudio, new Area ());
}
void ProcessDrawing (PlaylistDrawing drawing)
@@ -239,6 +239,7 @@ namespace LongoMatch.Services
MediaFile file;
IEnumerable<FrameDrawing> drawings;
int cameraIndex;
+ Area roi;
play = element.Play;
Log.Debug (String.Format ("Adding segment with {0} drawings", play.Drawings.Count));
@@ -246,8 +247,10 @@ namespace LongoMatch.Services
lastTS = play.Start;
if (element.CamerasConfig.Count == 0) {
cameraIndex = 0;
+ roi = new Area ();
} else {
cameraIndex = element.CamerasConfig [0].Index;
+ roi = element.CamerasConfig [0].RegionOfInterest;
}
if (cameraIndex >= element.FileSet.Count) {
Log.Error (string.Format ("Camera index={0} not matching for current fileset
count={1}",
@@ -276,13 +279,13 @@ namespace LongoMatch.Services
}
videoEditor.AddSegment (file.FilePath, lastTS.MSeconds,
fd.Render.MSeconds - lastTS.MSeconds,
- element.Rate, play.Name, file.HasAudio);
- videoEditor.AddImageSegment (image_path, 0, fd.Pause.MSeconds, play.Name);
+ element.Rate, play.Name, file.HasAudio, roi);
+ videoEditor.AddImageSegment (image_path, 0, fd.Pause.MSeconds, play.Name,
fd.RegionOfInterest);
lastTS = fd.Render;
}
videoEditor.AddSegment (file.FilePath, lastTS.MSeconds,
play.Stop.MSeconds - lastTS.MSeconds,
- element.Rate, play.Name, file.HasAudio);
+ element.Rate, play.Name, file.HasAudio, roi);
return true;
}
diff --git a/Tests/Services/TestRenderingJobsManager.cs b/Tests/Services/TestRenderingJobsManager.cs
index 9c970c8..b96f23b 100644
--- a/Tests/Services/TestRenderingJobsManager.cs
+++ b/Tests/Services/TestRenderingJobsManager.cs
@@ -69,7 +69,7 @@ namespace Tests.Services
// Check that AddSegment is called with the right video file.
mock.Verify (m => m.AddSegment (p.Description.FileSet [0].FilePath,
- evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true),
Times.Once ());
+ evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true, new
Area ()), Times.Once ());
/* Test with a camera index bigger than the total cameras */
renderer.CancelAllJobs ();
@@ -81,7 +81,7 @@ namespace Tests.Services
job = new EditionJob (playlist, settings);
renderer.AddJob (job);
mock.Verify (m => m.AddSegment (p.Description.FileSet [1].FilePath,
- evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true),
Times.Once ());
+ evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true, new
Area ()), Times.Once ());
/* Test with the secondary camera */
renderer.CancelAllJobs ();
@@ -93,7 +93,7 @@ namespace Tests.Services
job = new EditionJob (playlist, settings);
renderer.AddJob (job);
mock.Verify (m => m.AddSegment (p.Description.FileSet [0].FilePath,
- evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true),
Times.Once ());
+ evt.Start.MSeconds, evt.Stop.MSeconds, evt.Rate, evt.Name, true, new
Area ()), Times.Once ());
} finally {
Utils.DeleteProject (p);
}
diff --git a/libcesarplayer/gst-video-editor.c b/libcesarplayer/gst-video-editor.c
index bbb8b2b..bc57d9e 100644
--- a/libcesarplayer/gst-video-editor.c
+++ b/libcesarplayer/gst-video-editor.c
@@ -498,7 +498,8 @@ gve_on_buffer_cb (GstPad * pad, GstBuffer * buf, GstVideoEditor * gve)
void
gst_video_editor_add_segment (GstVideoEditor * gve, gchar * file,
gint64 start, gint64 duration, gdouble rate,
- gchar * title, gboolean hasAudio)
+ gchar * title, gboolean hasAudio,
+ guint roi_x, guint roi_y, guint roi_w, guint roi_h)
{
GstState cur_state;
@@ -525,7 +526,8 @@ gst_video_editor_add_segment (GstVideoEditor * gve, gchar * file,
void
gst_video_editor_add_image_segment (GstVideoEditor * gve, gchar * file,
- guint64 start, gint64 duration, gchar * title)
+ guint64 start, gint64 duration, gchar * title,
+ guint roi_x, guint roi_y, guint roi_w, guint roi_h)
{
GstState cur_state;
diff --git a/libcesarplayer/gst-video-editor.h b/libcesarplayer/gst-video-editor.h
index 0951c8c..088b540 100644
--- a/libcesarplayer/gst-video-editor.h
+++ b/libcesarplayer/gst-video-editor.h
@@ -86,8 +86,10 @@ EXPORT void gst_video_editor_set_encoding_format (GstVideoEditor *
EXPORT void gst_video_editor_clear_segments_list (GstVideoEditor * gve);
EXPORT void gst_video_editor_add_segment (GstVideoEditor * gve,
gchar * file, gint64 start,
- gint64 duration, gdouble rate, gchar * title, gboolean hasAudio);
+ gint64 duration, gdouble rate, gchar * title, gboolean hasAudio,
+ guint roi_x, guint roi_y, guint roi_w, guint roi_h);
EXPORT void gst_video_editor_add_image_segment (GstVideoEditor * gve, gchar * file,
- guint64 start, gint64 duration, gchar * title);
+ guint64 start, gint64 duration, gchar * title,
+ guint roi_x, guint roi_y, guint roi_w, guint roi_h);
G_END_DECLS
#endif /* _GST_VIDEO_EDITOR_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]