Go to the documentation of this file.
20 #ifndef GNASH_NETSTREAM_H
21 #define GNASH_NETSTREAM_H
24 #ifndef __STDC_CONSTANT_MACROS
25 #define __STDC_CONSTANT_MACROS
33 #include <boost/intrusive_ptr.hpp>
34 #include <boost/ptr_container/ptr_deque.hpp>
42 class InterruptableVirtualClock;
46 class NetConnection_as;
156 unsigned int fetch(std::int16_t* samples,
unsigned int nSamples,
160 static unsigned int fetchWrapper(
void* owner, std::int16_t* samples,
161 unsigned int nSamples,
bool& eof);
240 void seek(std::uint32_t pos);
306 std::unique_ptr<image::GnashImage>
get_video();
311 _invalidatedVideoCharacter = ch;
324 unsigned int nSamples,
bool& eof);
366 typedef std::pair<std::string, std::string> NetStreamStatus;
373 void getStatusCodeInfo(StatusCode
code, NetStreamStatus& info);
376 as_object* getStatusObject(StatusCode
code);
382 void initVideoDecoder(
const media::VideoInfo& info);
388 void initAudioDecoder(
const media::AudioInfo& parser);
391 bool startPlayback();
400 void pausePlayback();
410 void unpausePlayback();
426 void refreshVideoFrame(
bool alsoIfPaused =
false);
430 void refreshAudioBuffer();
436 std::unique_ptr<image::GnashImage> decodeNextVideoFrame();
442 BufferedAudioStreamer::CursoredBuffer* decodeNextAudioFrame();
447 void pushDecodedAudioFrames(std::uint32_t
ts);
459 std::unique_ptr<image::GnashImage> getDecodedVideoFrame(std::uint32_t
ts);
461 DecodingState decodingStatus(DecodingState newstate = DEC_NONE);
466 void parseNextChunk();
486 void setStatus(StatusCode
code);
498 void processStatusNotifications();
501 void stopAdvanceTimer();
504 void startAdvanceTimer();
506 NetConnection_as* _netCon;
508 std::unique_ptr<CharacterProxy> _audioController;
511 std::uint32_t _bufferTime;
514 std::mutex image_mutex;
517 std::unique_ptr<image::GnashImage> _imageframe;
523 std::unique_ptr<media::MediaParser> _parser;
529 DisplayObject* _invalidatedVideoCharacter;
532 std::atomic<int> _decoding_state;
535 std::unique_ptr<media::VideoDecoder> _videoDecoder;
538 bool _videoInfoKnown;
541 std::unique_ptr<media::AudioDecoder> _audioDecoder;
544 bool _audioInfoKnown;
547 std::unique_ptr<InterruptableVirtualClock> _playbackClock;
553 sound::sound_handler* _soundHandler;
556 media::MediaHandler* _mediaHandler;
563 std::unique_ptr<IOChannel> _inputStream;
566 BufferedAudioStreamer _audioStreamer;
571 std::atomic<int> _statusCode;
A proxy for DisplayObject pointers.
Definition: CharacterProxy.h:44
long bytesTotal()
Returns the total number of bytes (size) of the media file.
Definition: NetStream_as.cpp:1427
bool isNativeType(const as_object *obj, T *&relay)
Check whether the object is an instance of a known type.
Definition: as_object.h:875
void removeAdvanceCallback(ActiveRelay *obj)
Definition: movie_root.cpp:1464
double toNumber(const as_value &v, const VM &vm)
Convert an as_value to a double.
Definition: VM.cpp:451
std::unique_ptr< IOChannel > getStream(const std::string &name)
Get an stream by name.
Definition: NetConnection_as.cpp:628
@ pauseModeToggle
Definition: NetStream_as.h:187
static unsigned int audio_streamer(void *udata, std::int16_t *samples, unsigned int nSamples, bool &eof)
Callback used by sound_handler to get audio data.
void seek(std::uint32_t pos)
Seek in the media played by the current instance.
Definition: NetStream_as.cpp:725
double getCurrentFPS()
Returns the current framerate in frames per second.
Definition: NetStream_as.h:255
std::uint64_t getPosition() const
Get current playhead position (milliseconds)
Definition: PlayHead.h:77
bool toBool(const as_value &v, const VM &vm)
Convert an as_value to boolean type.
Definition: VM.cpp:445
The base class for all ActionScript objects.
Definition: as_object.h:162
void setRelay(Relay *p)
Set the as_object's Relay object.
Definition: as_object.h:604
@ NOTIFY_ERROR
Definition: HostInterface.h:166
as_object * toObject(const as_value &v, VM &vm)
Convert an as_value to an object.
Definition: VM.cpp:457
void attachAuxStreamer()
Attach the aux streamer.
Definition: NetStream_as.cpp:1450
PauseMode
Definition: NetStream_as.h:186
sound::sound_handler * _soundHandler
Definition: NetStream_as.h:125
virtual void unplugInputStream(InputStream *id)
Unplug an external InputStream from the mixer.
Definition: sound_handler.cpp:373
PlayHead::PlaybackStatus playbackState() const
Definition: NetStream_as.h:196
@ PLAY_PLAYING
Definition: PlayHead.h:40
void log_debug(StringType msg, Args... args)
Definition: log.h:301
void cleanAudioQueue()
Definition: NetStream_as.cpp:1573
void setAudioController(DisplayObject *controller)
Make audio controlled by given DisplayObject.
Definition: NetStream_as.cpp:278
#define LOG_ONCE(x)
Definition: log.h:49
void play(const std::string &source)
Starts the playback of the media.
Definition: NetStream_as.cpp:359
#define _(String)
Definition: log.h:44
as_object & owner() const
Return the as_object that this Relay is attached to.
Definition: Relay.h:108
@ pauseModePause
Definition: NetStream_as.h:188
The AVM1 virtual machine.
Definition: VM.h:72
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
An exception from SoundHandler subsystem.
Definition: GnashException.h:70
std::uint8_t * m_ptr
Cursor into the data.
Definition: NetStream_as.h:117
void setInvalidatedVideo(DisplayObject *ch)
Register the DisplayObject to invalidate on video updates.
Definition: NetStream_as.h:309
std::mutex _audioQueueMutex
Definition: NetStream_as.h:136
#define GNASH_REPORT_FUNCTION
Definition: log.h:452
NetStream_as(as_object *owner)
Contruct a NetStream object.
Definition: NetStream_as.cpp:100
std::uint8_t * m_data
Actual data.
Definition: NetStream_as.h:114
@ m
Definition: GnashKey.h:159
unsigned int fetch(std::int16_t *samples, unsigned int nSamples, bool &eof)
Fetch samples from the audio queue.
Definition: NetStream_as.cpp:1505
void setAudioConsumerAvailable()
Set an audio consumer as available.
Definition: PlayHead.h:71
@ n
Definition: GnashKey.h:160
@ start
Definition: klash_part.cpp:330
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
BufferedAudioStreamer(sound::sound_handler *handler)
Definition: NetStream_as.cpp:1495
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
std::uint32_t ts
Definition: LocalConnection_as.cpp:150
NetConnection ActionScript class.
Definition: NetConnection_as.h:46
virtual void markReachableResources() const
Mark any reachable resources other than the owner.
Definition: NetStream_as.cpp:284
boost::ptr_deque< CursoredBuffer > AudioQueue
Definition: NetStream_as.h:120
#define UNUSED(x)
Definition: utility.h:113
void log_error(StringType msg, Args... args)
Definition: log.h:283
std::int32_t time()
Tells where the playhead currently is.
Definition: NetStream_as.cpp:1380
AudioQueue _audioQueue
Definition: NetStream_as.h:129
void setAudioConsumed()
Mark current position as being consumed by audio consumer.
Definition: PlayHead.h:107
as_object * createObject(const Global_as &gl)
Definition: Global_as.cpp:303
CursoredBuffer()
Definition: NetStream_as.h:95
Parameters/environment for builtin or user-defined functions callable from ActionScript.
Definition: fn_call.h:118
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
std::uint32_t m_size
Number of samples left in buffer starting from cursor.
Definition: NetStream_as.h:108
int videoWidth() const
Get the real width of the video in pixels if the decoder exists.
Definition: NetStream_as.cpp:1200
void netstream_class_init(as_object &where, const ObjectURI &uri)
Definition: NetStream_as.cpp:130
void adjustVolume(T *start, T *end, float volume)
Volume adjustment.
Definition: SoundUtils.h:39
const RunResources & getRunResources(const as_object &o)
Get the RunResources from an as_object.
Definition: as_object.cpp:1142
@ PROP_ON_STATUS
Definition: namedStrings.h:179
std::string readString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a string value from the buffer.
Definition: AMF.cpp:87
virtual InputStream * attach_aux_streamer(aux_streamer_ptr ptr, void *udata)
Plug an external InputStream into the mixer.
Definition: sound_handler.cpp:820
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
code
Definition: GnashKey.h:44
T * get(as_object *o)
Extract the DisplayObject attached to an object.
Definition: as_object.h:842
A native type that requires periodic updates from the core (movie_root).
Definition: Relay.h:80
~NetStream_as()
Definition: NetStream_as.cpp:303
void registerNative(as_c_function_ptr fun, unsigned int x, unsigned int y)
Definition: VM.cpp:268
size_t _audioQueueSize
Number of bytes in the audio queue, protected by _audioQueueMutex.
Definition: NetStream_as.h:132
void seekTo(std::uint64_t position)
Change current position to the given time.
Definition: PlayHead.cpp:112
Args::size_type nargs
Number of arguments to this ActionScript function call.
Definition: fn_call.h:178
@ pauseModeUnPause
Definition: NetStream_as.h:189
PlaybackStatus
Flags for playback state.
Definition: PlayHead.h:39
void set_invalidated()
This function marks the DisplayObject as being modified in aspect and keeps track of current invalida...
Definition: DisplayObject.cpp:183
ActionScript value type.
Definition: as_value.h:95
NetStream_as ActionScript class.
Definition: NetStream_as.h:182
void push(CursoredBuffer *audio)
Push a buffer to the audio queue.
Definition: NetStream_as.cpp:1555
long bufferLength()
Definition: NetStream_as.cpp:192
PlaybackStatus getState() const
Get current playback state.
Definition: PlayHead.h:80
std::unique_ptr< image::GnashImage > get_video()
Returns the video frame closest to current cursor. See time().
Definition: NetStream_as.cpp:203
void update()
Definition: NetStream_as.cpp:1208
void close()
Definition: NetStream_as.cpp:335
bool isConnected() const
Definition: NetConnection_as.h:92
bool isVideoConsumed() const
Return true if video of current position have been consumed.
Definition: PlayHead.h:89
bool isConnected() const
Return true if the NetStream has an associated NetConnection.
Definition: NetStream_as.h:267
const Args::value_type & arg(unsigned int n) const
Access a particular argument.
Definition: fn_call.h:194
void advanceIfConsumed()
Advance position if all available consumers consumed the current one.
Definition: PlayHead.cpp:89
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
sound::InputStream * _auxStreamer
Definition: NetStream_as.h:139
movie_root & getRoot(const as_environment &env)
Definition: as_environment.cpp:645
std::uint32_t bufferTime()
Definition: NetStream_as.h:282
int videoHeight() const
Get the real height of the video in pixels if the decoder exists.
Definition: NetStream_as.cpp:1193
as_object * get_prototype() const
Return this object's proto member.
Definition: as_object.cpp:932
Sound mixer.
Definition: sound_handler.h:88
A VirtualClock wrapper adding pause/resume capabilities.
Definition: VirtualClock.h:55
~CursoredBuffer()
Definition: NetStream_as.h:102
as_object * registerBuiltinClass(as_object &where, Global_as::ASFunction ctor, Global_as::Properties p, Global_as::Properties c, const ObjectURI &uri)
Register a built-in class.
Definition: Global_as.h:144
void detachAuxStreamer()
Detach the aux streamer.
Definition: NetStream_as.cpp:1472
uri
Definition: test.py:12
void log_security(StringType msg, Args... args)
Definition: log.h:319
long bytesLoaded()
Returns the number of bytes of the media file that have been buffered.
Definition: NetStream_as.cpp:1416
virtual void setReachable()
Mark any other reachable resources, and finally mark our owner.
Definition: Relay.cpp:36
void registerNetStreamNative(as_object &global)
Definition: NetStream_as.cpp:139
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
@ PLAY_PAUSED
Definition: PlayHead.h:41
A buffer with a cursor state.
Definition: NetStream_as.h:93
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
static unsigned int fetchWrapper(void *owner, std::int16_t *samples, unsigned int nSamples, bool &eof)
Fetch samples from the audio queue.
Definition: NetStream_as.cpp:1486
void setVideoConsumerAvailable()
Set a video consumer as available.
Definition: PlayHead.h:61
@ source
Definition: klash_part.cpp:329
as_object * this_ptr
Definition: fn_call.h:170
@ o
Definition: GnashKey.h:161
void setBufferTime(std::uint32_t time)
Definition: NetStream_as.cpp:184
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
A URI for describing as_objects.
Definition: ObjectURI.h:45
bool isAudioConsumed() const
Return true if audio of current position have been consumed.
Definition: PlayHead.h:101
Buffered AudioStreamer.
Definition: NetStream_as.h:79
void pause(PauseMode mode)
Pauses/starts the playback of the media played by the current instance.
Definition: NetStream_as.cpp:311
@ e
Definition: GnashKey.h:151
PlaybackStatus setState(PlaybackStatus newState)
Set playback state, returning old state.
Definition: PlayHead.cpp:45
void setVideoConsumed()
Mark current position as being consumed by video consumer.
Definition: PlayHead.h:95
void addAdvanceCallback(ActiveRelay *obj)
Definition: movie_root.cpp:1458
void setNetCon(NetConnection_as *nc)
Sets the NetConnection needed to access external files.
Definition: NetStream_as.h:262
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92