TSCodecAVC.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. using System;
  20. using System.Collections.Generic;
  21. using System.Text;
  22. namespace BDInfo
  23. {
  24. public abstract class TSCodecAVC
  25. {
  26. public static void Scan(
  27. TSVideoStream stream,
  28. TSStreamBuffer buffer,
  29. ref string tag)
  30. {
  31. uint parse = 0;
  32. byte accessUnitDelimiterParse = 0;
  33. byte sequenceParameterSetParse = 0;
  34. string profile = null;
  35. string level = null;
  36. byte constraintSet0Flag = 0;
  37. byte constraintSet1Flag = 0;
  38. byte constraintSet2Flag = 0;
  39. byte constraintSet3Flag = 0;
  40. for (int i = 0; i < buffer.Length; i++)
  41. {
  42. parse = (parse << 8) + buffer.ReadByte();
  43. if (parse == 0x00000109)
  44. {
  45. accessUnitDelimiterParse = 1;
  46. }
  47. else if (accessUnitDelimiterParse > 0)
  48. {
  49. --accessUnitDelimiterParse;
  50. if (accessUnitDelimiterParse == 0)
  51. {
  52. switch ((parse & 0xFF) >> 5)
  53. {
  54. case 0: // I
  55. case 3: // SI
  56. case 5: // I, SI
  57. tag = "I";
  58. break;
  59. case 1: // I, P
  60. case 4: // SI, SP
  61. case 6: // I, SI, P, SP
  62. tag = "P";
  63. break;
  64. case 2: // I, P, B
  65. case 7: // I, SI, P, SP, B
  66. tag = "B";
  67. break;
  68. }
  69. if (stream.IsInitialized) return;
  70. }
  71. }
  72. else if (parse == 0x00000127 || parse == 0x00000167)
  73. {
  74. sequenceParameterSetParse = 3;
  75. }
  76. else if (sequenceParameterSetParse > 0)
  77. {
  78. --sequenceParameterSetParse;
  79. switch (sequenceParameterSetParse)
  80. {
  81. case 2:
  82. switch (parse & 0xFF)
  83. {
  84. case 66:
  85. profile = "Baseline Profile";
  86. break;
  87. case 77:
  88. profile = "Main Profile";
  89. break;
  90. case 88:
  91. profile = "Extended Profile";
  92. break;
  93. case 100:
  94. profile = "High Profile";
  95. break;
  96. case 110:
  97. profile = "High 10 Profile";
  98. break;
  99. case 122:
  100. profile = "High 4:2:2 Profile";
  101. break;
  102. case 144:
  103. profile = "High 4:4:4 Profile";
  104. break;
  105. default:
  106. profile = "Unknown Profile";
  107. break;
  108. }
  109. break;
  110. case 1:
  111. constraintSet0Flag = (byte)
  112. ((parse & 0x80) >> 7);
  113. constraintSet1Flag = (byte)
  114. ((parse & 0x40) >> 6);
  115. constraintSet2Flag = (byte)
  116. ((parse & 0x20) >> 5);
  117. constraintSet3Flag = (byte)
  118. ((parse & 0x10) >> 4);
  119. break;
  120. case 0:
  121. byte b = (byte)(parse & 0xFF);
  122. if (b == 11 && constraintSet3Flag == 1)
  123. {
  124. level = "1b";
  125. }
  126. else
  127. {
  128. level = string.Format(
  129. "{0:D}.{1:D}",
  130. b / 10, (b - ((b / 10) * 10)));
  131. }
  132. stream.EncodingProfile = string.Format(
  133. "{0} {1}", profile, level);
  134. stream.IsVBR = true;
  135. stream.IsInitialized = true;
  136. break;
  137. }
  138. }
  139. }
  140. return;
  141. }
  142. }
  143. }