MatroskaFileServerDemux.hh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // A server demultiplexor for a Matroska file
  17. // C++ header
  18. #ifndef _MATROSKA_FILE_SERVER_DEMUX_HH
  19. #define _MATROSKA_FILE_SERVER_DEMUX_HH
  20. #ifndef _SERVER_MEDIA_SESSION_HH
  21. #include "ServerMediaSession.hh"
  22. #endif
  23. #ifndef _MATROSKA_FILE_HH
  24. #include "MatroskaFile.hh"
  25. #endif
  26. class MatroskaFileServerDemux: public Medium {
  27. public:
  28. typedef void (onCreationFunc)(MatroskaFileServerDemux* newDemux, void* clientData);
  29. static void createNew(UsageEnvironment& env, char const* fileName,
  30. onCreationFunc* onCreation, void* onCreationClientData,
  31. char const* preferredLanguage = "eng");
  32. // Note: Unlike most "createNew()" functions, this one doesn't return a new object immediately. Instead, because this class
  33. // requires file reading (to parse the Matroska 'Track' headers) before a new object can be initialized, the creation of a new
  34. // object is signalled by calling - from the event loop - an 'onCreationFunc' that is passed as a parameter to "createNew()".
  35. ServerMediaSubsession* newServerMediaSubsession();
  36. ServerMediaSubsession* newServerMediaSubsession(unsigned& resultTrackNumber);
  37. // Returns a new "ServerMediaSubsession" object that represents the next preferred media track
  38. // (video, audio, subtitle - in that order) from the file. (Preferred media tracks are based on the file's language preference.)
  39. // This function returns NULL when no more media tracks exist.
  40. ServerMediaSubsession* newServerMediaSubsessionByTrackNumber(unsigned trackNumber);
  41. // As above, but creates a new "ServerMediaSubsession" object for a specific track number within the Matroska file.
  42. // (You should not call this function more than once with the same track number.)
  43. // The following public: member functions are called only by the "ServerMediaSubsession" objects:
  44. MatroskaFile* ourMatroskaFile() { return fOurMatroskaFile; }
  45. char const* fileName() const { return fFileName; }
  46. float fileDuration() const { return fOurMatroskaFile->fileDuration(); }
  47. FramedSource* newDemuxedTrack(unsigned clientSessionId, unsigned trackNumber);
  48. // Used by the "ServerMediaSubsession" objects to implement their "createNewStreamSource()" virtual function.
  49. private:
  50. MatroskaFileServerDemux(UsageEnvironment& env, char const* fileName,
  51. onCreationFunc* onCreation, void* onCreationClientData,
  52. char const* preferredLanguage);
  53. // called only by createNew()
  54. virtual ~MatroskaFileServerDemux();
  55. static void onMatroskaFileCreation(MatroskaFile* newFile, void* clientData);
  56. void onMatroskaFileCreation(MatroskaFile* newFile);
  57. private:
  58. char const* fFileName;
  59. onCreationFunc* fOnCreation;
  60. void* fOnCreationClientData;
  61. MatroskaFile* fOurMatroskaFile;
  62. // Used to implement "newServerMediaSubsession()":
  63. u_int8_t fNextTrackTypeToCheck;
  64. // Used to set up demuxing, to implement "newDemuxedTrack()":
  65. unsigned fLastClientSessionId;
  66. MatroskaDemux* fLastCreatedDemux;
  67. };
  68. #endif