Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GNASH_NETSTREAM_H
00021 #define GNASH_NETSTREAM_H
00022
00023
00024 #ifndef __STDC_CONSTANT_MACROS
00025 #define __STDC_CONSTANT_MACROS
00026 #endif
00027
00028 #include "MediaParser.h"
00029 #include "PlayHead.h"
00030
00031 #include "VideoDecoder.h"
00032 #include "AudioDecoder.h"
00033
00034 #include "VirtualClock.h"
00035
00036 #include "Relay.h"
00037
00038 #include <boost/intrusive_ptr.hpp>
00039 #include <string>
00040 #include <deque>
00041 #include <boost/scoped_ptr.hpp>
00042
00043
00044 namespace gnash {
00045 class CharacterProxy;
00046 class IOChannel;
00047 class NetConnection_as;
00048 class as_function;
00049 class DisplayObject;
00050 struct ObjectURI;
00051 namespace media {
00052 class MediaHandler;
00053 }
00054 namespace sound {
00055 class sound_handler;
00056 class InputStream;
00057 }
00058 }
00059
00060 namespace gnash {
00061
00063
00072 class BufferedAudioStreamer {
00073 public:
00074
00078 BufferedAudioStreamer(sound::sound_handler* handler);
00079
00081
00085 class CursoredBuffer
00086 {
00087 public:
00088 CursoredBuffer()
00089 :
00090 m_size(0),
00091 m_data(NULL),
00092 m_ptr(NULL)
00093 {}
00094
00095 ~CursoredBuffer()
00096 {
00097 delete [] m_data;
00098 }
00099
00101 boost::uint32_t m_size;
00102
00104
00107 boost::uint8_t* m_data;
00108
00110 boost::uint8_t* m_ptr;
00111 };
00112
00113 typedef std::deque<CursoredBuffer*> AudioQueue;
00114
00115
00116 void cleanAudioQueue();
00117
00118 sound::sound_handler* _soundHandler;
00119
00122 AudioQueue _audioQueue;
00123
00125 size_t _audioQueueSize;
00126
00129 boost::mutex _audioQueueMutex;
00130
00131
00132 sound::InputStream* _auxStreamer;
00133
00135
00139 void attachAuxStreamer();
00140
00142
00146 void detachAuxStreamer();
00147
00149 unsigned int fetch(boost::int16_t* samples, unsigned int nSamples,
00150 bool& eof);
00151
00153 static unsigned int fetchWrapper(void* owner, boost::int16_t* samples,
00154 unsigned int nSamples, bool& eof);
00155
00157
00163 void push(CursoredBuffer* audio);
00164
00165 };
00166
00167
00168
00170
00174 class NetStream_as : public ActiveRelay
00175 {
00176
00177 public:
00178
00179 enum PauseMode {
00180 pauseModeToggle = -1,
00181 pauseModePause = 0,
00182 pauseModeUnPause = 1
00183 };
00184
00185 NetStream_as(as_object* owner);
00186
00187 ~NetStream_as();
00188
00189 PlayHead::PlaybackStatus playbackState() const {
00190 return _playHead.getState();
00191 }
00192
00194
00198 int videoHeight() const;
00199
00201
00205 int videoWidth() const;
00206
00209 void close();
00210
00212 void setAudioController(DisplayObject* controller);
00213
00215
00218 void pause(PauseMode mode);
00219
00221
00225 void play(const std::string& source);
00226
00228
00233 void seek(boost::uint32_t pos);
00234
00236
00239 boost::int32_t time();
00240
00245 void update();
00246
00248 double getCurrentFPS() { return 0; }
00249
00251
00255 void setNetCon(NetConnection_as* nc) {
00256 _netCon = nc;
00257 }
00258
00260 bool isConnected() const { return (_netCon); }
00261
00264
00268 void setBufferTime(boost::uint32_t time);
00269
00272
00275 boost::uint32_t bufferTime() { return m_bufferTime; }
00276
00278 long bytesLoaded();
00279
00281
00284 long bytesTotal();
00285
00288
00292 long bufferLength();
00293
00295
00297 bool newFrameReady();
00298
00300
00304 std::auto_ptr<GnashImage> get_video();
00305
00307 void setInvalidatedVideo(DisplayObject* ch)
00308 {
00309 _invalidatedVideoCharacter = ch;
00310 }
00311
00312 virtual void markReachableResources() const;
00313
00315
00321 static unsigned int audio_streamer(void *udata, boost::int16_t* samples,
00322 unsigned int nSamples, bool& eof);
00323
00324 protected:
00325
00327 enum StatusCode {
00328
00329
00330 invalidStatus,
00331
00333 bufferEmpty,
00334
00336 bufferFull,
00337
00339 bufferFlush,
00340
00342 playStart,
00343
00345 playStop,
00346
00348 seekNotify,
00349
00351 streamNotFound,
00352
00354 invalidTime
00355 };
00356
00357 NetConnection_as* _netCon;
00358
00359 boost::scoped_ptr<CharacterProxy> _audioController;
00360
00362
00379 void setStatus(StatusCode code);
00380
00384
00391 void processStatusNotifications();
00392
00393
00394 boost::uint32_t m_bufferTime;
00395
00396
00397 volatile bool m_newFrameReady;
00398
00399
00400 boost::mutex image_mutex;
00401
00402
00403 std::auto_ptr<GnashImage> m_imageframe;
00404
00405
00406 std::string url;
00407
00408
00409 std::auto_ptr<media::MediaParser> m_parser;
00410
00411
00412
00413 boost::intrusive_ptr<as_function> _statusHandler;
00414
00415
00416 long inputPos;
00417
00419 void stopAdvanceTimer();
00420
00422 void startAdvanceTimer();
00423
00425 DisplayObject* _invalidatedVideoCharacter;
00426
00427 private:
00428
00429 enum DecodingState {
00430 DEC_NONE,
00431 DEC_STOPPED,
00432 DEC_DECODING,
00433 DEC_BUFFERING
00434 };
00435
00436 typedef std::pair<std::string, std::string> NetStreamStatus;
00437
00439
00443 void getStatusCodeInfo(StatusCode code, NetStreamStatus& info);
00444
00446 as_object* getStatusObject(StatusCode code);
00447
00449
00452 void initVideoDecoder(const media::VideoInfo& info);
00453
00455
00458 void initAudioDecoder(const media::AudioInfo& parser);
00459
00460
00461 bool startPlayback();
00462
00463
00464
00465
00466
00467
00468
00469
00470 void pausePlayback();
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 void unpausePlayback();
00481
00483
00496 void refreshVideoFrame(bool alsoIfPaused = false);
00497
00500 void refreshAudioBuffer();
00501
00504 bool decodeMediaFrame();
00505
00507
00510 std::auto_ptr<GnashImage> decodeNextVideoFrame();
00511
00513
00516 BufferedAudioStreamer::CursoredBuffer* decodeNextAudioFrame();
00517
00521 void pushDecodedAudioFrames(boost::uint32_t ts);
00522
00524
00533 std::auto_ptr<GnashImage> getDecodedVideoFrame(boost::uint32_t ts);
00534
00535 DecodingState decodingStatus(DecodingState newstate = DEC_NONE);
00536
00540 void parseNextChunk();
00541
00542 DecodingState _decoding_state;
00543
00544
00545
00546 boost::mutex _state_mutex;
00547
00549 std::auto_ptr<media::VideoDecoder> _videoDecoder;
00550
00552 bool _videoInfoKnown;
00553
00555 std::auto_ptr<media::AudioDecoder> _audioDecoder;
00556
00558 bool _audioInfoKnown;
00559
00561 boost::scoped_ptr<InterruptableVirtualClock> _playbackClock;
00562
00564 PlayHead _playHead;
00565
00566
00567 sound::sound_handler* _soundHandler;
00568
00569
00570 media::MediaHandler* _mediaHandler;
00571
00573
00577 std::auto_ptr<IOChannel> _inputStream;
00578
00580 BufferedAudioStreamer _audioStreamer;
00581
00583 StatusCode _statusCode;
00584
00586 boost::mutex statusMutex;
00587
00588 };
00589
00590 void netstream_class_init(as_object& global, const ObjectURI& uri);
00591
00592 void registerNetStreamNative(as_object& global);
00593
00594 }
00595
00596 #endif
00597