audio: modify get audio info API [1/1]

PD#SWPL-195634

Problem:
modify get audio info API.

Solution:
modify get audio info API.

Verify:
yocto-t6d

Change-Id: I14529aa94c1b6a14fe0d2688a1a02e3fc505186e
Signed-off-by: yayun.shi <yayun.shi@amlogic.com>
diff --git a/audio_hal/aml_audio_ms12_render.c b/audio_hal/aml_audio_ms12_render.c
index 456fe3e..5104985 100644
--- a/audio_hal/aml_audio_ms12_render.c
+++ b/audio_hal/aml_audio_ms12_render.c
@@ -224,6 +224,8 @@
             aml_decoder_get_info(aml_dec, AML_DEC_STREMAM_INFO, &adev->dec_stream_info);
             adev->audio_hal_info.first_decoding_frame = true;
             adev->audio_hal_info.is_decoding = true;
+            adev->audio_hal_info.sample_rate = adev->dec_stream_info.dec_info.stream_sr;
+            adev->audio_hal_info.channel_number = adev->dec_stream_info.dec_info.stream_ch;
             struct dolby_ms12_desc *ms12 = &(adev->ms12);
             //ALOGI("[%s:%d] aml_decoder_stream_info %d %d", __func__, __LINE__, adev->dec_stream_info.dec_info.stream_ch, adev->dec_stream_info.dec_info.stream_sr);
             if (48000 != aml_out->hal_rate || ms12->config_channel_mask != 0x3)
diff --git a/audio_hal/aml_audio_nonms12_render.c b/audio_hal/aml_audio_nonms12_render.c
index 2bba6c2..1beae5d 100644
--- a/audio_hal/aml_audio_nonms12_render.c
+++ b/audio_hal/aml_audio_nonms12_render.c
@@ -374,6 +374,8 @@
                     aml_decoder_get_info(aml_dec, AML_DEC_STREMAM_INFO, &adev->dec_stream_info);
                     adev->audio_hal_info.first_decoding_frame = true;
                     adev->audio_hal_info.is_decoding = true;
+                    adev->audio_hal_info.sample_rate = adev->dec_stream_info.dec_info.stream_sr;
+                    adev->audio_hal_info.channel_number = adev->dec_stream_info.dec_info.stream_ch;
                     ALOGI("[%s:%d] aml_decoder_stream_info %d %d", __func__, __LINE__, adev->dec_stream_info.dec_info.stream_ch, adev->dec_stream_info.dec_info.stream_sr);
                 }
                 if (aml_out->source_type == DTV_SRC && aml_out->mixer_handle) {
diff --git a/audio_hal/audio_hw.c b/audio_hal/audio_hw.c
index dca1f5d..862e804 100644
--- a/audio_hal/audio_hw.c
+++ b/audio_hal/audio_hw.c
@@ -5744,16 +5744,10 @@
             //AUDIO_PARAMTYPE_PTS
             break;
         case AUDIO_PARAMTYPE_SAMPLE_RATE:
-            if (adev->dec_stream_info.dec_info.stream_sr == 0) {
-                sprintf (temp_buf,"audio_information_s=%d", adev->audio_hal_info.sample_rate);
-            } else
-                sprintf (temp_buf,"audio_information_s=%d", adev->dec_stream_info.dec_info.stream_sr);
+            sprintf (temp_buf,"audio_information_s=%d", adev->audio_hal_info.sample_rate);
             break;
         case AUDIO_PARAMTYPE_CHANNEL_MODE:
-            if (adev->dec_stream_info.dec_info.stream_ch == 0) {
-                sprintf (temp_buf,"audio_information_c=%d", adev->audio_hal_info.channel_number);
-            } else
-                sprintf (temp_buf,"audio_information_c=%d", adev->dec_stream_info.dec_info.stream_ch);
+            sprintf (temp_buf,"audio_information_c=%d", adev->audio_hal_info.channel_number);
             break;
         case AUDIO_PARAMTYPE_DIGITAL_AUDIO_INFO:
             //AUDIO_PARAMTYPE_DIGITAL_AUDIO_INFO;
diff --git a/audio_hal/audio_hw_ms12_v2.c b/audio_hal/audio_hw_ms12_v2.c
index 89e17fa..11b804f 100644
--- a/audio_hal/audio_hw_ms12_v2.c
+++ b/audio_hal/audio_hw_ms12_v2.c
@@ -773,6 +773,23 @@
              stream, aml_out->ms12_dec_handle, index, ret);
 }
 
