Rev Author Line No. Line
23 ovan 1 /************************************************************************************
2 This source file is part of the Theora Video Playback Library
3 For latest info, see http://libtheoraplayer.sourceforge.net/
4 *************************************************************************************
5 Copyright (c) 2008-2010 Kresimir Spes (kreso@cateia.com)
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the BSD license: http://www.opensource.org/licenses/bsd-license.php
8 *************************************************************************************/
9 #ifndef _TheoraDataSource_h
10 #define _TheoraDataSource_h
11  
12 #include <fstream>
13 #include <string>
14 #include "TheoraExport.h"
15  
16 /**
17         This is a simple class that provides abstracted data feeding. You can use the
18         TheoraFileDataSource for regular file playback or you can implement your own
19         internet streaming solution, or a class that uses encrypted datafiles etc.
20         The sky is the limit
21 */
22 class TheoraPlayerExport TheoraDataSource
23 {
24 public:
25  
26     virtual ~TheoraDataSource();
27         /**
28                 Reads nBytes bytes from data source and returns number of read bytes.
29                 if function returns less bytes then nBytes, the system assumes EOF is reached.
30         */
31         virtual int read(void* output,int nBytes)=0;
32     //! returns a string representation of the DataSource, eg 'File: source.ogg'
33         virtual std::string repr()=0;
34         //! position the source pointer to byte_index from the start of the source
35         virtual void seek(unsigned long byte_index)=0;
36         //! return the size of the stream in bytes
37         virtual unsigned long size()=0;
38         //! return the current position of the source pointer
39         virtual unsigned long tell()=0;
40 };
41  
42  
43 /**
44         provides standard file IO
45 */
46 class TheoraPlayerExport TheoraFileDataSource : public TheoraDataSource
47 {
48         std::ifstream mFilePtr;
49         std::string mFilename;
50         unsigned long mSize;
51 public:
52         TheoraFileDataSource(std::string filename);
53         ~TheoraFileDataSource();
54  
55         int read(void* output,int nBytes);
56         void seek(unsigned long byte_index);
57         std::string repr() { return mFilename; }
58         unsigned long size();
59         unsigned long tell();
60 };
61  
62 /**
63         Pre-loads the entire file and streams from memory.
64         Very useful if you're continuously displaying a video and want to avoid disk reads.
65         Not very practical for large files.
66 */
67 class TheoraPlayerExport TheoraMemoryFileDataSource : public TheoraDataSource
68 {
69         std::string mFilename;
70         unsigned long mSize,mReadPointer;
71         unsigned char* mData;
72 public:
73         TheoraMemoryFileDataSource(std::string filename);
74         ~TheoraMemoryFileDataSource();
75  
76         int read(void* output,int nBytes);
77         void seek(unsigned long byte_index);
78         std::string repr() { return "MEM:"+mFilename; }
79         unsigned long size();
80         unsigned long tell();
81 };
82  
83 #endif