playback_window.h
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:5k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- */
- #ifndef _playback_window_h_
- #define _playback_window_h_
- #undef HAVE_UNISTD_H
- #include <mtvp/mtvp.h>
- #undef assert
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include "session.h"
- #include "basic_exception.h"
- #include "../../pusher/src/timeval.h"
- #include "../../pusher/src/sockaddr.h"
- #include "../../pusher/src/packet_header.h"
- #include "movie_item.h"
- /** manage mpeg player. Should be only single instance.
- The new SIH plugin interface for mpeg-tv operates through URL.
- So the play source is defined by calling COM_OPEN_STREAM_URL.
- Plug-in doesn't handle the difference between playback and broadcast
- handles. Instead plug-in keeps all sockets on and build the map of
- all existing URL's to corresponding socket. If entry already exists in
- the tree - no needs to re-open it.
- */
- class PlaybackWindow
- {
- /** reference to Session */
- Session &session;
- /** only one player */
- PMP_STRUCT Player;
- /** always holds the latest push server control port */
- Sockaddr pushServControlAddr;
- /** send/receive messages to push server by UDP socket */
- int serverSocketOut;
- /** to compare incoming packets with */
- //struct sockaddr_in serverSockaddr;
- /** remember the time when last packet was received. Play if timeout */
- Timeval lastPacketReceivedTime;
- /** if stopped or paused - buffer incoming stream, if playing - put data
- immediately in pipe
- */
- int playerState;
- /** what user wants */
- int playerStateMustBe;
- bool playerIsReady;
- /** both playback window and SII plugin must be sinchronized
- to the same mode
- */
- typedef enum { playback, broadcast } operatingModeT;
- /** playback or broadcast mode. The stopped mode is not used - to keep
- data consistent application should check playerStateMustBe.
- The only difference between p. and b. modes is that in p. mode, when
- stopped, client must post the stop message to push server. In
- brcst mode, it just have to stop reading the port.
- */
- operatingModeT operatingMode;
- /** remember the id of movie which is playing now
- */
- int currentMovieId;
- /** this handler is used to deal with sih plugin.
- To get the handler_id of an SIH plugin, you should ask for the
- return status of the COM_SIH_LINK message.
- If the status indicates that no error occured (i.e. if you get a
- message of type A2G_COM_RETURN_SUCCESS in return), the handler_id
- is passed back in the data.data_return_success.value of the
- A2G_COM_RETURN_SUCCESS message.
- */
- int sih_handler_id;
- /** When calling plug-in with flag PMP_FLAG_RETURN_STATUS, dispatcher may
- take actions on return value. It must know, what command requested
- status
- */
- typedef enum { nothing, plugin_link } command_requested_statusT;
- /** value */
- command_requested_statusT command_requested_status;
- /** set flag that tell that player is in state of shutdown, don't throw
- exceptions, etc.
- */
- bool cleanup_flag;
-
- public:
- PlaybackWindow( const char *argv0, Session &ses );
- void prepare_to_die();
- ~PlaybackWindow();
- protected:
- /** don't open any listen socket at that time
- */
- void init_player( const char *argv0 );
- public:
- /** At the beginning, player does not open any socket.
- Player play is operated by 3 functions: playback_mode,
- broadcast_mode and stop. Plugin is designed the way that you
- must just post the URL which describe the protocol, optionally
- the server and the listen sock number. It take care to open
- socket. When stopped, player actually does not close the socket,
- but discontinue to read it. Parameters of the push server are
- inside each movieFiles item
- */
- void playback_mode( const MovieFilesT &movieFiles,
- struct tm t, int movid );
- void broadcast_mode( const string &url );
- void stop();
- /** periodically called */
- void timeout();
- protected:
- void check_player_msgs();
- void process_feedback( const PMP_DATA_A2G *data, int size );
- void wait_player_msg_sec( int sec );
- };
- /**
- */
- class PlayerException : public BasicException {
- public:
- PlayerException( int line, const char *format, ... );
- };
- /** prefix of URL that our plug-in may handle
- */
- const char plugin_url_prefix[] = "sbvideo://";
- /** messages from player
- */
- struct mtv_msg {
- /** params: debug - data is string, int_param is verbose level
- timestamp - data is struct timeval
- */
- enum typeT { error = 0, debug = 1, timestamp = 2 };
- typeT type;
- int int_param;
- /** the first byte
- */
- char data[1];
- };
- #endif // _playback_window_h_