]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_widgets.c
Allowed to use mp2/mp3 to specify layer 2/3 for mpeg audio encoder.
[vlc] / src / video_output / video_widgets.c
index 5d3e21be9f3f154ae85c408e8ec599fe04112e16..a03aaf7925bf61bdced1fcfd01007dc541b8c1d7 100644 (file)
 static void DrawRect(subpicture_region_t *r, int fill,
                      int x1, int y1, int x2, int y2)
 {
-    uint8_t *a    = r->p_picture->A_PIXELS;
-    int     pitch = r->p_picture->A_PITCH;
+    uint8_t *p    = r->p_picture->p->p_pixels;
+    int     pitch = r->p_picture->p->i_pitch;
 
     if (fill == STYLE_FILLED) {
         for (int y = y1; y <= y2; y++) {
             for (int x = x1; x <= x2; x++)
-                a[x + pitch * y] = 0xff;
+                p[x + pitch * y] = 1;
         }
     } else {
         for (int y = y1; y <= y2; y++) {
-            a[x1 + pitch * y] = 0xff;
-            a[x2 + pitch * y] = 0xff;
+            p[x1 + pitch * y] = 1;
+            p[x2 + pitch * y] = 1;
         }
         for (int x = x1; x <= x2; x++) {
-            a[x + pitch * y1] = 0xff;
-            a[x + pitch * y2] = 0xff;
+            p[x + pitch * y1] = 1;
+            p[x + pitch * y2] = 1;
         }
     }
 }
