picture_meta_data.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. //--=========================================================================--
  3. // This file is a part of VPU Reference API project
  4. //-----------------------------------------------------------------------------
  5. //
  6. // This confidential and proprietary software may be used only
  7. // as authorized by a licensing agreement from Chips&Media Inc.
  8. // In the event of publication, the following notice is applicable:
  9. //
  10. // (C) COPYRIGHT CHIPS&MEDIA INC.
  11. // ALL RIGHTS RESERVED
  12. //
  13. // The entire notice above must be reproduced on all authorized
  14. // copies.
  15. //
  16. //--=========================================================================--
  17. #include <assert.h>
  18. #include <string.h>
  19. #include "main_helper.h"
  20. FILE * CreatePicInfoXmlFile(
  21. const char *yuvPath
  22. )
  23. {
  24. char strXmlFilePath[256];
  25. FILE *fp;
  26. if (yuvPath != NULL) {
  27. sprintf(strXmlFilePath, "%s.xml", yuvPath);
  28. }
  29. else {
  30. strcpy(strXmlFilePath, "out.xml");
  31. }
  32. if ((fp=osal_fopen(strXmlFilePath, "wb")) == NULL) {
  33. printf("%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strXmlFilePath);
  34. return NULL;
  35. }
  36. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n",fp);
  37. fputs("<ffprobe>\r\n", fp);
  38. fputs("<frames>\r\n", fp);
  39. return fp;
  40. }
  41. void ClosePicInfoXMLFile(
  42. FILE *fpXML
  43. )
  44. {
  45. if (fpXML != NULL) {
  46. fputs("</frames>\r\n", fpXML);
  47. fputs("</ffprobe>\r\n", fpXML);
  48. osal_fclose(fpXML);
  49. }
  50. }
  51. void SavePicInfoToXml(
  52. FILE* fpXml,
  53. DecOutputInfo* fbInfo
  54. )
  55. {
  56. //BOOL bCrop;
  57. BOOL bKeyFrame;
  58. Uint32 pkt_pts;
  59. Uint32 pkt_dts;
  60. Uint32 pkt_pos;
  61. double pkt_pts_sec;
  62. double pkt_dts_sec;
  63. Uint32 pkt_size;
  64. Uint32 width;
  65. Uint32 height;
  66. Uint32 bitdepthY;
  67. Uint32 bitdepthC;
  68. char strFormat[256] = {"yuv420p"};
  69. char strPicType[8];
  70. pkt_size = fbInfo->consumedByte;
  71. pkt_pos = 0;
  72. pkt_size = 0;
  73. pkt_pts = 0;
  74. pkt_dts = 0;
  75. pkt_pts_sec = pkt_pts/1000.0;
  76. pkt_dts_sec = pkt_dts/1000.0;
  77. bKeyFrame = FALSE;
  78. switch(fbInfo->picType) {
  79. case PIC_TYPE_I:
  80. strcpy(strPicType, "I");
  81. bKeyFrame = TRUE;
  82. break;
  83. case PIC_TYPE_P:
  84. strcpy(strPicType, "P");
  85. break;
  86. case PIC_TYPE_B:
  87. strcpy(strPicType, "B");
  88. break;
  89. default:
  90. strcpy(strPicType, "B");
  91. break;
  92. }
  93. if (fbInfo->dispFrame.format == FORMAT_420) {
  94. if (fbInfo->dispFrame.cbcrInterleave == TRUE) {
  95. strcpy(strFormat, "nv12");
  96. }
  97. else {
  98. strcpy(strFormat, "yuv420p");
  99. }
  100. if (fbInfo->dispFrame.nv21 == TRUE) {
  101. strcpy(strFormat, "nv21");
  102. }
  103. }
  104. width = fbInfo->dispPicWidth;
  105. height = fbInfo->dispPicHeight;
  106. bitdepthY = fbInfo->dispFrame.lumaBitDepth;
  107. bitdepthC = fbInfo->dispFrame.chromaBitDepth;
  108. fprintf(fpXml, "<frame media_type=\"video\" key_frame=\"%d\" pkt_pts=\"%d\" pkt_pts_time=\"%.1f\" "
  109. "pkt_dts=\"%d\" pkt_dts_time=\"%.1f\" pkt_pos=\"%d\" pkt_size=\"%d\" width=\"%d\" "
  110. "height=\"%d\" pix_fmt=\"%s\" pict_type=\"%s\" coded_picture_number=\"0\" display_picture_number=\"0\""
  111. "interlaced_frame=\"0\" top_field_first=\"0\" repeat_pict=\"0\" bitdepthY=\"%d\" bitdepthC=\"%d\"/>\r\n",
  112. bKeyFrame, pkt_pts, pkt_pts_sec, pkt_dts, pkt_dts_sec, pkt_pos, pkt_size, width, height, strFormat, strPicType, bitdepthY, bitdepthC);
  113. osal_fflush(fpXml);
  114. return;
  115. }