Commit 4d9bf01b authored by Pierre d'Herbemont's avatar 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)
parent f7a324a5
...@@ -52,6 +52,10 @@ ...@@ -52,6 +52,10 @@
#define LT_CHROMA N_("Output chroma for the memory image as a 4-character " \ #define LT_CHROMA N_("Output chroma for the memory image as a 4-character " \
"string, eg. \"RV32\".") "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 int Open (vlc_object_t *);
static void Close(vlc_object_t *); static void Close(vlc_object_t *);
...@@ -71,6 +75,7 @@ vlc_module_begin() ...@@ -71,6 +75,7 @@ vlc_module_begin()
change_private() change_private()
add_string("vmem-chroma", "RV16", T_CHROMA, LT_CHROMA, true) add_string("vmem-chroma", "RV16", T_CHROMA, LT_CHROMA, true)
change_private() 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-lock") /* obsoleted since 1.1.1 */
add_obsolete_string("vmem-unlock") /* 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 */ add_obsolete_string("vmem-data") /* obsoleted since 1.1.1 */
...@@ -83,11 +88,15 @@ vlc_module_end() ...@@ -83,11 +88,15 @@ vlc_module_end()
*****************************************************************************/ *****************************************************************************/
struct picture_sys_t { struct picture_sys_t {
vout_display_sys_t *sys; vout_display_sys_t *sys;
void *original_planes[PICTURE_PLANE_MAX]; /** planes sent by the client */
void *id; void *id;
}; };
struct vout_display_sys_t { struct vout_display_sys_t {
picture_pool_t *pool; picture_pool_t *pool;
vout_display_place_t place;
int vmem_pitch;
int vmem_width;
void *(*lock)(void *sys, void **plane); void *(*lock)(void *sys, void **plane);
void (*unlock)(void *sys, void *id, void *const *plane); void (*unlock)(void *sys, void *id, void *const *plane);
void (*display)(void *sys, void *id); void (*display)(void *sys, void *id);
...@@ -173,8 +182,27 @@ static int Open(vlc_object_t *object) ...@@ -173,8 +182,27 @@ static int Open(vlc_object_t *object)
sys->display = var_InheritAddress(vd, "vmem-display"); sys->display = var_InheritAddress(vd, "vmem-display");
sys->opaque = var_InheritAddress(vd, "vmem-data"); 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; picture_resource_t rsc;
rsc.p_sys = malloc(sizeof(*rsc.p_sys)); rsc.p_sys = malloc(sizeof(*rsc.p_sys));
if(unlikely(!rsc.p_sys)) { if(unlikely(!rsc.p_sys)) {
...@@ -186,8 +214,8 @@ static int Open(vlc_object_t *object) ...@@ -186,8 +214,8 @@ static int Open(vlc_object_t *object)
for (int i = 0; i < PICTURE_PLANE_MAX; i++) { for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
/* vmem-lock is responsible for the allocation */ /* vmem-lock is responsible for the allocation */
rsc.p[i].p_pixels = NULL; rsc.p[i].p_pixels = NULL;
rsc.p[i].i_lines = fmt.i_height; rsc.p[i].i_lines = sys->place.height;
rsc.p[i].i_pitch = pitch; rsc.p[i].i_pitch = sys->vmem_pitch;
} }
picture_t *picture = picture_NewFromResource(&fmt, &rsc); picture_t *picture = picture_NewFromResource(&fmt, &rsc);
if (!picture) { if (!picture) {
...@@ -266,6 +294,7 @@ static int Control(vout_display_t *vd, int query, va_list args) ...@@ -266,6 +294,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
return VLC_EGENERIC; return VLC_EGENERIC;
if (cfg->is_fullscreen) if (cfg->is_fullscreen)
return VLC_EGENERIC; return VLC_EGENERIC;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
default: default:
...@@ -286,8 +315,17 @@ static int Lock(picture_t *picture) ...@@ -286,8 +315,17 @@ static int Lock(picture_t *picture)
picsys->id = sys->lock(sys->opaque, planes); picsys->id = sys->lock(sys->opaque, planes);
for (int i = 0; i < picture->i_planes; i++) const int y = sys->place.y;
picture->p[i].p_pixels = planes[i]; 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; return VLC_SUCCESS;
} }
...@@ -300,7 +338,7 @@ static void Unlock(picture_t *picture) ...@@ -300,7 +338,7 @@ static void Unlock(picture_t *picture)
void *planes[PICTURE_PLANE_MAX]; void *planes[PICTURE_PLANE_MAX];
for (int i = 0; i < picture->i_planes; i++) 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) if (sys->unlock != NULL)
sys->unlock(sys->opaque, picsys->id, planes); sys->unlock(sys->opaque, picsys->id, planes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment