--- stream/asf_mmst_streaming.c 2009-03-20 09:22:36.000000000 +0100 +++ stream/asf_mmst_streaming.c.ultimo_riferimento 2009-03-20 09:26:57.000000000 +0100 @@ -66,6 +66,7 @@ extern int audio_id; extern int video_id; +extern int network_bandwidth; #define BUF_SIZE 102400 #define HDR_BUF_SIZE 8192 @@ -402,6 +403,62 @@ return -1; } +static uint32_t select_best_single_stream(struct asf_mms_streaming_ctrl *mms_ctrl, ASFtype ASF_type, unsigned int bandwidth) +{ + int i, id; + uint32_t max = 0; + + for (i = 1; i < MAX_STREAMS; i++) + if (mms_ctrl->stream_type[i] == ASF_type) { + uint32_t rate = mms_ctrl->stream_bitrates[i]; + if (rate <= bandwidth && rate > max) { + id = i; + max = rate; + } + } + + if (max) { + if (ASF_type == ASF_AUDIO_STREAM) + mms_ctrl->audio_id = id; + else + if (ASF_type == ASF_VIDEO_STREAM) + mms_ctrl->video_id = id; + } + return max; +} + +static void select_best_streams(struct asf_mms_streaming_ctrl *mms_ctrl) +{ + unsigned int bandwidth = network_bandwidth ? network_bandwidth : INT_MAX; + int i, k; + uint32_t max = 0; + + mp_msg(MSGT_NETWORK, MSGL_V, "Max bandwidth set to %d\n", bandwidth); + + if (mms_ctrl->audio_id && mms_ctrl->video_id) + for (i = 1; i < MAX_STREAMS; i++) + for (k = 1; k < MAX_STREAMS; k++) { + if (mms_ctrl->stream_type[i] == ASF_VIDEO_STREAM && + mms_ctrl->stream_type[k] == ASF_AUDIO_STREAM) { + uint32_t sum = mms_ctrl->stream_bitrates[i] + mms_ctrl->stream_bitrates[k]; + if (sum <= bandwidth && sum > max) { + mms_ctrl->audio_id = k; + mms_ctrl->video_id = i; + max = sum; + } + } + } + else + if (mms_ctrl->audio_id) + max = select_best_single_stream(mms_ctrl, ASF_AUDIO_STREAM, bandwidth); + else + if (mms_ctrl->video_id) + max = select_best_single_stream(mms_ctrl, ASF_VIDEO_STREAM, bandwidth); + if (!max) + mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_ASF_Bandwidth2SmallCannotPlay); +} + + static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) { unsigned char pre_header[8]; char data[BUF_SIZE]; @@ -663,6 +720,9 @@ if (audio_id == -2) /* sound disabled */ mms_ctrl->audio_id = 0; + if (video_id < 0 || audio_id < 0) + select_best_streams(mms_ctrl); + if (audio_id > 0) { if (mms_ctrl->stream_type[audio_id] == ASF_AUDIO_STREAM) mms_ctrl->audio_id = audio_id;