adts_vlb.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "adts_vlb.h"
  2. #include "giofile.h"
  3. #include "in2.h"
  4. extern In_Module mod;
  5. ADTS_VLB::ADTS_VLB() : decoder(0), needsync(1)
  6. {}
  7. int ADTS_VLB::Initialize(bool forceMono, bool reverseStereo, bool allowSurround, int maxBits, bool allowRG, bool _useFloat, bool _useCRC)
  8. {
  9. return 0;
  10. }
  11. bool ADTS_VLB::Open(ifc_mpeg_stream_reader *file)
  12. {
  13. waServiceFactory *factory = mod.service->service_getServiceByGuid(obj_vlbDecoderGUID);
  14. if (factory)
  15. decoder = (obj_vlbDecoder *)factory->getInterface();
  16. if (decoder)
  17. {
  18. int status = decoder->Open((DataIOControl *)(CGioFile *)file);
  19. if (status == 0)
  20. return true;
  21. }
  22. return false;
  23. }
  24. void ADTS_VLB::Close()
  25. {
  26. if (decoder)
  27. {
  28. waServiceFactory *factory = mod.service->service_getServiceByGuid(obj_vlbDecoderGUID);
  29. if (factory)
  30. factory->releaseInterface(decoder);
  31. }
  32. decoder = 0;
  33. }
  34. void ADTS_VLB::GetOutputParameters(size_t *numBits, int *numChannels, int *sampleRate)
  35. {
  36. *sampleRate = params.sampling_frequency;
  37. *numChannels = params.num_channels;
  38. *numBits = 16;
  39. }
  40. void ADTS_VLB::CalculateFrameSize( int *frameSize )
  41. {
  42. *frameSize = 576 * 2 * params.num_channels;
  43. if ( *frameSize > 576 * 2 * 2 )
  44. *frameSize = 576 * 2 * 2;
  45. }
  46. void ADTS_VLB::Flush(ifc_mpeg_stream_reader *file)
  47. {
  48. decoder->Flush();
  49. decoder->Close();
  50. decoder->Open((DataIOControl *)(CGioFile *)file);
  51. needsync = 1;
  52. }
  53. size_t ADTS_VLB::GetCurrentBitrate()
  54. {
  55. return params.bitrate / 1000;
  56. }
  57. size_t ADTS_VLB::GetDecoderDelay()
  58. {
  59. return 0; // not really sure
  60. }
  61. int ADTS_VLB::Sync(ifc_mpeg_stream_reader *file, unsigned __int8 *output, size_t outputSize, size_t *outputWritten, size_t *bitrate)
  62. {
  63. int status = decoder->Synchronize(&params);
  64. if (!status)
  65. {
  66. needsync = 0;
  67. return SUCCESS;
  68. }
  69. if (file->MPEGStream_EOF())
  70. return ENDOFFILE;
  71. return NEEDMOREDATA;
  72. }
  73. int ADTS_VLB::Decode(ifc_mpeg_stream_reader *file, unsigned __int8 *output, size_t outputSize, size_t *outputWritten, size_t *bitrate, size_t *endCut)
  74. {
  75. if (*outputWritten = decoder->Read(output, outputSize))
  76. {
  77. // TODO: benski> verify that params is valid here
  78. *bitrate = params.bitrate / 1000;
  79. return adts::SUCCESS;
  80. }
  81. if (needsync)
  82. {
  83. int status = decoder->Synchronize(&params);
  84. if (!status)
  85. {
  86. needsync = 0;
  87. }
  88. else if (file->MPEGStream_EOF())
  89. {
  90. return adts::ENDOFFILE;
  91. }
  92. }
  93. if (!needsync)
  94. {
  95. int status = decoder->DecodeFrame(&params);
  96. if (status > ERR_NO_ERROR && status != ERR_END_OF_FILE)
  97. {
  98. needsync = 1;
  99. return adts::FAILURE;
  100. }
  101. else
  102. {
  103. if (status == ERR_END_OF_FILE)
  104. {
  105. if (file->MPEGStream_EOF())
  106. {
  107. return adts::ENDOFFILE;
  108. }
  109. else
  110. {
  111. *bitrate = params.bitrate / 1000;
  112. return adts::NEEDMOREDATA;
  113. }
  114. }
  115. *bitrate = params.bitrate / 1000;
  116. return adts::SUCCESS;
  117. }
  118. }
  119. return adts::SUCCESS;
  120. }
  121. int ADTS_VLB::GetLayer()
  122. {
  123. return 4;
  124. }
  125. void ADTS_VLB::Release()
  126. {
  127. delete this;
  128. }