mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 23:00:41 +00:00
Support 'default' attribute for audio and subtitle tracks.
The first default track is chosen for playback if language-based selection failes. Additionally, for audio tracks, the first one is chosen if there are no default tracks at all. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26301 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
37d20cbc93
commit
7cc46c2e87
@ -337,6 +337,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
|
|||||||
}
|
}
|
||||||
if (st->language)
|
if (st->language)
|
||||||
sh_audio->lang = strdup(st->language);
|
sh_audio->lang = strdup(st->language);
|
||||||
|
if (st->disposition & AV_DISPOSITION_DEFAULT)
|
||||||
|
sh_audio->default_track = 1;
|
||||||
if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
|
if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
|
||||||
// select the first audio stream
|
// select the first audio stream
|
||||||
if (!demuxer->audio->sh) {
|
if (!demuxer->audio->sh) {
|
||||||
@ -433,6 +435,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
|
|||||||
}
|
}
|
||||||
if (st->language)
|
if (st->language)
|
||||||
sh_sub->lang = strdup(st->language);
|
sh_sub->lang = strdup(st->language);
|
||||||
|
if (st->disposition & AV_DISPOSITION_DEFAULT)
|
||||||
|
sh_sub->default_track = 1;
|
||||||
priv->sub_streams++;
|
priv->sub_streams++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1849,6 +1849,7 @@ demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track, int aid)
|
|||||||
|
|
||||||
if (track->language && (strcmp(track->language, "und") != 0))
|
if (track->language && (strcmp(track->language, "und") != 0))
|
||||||
sh_a->lang = strdup(track->language);
|
sh_a->lang = strdup(track->language);
|
||||||
|
sh_a->default_track = track->default_track;
|
||||||
sh_a->ds = demuxer->audio;
|
sh_a->ds = demuxer->audio;
|
||||||
sh_a->wf = malloc (sizeof (WAVEFORMATEX));
|
sh_a->wf = malloc (sizeof (WAVEFORMATEX));
|
||||||
if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX)))
|
if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX)))
|
||||||
@ -2217,6 +2218,7 @@ demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid)
|
|||||||
sh->extradata_len = track->private_size;
|
sh->extradata_len = track->private_size;
|
||||||
if (track->language && (strcmp(track->language, "und") != 0))
|
if (track->language && (strcmp(track->language, "und") != 0))
|
||||||
sh->lang = strdup(track->language);
|
sh->lang = strdup(track->language);
|
||||||
|
sh->default_track = track->default_track;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1441,3 +1441,31 @@ int demuxer_sub_track_by_lang(demuxer_t* d, char* lang)
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int demuxer_default_audio_track(demuxer_t* d)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0; i < MAX_A_STREAMS; ++i) {
|
||||||
|
sh_audio_t* sh = d->a_streams[i];
|
||||||
|
if (sh && sh->default_track)
|
||||||
|
return sh->aid;
|
||||||
|
}
|
||||||
|
for (i=0; i < MAX_A_STREAMS; ++i) {
|
||||||
|
sh_audio_t* sh = d->a_streams[i];
|
||||||
|
if (sh)
|
||||||
|
return sh->aid;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demuxer_default_sub_track(demuxer_t* d)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0; i < MAX_S_STREAMS; ++i) {
|
||||||
|
sh_sub_t* sh = d->s_streams[i];
|
||||||
|
if (sh && sh->default_track)
|
||||||
|
return sh->sid;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -431,4 +431,10 @@ int demuxer_angles_count(demuxer_t *demuxer);
|
|||||||
int demuxer_audio_track_by_lang(demuxer_t* demuxer, char* lang);
|
int demuxer_audio_track_by_lang(demuxer_t* demuxer, char* lang);
|
||||||
int demuxer_sub_track_by_lang(demuxer_t* demuxer, char* lang);
|
int demuxer_sub_track_by_lang(demuxer_t* demuxer, char* lang);
|
||||||
|
|
||||||
|
// find the default track
|
||||||
|
// for subtitles, it is the first track with default attribute
|
||||||
|
// for audio, additionally, the first track is selected if no track has default attribute set
|
||||||
|
int demuxer_default_audio_track(demuxer_t* d);
|
||||||
|
int demuxer_default_sub_track(demuxer_t* d);
|
||||||
|
|
||||||
#endif /* MPLAYER_DEMUXER_H */
|
#endif /* MPLAYER_DEMUXER_H */
|
||||||
|
@ -51,6 +51,7 @@ typedef struct {
|
|||||||
double pts; // last known pts value in output from decoder
|
double pts; // last known pts value in output from decoder
|
||||||
int pts_bytes; // bytes output by decoder after last known pts
|
int pts_bytes; // bytes output by decoder after last known pts
|
||||||
char* lang; // track language
|
char* lang; // track language
|
||||||
|
int default_track;
|
||||||
} sh_audio_t;
|
} sh_audio_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -108,6 +109,7 @@ typedef struct {
|
|||||||
ass_track_t* ass_track; // for SSA/ASS streams (type == 'a')
|
ass_track_t* ass_track; // for SSA/ASS streams (type == 'a')
|
||||||
#endif
|
#endif
|
||||||
char* lang; // track language
|
char* lang; // track language
|
||||||
|
int default_track;
|
||||||
} sh_sub_t;
|
} sh_sub_t;
|
||||||
|
|
||||||
// demuxer.c:
|
// demuxer.c:
|
||||||
|
@ -601,6 +601,9 @@ if(stream->type==STREAMTYPE_DVDNAV){
|
|||||||
if (dvdsub_id < 0 && dvdsub_lang)
|
if (dvdsub_id < 0 && dvdsub_lang)
|
||||||
dvdsub_id = demuxer_sub_track_by_lang(demuxer, dvdsub_lang);
|
dvdsub_id = demuxer_sub_track_by_lang(demuxer, dvdsub_lang);
|
||||||
|
|
||||||
|
if (dvdsub_id < 0)
|
||||||
|
dvdsub_id = demuxer_default_sub_track(demuxer);
|
||||||
|
|
||||||
for (i = 0; i < MAX_S_STREAMS; i++) {
|
for (i = 0; i < MAX_S_STREAMS; i++) {
|
||||||
sh_sub_t *sh = demuxer->s_streams[i];
|
sh_sub_t *sh = demuxer->s_streams[i];
|
||||||
if (sh && sh->sid == dvdsub_id) {
|
if (sh && sh->sid == dvdsub_id) {
|
||||||
|
@ -195,6 +195,8 @@ int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang)
|
|||||||
{
|
{
|
||||||
if (audio_id == -1 && audio_lang)
|
if (audio_id == -1 && audio_lang)
|
||||||
audio_id = demuxer_audio_track_by_lang(demuxer, audio_lang);
|
audio_id = demuxer_audio_track_by_lang(demuxer, audio_lang);
|
||||||
|
if (audio_id == -1)
|
||||||
|
audio_id = demuxer_default_audio_track(demuxer);
|
||||||
if (audio_id != -1) // -1 (automatic) is the default behaviour of demuxers
|
if (audio_id != -1) // -1 (automatic) is the default behaviour of demuxers
|
||||||
demuxer_switch_audio(demuxer, audio_id);
|
demuxer_switch_audio(demuxer, audio_id);
|
||||||
if (audio_id == -2) { // some demuxers don't yet know how to switch to no sound
|
if (audio_id == -2) { // some demuxers don't yet know how to switch to no sound
|
||||||
|
@ -3459,6 +3459,8 @@ if (mpctx->global_sub_size) {
|
|||||||
int vobsub_index_id = vobsub_get_index_by_id(vo_vobsub, vobsub_id);
|
int vobsub_index_id = vobsub_get_index_by_id(vo_vobsub, vobsub_id);
|
||||||
if (dvdsub_id < 0 && dvdsub_lang)
|
if (dvdsub_id < 0 && dvdsub_lang)
|
||||||
dvdsub_id = demuxer_sub_track_by_lang(mpctx->demuxer, dvdsub_lang);
|
dvdsub_id = demuxer_sub_track_by_lang(mpctx->demuxer, dvdsub_lang);
|
||||||
|
if (dvdsub_id < 0)
|
||||||
|
dvdsub_id = demuxer_default_sub_track(mpctx->demuxer);
|
||||||
if (vobsub_index_id >= 0) {
|
if (vobsub_index_id >= 0) {
|
||||||
// if user asks for a vobsub id, use that first.
|
// if user asks for a vobsub id, use that first.
|
||||||
mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_index_id;
|
mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_index_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user