Mercurial > mplayer.hg
comparison libmpdemux/demux_lavf.c @ 18762:369074e0eb7b
support for audio stream switching
author | nicodvb |
---|---|
date | Tue, 20 Jun 2006 19:57:16 +0000 |
parents | f70772d02eaa |
children | bdcbf1070680 |
comparison
equal
deleted
inserted
replaced
18761:4168044c1be4 | 18762:369074e0eb7b |
---|---|
42 AVFormatContext *avfc; | 42 AVFormatContext *avfc; |
43 ByteIOContext pb; | 43 ByteIOContext pb; |
44 int audio_streams; | 44 int audio_streams; |
45 int video_streams; | 45 int video_streams; |
46 int64_t last_pts; | 46 int64_t last_pts; |
47 int astreams[MAX_A_STREAMS]; | |
47 }lavf_priv_t; | 48 }lavf_priv_t; |
48 | 49 |
49 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); | 50 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
50 extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level); | 51 extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level); |
51 | 52 |
182 #endif | 183 #endif |
183 | 184 |
184 switch(codec->codec_type){ | 185 switch(codec->codec_type){ |
185 case CODEC_TYPE_AUDIO:{ | 186 case CODEC_TYPE_AUDIO:{ |
186 WAVEFORMATEX *wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1); | 187 WAVEFORMATEX *wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1); |
188 if(priv->audio_streams >= MAX_A_STREAMS) | |
189 break; | |
187 sh_audio_t* sh_audio=new_sh_audio(demuxer, i); | 190 sh_audio_t* sh_audio=new_sh_audio(demuxer, i); |
191 if(!sh_audio) | |
192 break; | |
193 priv->astreams[priv->audio_streams] = i; | |
188 priv->audio_streams++; | 194 priv->audio_streams++; |
189 if(!codec->codec_tag) | 195 if(!codec->codec_tag) |
190 codec->codec_tag= codec_get_wav_tag(codec->codec_id); | 196 codec->codec_tag= codec_get_wav_tag(codec->codec_id); |
191 wf->wFormatTag= codec->codec_tag; | 197 wf->wFormatTag= codec->codec_tag; |
192 wf->nChannels= codec->channels; | 198 wf->nChannels= codec->channels; |
416 if (priv->avfc->duration == 0) | 422 if (priv->avfc->duration == 0) |
417 return DEMUXER_CTRL_DONTKNOW; | 423 return DEMUXER_CTRL_DONTKNOW; |
418 | 424 |
419 *((int *)arg) = (int)(priv->last_pts*100 / priv->avfc->duration); | 425 *((int *)arg) = (int)(priv->last_pts*100 / priv->avfc->duration); |
420 return DEMUXER_CTRL_OK; | 426 return DEMUXER_CTRL_OK; |
421 | 427 case DEMUXER_CTRL_SWITCH_AUDIO: |
428 { | |
429 int id = *((int*)arg); | |
430 int newid = -2; | |
431 int i, curridx = -2; | |
432 | |
433 if(demuxer->audio->id == -2) | |
434 return DEMUXER_CTRL_NOTIMPL; | |
435 for(i = 0; i < priv->audio_streams; i++) | |
436 { | |
437 if(priv->astreams[i] == demuxer->audio->id) //current stream id | |
438 { | |
439 curridx = i; | |
440 break; | |
441 } | |
442 } | |
443 | |
444 if(id < 0) | |
445 { | |
446 i = (curridx + 1) % priv->audio_streams; | |
447 newid = priv->astreams[i]; | |
448 } | |
449 else | |
450 { | |
451 for(i = 0; i < priv->audio_streams; i++) | |
452 { | |
453 if(priv->astreams[i] == id) | |
454 { | |
455 newid = id; | |
456 break; | |
457 } | |
458 } | |
459 } | |
460 if(newid == -2 || i == curridx) | |
461 return DEMUXER_CTRL_NOTIMPL; | |
462 else | |
463 { | |
464 ds_free_packs(demuxer->audio); | |
465 priv->avfc->streams[demuxer->audio->id]->discard = AVDISCARD_ALL; | |
466 *((int*)arg) = demuxer->audio->id = newid; | |
467 priv->avfc->streams[newid]->discard = AVDISCARD_NONE; | |
468 return DEMUXER_CTRL_OK; | |
469 } | |
470 } | |
422 default: | 471 default: |
423 return DEMUXER_CTRL_NOTIMPL; | 472 return DEMUXER_CTRL_NOTIMPL; |
424 } | 473 } |
425 } | 474 } |
426 | 475 |