Index: libhb/stream.c =================================================================== --- libhb/stream.c (revision 968) +++ libhb/stream.c (working copy) @@ -574,58 +574,64 @@ } lang = lang_for_code(stream->a52_info[i].lang_code); - audio->rate = stream->a52_info[i].rate; - audio->bitrate = stream->a52_info[i].bitrate; - audio->config.a52.ac3flags = audio->ac3flags = stream->a52_info[i].flags; + if (!audio->rate) + audio->rate = stream->a52_info[i].rate; + if (!audio->bitrate) + audio->bitrate = stream->a52_info[i].bitrate; + if (!audio->config.a52.ac3flags) + audio->config.a52.ac3flags = audio->ac3flags = stream->a52_info[i].flags; } - switch( audio->ac3flags & A52_CHANNEL_MASK ) + if (!audio->input_channel_layout) { - /* mono sources */ - case A52_MONO: - case A52_CHANNEL1: - case A52_CHANNEL2: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_MONO; - break; - /* stereo input */ - case A52_CHANNEL: - case A52_STEREO: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_STEREO; - break; - /* dolby (DPL1 aka Dolby Surround = 4.0 matrix-encoded) input */ - case A52_DOLBY: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_DOLBY; - break; - /* 3F/2R input */ - case A52_3F2R: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F2R; - break; - /* 3F/1R input */ - case A52_3F1R: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F1R; - break; - /* other inputs */ - case A52_3F: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F; - break; - case A52_2F1R: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_2F1R; - break; - case A52_2F2R: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_2F2R; - break; - /* unknown */ - default: - audio->input_channel_layout = HB_INPUT_CH_LAYOUT_STEREO; - } + switch( audio->ac3flags & A52_CHANNEL_MASK ) + { + /* mono sources */ + case A52_MONO: + case A52_CHANNEL1: + case A52_CHANNEL2: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_MONO; + break; + /* stereo input */ + case A52_CHANNEL: + case A52_STEREO: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_STEREO; + break; + /* dolby (DPL1 aka Dolby Surround = 4.0 matrix-encoded) input */ + case A52_DOLBY: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_DOLBY; + break; + /* 3F/2R input */ + case A52_3F2R: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F2R; + break; + /* 3F/1R input */ + case A52_3F1R: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F1R; + break; + /* other inputs */ + case A52_3F: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_3F; + break; + case A52_2F1R: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_2F1R; + break; + case A52_2F2R: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_2F2R; + break; + /* unknown */ + default: + audio->input_channel_layout = HB_INPUT_CH_LAYOUT_STEREO; + } - /* add in our own LFE flag if the source has LFE */ - if (audio->ac3flags & A52_LFE) - { - audio->input_channel_layout = audio->input_channel_layout | HB_INPUT_CH_LAYOUT_HAS_LFE; + /* add in our own LFE flag if the source has LFE */ + if (audio->ac3flags & A52_LFE) + { + audio->input_channel_layout = audio->input_channel_layout | HB_INPUT_CH_LAYOUT_HAS_LFE; + } } - + snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)", strlen(lang->native_name) ? lang->native_name : lang->eng_name, audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec == HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) ); snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s", strlen(lang->native_name) ? lang->native_name : lang->eng_name ); @@ -1933,17 +1939,19 @@ // if (pid == stream->ts_audio_pids[0] /*&& audstreamid == 0xBD*/) if (index_of_audio_pid(pid, stream) >= 0) { - if ((stream->ts_audio_stream_type[curstream] == 0x04) || (stream->ts_audio_stream_type[curstream] == 0x81)) + // Curstream is a zero based index of streams and includes both video and audio streams, so we must subtract the numver of video streams + // from the indes value used here since ts_audio_stream_type is indexed only by audio streams. + if ((stream->ts_audio_stream_type[curstream - stream->ts_number_video_pids] == 0x04) || (stream->ts_audio_stream_type[curstream - stream->ts_number_video_pids] == 0x81)) { write_ac3 = hb_ts_handle_ac3_audio(stream, curstream, buf, adapt_len); } - else if (stream->ts_audio_stream_type[curstream] == 0x03) + else if (stream->ts_audio_stream_type[curstream - stream->ts_number_video_pids] == 0x03) { hb_ts_handle_mpeg_audio(stream, curstream, buf, adapt_len); } else { - hb_log("hb_ts_stream_decode - Unknown Audio Stream type ! 0x%x (%d)", stream->ts_audio_stream_type[curstream], stream->ts_audio_stream_type[curstream]); + hb_log("hb_ts_stream_decode - Unknown Audio Stream type ! 0x%x (%d)", stream->ts_audio_stream_type[curstream - stream->ts_number_video_pids], stream->ts_audio_stream_type[curstream - stream->ts_number_video_pids]); } }