[vlc-commits] commit: vmem: By default keep the original image aspect ratio. (Pierre d' Herbemont )

git at videolan.org git at videolan.org
Sun Oct 31 11:17:46 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Sun Oct 31 10:53:57 2010 +0100| [4d9bf01bb1bad90a28100e2a80bb1482b0997a54] | committer: Pierre d'Herbemont 

vmem: By default keep the original image aspect ratio.

Old behavior is accessible via vmem-preserve-aspect-ratio.

I believe this is the most sensitive defaults even though this is not the current libvlc API. I wouldn't expect client breakage, but I may be mistaken here. Please shout if so.

(Note, This is being used to do the iOS thumbnailing)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4d9bf01bb1bad90a28100e2a80bb1482b0997a54
---

 modules/video_output/vmem.c |   50 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c
index f1c3fb4..135a0f9 100644
--- a/modules/video_output/vmem.c
+++ b/modules/video_output/vmem.c
@@ -52,6 +52,10 @@
 #define LT_CHROMA N_("Output chroma for the memory image as a 4-character " \
                       "string, eg. \"RV32\".")
 
+#define T_RATIO N_("Preserve aspect ratio")
+#define LT_RATIO N_("Preserve original video image aspect ratio when " \
+                     "rendering to the given video memory buffer.")
+
 static int  Open (vlc_object_t *);
 static void Close(vlc_object_t *);
 
@@ -71,6 +75,7 @@ vlc_module_begin()
         change_private()
     add_string("vmem-chroma", "RV16", T_CHROMA, LT_CHROMA, true)
         change_private()
+    add_bool("vmem-preserve-aspect-ratio", true, T_RATIO, LT_RATIO, true)
     add_obsolete_string("vmem-lock") /* obsoleted since 1.1.1 */
     add_obsolete_string("vmem-unlock") /* obsoleted since 1.1.1 */
     add_obsolete_string("vmem-data") /* obsoleted since 1.1.1 */
@@ -83,11 +88,15 @@ vlc_module_end()
  *****************************************************************************/
 struct picture_sys_t {
     vout_display_sys_t *sys;
+    void *original_planes[PICTURE_PLANE_MAX]; /** planes sent by the client */
     void *id;
 };
 
 struct vout_display_sys_t {
     picture_pool_t *pool;
+    vout_display_place_t place;
+    int vmem_pitch;
+    int vmem_width;
     void *(*lock)(void *sys, void **plane);
     void (*unlock)(void *sys, void *id, void *const *plane);
     void (*display)(void *sys, void *id);
@@ -173,8 +182,27 @@ static int Open(vlc_object_t *object)
     sys->display = var_InheritAddress(vd, "vmem-display");
     sys->opaque = var_InheritAddress(vd, "vmem-data");
 
+    sys->vmem_width = fmt.i_width;
+
+    const bool keep_ratio = var_InheritBool(vd, "vmem-preserve-aspect-ratio");
+    if (keep_ratio) {
+        /* place the picture */
+        vout_display_cfg_t place_cfg = *vd->cfg;
+        place_cfg.display.width  = fmt.i_width;
+        place_cfg.display.height = fmt.i_height;
+        vout_display_PlacePicture(&sys->place, &vd->source, &place_cfg, false);
+
+
+        /* Request a slightly different picture */
+        fmt.i_width = vd->sys->place.width;
+        fmt.i_height = vd->sys->place.height;
+    } else {
+        sys->place.width = fmt.i_width;
+        sys->place.height = fmt.i_height;
+    }
+
     /* */
-    const int pitch = var_InheritInteger(vd, "vmem-pitch");
+    sys->vmem_pitch = var_InheritInteger(vd, "vmem-pitch");
     picture_resource_t rsc;
     rsc.p_sys = malloc(sizeof(*rsc.p_sys));
     if(unlikely(!rsc.p_sys)) {
@@ -186,8 +214,8 @@ static int Open(vlc_object_t *object)
     for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
         /* vmem-lock is responsible for the allocation */
         rsc.p[i].p_pixels = NULL;
-        rsc.p[i].i_lines  = fmt.i_height;
-        rsc.p[i].i_pitch  = pitch;
+        rsc.p[i].i_lines  = sys->place.height;
+        rsc.p[i].i_pitch  = sys->vmem_pitch;
     }
     picture_t *picture = picture_NewFromResource(&fmt, &rsc);
     if (!picture) {
@@ -266,6 +294,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
             return VLC_EGENERIC;
         if (cfg->is_fullscreen)
             return VLC_EGENERIC;
+
         return VLC_SUCCESS;
     }
     default:
@@ -286,8 +315,17 @@ static int Lock(picture_t *picture)
 
     picsys->id = sys->lock(sys->opaque, planes);
 
-    for (int i = 0; i < picture->i_planes; i++)
-        picture->p[i].p_pixels = planes[i];
+    const int y = sys->place.y;
+    const int x = sys->place.x;
+    const int pitch = sys->vmem_pitch;
+    const int bbp = pitch / sys->vmem_width;
+
+    for (int i = 0; i < picture->i_planes; i++) {
+        uint8_t *p = planes[i];
+        picsys->original_planes[i] = p;
+        picture->p[i].p_pixels = p + x * bbp + y * pitch;
+        picture->p[i].i_lines = sys->place.height;
+    }
 
     return VLC_SUCCESS;
 }
@@ -300,7 +338,7 @@ static void Unlock(picture_t *picture)
     void *planes[PICTURE_PLANE_MAX];
 
     for (int i = 0; i < picture->i_planes; i++)
-        planes[i] = picture->p[i].p_pixels;
+        planes[i] = picsys->original_planes[i];
 
     if (sys->unlock != NULL)
         sys->unlock(sys->opaque, picsys->id, planes);



More information about the vlc-commits mailing list