picture_meta_data.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <assert.h>
  27. #include <string.h>
  28. #include "main_helper.h"
  29. FILE * CreatePicInfoXmlFile(
  30. const char *yuvPath
  31. )
  32. {
  33. char strXmlFilePath[256];
  34. FILE *fp;
  35. if (yuvPath != NULL) {
  36. sprintf(strXmlFilePath, "%s.xml", yuvPath);
  37. }
  38. else {
  39. strcpy(strXmlFilePath, "out.xml");
  40. }
  41. if ((fp=osal_fopen(strXmlFilePath, "wb")) == NULL) {
  42. printf("%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strXmlFilePath);
  43. return NULL;
  44. }
  45. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n",fp);
  46. fputs("<ffprobe>\r\n", fp);
  47. fputs("<frames>\r\n", fp);
  48. return fp;
  49. }
  50. void ClosePicInfoXMLFile(
  51. FILE *fpXML
  52. )
  53. {
  54. if (fpXML != NULL) {
  55. fputs("</frames>\r\n", fpXML);
  56. fputs("</ffprobe>\r\n", fpXML);
  57. osal_fclose(fpXML);
  58. }
  59. }
  60. void SavePicInfoToXml(
  61. FILE* fpXml,
  62. DecOutputInfo* fbInfo
  63. )
  64. {
  65. //BOOL bCrop;
  66. BOOL bKeyFrame;
  67. Uint32 pkt_pts;
  68. Uint32 pkt_dts;
  69. Uint32 pkt_pos;
  70. double pkt_pts_sec;
  71. double pkt_dts_sec;
  72. Uint32 pkt_size;
  73. Uint32 width;
  74. Uint32 height;
  75. Uint32 bitdepthY;
  76. Uint32 bitdepthC;
  77. char strFormat[256] = {"yuv420p"};
  78. char strPicType[8];
  79. pkt_size = fbInfo->consumedByte;
  80. pkt_pos = 0;
  81. pkt_size = 0;
  82. pkt_pts = 0;
  83. pkt_dts = 0;
  84. pkt_pts_sec = pkt_pts/1000.0;
  85. pkt_dts_sec = pkt_dts/1000.0;
  86. bKeyFrame = FALSE;
  87. switch(fbInfo->picType) {
  88. case PIC_TYPE_I:
  89. strcpy(strPicType, "I");
  90. bKeyFrame = TRUE;
  91. break;
  92. case PIC_TYPE_P:
  93. strcpy(strPicType, "P");
  94. break;
  95. case PIC_TYPE_B:
  96. strcpy(strPicType, "B");
  97. break;
  98. default:
  99. strcpy(strPicType, "B");
  100. break;
  101. }
  102. if (fbInfo->dispFrame.format == FORMAT_420) {
  103. if (fbInfo->dispFrame.cbcrInterleave == TRUE) {
  104. strcpy(strFormat, "nv12");
  105. }
  106. else {
  107. strcpy(strFormat, "yuv420p");
  108. }
  109. if (fbInfo->dispFrame.nv21 == TRUE) {
  110. strcpy(strFormat, "nv21");
  111. }
  112. }
  113. width = fbInfo->dispPicWidth;
  114. height = fbInfo->dispPicHeight;
  115. bitdepthY = fbInfo->dispFrame.lumaBitDepth;
  116. bitdepthC = fbInfo->dispFrame.chromaBitDepth;
  117. fprintf(fpXml, "<frame media_type=\"video\" key_frame=\"%d\" pkt_pts=\"%d\" pkt_pts_time=\"%.1f\" "
  118. "pkt_dts=\"%d\" pkt_dts_time=\"%.1f\" pkt_pos=\"%d\" pkt_size=\"%d\" width=\"%d\" "
  119. "height=\"%d\" pix_fmt=\"%s\" pict_type=\"%s\" coded_picture_number=\"0\" display_picture_number=\"0\""
  120. "interlaced_frame=\"0\" top_field_first=\"0\" repeat_pict=\"0\" bitdepthY=\"%d\" bitdepthC=\"%d\"/>\r\n",
  121. bKeyFrame, pkt_pts, pkt_pts_sec, pkt_dts, pkt_dts_sec, pkt_pos, pkt_size, width, height, strFormat, strPicType, bitdepthY, bitdepthC);
  122. osal_fflush(fpXml);
  123. return;
  124. }