1
0

Header.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "Decoder.h"
  2. /*
  3. * decode headers from one input stream
  4. * until an End of Sequence or picture start code
  5. * is found
  6. */
  7. int Decoder::getheader()
  8. {
  9. unsigned int sorenson_version;
  10. /* look for startcode */
  11. startcode();
  12. buffer.getbits(PSC_LENGTH);
  13. sorenson_version = buffer.getbits(5);
  14. if (sorenson_version <= 1)
  15. {
  16. escapemode=sorenson_version;
  17. getpicturehdr();
  18. }
  19. else
  20. return 0;
  21. return 1;
  22. }
  23. /* align to start of next startcode */
  24. void Decoder::startcode()
  25. {
  26. /* search for new picture start code */
  27. while (buffer.showbits(PSC_LENGTH)!=1l)
  28. buffer.flushbits(1);
  29. }
  30. /* decode picture header */
  31. void Decoder::getpicturehdr()
  32. {
  33. int pei, tmp;
  34. buffer.getbits(8);
  35. tmp = buffer.getbits(3);
  36. switch(tmp)
  37. {
  38. case 0:
  39. horizontal_size = buffer.getbits(8);
  40. vertical_size = buffer.getbits(8);
  41. break;
  42. case 1:
  43. horizontal_size = buffer.getbits(16);
  44. vertical_size = buffer.getbits(16);
  45. break;
  46. case 2:
  47. horizontal_size = 352;
  48. vertical_size = 288;
  49. break;
  50. case 3:
  51. horizontal_size = 176;
  52. vertical_size = 144;
  53. break;
  54. case 4:
  55. horizontal_size = 128;
  56. vertical_size = 96;
  57. break;
  58. case 5:
  59. horizontal_size = 320;
  60. vertical_size = 240;
  61. break;
  62. case 6:
  63. horizontal_size = 160;
  64. vertical_size = 120;
  65. break;
  66. }
  67. pict_type = buffer.getbits(2);
  68. deblock=buffer.getbits(1); // deblocking flag
  69. quant = buffer.getbits(5);
  70. pei = buffer.getbits(1);
  71. pspare:
  72. if (pei) {
  73. /* extra info for possible future backward compatible additions */
  74. buffer.getbits(8); /* not used */
  75. pei = buffer.getbits(1);
  76. if (pei) goto pspare; /* keep on reading pspare until pei=0 */
  77. }
  78. }