Discussion:
[vlc-devel] [PATCH] libvlc: add function to get track id from video setup callback.
Jerome Forissier
2014-03-03 12:20:05 UTC
Permalink
This commit adds a new function to the media player interface:
libvlc_video_format_cb_get_track_id(), which may be called form the
video setup callback (libvlc_video_format_cb). It returns the ID of
the track for which the video decoder thread is creating the video
output. It is useful e.g., when playing an MP4 file with several
streams.
---
include/vlc/libvlc_media_player.h | 8 ++++++++
include/vlc_es.h | 2 ++
lib/libvlc.sym | 1 +
lib/media_player.c | 8 ++++++++
modules/video_output/vmem.c | 3 +++
src/input/decoder.c | 1 +
6 files changed, 23 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index fb91f59..75e7577 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -393,6 +393,14 @@ void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,
libvlc_video_cleanup_cb cleanup );

/**
+ * Return the track ID of the video stream for which @ref libvlc_video_format_cb
+ * is being called. This function is valid only when called from the setup
+ * callback.
+ */
+LIBVLC_API
+int libvlc_video_format_cb_get_track_id( void **opaque );
+
+/**
* Set the NSView handler where the media player should render its video output.
*
* Use the vout called "macosx".
diff --git a/include/vlc_es.h b/include/vlc_es.h
index 38d63da..536883e 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -202,6 +202,8 @@ struct video_format_t
int i_rbshift, i_lbshift;
video_palette_t *p_palette; /**< video palette from demuxer */
video_orientation_t orientation; /**< picture orientation */
+
+ int i_dec_es_id; /**< elementary stream ID from decoder */
};

