TSCodecVC1.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 TSCodecVC1
  22. {
  23. public static void Scan(
  24. TSVideoStream stream,
  25. TSStreamBuffer buffer,
  26. ref string tag)
  27. {
  28. int parse = 0;
  29. byte frameHeaderParse = 0;
  30. byte sequenceHeaderParse = 0;
  31. bool isInterlaced = false;
  32. for (int i = 0; i < buffer.Length; i++)
  33. {
  34. parse = (parse << 8) + buffer.ReadByte();
  35. if (parse == 0x0000010D)
  36. {
  37. frameHeaderParse = 4;
  38. }
  39. else if (frameHeaderParse > 0)
  40. {
  41. --frameHeaderParse;
  42. if (frameHeaderParse == 0)
  43. {
  44. uint pictureType = 0;
  45. if (isInterlaced)
  46. {
  47. if ((parse & 0x80000000) == 0)
  48. {
  49. pictureType =
  50. (uint)((parse & 0x78000000) >> 13);
  51. }
  52. else
  53. {
  54. pictureType =
  55. (uint)((parse & 0x3c000000) >> 12);
  56. }
  57. }
  58. else
  59. {
  60. pictureType =
  61. (uint)((parse & 0xf0000000) >> 14);
  62. }
  63. if ((pictureType & 0x20000) == 0)
  64. {
  65. tag = "P";
  66. }
  67. else if ((pictureType & 0x10000) == 0)
  68. {
  69. tag = "B";
  70. }
  71. else if ((pictureType & 0x8000) == 0)
  72. {
  73. tag = "I";
  74. }
  75. else if ((pictureType & 0x4000) == 0)
  76. {
  77. tag = "BI";
  78. }
  79. else
  80. {
  81. tag = null;
  82. }
  83. if (stream.IsInitialized) return;
  84. }
  85. }
  86. else if (parse == 0x0000010F)
  87. {
  88. sequenceHeaderParse = 6;
  89. }
  90. else if (sequenceHeaderParse > 0)
  91. {
  92. --sequenceHeaderParse;
  93. switch (sequenceHeaderParse)
  94. {
  95. case 5:
  96. int profileLevel = ((parse & 0x38) >> 3);
  97. if (((parse & 0xC0) >> 6) == 3)
  98. {
  99. stream.EncodingProfile = string.Format(
  100. "Advanced Profile {0}", profileLevel);
  101. }
  102. else
  103. {
  104. stream.EncodingProfile = string.Format(
  105. "Main Profile {0}", profileLevel);
  106. }
  107. break;
  108. case 0:
  109. if (((parse & 0x40) >> 6) > 0)
  110. {
  111. isInterlaced = true;
  112. }
  113. else
  114. {
  115. isInterlaced = false;
  116. }
  117. break;
  118. }
  119. stream.IsVBR = true;
  120. stream.IsInitialized = true;
  121. }
  122. }
  123. }
  124. }
  125. }