OSDN Git Service

FLV配信用パッチをマージ。(github:niwakazoider/peercast@21998fef7e24f437ef8d50e17562ba95eb5c1843)
[peercast-im/PeerCastIM.git] / core / common / mp3.cpp
1 // ------------------------------------------------
2 // File : mp3.cpp
3 // Date: 28-may-2003
4 // Author: giles
5 //
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.
12
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 // ------------------------------------------------
18
19 #include "channel.h"
20 #include "mp3.h"
21 #ifdef _DEBUG
22 #include "chkMemoryLeak.h"
23 #define DEBUG_NEW new(__FILE__, __LINE__)
24 #define new DEBUG_NEW
25 #endif
26
27
28 // ------------------------------------------
29 void MP3Stream::readEnd(Stream &,Channel *)
30 {
31 }
32
33 // ------------------------------------------
34 void MP3Stream::readHeader(Stream &,Channel *)
35 {
36 }
37 // ------------------------------------------
38 int MP3Stream::readPacket(Stream &in,Channel *ch)
39 {
40         ChanPacket pack;
41
42         if (ch->icyMetaInterval)
43         {
44
45                 int rlen = ch->icyMetaInterval;
46
47                 while (rlen)
48                 {
49                         int rl = rlen;
50                         if (rl > ChanMgr::MAX_METAINT)
51                                 rl = ChanMgr::MAX_METAINT;
52
53                         pack.init(ChanPacket::T_DATA,pack.data,rl,ch->streamPos);
54                         in.read(pack.data,pack.len);
55                         ch->newPacket(pack);
56                         ch->checkReadDelay(pack.len);
57                         ch->streamPos+=pack.len;
58
59                         rlen-=rl;
60                 }
61
62                 unsigned char len;
63                 in.read(&len,1);
64                 if (len)
65                 {
66                         if (len*16 > 1024) len = 1024/16;
67                         char buf[1024];
68                         in.read(buf,len*16);
69                         ch->processMp3Metadata(buf);
70                 }
71
72         }else{
73
74                 pack.init(ChanPacket::T_DATA,pack.data,ChanMgr::MAX_METAINT,ch->streamPos);
75                 in.read(pack.data,pack.len);
76                 ch->newPacket(pack);
77                 ch->checkReadDelay(pack.len);
78
79                 ch->streamPos += pack.len;
80         }
81         return 0;
82 }