/**
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index fdfd164..f24ad30 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -199,6 +199,7 @@ libvlc_toggle_fullscreen
libvlc_toggle_teletext
libvlc_track_description_release
libvlc_track_description_list_release
+libvlc_video_format_cb_get_track_id
libvlc_video_get_adjust_float
libvlc_video_get_adjust_int
libvlc_video_get_aspect_ratio
diff --git a/lib/media_player.c b/lib/media_player.c
index 868aefe..54c7cd1 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -861,6 +861,14 @@ void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,
var_SetAddress( mp, "vmem-cleanup", cleanup );
}

+/**************************************************************************
+ * Get track id from opaque pointer passed to libvlc_video_format_cb.
+ **************************************************************************/
+int libvlc_video_format_cb_get_track_id( void **opaque )
+{
+ return *(int *)(opaque + 1);
+}
+
void libvlc_video_set_format( libvlc_media_player_t *mp, const char *chroma,
unsigned width, unsigned height, unsigned pitch )
{
diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c
index 2575f75..8acfcb1 100644
--- a/modules/video_output/vmem.c
+++ b/modules/video_output/vmem.c
@@ -92,6 +92,8 @@ struct vout_display_sys_t {
unsigned count;

void *opaque;
+ int track_id; /* Keep at (int *)(opaque + 1) --
+ see libvlc_video_format_cb_get_track_id() */
void *(*lock)(void *sys, void **plane);
void (*unlock)(void *sys, void *id, void *const *plane);
void (*display)(void *sys, void *id);
@@ -136,6 +138,7 @@ static int Open(vlc_object_t *object)
sys->display = var_InheritAddress(vd, "vmem-display");
sys->cleanup = var_InheritAddress(vd, "vmem-cleanup");
sys->opaque = var_InheritAddress(vd, "vmem-data");
+ sys->track_id = vd->fmt.i_dec_es_id;
sys->pool = NULL;

/* Define the video format */
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 46129fc..892a3c7 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -2060,6 +2060,7 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )

video_format_t fmt = p_dec->fmt_out.video;
fmt.i_chroma = p_dec->fmt_out.i_codec;
+ fmt.i_dec_es_id = p_dec->fmt_in.i_id;
p_owner->video = fmt;

if( vlc_fourcc_IsYUV( fmt.i_chroma ) )
--
1.8.1.5
Rémi Denis-Courmont
2014-03-03 14:51:27 UTC
Permalink
On Mon, 3 Mar 2014 13:20:05 +0100, Jerome Forissier <jerome at taodyne.com>
Post by Jerome Forissier
diff --git a/include/vlc_es.h b/include/vlc_es.h
index 38d63da..536883e 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -202,6 +202,8 @@ struct video_format_t
int i_rbshift, i_lbshift;
video_palette_t *p_palette; /**< video palette from demuxer */
video_orientation_t orientation; /**< picture orientation */
+
+ int i_dec_es_id; /**< elementary stream ID from decoder */
IMHO, the ES id is meta-data which does not belong in the physical video
format. Furthermore, this is a reference and the video format is supposed
to be self-contained. And even otherwise, I suspect a lot of code paths
would leave the value undefined as of now.
Post by Jerome Forissier
};
/**
diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c
index 2575f75..8acfcb1 100644
--- a/modules/video_output/vmem.c
+++ b/modules/video_output/vmem.c
@@ -92,6 +92,8 @@ struct vout_display_sys_t {
unsigned count;
void *opaque;
+ int track_id; /* Keep at (int *)(opaque + 1) --
+ see libvlc_video_format_cb_get_track_id() */
Does this really need to be retained in sys?
Post by Jerome Forissier
void *(*lock)(void *sys, void **plane);
void (*unlock)(void *sys, void *id, void *const *plane);
void (*display)(void *sys, void *id);
@@ -136,6 +138,7 @@ static int Open(vlc_object_t *object)
sys->display = var_InheritAddress(vd, "vmem-display");
sys->cleanup = var_InheritAddress(vd, "vmem-cleanup");
sys->opaque = var_InheritAddress(vd, "vmem-data");
+ sys->track_id = vd->fmt.i_dec_es_id;
sys->pool = NULL;
/* Define the video format */
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 46129fc..892a3c7 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -2060,6 +2060,7 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
video_format_t fmt = p_dec->fmt_out.video;
fmt.i_chroma = p_dec->fmt_out.i_codec;
+ fmt.i_dec_es_id = p_dec->fmt_in.i_id;
I guess this will not work if the format is unchanged, but the track ID is
(kind of relates to the first comment).
Post by Jerome Forissier
p_owner->video = fmt;
if( vlc_fourcc_IsYUV( fmt.i_chroma ) )
--
R?mi Denis-Courmont
Sent from my collocated server
Jérôme Forissier
2014-03-03 15:38:37 UTC
Permalink
Post by Rémi Denis-Courmont
On Mon, 3 Mar 2014 13:20:05 +0100, Jerome Forissier <jerome at taodyne.com>
Post by Jerome Forissier
diff --git a/include/vlc_es.h b/include/vlc_es.h
index 38d63da..536883e 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -202,6 +202,8 @@ struct video_format_t
int i_rbshift, i_lbshift;
video_palette_t *p_palette; /**< video palette from demuxer */
video_orientation_t orientation; /**< picture orientation */
+
+ int i_dec_es_id; /**< elementary stream ID from decoder */
IMHO, the ES id is meta-data which does not belong in the physical video
format. Furthermore, this is a reference and the video format is supposed
to be self-contained.
Agreed. But then how would you recommend I pass this ID from vout_new_buffer()
to the Open() function of vmem.c? That's all I'm trying to accomplish...
Post by Rémi Denis-Courmont
And even otherwise, I suspect a lot of code paths
would leave the value undefined as of now.
Right, I forgot to update video_format_Init() / video_formar_Clean().
Post by Rémi Denis-Courmont
Post by Jerome Forissier
};
/**
diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c
index 2575f75..8acfcb1 100644
--- a/modules/video_output/vmem.c
+++ b/modules/video_output/vmem.c
@@ -92,6 +92,8 @@ struct vout_display_sys_t {
unsigned count;
void *opaque;
+ int track_id; /* Keep at (int *)(opaque + 1) --
+ see libvlc_video_format_cb_get_track_id() */
Does this really need to be retained in sys?
No. It just has to be sitting next to opaque for the duration of the setup()
callback, which can indeed be accomplished inside Open() without changing
vout_display_sys_t.
Post by Rémi Denis-Courmont
Post by Jerome Forissier
void *(*lock)(void *sys, void **plane);
void (*unlock)(void *sys, void *id, void *const *plane);
void (*display)(void *sys, void *id);
@@ -136,6 +138,7 @@ static int Open(vlc_object_t *object)
sys->display = var_InheritAddress(vd, "vmem-display");
sys->cleanup = var_InheritAddress(vd, "vmem-cleanup");
sys->opaque = var_InheritAddress(vd, "vmem-data");
+ sys->track_id = vd->fmt.i_dec_es_id;
sys->pool = NULL;
/* Define the video format */
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 46129fc..892a3c7 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -2060,6 +2060,7 @@ static picture_t *vout_new_buffer( decoder_t
*p_dec )
Post by Jerome Forissier
video_format_t fmt = p_dec->fmt_out.video;
fmt.i_chroma = p_dec->fmt_out.i_codec;
+ fmt.i_dec_es_id = p_dec->fmt_in.i_id;
I guess this will not work if the format is unchanged, but the track ID is
(kind of relates to the first comment).
Probably, but the purpose of the patch it just to be able to get the track ID at
the time the vout is created.

Thanks.
--
J?r?me
Loading...