TSCodecAVC.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //============================================================================
  2. // BDInfo - Blu-ray Video and Audio Analysis Tool
  3. // Copyright © 2010 Cinema Squid
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; either
  8. // version 2.1 of the License, or (at your option) any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. //=============================================================================
  19. namespace BDInfo
  20. {
  21. public abstract class TSCodecAVC
  22. {
  23. public static void Scan(
  24. TSVideoStream stream,
  25. TSStreamBuffer buffer,
  26. ref string tag)
  27. {
  28. uint parse = 0;
  29. byte accessUnitDelimiterParse = 0;
  30. byte sequenceParameterSetParse = 0;
  31. string profile = null;
  32. string level = null;
  33. byte constraintSet0Flag = 0;
  34. byte constraintSet1Flag = 0;
  35. byte constraintSet2Flag = 0;
  36. byte constraintSet3Flag = 0;
  37. for (int i = 0; i < buffer.Length; i++)
  38. {
  39. parse = (parse << 8) + buffer.ReadByte();
  40. if (parse == 0x00000109)
  41. {
  42. accessUnitDelimiterParse = 1;
  43. }
  44. else if (accessUnitDelimiterParse > 0)
  45. {
  46. --accessUnitDelimiterParse;
  47. if (accessUnitDelimiterParse == 0)
  48. {
  49. switch ((parse & 0xFF) >> 5)
  50. {
  51. case 0: // I
  52. case 3: // SI
  53. case 5: // I, SI
  54. tag = "I";
  55. break;
  56. case 1: // I, P
  57. case 4: // SI, SP
  58. case 6: // I, SI, P, SP
  59. tag = "P";
  60. break;
  61. case 2: // I, P, B
  62. case 7: // I, SI, P, SP, B
  63. tag = "B";
  64. break;
  65. }
  66. if (stream.IsInitialized) return;
  67. }
  68. }
  69. else if (parse == 0x00000127 || parse == 0x00000167)
  70. {
  71. sequenceParameterSetParse = 3;
  72. }
  73. else if (sequenceParameterSetParse > 0)
  74. {
  75. --sequenceParameterSetParse;
  76. switch (sequenceParameterSetParse)
  77. {
  78. case 2:
  79. switch (parse & 0xFF)
  80. {
  81. case 66:
  82. profile = "Baseline Profile";
  83. break;
  84. case 77:
  85. profile = "Main Profile";
  86. break;
  87. case 88:
  88. profile = "Extended Profile";
  89. break;
  90. case 100:
  91. profile = "High Profile";
  92. break;
  93. case 110:
  94. profile = "High 10 Profile";
  95. break;
  96. case 122:
  97. profile = "High 4:2:2 Profile";
  98. break;
  99. case 144:
  100. profile = "High 4:4:4 Profile";
  101. break;
  102. default:
  103. profile = "Unknown Profile";
  104. break;
  105. }
  106. break;
  107. case 1:
  108. constraintSet0Flag = (byte)
  109. ((parse & 0x80) >> 7);
  110. constraintSet1Flag = (byte)
  111. ((parse & 0x40) >> 6);
  112. constraintSet2Flag = (byte)
  113. ((parse & 0x20) >> 5);
  114. constraintSet3Flag = (byte)
  115. ((parse & 0x10) >> 4);
  116. break;
  117. case 0:
  118. byte b = (byte)(parse & 0xFF);
  119. if (b == 11 && constraintSet3Flag == 1)
  120. {
  121. level = "1b";
  122. }
  123. else
  124. {
  125. level = string.Format(
  126. "{0:D}.{1:D}",
  127. b / 10, (b - ((b / 10) * 10)));
  128. }
  129. stream.EncodingProfile = string.Format(
  130. "{0} {1}", profile, level);
  131. stream.IsVBR = true;
  132. stream.IsInitialized = true;
  133. break;
  134. }
  135. }
  136. }
  137. return;
  138. }
  139. }
  140. }