+int get_ms12_main_dec_info(struct audio_stream_out *stream, Aml_MS12_DecInfo_t *dec_info)
+{
+    struct aml_stream_out *aml_out = (struct aml_stream_out *)stream;
+    struct aml_audio_device *adev = aml_out->dev;
+    struct dolby_ms12_desc *ms12 = &(adev->ms12);
+    int ret = -1;
+    if (aml_out && aml_out->ms12_dec_handle && dec_info) {
+        ret = aml_ms12_decoder_getparameter(ms12, aml_out->ms12_dec_handle, MS12_CODEC_PARAMETER_DEC_INFO, dec_info, sizeof(Aml_MS12_DecInfo_t));
+        AM_LOGI("stream:%p ms12_dec_handle:%p ret:%d sr:%d acmod:%d lfe:%d", stream, aml_out->ms12_dec_handle, ret, dec_info->s32SampleRate,
+                dec_info->s32ChannelAcmod, dec_info->s32LfePresent);
+    } else {
+        AM_LOGE("Invalid parameter: stream:%p dec_info:%p", stream, dec_info);
+    }
+
+    return ret;
+}
+
 
 int get_aml_ac4_active_presentation(struct audio_stream_out *stream, int *presentation_group_index)
 {
@@ -1644,23 +1661,24 @@
         }
         ms12->latest_bypass_status = is_ms12_passthrough(stream);
         if (adev->audio_hal_info.first_decoding_frame == false) {
-#if 0
-            int sample_rate = 0;
-            int acmod = 0;
-            int b_lfe = 0;
-            dolby_ms12_get_main_audio_info(&sample_rate, &acmod, &b_lfe);
-
-            /*Default: 2ch, 48khz*/
-            if (sample_rate)
-                adev->audio_hal_info.sample_rate = sample_rate;
-            else
-                adev->audio_hal_info.sample_rate = 48000;
-            if (acmod_convert_to_channel_num(acmod,b_lfe))
-                adev->audio_hal_info.channel_number = acmod_convert_to_channel_num(acmod,b_lfe);
-            else
-                adev->audio_hal_info.channel_number = 2;
-#endif
-            adev->audio_hal_info.first_decoding_frame = true;
+            Aml_MS12_DecInfo_t dec_info;
+            memset(&dec_info, 0x00, sizeof(dec_info));
+            if (0 != get_ms12_main_dec_info(stream, &dec_info)) {
+                AM_LOGE("get_ms12_main_dec_info fail");
+            } else {
+                /*Default: 2ch, 48khz*/
+                if (dec_info.s32SampleRate) {
+                    adev->audio_hal_info.sample_rate = dec_info.s32SampleRate;
+                    adev->audio_hal_info.first_decoding_frame = true;
+                } else {
+                    adev->audio_hal_info.sample_rate = 48000;
+                }
+                adev->audio_hal_info.channel_number = acmod_convert_to_channel_num(dec_info.s32ChannelAcmod,dec_info.s32LfePresent);
+                if (0 == adev->audio_hal_info.channel_number) {
+                    adev->audio_hal_info.channel_number = 2;
+                }
+                AM_LOGI("sr:%d ch:%d", adev->audio_hal_info.sample_rate, adev->audio_hal_info.channel_number);
+            }
         }
 exit:
         if (get_ms12_dump_enable(DUMP_MS12_INPUT_MAIN) && main_frame_buffer && *use_size) {
@@ -3256,6 +3274,7 @@
     struct aml_audio_device *adev = aml_out->dev;
     struct dolby_ms12_desc *ms12 = &(adev->ms12);
     Aml_MS12_ProcessInfo_t *pstProcessInfo = (Aml_MS12_ProcessInfo_t *)info;
+    //AM_LOGI("ACMOD:%d:%d", pstProcessInfo->as32Acmod[0], pstProcessInfo->as32Acmod[1]);
 
     //ALOGI("FrameType %d, InBuffer %p, InBufferSize %d, ch %d", pstProcessInfo->s32InFrameType, pstProcessInfo->pu8InBuffer, pstProcessInfo->u32InBufferSize, pstProcessInfo->s32Channel);
     if (get_ms12_dump_enable(DUMP_MS12_PROCESS_CALLBACK_PCM)) {
diff --git a/audio_hal/audio_hw_ms12_v2.h b/audio_hal/audio_hw_ms12_v2.h
index 156647a..fd893df 100644
--- a/audio_hal/audio_hw_ms12_v2.h
+++ b/audio_hal/audio_hw_ms12_v2.h
@@ -360,6 +360,7 @@
 void set_ms12_ac4_presentation_group_index(struct audio_stream_out *stream, int index);
 int get_aml_ac4_active_presentation(struct audio_stream_out *stream, int *presentation_group_index);
 int check_aml_ac4dec_the_pgi_is_present(struct audio_stream_out *stream, int presentation_group_index);
+int get_ms12_main_dec_info(struct audio_stream_out *stream, Aml_MS12_DecInfo_t *dec_info);
 
 /*
  *@brief set ms12 main audio mute or non mute
diff --git a/decoder/libms12_v24/include/aml_audio_ms12.h b/decoder/libms12_v24/include/aml_audio_ms12.h
index 1993997..0d5dba9 100644
--- a/decoder/libms12_v24/include/aml_audio_ms12.h
+++ b/decoder/libms12_v24/include/aml_audio_ms12.h
@@ -82,6 +82,7 @@
     MS12_CODEC_PARAMETER_AC4DE_THE_PGI_IS_PRESENT = 22,
     MS12_CODEC_PARAMETER_MAIN_START_THRESHOLD = 23,
     MS12_CODEC_PARAMETER_MAIN_UNDERRUN = 24,
+    MS12_CODEC_PARAMETER_DEC_INFO = 25,
     MS12_CODEC_PARAMETER_MAX,
 }ms12_codec_parameter_type_t;
 
@@ -136,6 +137,13 @@
     int as32Acmod[2];
 } Aml_MS12_ProcessInfo_t;
 
+typedef struct Aml_MS12_DecInfo_s {
+    int s32SampleRate;
+    int s32ChannelAcmod;
+    int s32LfePresent;
+    int reserved[5];
+} Aml_MS12_DecInfo_t;
+
 typedef struct AML_MS12_CodecInfo_s
 {
     unsigned int u32AudioFormat;