Mercurial > mplayer.hg
comparison libmpdemux/demux_mkv.c @ 18754:e0077bdf5ee5
feed any audio track present in the mux; switch to any of the available audio tracks
author | nicodvb |
---|---|
date | Mon, 19 Jun 2006 18:34:29 +0000 |
parents | 9e2b300db17b |
children | 5c8acc972551 |
comparison
equal
deleted
inserted
replaced
18753:45342b9b2789 | 18754:e0077bdf5ee5 |
---|---|
177 int v_skip_to_keyframe, a_skip_to_keyframe; | 177 int v_skip_to_keyframe, a_skip_to_keyframe; |
178 | 178 |
179 mkv_chapter_t *chapters; | 179 mkv_chapter_t *chapters; |
180 int num_chapters; | 180 int num_chapters; |
181 int64_t stop_timecode; | 181 int64_t stop_timecode; |
182 | |
183 int last_aid; | |
184 int audio_tracks[MAX_A_STREAMS]; | |
182 } mkv_demuxer_t; | 185 } mkv_demuxer_t; |
183 | 186 |
184 | 187 |
185 typedef struct | 188 typedef struct |
186 { | 189 { |
1748 } | 1751 } |
1749 | 1752 |
1750 static int | 1753 static int |
1751 demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track) | 1754 demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track) |
1752 { | 1755 { |
1756 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv; | |
1753 sh_audio_t *sh_a = new_sh_audio(demuxer, track->tnum); | 1757 sh_audio_t *sh_a = new_sh_audio(demuxer, track->tnum); |
1758 if(!sh_a) return 1; | |
1759 mkv_d->audio_tracks[mkv_d->last_aid] = track->tnum; | |
1754 demux_packet_t *dp; | 1760 demux_packet_t *dp; |
1755 | 1761 |
1756 sh_a->ds = demuxer->audio; | 1762 sh_a->ds = demuxer->audio; |
1757 sh_a->wf = (WAVEFORMATEX *) malloc (sizeof (WAVEFORMATEX)); | 1763 sh_a->wf = (WAVEFORMATEX *) malloc (sizeof (WAVEFORMATEX)); |
1758 if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX))) | 1764 if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX))) |
2339 } | 2345 } |
2340 } | 2346 } |
2341 else if (demuxer->audio->id != -2) /* -2 = no audio at all */ | 2347 else if (demuxer->audio->id != -2) /* -2 = no audio at all */ |
2342 track = demux_mkv_find_track_by_num (mkv_d, demuxer->audio->id, | 2348 track = demux_mkv_find_track_by_num (mkv_d, demuxer->audio->id, |
2343 MATROSKA_TRACK_AUDIO); | 2349 MATROSKA_TRACK_AUDIO); |
2344 | |
2345 if (track && !demux_mkv_open_audio (demuxer, track)) | |
2346 { | |
2347 mp_msg (MSGT_DEMUX, MSGL_INFO, | |
2348 "[mkv] Will play audio track %u\n", track->tnum); | |
2349 demuxer->audio->id = track->tnum; | |
2350 demuxer->audio->sh = demuxer->a_streams[track->tnum]; | |
2351 } | |
2352 else | 2350 else |
2353 { | 2351 { |
2354 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n"); | 2352 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n"); |
2355 demuxer->audio->id = -2; | 2353 demuxer->audio->id = -2; |
2354 } | |
2355 | |
2356 | |
2357 if(demuxer->audio->id != -2) | |
2358 for (i=0; i < mkv_d->num_tracks; i++) | |
2359 { | |
2360 if(mkv_d->tracks[i]->type != MATROSKA_TRACK_AUDIO) | |
2361 continue; | |
2362 if(!demux_mkv_open_audio (demuxer, mkv_d->tracks[i])) | |
2363 { | |
2364 if(track && mkv_d->tracks[i] == track) | |
2365 { | |
2366 demuxer->audio->id = track->tnum; | |
2367 demuxer->audio->sh = demuxer->a_streams[track->tnum]; | |
2368 } | |
2369 mkv_d->last_aid++; | |
2370 if(mkv_d->last_aid == MAX_A_STREAMS) | |
2371 break; | |
2372 } | |
2356 } | 2373 } |
2357 | 2374 |
2358 demux_mkv_parse_vobsub_data (demuxer); | 2375 demux_mkv_parse_vobsub_data (demuxer); |
2359 /* DO NOT automatically select a subtitle track and behave like DVD */ | 2376 /* DO NOT automatically select a subtitle track and behave like DVD */ |
2360 /* playback: only show subtitles if the user explicitely wants them. */ | 2377 /* playback: only show subtitles if the user explicitely wants them. */ |
3467 case DEMUXER_CTRL_SWITCH_AUDIO: | 3484 case DEMUXER_CTRL_SWITCH_AUDIO: |
3468 if (demuxer->audio && demuxer->audio->sh) { | 3485 if (demuxer->audio && demuxer->audio->sh) { |
3469 int i; | 3486 int i; |
3470 demux_stream_t *d_audio = demuxer->audio; | 3487 demux_stream_t *d_audio = demuxer->audio; |
3471 int idx = d_audio->id - 1; // track ids are 1 based | 3488 int idx = d_audio->id - 1; // track ids are 1 based |
3472 int num = mkv_d->num_tracks; | |
3473 mkv_track_t *otrack = mkv_d->tracks[idx]; | 3489 mkv_track_t *otrack = mkv_d->tracks[idx]; |
3474 mkv_track_t *track = 0; | 3490 mkv_track_t *track = 0; |
3475 if (*((int*)arg) < 0) | 3491 if (*((int*)arg) < 0) |
3476 for (i = 1; i <= num; i++) { | 3492 for(i = 0; i < mkv_d->last_aid; i++) { |
3477 track = mkv_d->tracks[(idx+i)%num]; | 3493 if(mkv_d->audio_tracks[i] == d_audio->id) { |
3478 if ((track->type == MATROSKA_TRACK_AUDIO) && | 3494 idx = mkv_d->audio_tracks[(i+1) % mkv_d->last_aid] - 1; |
3479 !strcmp(track->codec_id, otrack->codec_id) && | 3495 track = mkv_d->tracks[idx]; |
3480 (track->private_size == otrack->private_size) && | 3496 if(! track) |
3481 !memcmp(track->private_data, otrack->private_data, track->private_size) && | 3497 continue; |
3482 (track->a_channels == otrack->a_channels) && | 3498 if (track->type == MATROSKA_TRACK_AUDIO) break; |
3483 (track->a_bps == otrack->a_bps) && | 3499 } |
3484 (track->a_sfreq == otrack->a_sfreq)) { | 3500 } |
3485 break; | |
3486 } | |
3487 } | |
3488 else { | 3501 else { |
3489 track = demux_mkv_find_track_by_num (mkv_d, *((int*)arg), MATROSKA_TRACK_AUDIO); | 3502 track = demux_mkv_find_track_by_num (mkv_d, *((int*)arg), MATROSKA_TRACK_AUDIO); |
3490 if (track == NULL || | 3503 if (track == NULL) |
3491 strcmp (track->codec_id, otrack->codec_id) || | |
3492 (track->private_size != otrack->private_size) || | |
3493 memcmp(track->private_data, otrack->private_data, track->private_size) || | |
3494 track->a_channels != otrack->a_channels || | |
3495 track->a_bps != otrack->a_bps || | |
3496 track->a_sfreq != otrack->a_sfreq) | |
3497 track = otrack; | 3504 track = otrack; |
3498 } | 3505 } |
3499 if (track != otrack) { | 3506 if (track != otrack) { |
3500 d_audio->id = track->tnum; | 3507 d_audio->id = track->tnum; |
3501 ds_free_packs(d_audio); | 3508 ds_free_packs(d_audio); |
3502 } | 3509 } |
3503 } | 3510 } |
3504 *((int*)arg) = demux_mkv_reverse_id (mkv_d, demuxer->audio->id, MATROSKA_TRACK_AUDIO); | 3511 *((int*)arg) = demuxer->audio->id; |
3505 return DEMUXER_CTRL_OK; | 3512 return DEMUXER_CTRL_OK; |
3506 | 3513 |
3507 default: | 3514 default: |
3508 return DEMUXER_CTRL_NOTIMPL; | 3515 return DEMUXER_CTRL_NOTIMPL; |
3509 } | 3516 } |