[libbluray-devel] [Git][videolan/libbluray][master] 6 commits: refcnt: remove const cast

Petri Hintukainen gitlab at videolan.org
Sat Oct 24 16:03:43 CEST 2020



Petri Hintukainen pushed to branch master at VideoLAN / libbluray


Commits:
2b4114ba by hpi1 at 2020-10-24T16:44:16+03:00
refcnt: remove const cast

- - - - -
fb3030a3 by hpi1 at 2020-10-24T16:44:29+03:00
refcnt: sanity check pointers

- - - - -
646718ba by hpi1 at 2020-10-24T16:51:30+03:00
refcnt: clean up refcnt.h and move exported bd_refcnt_*() to graphics controller

- - - - -
af7a3628 by hpi1 at 2020-10-24T16:55:06+03:00
refcnt_realloc(): improve error handling

Check if pointer is valid.
Return NULL instead of new object when reallocating locked (shared) object.

- - - - -
93bb8d61 by hpi1 at 2020-10-24T16:56:55+03:00
refcnt_dec(): avoid dangling pointers

- - - - -
a798b053 by hpi1 at 2020-10-24T16:56:55+03:00
Add bd_event_name().

Improve event queue overflow logging.

- - - - -


6 changed files:

- ChangeLog
- src/libbluray/bluray.c
- src/libbluray/bluray.h
- src/libbluray/decoders/graphics_controller.c
- src/util/refcnt.c
- src/util/refcnt.h


Changes:

=====================================
ChangeLog
=====================================
@@ -1,3 +1,5 @@
+- Add bd_event_name().
+
 2020-10-25: Version 1.2.1
 - Add initial support for .fmts files.
 - Improve missing/broken playlist handling ("Star Trek Beyond 4K").


=====================================
src/libbluray/bluray.c
=====================================
@@ -190,6 +190,49 @@ void bd_get_version(int *major, int *minor, int *micro)
  * Navigation mode event queue
  */
 
+const char *bd_event_name(uint32_t event)
+{
+  switch ((bd_event_e)event) {
+#define EVENT_ENTRY(e) case e : return #e + 9
+        EVENT_ENTRY(BD_EVENT_NONE);
+        EVENT_ENTRY(BD_EVENT_ERROR);
+        EVENT_ENTRY(BD_EVENT_READ_ERROR);
+        EVENT_ENTRY(BD_EVENT_ENCRYPTED);
+        EVENT_ENTRY(BD_EVENT_ANGLE);
+        EVENT_ENTRY(BD_EVENT_TITLE);
+        EVENT_ENTRY(BD_EVENT_PLAYLIST);
+        EVENT_ENTRY(BD_EVENT_PLAYITEM);
+        EVENT_ENTRY(BD_EVENT_CHAPTER);
+        EVENT_ENTRY(BD_EVENT_PLAYMARK);
+        EVENT_ENTRY(BD_EVENT_END_OF_TITLE);
+        EVENT_ENTRY(BD_EVENT_AUDIO_STREAM);
+        EVENT_ENTRY(BD_EVENT_IG_STREAM);
+        EVENT_ENTRY(BD_EVENT_PG_TEXTST_STREAM);
+        EVENT_ENTRY(BD_EVENT_PIP_PG_TEXTST_STREAM);
+        EVENT_ENTRY(BD_EVENT_SECONDARY_AUDIO_STREAM);
+        EVENT_ENTRY(BD_EVENT_SECONDARY_VIDEO_STREAM);
+        EVENT_ENTRY(BD_EVENT_PG_TEXTST);
+        EVENT_ENTRY(BD_EVENT_PIP_PG_TEXTST);
+        EVENT_ENTRY(BD_EVENT_SECONDARY_AUDIO);
+        EVENT_ENTRY(BD_EVENT_SECONDARY_VIDEO);
+        EVENT_ENTRY(BD_EVENT_SECONDARY_VIDEO_SIZE);
+        EVENT_ENTRY(BD_EVENT_PLAYLIST_STOP);
+        EVENT_ENTRY(BD_EVENT_DISCONTINUITY);
+        EVENT_ENTRY(BD_EVENT_SEEK);
+        EVENT_ENTRY(BD_EVENT_STILL);
+        EVENT_ENTRY(BD_EVENT_STILL_TIME);
+        EVENT_ENTRY(BD_EVENT_SOUND_EFFECT);
+        EVENT_ENTRY(BD_EVENT_IDLE);
+        EVENT_ENTRY(BD_EVENT_POPUP);
+        EVENT_ENTRY(BD_EVENT_MENU);
+        EVENT_ENTRY(BD_EVENT_STEREOSCOPIC_STATUS);
+        EVENT_ENTRY(BD_EVENT_KEY_INTEREST_TABLE);
+        EVENT_ENTRY(BD_EVENT_UO_MASK_CHANGED);
+#undef EVENT_ENTRY
+    }
+    return NULL;
+}
+
 static int _get_event(BLURAY *bd, BD_EVENT *ev)
 {
     int result = event_queue_get(bd->event_queue, ev);
@@ -206,7 +249,8 @@ static int _queue_event(BLURAY *bd, uint32_t event, uint32_t param)
         BD_EVENT ev = { event, param };
         result = event_queue_put(bd->event_queue, &ev);
         if (!result) {
-            BD_DEBUG(DBG_BLURAY|DBG_CRIT, "_queue_event(%d, %d): queue overflow !\n", event, param);
+            const char *name = bd_event_name(event);
+            BD_DEBUG(DBG_BLURAY|DBG_CRIT, "_queue_event(%s:%d, %d): queue overflow !\n", name ? name : "?", event, param);
         }
     }
     return result;


