1 // ------------------------------------------------
6 // (c) 2002-3 peercast.org
7 // ------------------------------------------------
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 // ------------------------------------------------
23 #include "chkMemoryLeak.h"
24 #define DEBUG_NEW new(__FILE__, __LINE__)
28 // ------------------------------------------
29 ASFInfo parseASFHeader(Stream &in);
32 // ------------------------------------------
33 void MMSStream::readEnd(Stream &,Channel *)
37 // ------------------------------------------
38 void MMSStream::readHeader(Stream &,Channel *)
41 // ------------------------------------------
42 int MMSStream::readPacket(Stream &in,Channel *ch)
51 case 0x4824: // asf header
53 MemoryStream mem(ch->headPack.data,sizeof(ch->headPack.data));
60 MemoryStream asfm(chunk.data,chunk.dataLen);
62 asfHead.readHead(asfm);
64 ASFInfo asf = parseASFHeader(asfm);
65 LOG_DEBUG("ASF Info: pnum=%d, psize=%d, br=%d",asf.numPackets,asf.packetSize,asf.bitrate);
66 for(int i=0; i<ASFInfo::MAX_STREAMS; i++)
68 ASFStream *s = &asf.streams[i];
70 LOG_DEBUG("ASF Stream %d : %s, br=%d",s->id,s->getTypeName(),s->bitrate);
73 ch->info.bitrate = asf.bitrate/1000;
75 ch->headPack.type = ChanPacket::T_HEAD;
76 ch->headPack.len = mem.pos;
77 ch->headPack.pos = ch->streamPos;
78 ch->newPacket(ch->headPack);
80 ch->streamPos += ch->headPack.len;
84 case 0x4424: // asf data
89 MemoryStream mem(pack.data,sizeof(pack.data));
93 pack.type = ChanPacket::T_DATA;
95 pack.pos = ch->streamPos;
98 ch->streamPos += pack.len;
103 throw StreamException("Unknown ASF chunk");
112 // -----------------------------------
113 ASFInfo parseASFHeader(Stream &in)
119 int numHeaders = in.readLong();
124 LOG_CHANNEL("ASF Headers: %d",numHeaders);
125 for(int i=0; i<numHeaders; i++)
130 unsigned int l = obj.readHead(in);
134 MemoryStream data(obj.data,obj.lenLo);
139 case ASFObject::T_FILE_PROP:
143 unsigned int dpLo = data.readLong();
144 unsigned int dpHi = data.readLong();
149 //data.writeLong(1); // flags = broadcast, not seekable
151 int min = data.readLong();
152 int max = data.readLong();
153 int br = data.readLong();
156 throw StreamException("ASF packetsizes (min/max) must match");
158 asf.packetSize = max;
160 asf.numPackets = dpLo;
163 case ASFObject::T_STREAM_BITRATE:
165 int cnt = data.readShort();
166 for(int i=0; i<cnt; i++)
168 unsigned int id = data.readShort();
169 int bitrate = data.readLong();
170 if (id < ASFInfo::MAX_STREAMS)
171 asf.streams[id].bitrate = bitrate;
175 case ASFObject::T_STREAM_PROP:
179 asf.streams[s.id].id = s.id;
180 asf.streams[s.id].type = s.type;
186 }catch(StreamException &e)
188 LOG_ERROR("ASF: %s",e.msg);