WebMDemuxer.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. MIT License
  3. Copyright (c) 2016 Błażej Szczygieł
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. #ifndef WEBMDEMUXER_HPP
  21. #define WEBMDEMUXER_HPP
  22. #include <stddef.h>
  23. namespace mkvparser {
  24. class IMkvReader;
  25. class Segment;
  26. class Cluster;
  27. class Block;
  28. class BlockEntry;
  29. class VideoTrack;
  30. class AudioTrack;
  31. }
  32. class WebMFrame
  33. {
  34. WebMFrame(const WebMFrame &);
  35. void operator =(const WebMFrame &);
  36. public:
  37. WebMFrame();
  38. ~WebMFrame();
  39. inline bool isValid() const
  40. {
  41. return bufferSize > 0;
  42. }
  43. long bufferSize, bufferCapacity;
  44. unsigned char *buffer;
  45. double time;
  46. bool key;
  47. };
  48. class WebMDemuxer
  49. {
  50. WebMDemuxer(const WebMDemuxer &);
  51. void operator =(const WebMDemuxer &);
  52. public:
  53. enum VIDEO_CODEC
  54. {
  55. NO_VIDEO,
  56. VIDEO_VP8,
  57. VIDEO_VP9
  58. };
  59. enum AUDIO_CODEC
  60. {
  61. NO_AUDIO,
  62. AUDIO_VORBIS,
  63. AUDIO_OPUS
  64. };
  65. WebMDemuxer(mkvparser::IMkvReader *reader, int videoTrack = 0, int audioTrack = 0);
  66. ~WebMDemuxer();
  67. inline bool isOpen() const
  68. {
  69. return m_isOpen;
  70. }
  71. inline bool isEOS() const
  72. {
  73. return m_eos;
  74. }
  75. double getLength() const;
  76. VIDEO_CODEC getVideoCodec() const;
  77. int getWidth() const;
  78. int getHeight() const;
  79. AUDIO_CODEC getAudioCodec() const;
  80. const unsigned char *getAudioExtradata(size_t &size) const; // Needed for Vorbis
  81. double getSampleRate() const;
  82. int getChannels() const;
  83. int getAudioDepth() const;
  84. bool readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame);
  85. private:
  86. inline bool notSupportedTrackNumber(long videoTrackNumber, long audioTrackNumber) const;
  87. mkvparser::IMkvReader *m_reader;
  88. mkvparser::Segment *m_segment;
  89. const mkvparser::Cluster *m_cluster;
  90. const mkvparser::Block *m_block;
  91. const mkvparser::BlockEntry *m_blockEntry;
  92. int m_blockFrameIndex;
  93. const mkvparser::VideoTrack *m_videoTrack;
  94. VIDEO_CODEC m_vCodec;
  95. const mkvparser::AudioTrack *m_audioTrack;
  96. AUDIO_CODEC m_aCodec;
  97. bool m_isOpen;
  98. bool m_eos;
  99. };
  100. #endif // WEBMDEMUXER_HPP