1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * mms-downloader.h: MMS Downloader class.
6 * Moonlight List (moonlist-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
14 #ifndef __MMS_DOWNLOADER_H__
15 #define __MMS_DOWNLOADER_H__
20 class ContentDescriptionList
;
22 #include "internal-downloader.h"
23 #include "downloader.h"
24 #include "http-streaming.h"
26 #include "pipeline-asf.h"
30 #define MMS_HEADER 0x48
31 #define MMS_METADATA 0x4D
32 #define MMS_STREAM_C 0x43
34 #define MMS_PAIR_P 0x50
43 struct MmsHeaderReason
{
51 struct MmsDataPacket
{
65 typedef struct MmsHeader MmsHeader
;
66 typedef struct MmsPacket MmsPacket
;
68 class MmsDownloader
: public InternalDownloader
{
73 char *playlist_gen_id
;
77 guint64 requested_pts
;
80 TimeSpan p_packet_times
[3];
81 gint32 p_packet_sizes
[3];
82 guint8 p_packet_count
;
89 ContentDescriptionList
*content_descriptions
;
91 static void PlayCallback (EventObject
*sender
);
92 void Play (); // sends a play request. if SetRequestedPts has been called, start from that pts
93 void SelectStreams (); // sends a select stream request
95 bool ProcessPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
97 bool ProcessDataPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
98 bool ProcessHeaderPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
99 bool ProcessMetadataPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
100 bool ProcessPairPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
101 bool ProcessStreamSwitchPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
102 bool ProcessEndPacket (MmsHeader
*header
, MmsPacket
*packet
, char *payload
, guint32
*size
);
104 static void ProcessResponseHeaderCallback (gpointer context
, const char *header
, const char *value
);
105 void ProcessResponseHeader (const char *header
, const char *value
);
108 virtual ~MmsDownloader ();
111 MmsDownloader (Downloader
*dl
);
113 virtual void Open (const char *verb
, const char *uri
);
114 virtual void Write (void *buf
, gint32 offset
, gint32 n
);
115 virtual char *GetDownloadedFilename (const char *partname
);
116 virtual char *GetResponseText (const char *partname
, gint64
*size
);
118 void SetSource (MmsSource
*src
); // main thread only
119 MmsPlaylistEntry
*GetCurrentEntryReffed (); // main thread only
121 void SetRequestedPts (guint64 value
); // thread safe
122 guint64
GetRequestedPts (); // thread safe
124 const char *GetUri () { return uri
; }
125 const char *GetClientId () { return client_id
; }
126 const char *GetPlaylistGenId () { return playlist_gen_id
; }
127 guint64
GetMaxBitrate () { return max_bitrate
; }
130 class ContentDescriptionList
{
133 bool Parse (const char *input
, gint32 length
);
136 class ContentDescription
: public List::Node
{
155 virtual ~ContentDescription ();
157 ValueType value_type
;
162 class MmsSecondDownloader
: public EventObject
{
168 EVENTHANDLER (MmsSecondDownloader
, DownloadFailed
, EventObject
, EventArgs
);
169 EVENTHANDLER (MmsSecondDownloader
, Completed
, EventObject
, EventArgs
);
170 static void data_write (void *data
, gint32 offset
, gint32 n
, void *closure
);
171 void CreateDownloader ();
172 static gboolean
KillTimeoutCallback (gpointer context
);
173 void KillTimeoutHandler ();
176 virtual ~MmsSecondDownloader () {}
179 MmsSecondDownloader (MmsDownloader
*mms
);
181 virtual void Dispose ();
182 void SendStreamSwitch ();
183 // TODO: void SendLog ();
184 void SetKillTimeout (guint seconds
); // the second downloader will kill itself after this amount of time
187 #endif /* __MMS_DOWNLOADER_H__ */