TSCodecVC1.cs 4.8 KB

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