Fixes ticket 1161.
Signed-off-by: Marton Balint <cus@passwd.hu>
... | ... |
@@ -232,6 +232,7 @@ typedef struct VideoState { |
232 | 232 |
#endif |
233 | 233 |
|
234 | 234 |
int refresh; |
235 |
+ int last_video_stream, last_audio_stream, last_subtitle_stream; |
|
235 | 236 |
} VideoState; |
236 | 237 |
|
237 | 238 |
typedef struct AllocEventProps { |
... | ... |
@@ -2263,9 +2264,9 @@ static int stream_component_open(VideoState *is, int stream_index) |
2263 | 2263 |
opts = filter_codec_opts(codec_opts, codec, ic, ic->streams[stream_index]); |
2264 | 2264 |
|
2265 | 2265 |
switch(avctx->codec_type){ |
2266 |
- case AVMEDIA_TYPE_AUDIO : if(audio_codec_name ) codec= avcodec_find_decoder_by_name( audio_codec_name); break; |
|
2267 |
- case AVMEDIA_TYPE_SUBTITLE: if(subtitle_codec_name) codec= avcodec_find_decoder_by_name(subtitle_codec_name); break; |
|
2268 |
- case AVMEDIA_TYPE_VIDEO : if(video_codec_name ) codec= avcodec_find_decoder_by_name( video_codec_name); break; |
|
2266 |
+ case AVMEDIA_TYPE_AUDIO : is->last_audio_stream = stream_index; if(audio_codec_name ) codec= avcodec_find_decoder_by_name( audio_codec_name); break; |
|
2267 |
+ case AVMEDIA_TYPE_SUBTITLE: is->last_subtitle_stream = stream_index; if(subtitle_codec_name) codec= avcodec_find_decoder_by_name(subtitle_codec_name); break; |
|
2268 |
+ case AVMEDIA_TYPE_VIDEO : is->last_video_stream = stream_index; if(video_codec_name ) codec= avcodec_find_decoder_by_name( video_codec_name); break; |
|
2269 | 2269 |
} |
2270 | 2270 |
if (!codec) |
2271 | 2271 |
return -1; |
... | ... |
@@ -2492,9 +2493,9 @@ static int read_thread(void *arg) |
2492 | 2492 |
int orig_nb_streams; |
2493 | 2493 |
|
2494 | 2494 |
memset(st_index, -1, sizeof(st_index)); |
2495 |
- is->video_stream = -1; |
|
2496 |
- is->audio_stream = -1; |
|
2497 |
- is->subtitle_stream = -1; |
|
2495 |
+ is->last_video_stream = is->video_stream = -1; |
|
2496 |
+ is->last_audio_stream = is->audio_stream = -1; |
|
2497 |
+ is->last_subtitle_stream = is->subtitle_stream = -1; |
|
2498 | 2498 |
|
2499 | 2499 |
ic = avformat_alloc_context(); |
2500 | 2500 |
ic->interrupt_callback.callback = decode_interrupt_cb; |
... | ... |
@@ -2772,16 +2773,19 @@ static void stream_cycle_channel(VideoState *is, int codec_type) |
2772 | 2772 |
{ |
2773 | 2773 |
AVFormatContext *ic = is->ic; |
2774 | 2774 |
int start_index, stream_index; |
2775 |
+ int old_index; |
|
2775 | 2776 |
AVStream *st; |
2776 | 2777 |
|
2777 |
- if (codec_type == AVMEDIA_TYPE_VIDEO) |
|
2778 |
- start_index = is->video_stream; |
|
2779 |
- else if (codec_type == AVMEDIA_TYPE_AUDIO) |
|
2780 |
- start_index = is->audio_stream; |
|
2781 |
- else |
|
2782 |
- start_index = is->subtitle_stream; |
|
2783 |
- if (start_index < (codec_type == AVMEDIA_TYPE_SUBTITLE ? -1 : 0)) |
|
2784 |
- return; |
|
2778 |
+ if (codec_type == AVMEDIA_TYPE_VIDEO) { |
|
2779 |
+ start_index = is->last_video_stream; |
|
2780 |
+ old_index = is->video_stream; |
|
2781 |
+ } else if (codec_type == AVMEDIA_TYPE_AUDIO) { |
|
2782 |
+ start_index = is->last_audio_stream; |
|
2783 |
+ old_index = is->audio_stream; |
|
2784 |
+ } else { |
|
2785 |
+ start_index = is->last_subtitle_stream; |
|
2786 |
+ old_index = is->subtitle_stream; |
|
2787 |
+ } |
|
2785 | 2788 |
stream_index = start_index; |
2786 | 2789 |
for (;;) { |
2787 | 2790 |
if (++stream_index >= is->ic->nb_streams) |
... | ... |
@@ -2789,9 +2793,12 @@ static void stream_cycle_channel(VideoState *is, int codec_type) |
2789 | 2789 |
if (codec_type == AVMEDIA_TYPE_SUBTITLE) |
2790 | 2790 |
{ |
2791 | 2791 |
stream_index = -1; |
2792 |
+ is->last_subtitle_stream = -1; |
|
2792 | 2793 |
goto the_end; |
2793 |
- } else |
|
2794 |
- stream_index = 0; |
|
2794 |
+ } |
|
2795 |
+ if (start_index == -1) |
|
2796 |
+ return; |
|
2797 |
+ stream_index = 0; |
|
2795 | 2798 |
} |
2796 | 2799 |
if (stream_index == start_index) |
2797 | 2800 |
return; |
... | ... |
@@ -2813,7 +2820,7 @@ static void stream_cycle_channel(VideoState *is, int codec_type) |
2813 | 2813 |
} |
2814 | 2814 |
} |
2815 | 2815 |
the_end: |
2816 |
- stream_component_close(is, start_index); |
|
2816 |
+ stream_component_close(is, old_index); |
|
2817 | 2817 |
stream_component_open(is, stream_index); |
2818 | 2818 |
} |
2819 | 2819 |
|