1 /*
2  * streamSerialize will output a serialized stream of packets from a file
3  *
4  * Copyright (C) 2008 Joern Seger
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21 
22 #ifndef STREAMSERIALIZER_H_
23 #define STREAMSERIALIZER_H_
24 
25 #include<map>
26 #include<vector>
27 
28 #include "definition.h"
29 #include "mediaRepository.h"
30 #include "oggDecoder.h"
31 #include "oggStreamDecoder.h"
32 #include "granulePosInterpreter.h"
33 #include "streamConfig.h"
34 
35 class StreamEntry {
36 
37 public:
38   StreamConfig           streamConfig;
39   OggStreamDecoder*      streamDecoder;
40   GranulePosInterpreter* posInterpreter;
41 
42   OggPacket              nextPacket;
43   double                 nextTime;
44   bool                   endOfStream;
45   bool                   empty;
46 
47   StreamEntry();
48   StreamEntry(StreamConfig& config, OggStreamDecoder* sDecoder);
49   virtual ~StreamEntry();
50 
51   bool allHeadersCollected();
52 };
53 
54 //! class to reserialize ogg packets
55 /* reserializing an ogg stream is not as easy as it seems:
56  * you always */
57 class StreamSerializer {
58 
59 protected:
60   enum InitStates {
61     created,
62     reposOpened,
63     initialized
64   };
65 
66   InitStates       initState;
67   MediaRepository* repository;
68   OggDecoder*      oggDecoder;
69   std::map<uint32, StreamEntry> streamList;
70 
71   uint32 streamEndCounter;
72 
73   bool fillPage();
74   bool fillStreams();
75   bool extractStreams();
76 
77   void insertNextPacket(StreamEntry& entry);
78 
79   // none copieable serializer
StreamSerializer(const StreamSerializer & streamSerializer)80   StreamSerializer(const StreamSerializer& streamSerializer) {}
81 
82 public:
83   StreamSerializer();
84   virtual ~StreamSerializer();
85 
86   void getStreamConfig(std::vector<StreamConfig>& configList);
87 
88   bool available();
89 
90   bool open(std::string& datasource);
91   bool open(MediaRepository* _repository);
92   void close();
93 
94   double getNextPacket(OggPacket& packet);
95 
96 };
97 
98 #endif /*STREAMSERIALIZER_H_*/
99