Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvsyncstream.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2002 Net Integration Technologies, Inc. 00004 * 00005 * A throttled stream. 00006 */ 00007 #ifndef __WVSYNCSTREAM_H 00008 #define __WVSYNCSTREAM_H 00009 00010 #ifndef _WIN32 00011 #include <sys/time.h> 00012 #endif 00013 #include <time.h> 00014 #include "wvstream.h" 00015 #include "wvstreamclone.h" 00016 00017 /** 00018 * WvSyncStream throttles its input to the specified bitrate. 00019 * 00020 * It only becomes readable at periodic intervals. 00021 */ 00022 class WvSyncStream : public WvStreamClone 00023 { 00024 size_t bps; 00025 size_t avgchunk; 00026 size_t maxchunk; 00027 size_t availchunk; 00028 size_t usedchunk; 00029 size_t lowater, hiwater; // controls latency 00030 bool waiting; 00031 00032 struct timeval reference; // last reference time taken 00033 00034 public: 00035 /** 00036 * Creates a new WvSyncStream. 00037 * 00038 * "cloned" is the stream to wrap 00039 * "bps" is the number of bytes per second to allow 00040 * "avgchunk" is the average number of bytes to process at once 00041 * "maxchunk" is the maximum number of bytes to process at once 00042 */ 00043 WvSyncStream(WvStream *cloned, size_t bps, 00044 size_t avgchunk, size_t maxchunk); 00045 virtual ~WvSyncStream(); 00046 00047 /** 00048 * Convenience constructor for throttling monaural audio streams. 00049 * 00050 * "cloned" is the stream to wrap 00051 * "owner" is if false, sets disassociate_on_close 00052 * "srate" is the sampling rate in Hz 00053 * "bits" is the number of bits per sample 00054 * "msec" is the allowable average latency 00055 * @deprecated 00056 */ 00057 WvSyncStream(WvStream *cloned, bool owner, int srate, int bits, 00058 int msec = 10); 00059 00060 virtual size_t uread(void *buf, size_t count); 00061 virtual bool pre_select(SelectInfo &si); 00062 virtual bool post_select(SelectInfo &si); 00063 00064 private: 00065 void init(size_t _bps, size_t _avgchunk, size_t _maxchunk); 00066 00067 // updates availchunk to reflect the max amount of data available now 00068 void poll(); 00069 // resets the timing information 00070 void resettimer(); 00071 }; 00072 00073 #endif // __WVSYNCSTREAM_H

Generated on Tue Oct 5 01:09:21 2004 for WvStreams by doxygen 1.3.7