mkv_flac_decoder.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "../in_mkv/svc_mkvdecoder.h"
  3. #include "../in_mkv/ifc_mkvaudiodecoder.h"
  4. #include <FLAC/all.h>
  5. // {F6AF0AD9-608F-4206-892F-765412574A7D}
  6. static const GUID FLACMKVGUID =
  7. { 0xf6af0ad9, 0x608f, 0x4206, { 0x89, 0x2f, 0x76, 0x54, 0x12, 0x57, 0x4a, 0x7d } };
  8. class packet_client_data_s
  9. {
  10. public:
  11. const uint8_t *buffer;
  12. size_t buffer_length;
  13. void *outputBuffer;
  14. size_t *outputBufferBytes;
  15. uint32_t frame_size;
  16. uint32_t bps;
  17. uint32_t bytes_per_sample;
  18. uint32_t channels;
  19. uint32_t sample_rate;
  20. uint64_t samples;
  21. };
  22. typedef packet_client_data_s *packet_client_data_t;
  23. class MKVDecoder : public svc_mkvdecoder
  24. {
  25. public:
  26. static const char *getServiceName() { return "FLAC MKV Decoder"; }
  27. static GUID getServiceGuid() { return FLACMKVGUID; }
  28. int CreateAudioDecoder(const char *codec_id, const nsmkv::TrackEntryData *track_entry_data, const nsmkv::AudioData *audio_data, unsigned int preferred_bits, unsigned int preferred_channels, bool floating_point, ifc_mkvaudiodecoder **decoder);
  29. protected:
  30. RECVS_DISPATCH;
  31. };
  32. class MKVFLACDecoder : public ifc_mkvaudiodecoder
  33. {
  34. public:
  35. static MKVFLACDecoder *Create(const nsmkv::TrackEntryData *track_entry_data, const nsmkv::AudioData *audio_data, unsigned int preferred_bits, unsigned int max_channels);
  36. protected:
  37. RECVS_DISPATCH;
  38. private:
  39. /* ifc_mkvaudiodecoder implementation */
  40. int OutputFrameSize(size_t *frame_size);
  41. int GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat);
  42. int DecodeBlock(void *inputBuffer, size_t inputBufferBytes, void *outputBuffer, size_t *outputBufferBytes);
  43. void Flush();
  44. void Close();
  45. private:
  46. MKVFLACDecoder(FLAC__StreamDecoder *decoder, packet_client_data_t packet, unsigned int bps);
  47. ~MKVFLACDecoder();
  48. /* internal implementation */
  49. /* data */
  50. FLAC__StreamDecoder *decoder;
  51. unsigned int bps;
  52. packet_client_data_t packet;
  53. };