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