| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #ifndef LOVE_VIDEO_THEORA_OGGDEMUXER_H |
| 22 | #define LOVE_VIDEO_THEORA_OGGDEMUXER_H |
| 23 | |
| 24 | // STL |
| 25 | #include <functional> |
| 26 | |
| 27 | // LOVE |
| 28 | #include "filesystem/File.h" |
| 29 | |
| 30 | // OGG |
| 31 | #include <ogg/ogg.h> |
| 32 | |
| 33 | namespace love |
| 34 | { |
| 35 | namespace video |
| 36 | { |
| 37 | namespace theora |
| 38 | { |
| 39 | |
| 40 | class OggDemuxer |
| 41 | { |
| 42 | public: |
| 43 | enum StreamType |
| 44 | { |
| 45 | TYPE_THEORA, |
| 46 | TYPE_UNKNOWN, |
| 47 | }; |
| 48 | |
| 49 | OggDemuxer(love::filesystem::File *file); |
| 50 | ~OggDemuxer(); |
| 51 | |
| 52 | StreamType findStream(); |
| 53 | bool readPacket(ogg_packet &packet, bool mustSucceed = false); |
| 54 | void resync(); |
| 55 | bool isEos() const; |
| 56 | const std::string &getFilename() const; |
| 57 | bool seek(ogg_packet &packet, double target, std::function<double(int64)> getTime); |
| 58 | |
| 59 | private: |
| 60 | StrongRef<love::filesystem::File> file; |
| 61 | |
| 62 | ogg_sync_state sync; |
| 63 | ogg_stream_state stream; |
| 64 | ogg_page page; |
| 65 | |
| 66 | bool streamInited; |
| 67 | int videoSerial; |
| 68 | bool eos; |
| 69 | |
| 70 | bool readPage(bool erroreof = false); |
| 71 | StreamType determineType(); |
| 72 | }; // OggDemuxer |
| 73 | |
| 74 | } // theora |
| 75 | } // video |
| 76 | } // love |
| 77 | |
| 78 | #endif // LOVE_VIDEO_THEORA_OGGDEMUXER_H |
| 79 | |