@@ -73,8 +73,8 @@ static void DrawRect(subpicture_region_t *r, int fill,
 static void DrawTriangle(subpicture_region_t *r, int fill,
                          int x1, int y1, int x2, int y2)
 {
-    uint8_t *a    = r->p_picture->A_PIXELS;
-    int     pitch = r->p_picture->A_PITCH;
+    uint8_t *p    = r->p_picture->p->p_pixels;
+    int     pitch = r->p_picture->p->i_pitch;
     const int mid = y1 + (y2 - y1) / 2;
 
     /* TODO factorize it */
@@ -83,17 +83,17 @@ static void DrawTriangle(subpicture_region_t *r, int fill,
             for (int y = y1; y <= mid; y++) {
                 int h = y - y1;
                 for (int x = x1; x <= x1 + h && x <= x2; x++) {
-                    a[x + pitch * y         ] = 0xff;
-                    a[x + pitch * (y2 - h)] = 0xff;
+                    p[x + pitch * y         ] = 1;
+                    p[x + pitch * (y2 - h)] = 1;
                 }
             }
         } else {
             for (int y = y1; y <= mid; y++) {
                 int h = y - y1;
-                a[x1 +     pitch * y         ] = 0xff;
-                a[x1 + h + pitch * y         ] = 0xff;
-                a[x1 +     pitch * (y2 - h)] = 0xff;
-                a[x1 + h + pitch * (y2 - h)] = 0xff;
+                p[x1 +     pitch * y         ] = 1;
+                p[x1 + h + pitch * y         ] = 1;
+                p[x1 +     pitch * (y2 - h)] = 1;
+                p[x1 + h + pitch * (y2 - h)] = 1;
             }
         }
     } else {
@@ -101,17 +101,17 @@ static void DrawTriangle(subpicture_region_t *r, int fill,
             for (int y = y1; y <= mid; y++) {
                 int h = y - y1;
                 for (int x = x1; x >= x1 - h && x >= x2; x--) {
-                    a[x + pitch * y       ] = 0xff;
-                    a[x + pitch * (y2 - h)] = 0xff;
+                    p[x + pitch * y       ] = 1;
+                    p[x + pitch * (y2 - h)] = 1;
                 }
             }
         } else {
             for (int y = y1; y <= mid; y++) {
                 int h = y - y1;
-                a[ x1 +     pitch * y       ] = 0xff;
-                a[ x1 - h + pitch * y       ] = 0xff;
-                a[ x1 +     pitch * (y2 - h)] = 0xff;
-                a[ x1 - h + pitch * (y2 - h)] = 0xff;
+                p[ x1 +     pitch * y       ] = 1;
+                p[ x1 - h + pitch * y       ] = 1;
+                p[ x1 +     pitch * (y2 - h)] = 1;
+                p[ x1 - h + pitch * (y2 - h)] = 1;
             }
         }
     }
@@ -122,28 +122,31 @@ static void DrawTriangle(subpicture_region_t *r, int fill,
  */
 static subpicture_region_t *OSDRegion(int x, int y, int width, int height)
 {
+    video_palette_t palette = {
+        .i_entries = 2,
+        .palette = {
+            [0] = { 0xff, 0x80, 0x80, 0x00 },
+            [1] = { 0xff, 0x80, 0x80, 0xff },
+        },
+    };
+
     video_format_t fmt;
-    video_format_Init(&fmt, VLC_CODEC_YUVA);
+    video_format_Init(&fmt, VLC_CODEC_YUVP);
     fmt.i_width          =
     fmt.i_visible_width  = width;
     fmt.i_height         =
     fmt.i_visible_height = height;
-    fmt.i_sar_num        = 0;
+    fmt.i_sar_num        = 1;
     fmt.i_sar_den        = 1;
+    fmt.p_palette        = &palette;
 
     subpicture_region_t *r = subpicture_region_New(&fmt);
     if (!r)
         return NULL;
     r->i_x = x;
     r->i_y = y;
+    memset(r->p_picture->p->p_pixels, 0, r->p_picture->p->i_pitch * height);
 
-    for (int i = 0; i < r->p_picture->i_planes; i++) {
-        plane_t *p = &r->p_picture->p[i];
-        int colors[PICTURE_PLANE_MAX] = {
-            0xff, 0x80, 0x80, 0x00
-        };
-        memset(p->p_pixels, colors[i], p->i_pitch * height);
-    }
     return r;
 }
 
@@ -248,10 +251,11 @@ static int OSDWidgetValidate(subpicture_t *subpic,
                            bool has_dst_changed, const video_format_t *fmt_dst,
                            mtime_t ts)
 {
-    VLC_UNUSED(subpic); VLC_UNUSED(ts); VLC_UNUSED(fmt_src);
-    VLC_UNUSED(has_dst_changed); VLC_UNUSED(fmt_dst);
+    VLC_UNUSED(subpic); VLC_UNUSED(ts);
+    VLC_UNUSED(fmt_src); VLC_UNUSED(has_src_changed);
+    VLC_UNUSED(fmt_dst);
 
-    if (!has_src_changed && !has_dst_changed)
+    if (!has_dst_changed)
         return VLC_SUCCESS;
     return VLC_EGENERIC;
 }
@@ -262,14 +266,21 @@ static void OSDWidgetUpdate(subpicture_t *subpic,
                           mtime_t ts)
 {
     subpicture_updater_sys_t *sys = subpic->updater.p_sys;
-    VLC_UNUSED(fmt_dst); VLC_UNUSED(ts);
+    VLC_UNUSED(fmt_src); VLC_UNUSED(ts);
+
+    video_format_t fmt = *fmt_dst;
+    fmt.i_width         = fmt.i_width         * fmt.i_sar_num / fmt.i_sar_den;
+    fmt.i_visible_width = fmt.i_visible_width * fmt.i_sar_num / fmt.i_sar_den;
+    fmt.i_x_offset      = fmt.i_x_offset      * fmt.i_sar_num / fmt.i_sar_den;
+    fmt.i_sar_num       = 1;
+    fmt.i_sar_den       = 1;
 
-    subpic->i_original_picture_width  = fmt_src->i_width;
-    subpic->i_original_picture_height = fmt_src->i_height;
+    subpic->i_original_picture_width  = fmt.i_width;
+    subpic->i_original_picture_height = fmt.i_height;
     if (sys->type == OSD_HOR_SLIDER || sys->type == OSD_VERT_SLIDER)
-        subpic->p_region = OSDSlider(sys->type, sys->position, fmt_src);
+        subpic->p_region = OSDSlider(sys->type, sys->position, &fmt);
     else
-        subpic->p_region = OSDIcon(sys->type, fmt_src);
+        subpic->p_region = OSDIcon(sys->type, &fmt);
 }
 
 static void OSDWidgetDestroy(subpicture_t *subpic)