• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

diskstream.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 //
00018 
00019 #ifndef __DISKSTREAM_H__
00020 #define __DISKSTREAM_H__
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include <string>
00027 #include <iostream> 
00028 
00029 #include "amf.h"
00030 #include "buffer.h"
00031 #include "flv.h"
00032 #include "cque.h"
00033 #include "statistics.h"
00034 #include "getclocktime.hpp"
00035 #include "dsodefs.h"
00036 #include <boost/scoped_ptr.hpp>
00037 
00040 namespace gnash {
00041 
00047 class DSOEXPORT DiskStream {
00048 public:
00051     typedef enum {
00052         NO_STATE,
00053         CREATED,
00054         CLOSED,
00055         OPEN,
00056         PLAY,
00057         PREVIEW,
00058         THUMBNAIL,
00059         PAUSE,
00060         SEEK,
00061         UPLOAD,
00062         MULTICAST,
00063         DONE
00064     } state_e;
00065 
00066   typedef enum {
00067     FILETYPE_NONE,
00068     FILETYPE_AMF,
00069     FILETYPE_SWF,
00070     FILETYPE_HTML,
00071     FILETYPE_PNG,
00072     FILETYPE_JPEG,
00073     FILETYPE_GIF,
00074     FILETYPE_MP3,
00075     FILETYPE_MP4,
00076     FILETYPE_OGG,
00077     FILETYPE_VORBIS,
00078     FILETYPE_THEORA,
00079     FILETYPE_DIRAC,
00080     FILETYPE_TEXT,
00081     FILETYPE_FLV,
00082     FILETYPE_VP6,
00083     FILETYPE_XML,
00084     FILETYPE_FLAC,
00085     FILETYPE_ENCODED,
00086     FILETYPE_PHP,
00087   } filetype_e;
00088 
00089     DSOEXPORT DiskStream();
00090     DSOEXPORT DiskStream(const std::string &filespec);
00091     DSOEXPORT DiskStream(const std::string &filespec, cygnal::Buffer &buf);
00092     DSOEXPORT DiskStream(const std::string &filespec, boost::uint8_t *data, size_t size);
00093     DSOEXPORT DiskStream(const std::string &filespec, int netfd);
00094     DSOEXPORT ~DiskStream();
00095 
00097     DSOEXPORT void close();
00098 
00110     DSOEXPORT bool open(const std::string &filespec);
00111     DSOEXPORT bool open(const std::string &filespec, int netfd);
00112     DSOEXPORT bool open(const std::string &filespec, int netfd, gnash::Statistics  &statistics);
00113 
00121     bool play();
00122     bool play(bool flag);
00123     bool play(int netfd, bool flag);
00124     
00136     bool preview(const std::string &filespec, int frames);
00137     
00149     bool thumbnail(const std::string &filespec, int quantity);
00150     
00154     bool pause();
00155     
00162     boost::uint8_t * seek(off_t offset);
00163     
00173     bool upload(const std::string &filespec);
00174     
00175     // Stream a single "real-time" source.
00176     bool multicast(const std::string &filespec);
00177 
00188     DSOEXPORT boost::uint8_t *loadToMem(size_t filesize, off_t offset);
00189     DSOEXPORT boost::uint8_t *loadToMem(off_t offset);
00190     DSOEXPORT boost::uint8_t *loadToMem() { return loadToMem(_offset); };
00191 
00202     DSOEXPORT bool writeToDisk(const std::string &filespec, boost::uint8_t *data, size_t size);
00203     DSOEXPORT bool writeToDisk(const std::string &filespec, cygnal::Buffer &data);
00204     DSOEXPORT bool writeToDisk(const std::string &filespec);
00205     DSOEXPORT bool writeToDisk();
00206 
00210     bool writeToNet(int start, int bytes);
00211 
00217     size_t getPagesize() { return _pagesize; };
00218     
00226     void setPagesize(size_t size) { _pagesize = size; };
00227 
00230     DiskStream &operator=(DiskStream *stream);
00231 
00234      void dump();
00235 //    friend std::ostream& operator<< (std::ostream &os, const DiskStream &ds);
00236 
00241     boost::uint8_t *get() { return _dataptr; };
00242     bool fullyPopulated();
00243 //    bool fullyPopulated() { return ((_seekptr - _filesize) == _dataptr); };
00244     
00248     size_t getFileSize() { return _filesize; };
00249 
00250     DiskStream::filetype_e getFileType() { return _filetype; };
00251 
00252     std::string &getFilespec() { return _filespec; }
00253     void setFilespec(std::string filespec) { _filespec = filespec; }
00254 
00258     struct timespec *getLastAccessTime() { return &_last_access; };
00259 
00260     state_e getState() { return _state; };
00261     void setState(state_e state) { _state = state; };
00262 
00263     int getFileFd() { return _filefd; };
00264     int getNetFd() { return _netfd; };
00265     
00266 #ifdef USE_STATS_CACHE
00267 
00268 
00269 
00270 
00271 
00272     struct timespec *getFirstAccessTime() { return &_first_access; };
00273     size_t getAccessCount() { return _accesses; };
00274 #endif    
00275 
00278     void dump() const { dump(std::cerr); }
00280     void dump(std::ostream& os) const;
00281 
00282 private:
00285     state_e     _state;
00286     
00289     int         _filefd;
00290     
00293     int         _netfd;
00294 
00297     std::string _filespec;
00298 
00302     gnash::Statistics  _statistics;
00303 
00306     boost::uint8_t *_dataptr;
00307 
00310     size_t      _max_memload;
00311     
00315     boost::uint8_t *_seekptr;
00316 
00319     size_t      _filesize;
00320 
00323     size_t      _pagesize;
00324 
00328     off_t       _offset;
00329 
00335     filetype_e determineFileType();
00336     filetype_e determineFileType( boost::uint8_t *data);
00337     filetype_e determineFileType(const std::string &filespec);
00338 
00339     // Get the file stats, so we know how to set the
00340     // Content-Length in the header.
00341     bool getFileStats(const std::string &filespec);
00342     DiskStream::filetype_e _filetype;
00343 
00344     struct timespec _last_access;
00345     
00346 #ifdef USE_STATS_CACHE
00347     struct timespec _first_access;      // used for timing how long data stays in the queue.
00348     size_t          _accesses;
00349 #endif
00350 
00351 #ifdef USE_STATS_FILE
00352     int         _bytes;
00353 #endif
00354 
00355     // The header, tag, and onMetaData from the FLV file.
00356     boost::shared_ptr<cygnal::Flv>    _flv;
00357 };
00358 
00360 inline std::ostream& operator << (std::ostream& os, const DiskStream& ds)
00361 {
00362         ds.dump(os);
00363         return os;
00364 }
00365 
00366 } // end of cygnal namespace
00367 
00368 #endif // __DISKSTREAM_H__
00369 
00370 // local Variables:
00371 // mode: C++
00372 // indent-tabs-mode: t
00373 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1