[vlc-commits] [Git][videolan/vlc][master] 5 commits: sout: hls: use const when reading a media from a const list

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Nov 14 07:51:16 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
cf15ed77 by Steve Lhomme at 2023-11-14T07:25:45+00:00
sout: hls: use const when reading a media from a const list

- - - - -
7740350d by Steve Lhomme at 2023-11-14T07:25:45+00:00
vout_subpictures: use const when counting regions

- - - - -
aa9a5632 by Steve Lhomme at 2023-11-14T07:25:45+00:00
input: reading the category as non-const category

The returned value needs to be non-const in some cases.
We may provide both const and a non-const variants.

- - - - -
473a66cb by Steve Lhomme at 2023-11-14T07:25:45+00:00
vout: read SPU regions as const

- - - - -
6d9b2a09 by Steve Lhomme at 2023-11-14T07:25:45+00:00
vlc_list: split reading from a const list a non-const list

Items read from a const list should also be const.

The start of the listing needs a matching const/non-const pointer.

- - - - -


15 changed files:

- include/vlc_list.h
- include/vlc_subpicture.h
- modules/hw/mmal/vout.c
- modules/stream_out/hls/hls.c
- modules/stream_out/hls/segments.h
- modules/video_output/android/display.c
- modules/video_output/apple/VLCSampleBufferDisplay.m
- modules/video_output/libplacebo/display.c
- modules/video_output/opengl/sub_renderer.c
- modules/video_output/win32/direct3d11.cpp
- modules/video_output/win32/direct3d9.c
- modules/video_output/xcb/render.c
- src/input/info.h
- src/input/item.c
- src/video_output/vout_subpictures.c


Changes:

=====================================
include/vlc_list.h
=====================================
@@ -209,7 +209,7 @@ struct vlc_list_it
 };
 
 static inline
-struct vlc_list_it vlc_list_it_start(const struct vlc_list *head)
+struct vlc_list_it vlc_list_it_start(struct vlc_list *head)
 {
     struct vlc_list *first = head->next;
 
@@ -218,7 +218,25 @@ struct vlc_list_it vlc_list_it_start(const struct vlc_list *head)
 }
 
 static inline
-struct vlc_list_it vlc_list_it_reverse_start(const struct vlc_list *head)
+struct vlc_list_it vlc_list_it_start_const(const struct vlc_list *head)
+{
+    struct vlc_list *first = head->next;
+
+    struct vlc_list_it it = { head, first, first->next };
+    return it;
+}
+
+static inline
+struct vlc_list_it vlc_list_it_reverse_start(struct vlc_list *head)
+{
+    struct vlc_list *first = head->prev;
+
+    struct vlc_list_it it = { head, first, first->prev };
+    return it;
+}
+
+static inline
+struct vlc_list_it vlc_list_it_reverse_start_const(const struct vlc_list *head)
 {
     struct vlc_list *first = head->prev;
 
@@ -268,6 +286,12 @@ static inline void vlc_list_it_prev(struct vlc_list_it *restrict it)
           && ((pos) = container_of((vlc_list_it__##pos).current, \
                                    typeof (*(pos)), member), true); \
          vlc_list_it_next(&(vlc_list_it__##pos)))
+#define vlc_list_foreach_const(pos, head, member) \
+    for (struct vlc_list_it vlc_list_it__##pos = vlc_list_it_start_const(head); \
+         vlc_list_it_continue(&(vlc_list_it__##pos)) \
+          && ((pos) = container_of((vlc_list_it__##pos).current, \
+                                   const typeof (*(pos)), member), true); \
+         vlc_list_it_next(&(vlc_list_it__##pos)))
 
 /**
  * List iteration macro.


=====================================
include/vlc_subpicture.h
=====================================
@@ -96,6 +96,8 @@ typedef struct vlc_list vlc_spu_regions;
     vlc_list_append(&(reg)->node, (p_rs))
 #define vlc_spu_regions_foreach(reg,p_rs) \
     vlc_list_foreach(reg, (p_rs), node)
+#define vlc_spu_regions_foreach_const(reg,p_rs) \
+    vlc_list_foreach_const(reg, (p_rs), node)
 #define vlc_spu_regions_is_empty(p_rs) \
     vlc_list_is_empty((p_rs))
 #define vlc_spu_regions_first_or_null(p_rs) \


=====================================
modules/hw/mmal/vout.c
=====================================
@@ -756,7 +756,7 @@ static int attach_subpics(vout_display_t * const vd, vout_display_sys_t * const
 
     // Attempt to import the subpics
     const subpicture_region_t *sreg;
-    vlc_spu_regions_foreach(sreg, &spic->regions) {
+    vlc_spu_regions_foreach_const(sreg, &spic->regions) {
         picture_t *const src = sreg->p_picture;
 
         // At this point I think the subtitles are being placed in the


=====================================
modules/stream_out/hls/hls.c
=====================================
@@ -224,7 +224,7 @@ static char *GeneratePlaylistCodecInfo(const struct vlc_list *media_list,
 
     /* Describe codecs from the playlist. */
     const hls_track_t *track;
-    vlc_list_foreach (track, &playlist->tracks, node)
+    vlc_list_foreach_const (track, &playlist->tracks, node)
     {
         if (IsCodecAlreadyDescribed(&already_described, &track->input->fmt))
             continue;
@@ -238,8 +238,8 @@ static char *GeneratePlaylistCodecInfo(const struct vlc_list *media_list,
     }
 
     /* Describe codecs from all the EXT-X-MEDIA tracks. */
-    hls_playlist_t *media;
-    vlc_list_foreach (media, media_list, node)
+    const hls_playlist_t *media;
+    vlc_list_foreach_const (media, media_list, node)
     {
         track = MediaGetTrack(media);
 
@@ -308,7 +308,7 @@ static struct hls_storage *GenerateMainManifest(const sout_stream_sys_t *sys)
     };
 
     const hls_playlist_t *playlist;
-    vlc_list_foreach (playlist, &sys->media_playlists, node)
+    vlc_list_foreach_const (playlist, &sys->media_playlists, node)
     {
         const hls_track_t *track = MediaGetTrack(playlist);
         const es_format_t *fmt = &track->input->fmt;
@@ -342,12 +342,12 @@ static struct hls_storage *GenerateMainManifest(const sout_stream_sys_t *sys)
     }
 
     /* Format EXT-X-STREAM-INF */
-    vlc_list_foreach (playlist, &sys->variant_playlists, node)
+    vlc_list_foreach_const (playlist, &sys->variant_playlists, node)
     {
         MANIFEST_START_TAG("#EXT-X-STREAM-INF")
             unsigned int bandwidth = 0;
             const hls_track_t *track;
-            vlc_list_foreach (track, &playlist->tracks, node)
+            vlc_list_foreach_const (track, &playlist->tracks, node)
                 bandwidth += track->input->fmt.i_bitrate;
             MANIFEST_ADD_ATTRIBUTE("BANDWIDTH=%u", bandwidth);
 
@@ -417,7 +417,7 @@ GeneratePlaylistManifest(const hls_playlist_t *playlist)
                      (first_seg == NULL) ? 0u : first_seg->id);
 
     const hls_segment_t *segment;
-    hls_segment_queue_Foreach(&playlist->segments, segment)
+    hls_segment_queue_Foreach_const(&playlist->segments, segment)
     {
         MANIFEST_ADD_TAG("#EXTINF:%.2f,", secf_from_vlc_tick(segment->length));
         MANIFEST_ADD_TAG("%s", segment->url);


=====================================
modules/stream_out/hls/segments.h
=====================================
@@ -56,6 +56,8 @@ typedef struct
 
 #define hls_segment_queue_Foreach(queue, it)                                   \
     vlc_list_foreach (it, &(queue)->segments, priv_node)
+#define hls_segment_queue_Foreach_const(queue, it)                             \
+    vlc_list_foreach_const (it, &(queue)->segments, priv_node)
 #define hls_segment_GetFirst(queue)                                            \
     vlc_list_first_entry_or_null(&(queue)->segments, hls_segment_t, priv_node);
 


=====================================
modules/video_output/android/display.c
=====================================
@@ -131,9 +131,9 @@ static bool subpicture_NeedDraw(vout_display_t *vd,
 
     sub->clear = true;
 
-    subpicture_region_t *r;
+    const subpicture_region_t *r;
     size_t count = 0;
-    vlc_spu_regions_foreach(r, &subpicture->regions)
+    vlc_spu_regions_foreach_const(r, &subpicture->regions)
         count++;
 
     if (subpicture->i_order != sub->last_order)
@@ -148,7 +148,7 @@ static bool subpicture_NeedDraw(vout_display_t *vd,
     if (count == sub->regions.size)
     {
         size_t i = 0;
-        vlc_spu_regions_foreach(r, &subpicture->regions)
+        vlc_spu_regions_foreach_const(r, &subpicture->regions)
         {
             struct sub_region *cmp = &sub->regions.data[i++];
             if (cmp->x != r->i_x || cmp->y != r->i_y
@@ -178,7 +178,7 @@ end:
 
     sub->regions.size = 0;
 
-    vlc_spu_regions_foreach(r, &subpicture->regions)
+    vlc_spu_regions_foreach_const(r, &subpicture->regions)
     {
         struct sub_region reg = {
             .x = r->i_x,


=====================================
modules/video_output/apple/VLCSampleBufferDisplay.m
=====================================
@@ -432,8 +432,8 @@ static void UpdateSubpictureRegions(vout_display_t *vd,
 
     NSMutableArray *regions = [NSMutableArray new];
     CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
-    subpicture_region_t *r;
-    vlc_spu_regions_foreach(r, &subpicture->regions) {
+    const subpicture_region_t *r;
+    vlc_spu_regions_foreach_const(r, &subpicture->regions) {
         CFIndex length = r->fmt.i_height * r->p_picture->p->i_pitch;
         const size_t pixels_offset =
                 r->fmt.i_y_offset * r->p_picture->p->i_pitch +
@@ -480,8 +480,8 @@ static bool IsSubpictureDrawNeeded(vout_display_t *vd, const vlc_render_subpictu
     }
 
     size_t count = 0;
-    subpicture_region_t *r;
-    vlc_spu_regions_foreach(r, &subpicture->regions)
+    const subpicture_region_t *r;
+    vlc_spu_regions_foreach_const(r, &subpicture->regions)
         count++;
 
     if (!sys.subpicture || subpicture->i_order != sys.subpicture.order)
@@ -499,7 +499,7 @@ static bool IsSubpictureDrawNeeded(vout_display_t *vd, const vlc_render_subpictu
     if (count == sys.subpicture.regions.count)
     {
         size_t i = 0;
-        vlc_spu_regions_foreach(r, &subpicture->regions)
+        vlc_spu_regions_foreach_const(r, &subpicture->regions)
         {
             VLCSampleBufferSubpictureRegion *region =
                 sys.subpicture.regions[i++];


=====================================
modules/video_output/libplacebo/display.c
=====================================
@@ -366,8 +366,8 @@ static void PictureRender(vout_display_t *vd, picture_t *pic,
 
     if (subpicture) {
         int num_regions = 0;
-        subpicture_region_t *r;
-        vlc_spu_regions_foreach(r, &subpicture->regions)
+        const subpicture_region_t *r;
+        vlc_spu_regions_foreach_const(r, &subpicture->regions)
             num_regions++;
 
         // Grow the overlays array if needed
@@ -389,7 +389,7 @@ static void PictureRender(vout_display_t *vd, picture_t *pic,
 
         // Upload all of the regions
         int i = 0;
-        vlc_spu_regions_foreach(r, &subpicture->regions) {
+        vlc_spu_regions_foreach_const(r, &subpicture->regions) {
             assert(r->p_picture->i_planes == 1);
             struct pl_plane_data subdata[4];
             if (!vlc_placebo_PlaneData(r->p_picture, subdata, NULL))


=====================================
modules/video_output/opengl/sub_renderer.c
=====================================
@@ -232,8 +232,8 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr,
 
     if (subpicture) {
         int count = 0;
-        subpicture_region_t *r;
-        vlc_spu_regions_foreach(r, &subpicture->regions)
+        const subpicture_region_t *r;
+        vlc_spu_regions_foreach_const(r, &subpicture->regions)
             count++;
 
         gl_region_t *regions = calloc(count, sizeof(*regions));
@@ -244,7 +244,7 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr,
         sr->regions = regions;
 
         int i = 0;
-        vlc_spu_regions_foreach(r, &subpicture->regions) {
+        vlc_spu_regions_foreach_const(r, &subpicture->regions) {
             gl_region_t *glr = &sr->regions[i];
 
             glr->width  = r->fmt.i_visible_width;


=====================================
modules/video_output/win32/direct3d11.cpp
=====================================
@@ -1284,8 +1284,8 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
         return VLC_EGENERIC;
 
     int count = 0;
-    subpicture_region_t *r;
-    vlc_spu_regions_foreach(r, &subpicture->regions)
+    const subpicture_region_t *r;
+    vlc_spu_regions_foreach_const(r, &subpicture->regions)
         count++;
 
     *region = static_cast<picture_t**>(calloc(count, sizeof(picture_t *)));
@@ -1294,7 +1294,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
     *subpicture_region_count = count;
 
     int i = 0;
-    vlc_spu_regions_foreach(r, &subpicture->regions) {
+    vlc_spu_regions_foreach_const(r, &subpicture->regions) {
         if (!r->fmt.i_visible_width || !r->fmt.i_visible_height)
         {
             i++;


=====================================
modules/video_output/win32/direct3d9.c
=====================================
@@ -873,8 +873,8 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
     vout_display_sys_t *sys = vd->sys;
 
     size_t count = 0;
-    subpicture_region_t *r;
-    vlc_spu_regions_foreach(r, &subpicture->regions)
+    const subpicture_region_t *r;
+    vlc_spu_regions_foreach_const(r, &subpicture->regions)
         count++;
 
     *count_ptr = count;
@@ -885,7 +885,7 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
     }
 
     int i = 0;
-    vlc_spu_regions_foreach(r, &subpicture->regions) {
+    vlc_spu_regions_foreach_const(r, &subpicture->regions) {
         d3d_region_t *d3dr = &(*region)[i];
         HRESULT hr;
 


=====================================
modules/video_output/xcb/render.c
=====================================
@@ -236,8 +236,8 @@ static void Prepare(vout_display_t *vd, picture_t *pic,
     /* Blend subpictures */
     if (subpic != NULL)
     {
-        subpicture_region_t *r;
-        vlc_spu_regions_foreach(r, &subpic->regions)
+        const subpicture_region_t *r;
+        vlc_spu_regions_foreach_const(r, &subpic->regions)
             RenderRegion(vd, subpic, r);
     }
 


=====================================
src/input/info.h
=====================================
@@ -53,7 +53,7 @@ static inline info_category_t *info_category_New(const char *name)
     return cat;
 }
 
-static inline info_t *info_category_FindInfo(const info_category_t *cat,
+static inline info_t *info_category_FindInfo(info_category_t *cat,
                                              const char *name)
 {
     info_t *info;


=====================================
src/input/item.c
=====================================
@@ -737,7 +737,7 @@ char *input_item_GetInfoLocked( input_item_t *p_i,
 {
     vlc_mutex_assert( &p_i->lock );
 
-    const info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
+    info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
     if( p_cat )
     {
         info_t *p_info = info_category_FindInfo( p_cat, psz_name );


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -1155,8 +1155,8 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
         const subpicture_t *subpic = p_entries[i].subpic;
 
         size_t count = 0;
-        subpicture_region_t *p_head;
-        vlc_spu_regions_foreach(p_head, &subpic->regions)
+        const subpicture_region_t *p_head;
+        vlc_spu_regions_foreach_const(p_head, &subpic->regions)
             count++;
 
         if (subpic->b_subtitle)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/701ea11d4ad9418270d8b5aba44fa72be8b50f04...6d9b2a09297e4fad9109100bbaeb3e4841d897c4

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/701ea11d4ad9418270d8b5aba44fa72be8b50f04...6d9b2a09297e4fad9109100bbaeb3e4841d897c4
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list