decoder_listener.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "cnm_app.h"
  26. #include "decoder_listener.h"
  27. #include "misc/debug.h"
  28. #include "misc/bw_monitor.h"
  29. static BOOL IsDifferentResolution(DecGetFramebufInfo* fbInfo, FrameBuffer* srcFb)
  30. {
  31. FrameBuffer* dstFb = &fbInfo->framebufPool[srcFb->myIndex];
  32. return (dstFb->width != srcFb->width || dstFb->height != srcFb->height);
  33. }
  34. static void PrintH265UserData(Uint8* pBase, Uint32 iFlags, vpu_buffer_t* vb)
  35. {
  36. user_data_entry_t* pEntry = NULL;
  37. user_data_entry_t* item = NULL;
  38. pEntry = (user_data_entry_t*)pBase;
  39. if (iFlags & (1<<H265_USERDATA_FLAG_VUI)) {
  40. h265_vui_param_t* vui = (h265_vui_param_t*)(pBase + pEntry[H265_USERDATA_FLAG_VUI].offset);
  41. VLOG(INFO, "[VUI]\n");
  42. VLOG(INFO, "vui::aspect_ratio_idc > %d\n", vui->aspect_ratio_idc);
  43. VLOG(INFO, "vui::video_signal_type_present_flag> %d\n", vui->video_signal_type_present_flag);
  44. VLOG(INFO, "vui::video_format > %d\n", vui->video_format);
  45. VLOG(INFO, "vui::vui_timing_info_present_flag > %d\n", vui->vui_timing_info_present_flag);
  46. VLOG(INFO, "vui::vui_num_units_in_tick > %d\n", vui->vui_num_units_in_tick);
  47. VLOG(INFO, "vui::vui_time_scale > %d\n", vui->vui_time_scale);
  48. }
  49. if (iFlags & (1UL<<H265_USERDATA_FLAG_PIC_TIMING)) {
  50. h265_sei_pic_timing_t* picTiming = (h265_sei_pic_timing_t*)(pBase + pEntry[H265_USERDATA_FLAG_PIC_TIMING].offset);
  51. VLOG(INFO, "[SEI::PIC_TIMING]\n");
  52. VLOG(INFO, "sei::pic_timing::pic_struct > %d\n", picTiming->pic_struct);
  53. VLOG(INFO, "sei::pic_timing::source_scan_type > %d\n", picTiming->source_scan_type);
  54. VLOG(INFO, "sei::pic_timing::duplicate_flag > %d\n", picTiming->duplicate_flag);
  55. }
  56. if (iFlags & (1UL<<H265_USERDATA_FLAG_MASTERING_COLOR_VOL)) {
  57. h265_mastering_display_colour_volume_t* mastering;
  58. mastering = (h265_mastering_display_colour_volume_t*)(pBase + pEntry[H265_USERDATA_FLAG_MASTERING_COLOR_VOL].offset);
  59. VLOG(INFO, "[SEI::MASTERING DISPLAY COLOR VOLUME]\n");
  60. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_x[0] > %d\n", mastering->display_primaries_x[0]);
  61. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_y[0] > %d\n", mastering->display_primaries_y[0]);
  62. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_x[1] > %d\n", mastering->display_primaries_x[1]);
  63. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_y[1] > %d\n", mastering->display_primaries_y[1]);
  64. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_x[2] > %d\n", mastering->display_primaries_x[2]);
  65. VLOG(INFO, "sei::mastering_display_colour_volume::display_primaries_y[2] > %d\n", mastering->display_primaries_y[2]);
  66. VLOG(INFO, "sei::mastering_display_colour_volume::white_point_x > %d\n", mastering->white_point_x);
  67. VLOG(INFO, "sei::mastering_display_colour_volume::white_point_y > %d\n", mastering->white_point_y);
  68. VLOG(INFO, "sei::mastering_display_colour_volume::max_display_mastering_luminance > %d%s\n", mastering->max_display_mastering_luminance);
  69. VLOG(INFO, "sei::mastering_display_colour_volume::min_display_mastering_luminance > %d %s\n", mastering->min_display_mastering_luminance);
  70. }
  71. if (iFlags & (1<<H265_USERDATA_FLAG_ITU_T_T35_PRE)) {
  72. Uint8* pData = NULL;
  73. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE];
  74. pData = (Uint8*)(pBase + item->offset);
  75. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (PREFIX)]\n");
  76. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  77. }
  78. if (iFlags & (1UL<<H265_USERDATA_FLAG_ITU_T_T35_PRE_1)) {
  79. Uint8* pData = NULL;
  80. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1];
  81. pData = (Uint8*)(pBase + item->offset);
  82. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (PREFIX1)]\n");
  83. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  84. }
  85. if (iFlags & (1UL<<H265_USERDATA_FLAG_ITU_T_T35_PRE_2)) {
  86. Uint8* pData = NULL;
  87. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2];
  88. pData = (Uint8*)(pBase + item->offset);
  89. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (PREFIX2)]\n");
  90. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  91. }
  92. if (iFlags & (1UL<<H265_USERDATA_FLAG_ITU_T_T35_SUF)) {
  93. Uint8* pData = NULL;
  94. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_SUF];
  95. pData = (Uint8*)(pBase + item->offset);
  96. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (SUFFIX)]\n");
  97. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  98. }
  99. if (iFlags & (1UL<<H265_USERDATA_FLAG_ITU_T_T35_SUF_1)) {
  100. Uint8* pData = NULL;
  101. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_SUF_1];
  102. pData = (Uint8*)(pBase + item->offset);
  103. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (SUFFIX 1)]\n");
  104. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  105. }
  106. if (iFlags & (1UL<<H265_USERDATA_FLAG_ITU_T_T35_SUF_2)) {
  107. Uint8* pData = NULL;
  108. item = &pEntry[H265_USERDATA_FLAG_ITU_T_T35_SUF_2];
  109. pData = (Uint8*)(pBase + item->offset);
  110. VLOG(INFO, "[H265::SEI::USER_DATA_REGISTERED_ITU_T_T35 (SUFFIX 2)]\n");
  111. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  112. }
  113. if (iFlags & (1UL<<H265_USERDATA_FLAG_UNREGISTERED_PRE)) {
  114. Uint8* pData = NULL;
  115. item = &pEntry[H265_USERDATA_FLAG_UNREGISTERED_PRE];
  116. pData = (Uint8*)(pBase + item->offset);
  117. VLOG(INFO, "[H265::SEI::USER_DATA_UNREGISTERED (PREFIX)]\n");
  118. DisplayHex(pData, item->size, "H265 ITU-T-T35");
  119. }
  120. if (iFlags & (1UL<<H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT)) {
  121. h265_chroma_resampling_filter_hint_t* pData = (h265_chroma_resampling_filter_hint_t*)(pBase + pEntry[H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT].offset);
  122. VLOG(INFO, "[H265::SEI::CHROMA_RESAMPLING_FILTER_HINT]\n");
  123. VLOG(INFO, "sei::chroma_resampling_filter_hint::ver_chroma_filter_idc > %d\n", pData->ver_chroma_filter_idc);
  124. VLOG(INFO, "sei::chroma_resampling_filter_hint::hor_chroma_filter_idc > %d\n", pData->hor_chroma_filter_idc);
  125. VLOG(INFO, "sei::chroma_resampling_filter_hint::ver_filtering_filed_processing_flag > %d\n", pData->ver_filtering_field_processing_flag);
  126. }
  127. if (iFlags & (1UL<<H265_USERDATA_FLAG_KNEE_FUNCTION_INFO)) {
  128. h265_knee_function_info_t* pData = (h265_knee_function_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_KNEE_FUNCTION_INFO].offset);
  129. VLOG(INFO, "[H265::SEI::KNEE_FUNCTION_INFO]\n");
  130. VLOG(INFO, "sei::knee_function_info::knee_function_id > %d\n", pData->knee_function_id);
  131. VLOG(INFO, "sei::knee_function_info::knee_function_cancel_flag > %d\n", pData->knee_function_cancel_flag);
  132. }
  133. if (iFlags & (1UL<<H265_USERDATA_FLAG_UNREGISTERED_SUF)) {
  134. Uint8* pData = NULL;
  135. item = &pEntry[H265_USERDATA_FLAG_UNREGISTERED_SUF];
  136. pData = (Uint8*)(pBase + item->offset);
  137. VLOG(INFO, "[SEI::USER_DATA_UNREGISTERED (PREFIX OR SUFFIX)]\n");
  138. DisplayHex(pData, item->size, "H265 USERDATA_UNREGISTERED");
  139. }
  140. if (iFlags & (1UL<<H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO)) {
  141. h265_content_light_level_info_t* pData = (h265_content_light_level_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO].offset);
  142. VLOG(INFO, "[SEI::CONTENT_LIGHT_LEVEL_INFO(PREFIX)]\n");
  143. VLOG(INFO, "sei::content_light_level_info::max_content_light_level > %04x\n", pData->max_content_light_level);
  144. VLOG(INFO, "sei::content_light_level_info::max_pic_average_light_level > %04x\n", pData->max_pic_average_light_level);
  145. }
  146. if (iFlags & (1UL<<H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO)) {
  147. h265_film_grain_characteristics_t* pData = (h265_film_grain_characteristics_t*)(pBase + pEntry[H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO].offset);
  148. VLOG(INFO, "[SEI::FILM_GRAIN_CHARACTERISTICS_INFO(REFIX)]\n");
  149. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_characteristics_cancel_flag > %04x\n", pData->film_grain_characteristics_cancel_flag);
  150. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_model_id > %04x\n", pData->film_grain_model_id);
  151. VLOG(INFO, "sei::film_grain_characteristics_info::separate_colour_description_present_flag > %04x\n", pData->separate_colour_description_present_flag);
  152. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_bit_depth_luma_minus8 > %04x\n", pData->film_grain_bit_depth_luma_minus8);
  153. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_bit_depth_chroma_minus8 > %04x\n", pData->film_grain_bit_depth_chroma_minus8);
  154. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_full_range_flag > %04x\n", pData->film_grain_full_range_flag);
  155. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_colour_primaries > %04x\n", pData->film_grain_colour_primaries);
  156. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_transfer_characteristics > %04x\n", pData->film_grain_transfer_characteristics);
  157. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_matrix_coeffs > %04x\n", pData->film_grain_matrix_coeffs);
  158. VLOG(INFO, "sei::film_grain_characteristics_info::blending_model_id > %04x\n", pData->blending_mode_id);
  159. VLOG(INFO, "sei::film_grain_characteristics_info::log2_scale_factor > %04x\n", pData->log2_scale_factor);
  160. VLOG(INFO, "sei::film_grain_characteristics_info::comp_model_present_flag[0] > %04x\n", pData->comp_model_present_flag[0]);
  161. VLOG(INFO, "sei::film_grain_characteristics_info::comp_model_present_flag[1] > %04x\n", pData->comp_model_present_flag[1]);
  162. VLOG(INFO, "sei::film_grain_characteristics_info::comp_model_present_flag[2] > %04x\n", pData->comp_model_present_flag[2]);
  163. VLOG(INFO, "sei::film_grain_characteristics_info::film_grain_characterics_persistence_flag > %04x\n", pData->film_grain_characteristics_persistence_flag);
  164. }
  165. if (iFlags & (1UL<<H265_USERDATA_FLAG_TONE_MAPPING_INFO)) {
  166. h265_tone_mapping_info_t* pData = (h265_tone_mapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_TONE_MAPPING_INFO].offset);
  167. VLOG(INFO, "sei::tone_mapping_info::tone_map_id > %04x\n", pData->tone_map_id);
  168. VLOG(INFO, "sei::tone_mapping_info::tone_map_cancel_flag > %04x\n", pData->tone_map_cancel_flag);
  169. }
  170. if (iFlags & (1UL<<H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO)) {
  171. h265_colour_remapping_info_t* pData = (h265_colour_remapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO].offset);
  172. VLOG(INFO, "sei::tone_mapping_info::colour_remap_id > %04x\n", pData->colour_remap_id);
  173. VLOG(INFO, "sei::tone_mapping_info::colour_rempa_cancel_flag > %04x\n", pData->colour_remap_cancel_flag);
  174. }
  175. return;
  176. }
  177. static void PrintH264UserData(Uint8* pBase, Uint32 iFlags, vpu_buffer_t* vb)
  178. {
  179. user_data_entry_t* pEntry = NULL;
  180. user_data_entry_t* item = NULL;
  181. pEntry = (user_data_entry_t*)pBase;
  182. if (iFlags & (1UL<<H264_USERDATA_FLAG_VUI)) {
  183. avc_vui_info_t* vui = (avc_vui_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_VUI].offset);
  184. VLOG(INFO, "[VUI]\n");
  185. VLOG(INFO, "vui::aspect_ration_info_present_flag > %d\n", vui->aspect_ratio_info_present_flag);
  186. VLOG(INFO, "vui::aspect_ratio_idc > %d\n", vui->aspect_ratio_idc);
  187. VLOG(INFO, "vui::overscan_info_present_flag > %d\n", vui->overscan_info_present_flag);
  188. VLOG(INFO, "vui::video_signal_type_present_flag > %d\n", vui->video_signal_type_present_flag);
  189. VLOG(INFO, "vui::vui_timing_info_present_flag > %d\n", vui->vui_timing_info_present_flag);
  190. VLOG(INFO, "vui::vui_num_units_in_tick > %d\n", vui->vui_num_units_in_tick);
  191. VLOG(INFO, "vui::vui_time_scale > %d\n", vui->vui_time_scale);
  192. VLOG(INFO, "vui::nal_hrd_parmeters_present_flag > %d\n", vui->nal_hrd_parameters_present_flag);
  193. VLOG(INFO, "vui::cpb_cnt > %d\n", vui->nal_hrd.cpb_cnt);
  194. VLOG(INFO, "vui::bit_rate_value > %d\n", vui->nal_hrd.bit_rate_value[0]);
  195. VLOG(INFO, "vui::cpb_size_value > %d\n", vui->nal_hrd.cpb_size_value[0]);
  196. VLOG(INFO, "vui::initial_cpb_removal_delay_length> %d\n", vui->nal_hrd.initial_cpb_removal_delay_length);
  197. VLOG(INFO, "vui::cpb_removal_delay_length > %d\n", vui->nal_hrd.cpb_removal_delay_length);
  198. VLOG(INFO, "vui::dpb_output_delay_length > %d\n", vui->nal_hrd.dpb_output_delay_length);
  199. VLOG(INFO, "vui::vcl_hrd_parmeters_present_flag > %d\n", vui->vcl_hrd_parameters_present_flag);
  200. VLOG(INFO, "vui::cpb_cnt > %d\n", vui->vcl_hrd.cpb_cnt);
  201. VLOG(INFO, "vui::bit_rate_value > %d\n", vui->vcl_hrd.bit_rate_value[0]);
  202. VLOG(INFO, "vui::cpb_size_value > %d\n", vui->vcl_hrd.cpb_size_value[0]);
  203. VLOG(INFO, "vui::initial_cpb_removal_delay_length> %d\n", vui->vcl_hrd.initial_cpb_removal_delay_length);
  204. VLOG(INFO, "vui::cpb_removal_delay_length > %d\n", vui->vcl_hrd.cpb_removal_delay_length);
  205. VLOG(INFO, "vui::dpb_output_delay_length > %d\n", vui->vcl_hrd.dpb_output_delay_length);
  206. }
  207. if (iFlags & (1UL<<H264_USERDATA_FLAG_PIC_TIMING)) {
  208. avc_sei_pic_timing_t* picTiming = (avc_sei_pic_timing_t*)(pBase + pEntry[H264_USERDATA_FLAG_PIC_TIMING].offset);
  209. VLOG(INFO, "[SEI::PIC_TIMING]\n");
  210. VLOG(INFO, "sei::pic_timing::cpb_removal_delay > %d\n", picTiming->cpb_removal_delay);
  211. VLOG(INFO, "sei::pic_timing::dpb_output_delay > %d\n", picTiming->dpb_output_delay);
  212. VLOG(INFO, "sei::pic_timing::pic_struct > %d\n", picTiming->pic_struct);
  213. VLOG(INFO, "sei::pic_timing::num_clock_ts > %d\n", picTiming->num_clock_ts);
  214. }
  215. if (iFlags & (1<<H264_USERDATA_FLAG_ITU_T_T35)) {
  216. Uint8* pData = NULL;
  217. item = &pEntry[H264_USERDATA_FLAG_ITU_T_T35];
  218. pData = (Uint8*)(pBase + item->offset);
  219. VLOG(INFO, "[H264::SEI::USER_DATA_REGISTERED_ITU_T_T35]\n");
  220. DisplayHex(pData, item->size, "ITU-T-T35");
  221. }
  222. if (iFlags & (1<<H264_USERDATA_FLAG_ITU_T_T35_1)) {
  223. Uint8* pData = NULL;
  224. item = &pEntry[H264_USERDATA_FLAG_ITU_T_T35_1];
  225. pData = (Uint8*)(pBase + item->offset);
  226. VLOG(INFO, "[H264::SEI::USER_DATA_REGISTERED_ITU_T_T35_1]\n");
  227. DisplayHex(pData, item->size, "ITU-T-T35_1");
  228. }
  229. if (iFlags & (1<<H264_USERDATA_FLAG_ITU_T_T35_2)) {
  230. Uint8* pData = NULL;
  231. item = &pEntry[H264_USERDATA_FLAG_ITU_T_T35_2];
  232. pData = (Uint8*)(pBase + item->offset);
  233. VLOG(INFO, "[H264::SEI::USER_DATA_REGISTERED_ITU_T_T35_2]\n");
  234. DisplayHex(pData, item->size, "ITU-T-T35_2");
  235. }
  236. if (iFlags & (1UL<<H264_USERDATA_FLAG_UNREGISTERED)) {
  237. Uint8* pData = NULL;
  238. item = &pEntry[H264_USERDATA_FLAG_UNREGISTERED];
  239. pData = (Uint8*)(pBase + item->offset);
  240. VLOG(INFO, "[AVC::SEI::USER_DATA_UNREGISTERED]\n");
  241. DisplayHex(pData, item->size, "UNREGISTERED");
  242. }
  243. if (iFlags & (1UL<<H264_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO)) {
  244. avc_sei_film_grain_t* pData = (avc_sei_film_grain_t*)(pBase + pEntry[H264_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO].offset);
  245. VLOG(INFO, "[SEI::FILM_GRAIN_CHARACTERISTICS]\n");
  246. VLOG(INFO, "sei::film_grain_characteristics::film_grain_characteristics_cancel_flag > %04x\n", pData->film_grain_characteristics_cancel_flag);
  247. VLOG(INFO, "sei::film_grain_characteristics::film_grain_model_id > %04x\n", pData->film_grain_model_id);
  248. VLOG(INFO, "sei::film_grain_characteristics::separate_colour_description_present_flag > %04x\n", pData->separate_colour_description_present_flag);
  249. VLOG(INFO, "sei::film_grain_characteristics::blending_model_id > %04x\n", pData->blending_mode_id);
  250. VLOG(INFO, "sei::film_grain_characteristics::log2_scale_factor > %04x\n", pData->log2_scale_factor);
  251. VLOG(INFO, "sei::film_grain_characteristics::comp_model_present_flag[0] > %04x\n", pData->comp_model_present_flag[0]);
  252. VLOG(INFO, "sei::film_grain_characteristics::comp_model_present_flag[1] > %04x\n", pData->comp_model_present_flag[1]);
  253. VLOG(INFO, "sei::film_grain_characteristics::comp_model_present_flag[2] > %04x\n", pData->comp_model_present_flag[2]);
  254. }
  255. if (iFlags & (1UL<<H264_USERDATA_FLAG_TONE_MAPPING_INFO)) {
  256. avc_sei_tone_mapping_info_t* pData = (avc_sei_tone_mapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_TONE_MAPPING_INFO].offset);
  257. VLOG(INFO, "[SEI::TONE_MAPPING_INFO]\n");
  258. VLOG(INFO, "sei::tone_mapping_info::tone_map_id > %04x\n", pData->tone_map_id);
  259. VLOG(INFO, "sei::tone_mapping_info::tone_map_cancel_flag > %04x\n", pData->tone_map_cancel_flag);
  260. VLOG(INFO, "sei::tone_mapping_info::tone_map_repetition_period > %04x\n", pData->tone_map_repetition_period);
  261. VLOG(INFO, "sei::tone_mapping_info::coded_data_bit_depth > %04x\n", pData->coded_data_bit_depth);
  262. VLOG(INFO, "sei::tone_mapping_info::target_bit_depth > %04x\n", pData->target_bit_depth);
  263. VLOG(INFO, "sei::tone_mapping_info::tone_map_model_id > %04x\n", pData->tone_map_model_id);
  264. VLOG(INFO, "sei::tone_mapping_info::min_value > %08x\n", pData->min_value);
  265. VLOG(INFO, "sei::tone_mapping_info::max_value > %08x\n", pData->max_value);
  266. }
  267. if (iFlags & (1UL<<H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO)) {
  268. avc_sei_colour_remap_info_t* pData = (avc_sei_colour_remap_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO].offset);
  269. VLOG(INFO, "[SEI::COLOR_MAPPING_INFO]\n");
  270. VLOG(INFO, "sei::tone_mapping_info::colour_remap_id > %04x\n", pData->colour_remap_id);
  271. VLOG(INFO, "sei::tone_mapping_info::colour_rempa_cancel_flag > %04x\n", pData->colour_cancel_flag);
  272. }
  273. return;
  274. }
  275. static void PrintUserData(DecListenerContext* ctx, CNMComListenerDecDone* lsnpDecDone)
  276. {
  277. vpu_buffer_t* vbUser = NULL;
  278. DecOutputExtData* ext = NULL;
  279. Uint32 numFlags = 0;
  280. Uint32 flags = 0;
  281. Uint8* pBase = NULL;
  282. ext = &lsnpDecDone->output->decOutputExtData;
  283. flags = ext->userDataHeader;
  284. numFlags = ext->userDataNum;
  285. vbUser = &lsnpDecDone->vbUser;
  286. if (0 == numFlags) {
  287. return;
  288. }
  289. VLOG(INFO, "----------------------------------------------------------------\n");
  290. VLOG(INFO, "- %d USERDATA(VUI, SEI)\n", numFlags);
  291. VLOG(INFO, "----------------------------------------------------------------\n");
  292. pBase = (Uint8*)osal_malloc(vbUser->size);
  293. if (pBase == NULL) {
  294. VLOG(ERR, "%s failed to allocate memory\n", __FUNCTION__);
  295. return;
  296. }
  297. VpuReadMem(lsnpDecDone->handle->coreIdx, vbUser->phys_addr, pBase, vbUser->size, VPU_USER_DATA_ENDIAN);
  298. switch (lsnpDecDone->bitstreamFormat) {
  299. case STD_HEVC:
  300. PrintH265UserData(pBase, flags, vbUser);
  301. break;
  302. case STD_AVC:
  303. PrintH264UserData(pBase, flags, vbUser);
  304. break;
  305. default:
  306. VLOG(ERR, "Not supported yet!!!\n");
  307. break;
  308. }
  309. osal_free(pBase);
  310. return;
  311. }
  312. void HandleDecCompleteSeqEvent(Component com, CNMComListenerDecCompleteSeq* param, DecListenerContext* ctx)
  313. {
  314. if (ctx->compareType == YUV_COMPARE) {
  315. Uint32 width = param->initialInfo->picWidth;
  316. Uint32 height = param->initialInfo->picHeight;
  317. if (ctx->enableScaler == TRUE) {
  318. width = VPU_CEIL(width, 16);
  319. height = VPU_CEIL(height, 4);
  320. }
  321. if ((ctx->comparator = Comparator_Create(YUV_COMPARE, param->refYuvPath, width, height, param->wtlFormat,
  322. param->cbcrInterleave, param->bitstreamFormat==STD_VP9)) == NULL) {
  323. VLOG(ERR, "%s:%d Failed to Comparator_Create(%s)\n", __FUNCTION__, __LINE__, param->refYuvPath);
  324. CNMErrorSet(CNM_ERROR_FAILURE);
  325. CNMAppStop();
  326. return ;
  327. }
  328. }
  329. }
  330. void HandleDecRegisterFbEvent(Component com, CNMComListenerDecRegisterFb* param, DecListenerContext* ctx)
  331. {
  332. Uint32 fps = (ctx->fps == 0) ? 30 : ctx->fps;
  333. //SimpleRenderer_SetFrameRate(ctx->renderer, 0);
  334. if ( ctx->bandwidth ) {
  335. ctx->bwCtx = BWMonitorSetup(param->handle, TRUE, GetBasename((const char *)ctx->inputPath));
  336. }
  337. if ( ctx->performance ) {
  338. ctx->pfCtx = PFMonitorSetup(param->handle->coreIdx, param->handle->instIndex, ctx->pfClock, fps, GetBasename((const char *)ctx->inputPath), 0);
  339. }
  340. }
  341. static void HandleDecInterruptEvent(Component com, CNMComListenerDecInt* param, DecListenerContext* ctx)
  342. {
  343. if ((1<<INT_WAVE5_DEC_PIC) == param->flag) {
  344. if (ctx->bwCtx != NULL) {
  345. BWMonitorUpdate(ctx->bwCtx, ctx->numVCores);
  346. BWMonitorReset(ctx->bwCtx);
  347. }
  348. }
  349. }
  350. void HandleDecGetOutputEvent(Component com, CNMComListenerDecDone* param, DecListenerContext* ctx)
  351. {
  352. DecOutputInfo* output = param->output;
  353. FrameBuffer* pFb = &output->dispFrame;
  354. void* decodedData = NULL;
  355. Uint8* pYuv = NULL;
  356. Uint32 decodedDataSize = 0;
  357. VpuRect rcDisplay = {0,};
  358. Uint32 width=0, height = 0, Bpp;
  359. size_t frameSizeInByte = 0;
  360. if (param->ret != RETCODE_SUCCESS) return;
  361. if (ctx->pfCtx != NULL) {
  362. if (output->indexFrameDecoded >= 0) {
  363. if (ctx->productId == PRODUCT_ID_517) {
  364. PFMonitorUpdate(param->handle->coreIdx, ctx->pfCtx, output->frameCycle, output->seekCycle, output->parseCycle, output->DecodedCycle);
  365. } else {
  366. PFMonitorUpdate(param->handle->coreIdx, ctx->pfCtx, output->frameCycle);
  367. }
  368. }
  369. }
  370. if (ctx->bwCtx != NULL) {
  371. BWMonitorUpdatePrint(ctx->bwCtx, output->picType);
  372. }
  373. // Finished decoding a frame
  374. if (output->indexFrameDecoded >= 0) {
  375. PrintUserData(ctx, param);
  376. ctx->notDecodedCount = 0;
  377. }
  378. else {
  379. ctx->notDecodedCount++;
  380. if (ctx->notDecodedCount == MAX_NOT_DEC_COUNT) {
  381. VLOG(ERR, "Continuous not-decoded-count is %d\nThere is something problem in DPB control.\n", ctx->notDecodedCount);
  382. CNMAppStop();
  383. }
  384. }
  385. if (output->indexFrameDisplay < 0) {
  386. return;
  387. }
  388. if (ctx->lastSeqNo < pFb->sequenceNo || IsDifferentResolution(&ctx->fbInfo, pFb)) {
  389. /* When the video sequence or the resolution of picture was changed. */
  390. ctx->lastSeqNo = pFb->sequenceNo;
  391. VPU_DecGiveCommand(param->handle, DEC_GET_FRAMEBUF_INFO, (void*)&ctx->fbInfo);
  392. }
  393. if (ctx->compareType == YUV_COMPARE) {
  394. rcDisplay.right = output->dispPicWidth;
  395. rcDisplay.bottom = output->dispPicHeight;
  396. if (ctx->enableScaler == TRUE) {
  397. rcDisplay.right = VPU_CEIL(rcDisplay.right, 16);
  398. rcDisplay.bottom = VPU_CEIL(rcDisplay.bottom, 2);
  399. }
  400. if (TRUE == PRODUCT_ID_W_SERIES(ctx->productId)) {
  401. pYuv = GetYUVFromFrameBuffer(param->handle, &output->dispFrame, rcDisplay, &width, &height, &Bpp, &frameSizeInByte);
  402. }
  403. decodedData = (void*)pYuv;
  404. decodedDataSize = frameSizeInByte;
  405. }
  406. if (ctx->comparator) {
  407. if ((ctx->match=Comparator_Act(ctx->comparator, decodedData, decodedDataSize)) == FALSE) {
  408. }
  409. }
  410. if (ctx->compareType == YUV_COMPARE) {
  411. osal_free(decodedData);
  412. }
  413. if (ctx->match == FALSE) CNMAppStop();
  414. }
  415. void HandleDecCloseEvent(Component com, CNMComListenerDecClose* param, DecListenerContext* ctx)
  416. {
  417. if (ctx->bwCtx != NULL)
  418. BWMonitorRelease(ctx->bwCtx);
  419. if (ctx->pfCtx != NULL)
  420. PFMonitorRelease(ctx->pfCtx);
  421. }
  422. void DecoderListener(Component com, Uint64 event, void* data, void* context)
  423. {
  424. #if defined(SUPPORT_MULTI_INSTANCE_TEST) || defined(SUPPORT_LOOK_AHEAD_RC)
  425. #else
  426. /* int key=0;
  427. if (osal_kbhit()) {
  428. key = osal_getch();
  429. osal_flush_ch();
  430. switch (key) {
  431. case 'q':
  432. case 'Q':
  433. CNMAppStop();
  434. return;
  435. case 'f':
  436. case 'F':
  437. ComponentSetParameter(NULL, com, SET_PARAM_DEC_FLUSH, NULL);
  438. break;
  439. default:
  440. break;
  441. }
  442. } */
  443. #endif
  444. switch (event) {
  445. case COMPONENT_EVENT_DEC_OPEN:
  446. break;
  447. case COMPONENT_EVENT_DEC_ISSUE_SEQ:
  448. break;
  449. case COMPONENT_EVENT_DEC_COMPLETE_SEQ:
  450. HandleDecCompleteSeqEvent(com, (CNMComListenerDecCompleteSeq*)data, (DecListenerContext*)context);
  451. break;
  452. case COMPONENT_EVENT_DEC_REGISTER_FB:
  453. HandleDecRegisterFbEvent(com, (CNMComListenerDecRegisterFb*)data, (DecListenerContext*)context);
  454. break;
  455. case COMPONENT_EVENT_DEC_READY_ONE_FRAME:
  456. break;
  457. case COMPONENT_EVENT_DEC_START_ONE_FRAME:
  458. break;
  459. case COMPONENT_EVENT_DEC_INTERRUPT:
  460. HandleDecInterruptEvent(com, (CNMComListenerDecInt*)data, (DecListenerContext*)context);
  461. break;
  462. case COMPONENT_EVENT_DEC_GET_OUTPUT_INFO:
  463. HandleDecGetOutputEvent(com, (CNMComListenerDecDone*)data, (DecListenerContext*)context);
  464. break;
  465. case COMPONENT_EVENT_DEC_DECODED_ALL:
  466. break;
  467. case COMPONENT_EVENT_DEC_CLOSE:
  468. HandleDecCloseEvent(com, (CNMComListenerDecClose*)data, (DecListenerContext*)context);
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. BOOL SetupDecListenerContext(DecListenerContext* ctx, CNMComponentConfig* config, Component renderer)
  475. {
  476. TestDecConfig* decConfig = &config->testDecConfig;
  477. Int32 md5Size = 0;
  478. osal_memset((void*)ctx, 0x00, sizeof(DecListenerContext));
  479. md5Size = PRODUCT_ID_W_SERIES(decConfig->productId) ? 12 : 8 ;
  480. if (decConfig->compareType == MD5_COMPARE) {
  481. if ((ctx->comparator=Comparator_Create(MD5_COMPARE, decConfig->md5Path, md5Size)) == NULL) {
  482. VLOG(ERR, "%s:%d Failed to Comparator_Create(%s)\n", __FUNCTION__, __LINE__, decConfig->md5Path);
  483. return FALSE;
  484. }
  485. }
  486. ctx->renderer = renderer;
  487. ctx->lastSeqNo = -1;
  488. ctx->compareType = decConfig->compareType;
  489. ctx->match = TRUE;
  490. ctx->performance = decConfig->performance;
  491. ctx->bandwidth = decConfig->bandwidth;
  492. ctx->fps = decConfig->fps;
  493. ctx->pfClock = decConfig->pfClock;
  494. ctx->numVCores = decConfig->wave.numVCores;
  495. ctx->bitFormat = decConfig->bitFormat;
  496. ctx->productId = decConfig->productId;
  497. ctx->enableScaler = (decConfig->scaleDownWidth > 0 || decConfig->scaleDownHeight > 0);
  498. osal_memcpy(ctx->inputPath, decConfig->inputPath, sizeof(ctx->inputPath));
  499. return TRUE;
  500. }
  501. void ClearDecListenerContext(DecListenerContext* ctx)
  502. {
  503. if (ctx->comparator) Comparator_Destroy(ctx->comparator);
  504. }