~ubuntu-branches/ubuntu/precise/gnash/precise-proposed

« back to all changes in this revision

Viewing changes to .pc/fixtypos.patch/cygnal/libnet/diskstream.h

  • Committer: Bazaar Package Importer
  • Author(s): Angel Abad, Angel Abad, Micah Gersten
  • Date: 2010-11-28 22:18:48 UTC
  • mfrom: (3.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20101128221848-apjipwy78m13612a
Tags: 0.8.8-6ubuntu1
[ Angel Abad <angelabad@ubuntu.com> ]
* Merge from debian unstable (LP: #682386). Remaining changes:
  - Add Ubuntu flash alternatives in postinst and prerm
    + update debian/browser-plugin-gnash.postinst
    + update debian/browser-plugin-gnash.prerm

[ Micah Gersten <micahg@ubuntu.com> ]
* Only install the flash alternative in /usr/lib/mozilla/plugins as the other
  locations are deprecated
  - update debian/browser-plugin-gnash.postinst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
//   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3
 
// 
4
 
// This program is free software; you can redistribute it and/or modify
5
 
// it under the terms of the GNU General Public License as published by
6
 
// the Free Software Foundation; either version 3 of the License, or
7
 
// (at your option) any later version.
8
 
// 
9
 
// This program is distributed in the hope that it will be useful,
10
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
// GNU General Public License for more details.
13
 
// 
14
 
// You should have received a copy of the GNU General Public License
15
 
// along with this program; if not, write to the Free Software
16
 
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
//
18
 
 
19
 
#ifndef __DISKSTREAM_H__
20
 
#define __DISKSTREAM_H__
21
 
 
22
 
#ifdef HAVE_CONFIG_H
23
 
#include "gnashconfig.h"
24
 
#endif
25
 
 
26
 
#include <string>
27
 
#include <iostream> 
28
 
 
29
 
#include "amf.h"
30
 
#include "buffer.h"
31
 
#include "flv.h"
32
 
#include "cque.h"
33
 
#include "statistics.h"
34
 
#include "getclocktime.hpp"
35
 
#include "dsodefs.h"
36
 
#include <boost/scoped_ptr.hpp>
37
 
 
38
 
/// \namespace gnash
39
 
///     This is the main namespace for Gnash and it's libraries.
40
 
namespace gnash {
41
 
 
42
 
/// \class DiskStream
43
 
///     This class handles the loading of files into memory. Instead
44
 
///     of using read() from the standard library, this uses mmap() to
45
 
///     map the file into memory in chunks of the memory pagesize,
46
 
///     which is much faster and less resource intensive.
47
 
class DSOEXPORT DiskStream {
48
 
public:
49
 
    /// \enum DiskStream::state_e
50
 
    ///         This represents the state of the current stream.
51
 
    typedef enum {
52
 
        NO_STATE,
53
 
        CREATED,
54
 
        CLOSED,
55
 
        OPEN,
56
 
        PLAY,
57
 
        PREVIEW,
58
 
        THUMBNAIL,
59
 
        PAUSE,
60
 
        SEEK,
61
 
        UPLOAD,
62
 
        MULTICAST,
63
 
        DONE
64
 
    } state_e;
65
 
 
66
 
  typedef enum {
67
 
    FILETYPE_NONE,
68
 
    FILETYPE_AMF,
69
 
    FILETYPE_SWF,
70
 
    FILETYPE_HTML,
71
 
    FILETYPE_PNG,
72
 
    FILETYPE_JPEG,
73
 
    FILETYPE_GIF,
74
 
    FILETYPE_MP3,
75
 
    FILETYPE_MP4,
76
 
    FILETYPE_OGG,
77
 
    FILETYPE_VORBIS,
78
 
    FILETYPE_THEORA,
79
 
    FILETYPE_DIRAC,
80
 
    FILETYPE_TEXT,
81
 
    FILETYPE_FLV,
82
 
    FILETYPE_VP6,
83
 
    FILETYPE_XML,
84
 
    FILETYPE_FLAC,
85
 
    FILETYPE_ENCODED,
86
 
    FILETYPE_PHP,
87
 
  } filetype_e;
88
 
 
89
 
    DSOEXPORT DiskStream();
90
 
    DSOEXPORT DiskStream(const std::string &filespec);
91
 
    DSOEXPORT DiskStream(const std::string &filespec, cygnal::Buffer &buf);
92
 
    DSOEXPORT DiskStream(const std::string &filespec, boost::uint8_t *data, size_t size);
93
 
    DSOEXPORT DiskStream(const std::string &filespec, int netfd);
94
 
    DSOEXPORT ~DiskStream();
95
 
 
96
 
    /// \brief Close the open disk file and it's associated stream.
97
 
    DSOEXPORT void close();
98
 
 
99
 
    /// \brief Open a file to be streamed.
100
 
    ///
101
 
    /// @param filespec The full path and file name for the data to be
102
 
    ///         read. The file must already exist.
103
 
    ///
104
 
    /// @param netfd An optional file descriptor to read data from
105
 
    ///
106
 
    /// @param statistics The optional data structure to use for
107
 
    ///         collecting statistics on this stream.
108
 
    ///
109
 
    /// @return True if the file was opened sucessfully, false if not.
110
 
    DSOEXPORT bool open(const std::string &filespec);
111
 
    DSOEXPORT bool open(const std::string &filespec, int netfd);
112
 
    DSOEXPORT bool open(const std::string &filespec, int netfd, gnash::Statistics  &statistics);
113
 
 
114
 
    /// \brief Stream the file that has been loaded,
115
 
    ///
116
 
    /// @param netfd An optional file descriptor to read data from
117
 
    ///
118
 
    /// @param flag True to play the entire file, false to play part.
119
 
    ///
120
 
    /// @return True if the data was streamed sucessfully, false if not.
121
 
    bool play();
122
 
    bool play(bool flag);
123
 
    bool play(int netfd, bool flag);
124
 
    
125
 
    /// \brief Stream a preview of the file.
126
 
    ///         A preview is a series of video frames from
127
 
    ///         the video file. Each video frame is taken by sampling
128
 
    ///         the file at a set interval.
129
 
    ///
130
 
    /// @param filespec The full path and file name for the data to be
131
 
    ///         read.
132
 
    ///
133
 
    /// @param quantity The number of frames to stream..
134
 
    ///
135
 
    /// @return True if the thumbnails were streamed sucessfully, false if not.
136
 
    bool preview(const std::string &filespec, int frames);
137
 
    
138
 
    /// \brief Stream a series of thumbnails.
139
 
    ///         A thumbnail is a series of jpg images of frames from
140
 
    ///         the video file instead of video frames. Each thumbnail
141
 
    ///         is taken by sampling the file at a set interval.
142
 
    ///
143
 
    /// @param filespec The full path and file name for the data to be
144
 
    ///         read.
145
 
    ///
146
 
    /// @param quantity The number of thumbnails to stream..
147
 
    ///
148
 
    /// @return True if the thumbnails were streamed sucessfully, false if not.
149
 
    bool thumbnail(const std::string &filespec, int quantity);
150
 
    
151
 
    /// \brief Pause the stream currently being played.
152
 
    ///
153
 
    /// @return True if the stream was paused sucessfully, false if not.
154
 
    bool pause();
155
 
    
156
 
    /// \brief Seek within the stream.
157
 
    ///
158
 
    /// @param the offset in bytes to the location within the file to
159
 
    ///         seek to.
160
 
    ///
161
 
    /// @return A real pointer to the location of the data seeked to.
162
 
    boost::uint8_t * seek(off_t offset);
163
 
    
164
 
    /// \brief Upload a file into a sandbox.
165
 
    ///         The sandbox is an area where uploaded files can get
166
 
    ///         written to safely. For SWF content, the file name also
167
 
    ///         includes a few optional paths used to seperate
168
 
    ///         applications from each other.
169
 
    ///
170
 
    /// @param filespec The file name for the data to be written.
171
 
    ///
172
 
    /// @return True if the file was uploaded sucessfully, false if not.
173
 
    bool upload(const std::string &filespec);
174
 
    
175
 
    // Stream a single "real-time" source.
176
 
    bool multicast(const std::string &filespec);
177
 
 
178
 
    /// \brief Load a chunk of the file into memory
179
 
    ///         This offset must be a multipe of the pagesize.
180
 
    ///
181
 
    /// @param size The amount of bytes to read, often the filesize
182
 
    ///         for smaller files below CACHE_LIMIT.
183
 
    ///
184
 
    /// @param offset The location in bytes in the file of the desired data.
185
 
    ///
186
 
    /// @return A real pointer to the location of the data at the
187
 
    ///         location pointed to by the offset.
188
 
    DSOEXPORT boost::uint8_t *loadToMem(size_t filesize, off_t offset);
189
 
    DSOEXPORT boost::uint8_t *loadToMem(off_t offset);
190
 
    DSOEXPORT boost::uint8_t *loadToMem() { return loadToMem(_offset); };
191
 
 
192
 
    /// \brief Write the data in memory to disk
193
 
    ///
194
 
    /// @param filespec The relative path to the file to write, which goes in
195
 
    ///         a safebox for storage.
196
 
    ///
197
 
    /// @param data The data to be written
198
 
    ///
199
 
    /// @param size The amount of data in bytes to be written
200
 
    ///
201
 
    /// @return true if the operation suceeded, false if it failed.
202
 
    DSOEXPORT bool writeToDisk(const std::string &filespec, boost::uint8_t *data, size_t size);
203
 
    DSOEXPORT bool writeToDisk(const std::string &filespec, cygnal::Buffer &data);
204
 
    DSOEXPORT bool writeToDisk(const std::string &filespec);
205
 
    DSOEXPORT bool writeToDisk();
206
 
 
207
 
    /// \brief Write the existing data to the Network.
208
 
    ///
209
 
    /// @return true is the write suceeded, false if it failed.
210
 
    bool writeToNet(int start, int bytes);
211
 
 
212
 
    /// \brief Get the memory page size
213
 
    ///         This is a cached value of the system configuration
214
 
    ///         value for the default size in bytes of a memory page.
215
 
    ///
216
 
    /// @return the currently cached memory page size.
217
 
    size_t getPagesize() { return _pagesize; };
218
 
    
219
 
    /// \brief Set the memory page size
220
 
    ///         This is a cached value of the system configuration
221
 
    ///         value for the default size in bytes of a memory page.
222
 
    ///
223
 
    /// @param size The size of a page of memory to cache.
224
 
    ///
225
 
    /// @return nothing.
226
 
    void setPagesize(size_t size) { _pagesize = size; };
227
 
 
228
 
    /// \brief copy another DiskStream into ourselves, so they share data
229
 
    ///         in memory.
230
 
    DiskStream &operator=(DiskStream *stream);
231
 
 
232
 
    /// \brief Dump the internal data of this class in a human readable form.
233
 
    /// @remarks This should only be used for debugging purposes.
234
 
     void dump();
235
 
//    friend std::ostream& operator<< (std::ostream &os, const DiskStream &ds);
236
 
 
237
 
    /// \brief Get the base address for the memory page.
238
 
    ///
239
 
    /// @return A real pointer to the base address data in the file, but after
240
 
    /// the header bytes.
241
 
    boost::uint8_t *get() { return _dataptr; };
242
 
    bool fullyPopulated();
243
 
//    bool fullyPopulated() { return ((_seekptr - _filesize) == _dataptr); };
244
 
    
245
 
    /// \brief Get the size of the file.
246
 
    ///
247
 
    /// @return A value that is the size of the file in bytes.
248
 
    size_t getFileSize() { return _filesize; };
249
 
 
250
 
    DiskStream::filetype_e getFileType() { return _filetype; };
251
 
 
252
 
    std::string &getFilespec() { return _filespec; }
253
 
    void setFilespec(std::string filespec) { _filespec = filespec; }
254
 
 
255
 
    /// \brief Get the time of the last access.
256
 
    ///
257
 
    /// @return A real pointer to the struct timespec of the last access.
258
 
    struct timespec *getLastAccessTime() { return &_last_access; };
259
 
 
260
 
    state_e getState() { return _state; };
261
 
    void setState(state_e state) { _state = state; };
262
 
 
263
 
    int getFileFd() { return _filefd; };
264
 
    int getNetFd() { return _netfd; };
265
 
    
266
 
#ifdef USE_STATS_CACHE
267
 
    /// \brief Get the time of the first access.
268
 
    ///         This function should only be used for debugging and
269
 
    ///         performance testing.
270
 
    ///
271
 
    /// @return A real pointer to the struct timespec of the last access.
272
 
    struct timespec *getFirstAccessTime() { return &_first_access; };
273
 
    size_t getAccessCount() { return _accesses; };
274
 
#endif    
275
 
 
276
 
    /// \brief Dump the internal data of this class in a human readable form.
277
 
    /// @remarks This should only be used for debugging purposes.
278
 
    void dump() const { dump(std::cerr); }
279
 
    /// \overload dump(std::ostream& os) const
280
 
    void dump(std::ostream& os) const;
281
 
 
282
 
private:
283
 
    /// \var DiskStream::_state
284
 
    ///         The current status of the stream while streaming.
285
 
    state_e     _state;
286
 
    
287
 
    /// \var DiskStream::_filefd
288
 
    ///         The file descriptor of the disk file.
289
 
    int         _filefd;
290
 
    
291
 
    /// \var DiskStream::_netfd
292
 
    ///         The file descriptor of the network connection.
293
 
    int         _netfd;
294
 
 
295
 
    /// \var DiskStream::_filespec
296
 
    ///         The path and file name of the disk file to stream.
297
 
    std::string _filespec;
298
 
 
299
 
    /// \var DiskStream::_statistics
300
 
    ///         The data structure for collecting statistical
301
 
    ///         information.
302
 
    gnash::Statistics  _statistics;
303
 
 
304
 
    /// \var DiskStream::_dataptr
305
 
    ///         The base address of the memory page.
306
 
    boost::uint8_t *_dataptr;
307
 
 
308
 
    /// \var DiskStream::_max_memload
309
 
    ///         The maximum amount of data to load into memory
310
 
    size_t      _max_memload;
311
 
    
312
 
    /// \var DiskStream::_seekptr
313
 
    ///         The current location within the current memory page where
314
 
    ///         the data ends, which is in increments of the empry page size.
315
 
    boost::uint8_t *_seekptr;
316
 
 
317
 
    /// \var DiskStream::_filesize
318
 
    ///         The size of the disk file to stream.
319
 
    size_t      _filesize;
320
 
 
321
 
    /// \var DiskStream::_pagesize
322
 
    ///         The memory page size.
323
 
    size_t      _pagesize;
324
 
 
325
 
    /// \var DiskStream::_offset
326
 
    ///         The offset within the file of the current memory
327
 
    ///         page.
328
 
    off_t       _offset;
329
 
 
330
 
    /// \brief An internal routine used to extract the type of file.
331
 
    ///
332
 
    /// @param filespec An optional filename to extract the type from.
333
 
    ///
334
 
    /// @return an AMF filetype
335
 
    filetype_e determineFileType();
336
 
    filetype_e determineFileType( boost::uint8_t *data);
337
 
    filetype_e determineFileType(const std::string &filespec);
338
 
 
339
 
    // Get the file stats, so we know how to set the
340
 
    // Content-Length in the header.
341
 
    bool getFileStats(const std::string &filespec);
342
 
    DiskStream::filetype_e _filetype;
343
 
 
344
 
    struct timespec _last_access;
345
 
    
346
 
#ifdef USE_STATS_CACHE
347
 
    struct timespec _first_access;      // used for timing how long data stays in the queue.
348
 
    size_t          _accesses;
349
 
#endif
350
 
 
351
 
#ifdef USE_STATS_FILE
352
 
    int         _bytes;
353
 
#endif
354
 
 
355
 
    // The header, tag, and onMetaData from the FLV file.
356
 
    boost::shared_ptr<cygnal::Flv>    _flv;
357
 
};
358
 
 
359
 
/// \brief Dump to the specified output stream.
360
 
inline std::ostream& operator << (std::ostream& os, const DiskStream& ds)
361
 
{
362
 
        ds.dump(os);
363
 
        return os;
364
 
}
365
 
 
366
 
} // end of cygnal namespace
367
 
 
368
 
#endif // __DISKSTREAM_H__
369
 
 
370
 
// local Variables:
371
 
// mode: C++
372
 
// indent-tabs-mode: t
373
 
// End: