decoder_listener.c 29 KB

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