[libbluray-devel] [Git][videolan/libbluray][master] Reference-count and reuse parsed CLPI files.
Petri Hintukainen
gitlab at videolan.org
Sun Jan 31 13:33:02 UTC 2021
Petri Hintukainen pushed to branch master at VideoLAN / libbluray
Commits:
ec5877cf by hpi1 at 2021-01-31T15:27:40+02:00
Reference-count and reuse parsed CLPI files.
Avoids reading same clpi file multiple times when clip is repeated (ex. in menu backgrounds).
- - - - -
5 changed files:
- ChangeLog
- src/libbluray/bdnav/clpi_parse.c
- src/libbluray/bdnav/clpi_parse.h
- src/libbluray/bdnav/navigation.c
- src/libbluray/bdnav/navigation.h
Changes:
=====================================
ChangeLog
=====================================
@@ -1,5 +1,6 @@
- Add bd_event_name().
- Add return value to bd_refcnt_inc().
+- Cache and reuse parsed clpi file data.
2020-10-25: Version 1.2.1
- Add initial support for .fmts files.
=====================================
src/libbluray/bdnav/clpi_parse.c
=====================================
@@ -31,6 +31,7 @@
#include "disc/disc.h"
#include "file/file.h"
+#include "util/refcnt.h"
#include "util/bits.h"
#include "util/macro.h"
#include "util/logging.h"
@@ -707,8 +708,9 @@ _clean_cpi(CLPI_CPI *cpi)
}
static void
-_clpi_free(CLPI_CL *cl)
+_clpi_clean(void *p)
{
+ CLPI_CL *cl = p;
int ii;
X_FREE(cl->clip.atc_delta);
@@ -729,8 +731,21 @@ _clpi_free(CLPI_CL *cl)
_clean_program(&cl->program_ss);
_clean_cpi(&cl->cpi_ss);
+}
- X_FREE(cl);
+static void
+_clpi_free(const CLPI_CL *cl)
+{
+ refcnt_dec(cl);
+}
+
+void
+clpi_unref(const CLPI_CL **cl)
+{
+ if (*cl) {
+ _clpi_free(*cl);
+ *cl = NULL;
+ }
}
void
@@ -753,7 +768,7 @@ _clpi_parse(BD_FILE_H *fp)
return NULL;
}
- cl = calloc(1, sizeof(CLPI_CL));
+ cl = refcnt_calloc(sizeof(CLPI_CL), _clpi_clean);
if (cl == NULL) {
BD_DEBUG(DBG_CRIT, "out of memory\n");
return NULL;
@@ -824,18 +839,26 @@ _clpi_get(BD_DISC *disc, const char *dir, const char *file)
return cl;
}
-CLPI_CL*
+const CLPI_CL*
clpi_get(BD_DISC *disc, const char *file)
{
- CLPI_CL *cl;
+ const CLPI_CL *cl;
- cl = _clpi_get(disc, "BDMV" DIR_SEP "CLIPINF", file);
+ cl = disc_cache_get(disc, file);
if (cl) {
return cl;
}
- /* if failed, try backup file */
- cl = _clpi_get(disc, "BDMV" DIR_SEP "BACKUP" DIR_SEP "CLIPINF", file);
+ cl = _clpi_get(disc, "BDMV" DIR_SEP "CLIPINF", file);
+ if (!cl) {
+ /* if failed, try backup file */
+ cl = _clpi_get(disc, "BDMV" DIR_SEP "BACKUP" DIR_SEP "CLIPINF", file);
+ }
+
+ if (cl) {
+ disc_cache_put(disc, file, cl);
+ }
+
return cl;
}
@@ -846,7 +869,7 @@ clpi_copy(const CLPI_CL* src_cl)
int ii, jj;
if (src_cl) {
- dest_cl = (CLPI_CL*) calloc(1, sizeof(CLPI_CL));
+ dest_cl = refcnt_calloc(sizeof(CLPI_CL), _clpi_clean);
if (!dest_cl) {
goto fail;
}
@@ -966,6 +989,6 @@ clpi_copy(const CLPI_CL* src_cl)
fail:
BD_DEBUG(DBG_CRIT, "out of memory\n");
- clpi_free(&dest_cl);
+ _clpi_free(dest_cl);
return NULL;
}
=====================================
src/libbluray/bdnav/clpi_parse.h
=====================================
@@ -27,14 +27,16 @@
struct clpi_cl;
struct bd_disc;
-BD_PRIVATE struct clpi_cl* clpi_parse(const char *path);
-BD_PRIVATE struct clpi_cl* clpi_get(struct bd_disc *disc, const char *file);
-BD_PRIVATE struct clpi_cl* clpi_copy(const struct clpi_cl* src_cl);
-BD_PRIVATE void clpi_free(struct clpi_cl **cl);
+BD_PRIVATE const struct clpi_cl* clpi_get(struct bd_disc *disc, const char *file);
+BD_PRIVATE void clpi_unref(const struct clpi_cl **cl);
BD_PRIVATE uint32_t clpi_find_stc_spn(const struct clpi_cl *cl, uint8_t stc_id);
BD_PRIVATE uint32_t clpi_lookup_spn(const struct clpi_cl *cl, uint32_t timestamp, int before, uint8_t stc_id);
BD_PRIVATE uint32_t clpi_access_point(const struct clpi_cl *cl, uint32_t pkt, int next, int angle_change, uint32_t *time);
+/* preserved for old clpi API */
+BD_PRIVATE struct clpi_cl* clpi_parse(const char *path);
+BD_PRIVATE struct clpi_cl* clpi_copy(const struct clpi_cl* src_cl); /* deep copy */
+BD_PRIVATE void clpi_free(struct clpi_cl **cl);
#endif // _CLPI_PARSE_H_
=====================================
src/libbluray/bdnav/navigation.c
=====================================
@@ -648,7 +648,7 @@ static void _fill_clip(NAV_TITLE *title,
memcpy(&clip->name[5], ".m2ts", 6);
clip->clip_id = atoi(mpls_clip[clip->angle].clip_id);
- clpi_free(&clip->cl);
+ clpi_unref(&clip->cl);
file = str_printf("%s.clpi", mpls_clip[clip->angle].clip_id);
if (file) {
@@ -698,7 +698,7 @@ void _nav_title_close(NAV_TITLE *title)
for (ss = 0; ss < title->sub_path_count; ss++) {
if (title->sub_path[ss].clip_list.clip) {
for (ii = 0; ii < title->sub_path[ss].clip_list.count; ii++) {
- clpi_free(&title->sub_path[ss].clip_list.clip[ii].cl);
+ clpi_unref(&title->sub_path[ss].clip_list.clip[ii].cl);
}
X_FREE(title->sub_path[ss].clip_list.clip);
}
@@ -708,7 +708,7 @@ void _nav_title_close(NAV_TITLE *title)
if (title->clip_list.clip) {
for (ii = 0; ii < title->clip_list.count; ii++) {
- clpi_free(&title->clip_list.clip[ii].cl);
+ clpi_unref(&title->clip_list.clip[ii].cl);
}
X_FREE(title->clip_list.clip);
}
=====================================
src/libbluray/bdnav/navigation.h
=====================================
@@ -88,7 +88,7 @@ struct nav_clip_s
uint8_t still_mode;
uint16_t still_time;
- struct clpi_cl *cl;
+ const struct clpi_cl *cl;
};
typedef struct nav_clip_list_s NAV_CLIP_LIST;
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/commit/ec5877cf8efeb59653f0a85832e820bfee6cdae1
--
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/commit/ec5877cf8efeb59653f0a85832e820bfee6cdae1
You're receiving this email because of your account on code.videolan.org.
More information about the libbluray-devel
mailing list