2009-06-17 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / mms-downloader.h
blobe7d4949562748e1b76cb97fb07ef26660d94539a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * mms-downloader.h: MMS Downloader class.
5 * Contact:
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__
17 #include <glib.h>
19 class MmsDownloader;
20 class ContentDescriptionList;
22 #include "internal-downloader.h"
23 #include "downloader.h"
24 #include "http-streaming.h"
25 #include "pipeline.h"
26 #include "pipeline-asf.h"
27 #include "mutex.h"
29 #define MMS_DATA 0x44
30 #define MMS_HEADER 0x48
31 #define MMS_METADATA 0x4D
32 #define MMS_STREAM_C 0x43
33 #define MMS_END 0x45
34 #define MMS_PAIR_P 0x50
36 struct MmsHeader {
37 char b:1;
38 char frame:7;
39 guint8 id;
40 guint16 length;
43 struct MmsHeaderReason {
44 char b:1;
45 char frame:7;
46 guint8 id;
47 guint16 length;
48 guint32 reason;
51 struct MmsDataPacket {
52 guint32 id;
53 guint8 incarnation;
54 guint8 flags;
55 guint16 size;
58 struct MmsPacket {
59 union {
60 guint32 reason;
61 MmsDataPacket data;
62 } packet;
65 typedef struct MmsHeader MmsHeader;
66 typedef struct MmsPacket MmsPacket;
68 class MmsDownloader : public InternalDownloader {
69 private:
70 char *uri;
71 char *buffer;
72 char *client_id;
73 char *playlist_gen_id;
75 guint32 size;
77 guint64 requested_pts;
78 Mutex request_mutex;
80 TimeSpan p_packet_times[3];
81 gint32 p_packet_sizes[3];
82 guint8 p_packet_count;
83 guint64 max_bitrate;
85 bool is_playing;
86 bool stream_switched;
88 MmsSource *source;
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);
107 protected:
108 virtual ~MmsDownloader ();
110 public:
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 {
131 public:
132 List list;
133 bool Parse (const char *input, gint32 length);
136 class ContentDescription : public List::Node {
137 public:
138 enum ValueType {
139 VT_BOOL = 11,
140 VT_BSTR = 8,
141 VT_CY = 6,
142 VT_ERROR = 10,
143 VT_I1 = 16,
144 VT_I2 = 2,
145 VT_I4 = 3,
146 VT_INT = 22,
147 VT_LPWSTR = 31,
148 VT_UI1 = 17,
149 VT_UI2 = 18,
150 VT_UI4 = 19,
151 VT_UINT = 23,
154 public:
155 virtual ~ContentDescription ();
156 char *name;
157 ValueType value_type;
158 void *value;
159 int value_length;
162 class MmsSecondDownloader : public EventObject {
163 private:
164 Downloader *dl;
165 MmsDownloader *mms;
166 guint kill_timeout;
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 ();
175 protected:
176 virtual ~MmsSecondDownloader () {}
178 public:
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__ */