=====================================
src/libbluray/bluray.h
=====================================
@@ -850,6 +850,7 @@ typedef struct {
  */
 int  bd_get_event(BLURAY *bd, BD_EVENT *event);
 
+const char *bd_event_name(uint32_t /* bd_event_e */ event);
 
 /*
  * On-screen display


=====================================
src/libbluray/decoders/graphics_controller.c
=====================================
@@ -634,10 +634,22 @@ static void _render_composition_object(GRAPHICS_CONTROLLER *gc,
 
         gc->overlay_proc(gc->overlay_proc_handle, &ov);
 
-        bd_refcnt_dec(cropped_img);
+        refcnt_dec(cropped_img);
     }
 }
 
+/* exported */
+void bd_refcnt_inc(const void *obj)
+{
+    refcnt_inc(obj);
+}
+
+/* exported */
+void bd_refcnt_dec(const void *obj)
+{
+    refcnt_dec(obj);
+}
+
 static void _render_rle(GRAPHICS_CONTROLLER *gc,
                         int64_t pts,
                         BD_PG_RLE_ELEM *img,


=====================================
src/util/refcnt.c
=====================================
@@ -33,7 +33,8 @@
  *
  */
 
-typedef struct {
+typedef struct bd_refcnt {
+  struct bd_refcnt *me;
   void    (*cleanup)(void *);
   BD_MUTEX mutex;   /* initialized only if counted == 1 */
   int      count;   /* reference count */
@@ -44,13 +45,19 @@ typedef struct {
  *
  */
 
-void bd_refcnt_inc(const void *obj)
+void refcnt_inc(const void *obj)
 {
+    BD_REFCNT *ref;
+
     if (!obj) {
         return;
     }
 
-    BD_REFCNT *ref = &(((BD_REFCNT *)(intptr_t)obj)[-1]);
+    ref = ((const BD_REFCNT *)obj)[-1].me;
+    if (obj != (const void *)&ref[1]) {
+        BD_DEBUG(DBG_CRIT, "refcnt_inc(): invalid object\n");
+        return;
+    }
 
     if (!ref->counted) {
         bd_mutex_init(&ref->mutex);
@@ -64,13 +71,19 @@ void bd_refcnt_inc(const void *obj)
     bd_mutex_unlock(&ref->mutex);
 }
 
-void bd_refcnt_dec(const void *obj)
+void refcnt_dec(const void *obj)
 {
+    BD_REFCNT *ref;
+
     if (!obj) {
         return;
     }
 
-    BD_REFCNT *ref = &((BD_REFCNT *)(intptr_t)obj)[-1];
+    ref = ((const BD_REFCNT *)obj)[-1].me;
+    if (obj != (const void *)&ref[1]) {
+        BD_DEBUG(DBG_CRIT, "refcnt_dec(): invalid object\n");
+        return;
+    }
 
     if (ref->counted) {
         int count;
@@ -89,6 +102,7 @@ void bd_refcnt_dec(const void *obj)
     if (ref->cleanup)
         ref->cleanup(&ref[1]);
 
+    memset(ref, 0, sizeof(*ref));
     free(ref);
 }
 
@@ -97,15 +111,18 @@ void *refcnt_realloc(void *obj, size_t sz, void (*cleanup)(void *))
     sz += sizeof(BD_REFCNT);
 
     if (obj) {
-        if (((BD_REFCNT *)obj)[-1].counted) {
-            bd_refcnt_dec(obj);
+        const BD_REFCNT *ref = ((const BD_REFCNT *)obj)[-1].me;
+        if (obj != (const void *)&ref[1]) {
+            BD_DEBUG(DBG_CRIT, "refcnt_realloc(): invalid object\n");
+            return NULL;
+        }
+
+        if (ref->counted) {
             BD_DEBUG(DBG_CRIT, "refcnt_realloc(): realloc locked object !\n");
-            obj = NULL;
+            return NULL;
         }
-    }
 
-    if (obj) {
-        obj = realloc(&((BD_REFCNT *)obj)[-1], sz);
+        obj = realloc(((BD_REFCNT *)obj)[-1].me, sz);
         if (!obj) {
             /* do not call cleanup() - nothing is free'd here */
             return NULL;
@@ -119,6 +136,7 @@ void *refcnt_realloc(void *obj, size_t sz, void (*cleanup)(void *))
     }
 
     ((BD_REFCNT *)obj)->cleanup = cleanup;
+    ((BD_REFCNT *)obj)->me = obj;
     return &((BD_REFCNT *)obj)[1];
 }
 


=====================================
src/util/refcnt.h
=====================================
@@ -52,10 +52,8 @@ extern "C" {
 
 BD_PRIVATE void *refcnt_realloc(void *obj, size_t sz, void (*cleanup)(void *));
 
-#ifndef BD_OVERLAY_INTERFACE_VERSION
-void bd_refcnt_inc(const void *obj);
-void bd_refcnt_dec(const void *obj);
-#endif
+BD_PRIVATE       void  refcnt_inc(const void *obj);
+BD_PRIVATE       void  refcnt_dec(const void *obj);
 
 #ifdef __cplusplus
 }



View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/2091174b7e6e80d5bf080a7ab1aa4e901546a29e...a798b0533f024d9168e37a8e72e5bdeeac4b7d30

-- 
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/2091174b7e6e80d5bf080a7ab1aa4e901546a29e...a798b0533f024d9168e37a8e72e5bdeeac4b7d30
You're receiving this email because of your account on code.videolan.org.




More information about the libbluray-devel mailing list