[vlc-commits] access: bluray: refactor and disambiguate es_pair
Francois Cartegnie
git at videolan.org
Tue Oct 30 18:12:24 CET 2018
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Oct 16 12:52:52 2018 +0200| [f4a804df7ab3341b76afcc0c0d6ed668e38449c0] | committer: Francois Cartegnie
access: bluray: refactor and disambiguate es_pair
(cherry picked from commit ec9c759baf4d0cd57e79ded10b348aebcb59d984)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=f4a804df7ab3341b76afcc0c0d6ed668e38449c0
---
modules/access/bluray.c | 141 ++++++++++++++++++++++++++++++++----------------
1 file changed, 94 insertions(+), 47 deletions(-)
diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index 16b3af1234..b0b5a15939 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -183,7 +183,7 @@ struct demux_sys_t
/* TS stream */
es_out_t *p_out;
- vlc_array_t es;
+ vlc_array_t es; /* es_pair_t */
int i_audio_stream_idx; /* Selected audio stream. -1 if default */
int i_spu_stream_idx; /* Selected subtitle stream. -1 if default */
bool b_spu_enable; /* enabled / disabled */
@@ -199,6 +199,73 @@ struct demux_sys_t
char *psz_bd_path;
};
+/*
+ * Local ES index storage
+ */
+typedef struct
+{
+ int i_pid;
+ es_out_id_t *p_es;
+} es_pair_t;
+
+static bool es_pair_Add(vlc_array_t *p_array, int i_pid, es_out_id_t *p_es)
+{
+ es_pair_t *p_pair = malloc(sizeof(*p_pair));
+ if (likely(p_pair != NULL))
+ {
+ p_pair->i_pid = i_pid;
+ p_pair->p_es = p_es;
+ if(vlc_array_append(p_array, p_pair) != VLC_SUCCESS)
+ {
+ free(p_pair);
+ p_pair = NULL;
+ }
+ }
+ return p_pair != NULL;
+}
+
+static void es_pair_Remove(vlc_array_t *p_array, es_pair_t *p_pair)
+{
+ vlc_array_remove(p_array, vlc_array_index_of_item(p_array, p_pair));
+ free(p_pair);
+}
+
+static es_pair_t *getEsPair(vlc_array_t *p_array,
+ bool (*match)(const es_pair_t *, const void *),
+ const void *param)
+{
+ for (size_t i = 0; i < vlc_array_count(p_array); ++i)
+ {
+ es_pair_t *p_pair = vlc_array_item_at_index(p_array, i);
+ if(match(p_pair, param))
+ return p_pair;
+ }
+ return NULL;
+}
+
+static bool es_pair_compare_PID(const es_pair_t *p_pair, const void *p_pid)
+{
+ return p_pair->i_pid == *((const int *)p_pid);
+}
+
+static bool es_pair_compare_ES(const es_pair_t *p_pair, const void *p_es)
+{
+ return p_pair->p_es == (const es_out_id_t *)p_es;
+}
+
+static es_pair_t *getEsPairByPID(vlc_array_t *p_array, int i_pid)
+{
+ return getEsPair(p_array, es_pair_compare_PID, &i_pid);
+}
+
+static es_pair_t *getEsPairByES(vlc_array_t *p_array, const es_out_id_t *p_es)
+{
+ return getEsPair(p_array, es_pair_compare_ES, p_es);
+}
+
+/*
+ * Subpicture updater
+*/
struct subpicture_updater_sys_t
{
vlc_mutex_t lock; // protect p_overlay pointer and ref_cnt
@@ -931,29 +998,6 @@ struct es_out_sys_t
void *priv;
};
-typedef struct fmt_es_pair {
- int i_id;
- es_out_id_t *p_es;
-} fmt_es_pair_t;
-
-static int findEsPairIndex(demux_sys_t *p_sys, int i_id)
-{
- for (size_t i = 0; i < vlc_array_count(&p_sys->es); ++i)
- if (((fmt_es_pair_t*)vlc_array_item_at_index(&p_sys->es, i))->i_id == i_id)
- return i;
-
- return -1;
-}
-
-static int findEsPairIndexByEs(demux_sys_t *p_sys, es_out_id_t *p_es)
-{
- for (size_t i = 0; i < vlc_array_count(&p_sys->es); ++i)
- if (((fmt_es_pair_t*)vlc_array_item_at_index(&p_sys->es, i))->p_es == p_es)
- return i;
-
- return -1;
-}
-
static void setStreamLang(demux_sys_t *p_sys, es_format_t *p_fmt)
{
const BLURAY_STREAM_INFO *p_streams;
@@ -1043,21 +1087,16 @@ static es_out_id_t *esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
es_out_id_t *p_es = es_out_Add(es_out_sys->p_dst_out, &fmt);
if (p_fmt->i_id >= 0) {
/* Ensure we are not overriding anything */
- int idx = findEsPairIndex(p_sys, p_fmt->i_id);
- if (idx == -1) {
- fmt_es_pair_t *p_pair = malloc(sizeof(*p_pair));
- if (likely(p_pair != NULL)) {
- p_pair->i_id = p_fmt->i_id;
- p_pair->p_es = p_es;
- msg_Info(p_demux, "Adding ES %d", p_fmt->i_id);
- vlc_array_append_or_abort(&p_sys->es, p_pair);
-
- if (b_select) {
- if (fmt.i_cat == AUDIO_ES) {
- var_SetInteger( p_demux->p_input, "audio-es", p_fmt->i_id );
- } else if (fmt.i_cat == SPU_ES) {
- var_SetInteger( p_demux->p_input, "spu-es", p_sys->b_spu_enable ? p_fmt->i_id : -1 );
- }
+ es_pair_t *p_pair = getEsPairByPID(&p_sys->es, p_fmt->i_id);
+ if (p_pair == NULL)
+ {
+ msg_Info(p_demux, "Adding ES %d", p_fmt->i_id);
+ if (es_pair_Add(&p_sys->es, p_fmt->i_id, p_es) && b_select)
+ {
+ if (fmt.i_cat == AUDIO_ES) {
+ var_SetInteger( p_demux->p_input, "audio-es", p_fmt->i_id );
+ } else if (fmt.i_cat == SPU_ES) {
+ var_SetInteger( p_demux->p_input, "spu-es", p_sys->b_spu_enable ? p_fmt->i_id : -1 );
}
}
}
@@ -1079,11 +1118,10 @@ static void esOutDel(es_out_t *p_out, es_out_id_t *p_es)
demux_t *p_demux = es_out_sys->priv;
demux_sys_t *p_sys = p_demux->p_sys;
- int idx = findEsPairIndexByEs(p_sys, p_es);
- if (idx >= 0) {
- free(vlc_array_item_at_index(&p_sys->es, idx));
- vlc_array_remove(&p_sys->es, idx);
- }
+ es_pair_t *p_pair = getEsPairByES(&p_sys->es, p_es);
+ if (p_pair)
+ es_pair_Remove(&p_sys->es, p_pair);
+
es_out_Del(es_out_sys->p_dst_out, p_es);
}
@@ -2225,14 +2263,23 @@ static void blurayStreamSelect(demux_t *p_demux, uint32_t i_type, uint32_t i_id)
i_pid = blurayEsPid(p_sys, SPU_ES, i_id);
}
- if (i_pid > 0) {
- int i_idx = findEsPairIndex(p_sys, i_pid);
- if (i_idx >= 0) {
+ if (i_pid > 0)
+ {
+ es_pair_t *p_pair = getEsPairByPID(&p_sys->es, i_pid);
+ if (p_pair)
+ {
+ assert(p_pair->p_es);
+
+ bool b_select = false;
if (i_type == BD_EVENT_AUDIO_STREAM) {
var_SetInteger( p_demux->p_input, "audio-es", i_pid );
} else if (i_type == BD_EVENT_PG_TEXTST_STREAM) {
+ b_select = p_sys->b_spu_enable;
var_SetInteger( p_demux->p_input, "spu-es", p_sys->b_spu_enable ? i_pid : -1 );
}
+
+ if(b_select)
+ blurayStreamSelected(p_sys, i_pid);
}
}
}
More information about the vlc-commits
mailing list