1 // ------------------------------------------------
4 // Author: niwakazoider
6 // Modified by Eru @2017.1.15 for compilation error at VS2008
8 // (c) 2002-3 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
26 #include "chkMemoryLeak.h"
27 #define DEBUG_NEW new(__FILE__, __LINE__)
32 // ------------------------------------------
33 void FLVStream::readEnd(Stream &, Channel *)
37 // ------------------------------------------
38 void FLVStream::readHeader(Stream &, Channel *)
42 // ------------------------------------------
43 int FLVStream::readPacket(Stream &in, Channel *ch)
45 bool headerUpdate = false;
47 if (ch->streamPos == 0) {
49 FLVFileHeader header = FLVFileHeader();
63 MemoryStream flvmem = MemoryStream(flvTag.data, flvTag.size);
64 if (amf.readMetaData(flvmem)) {
66 bitrate = amf.bitrate;
74 if (flvTag.data[0] == 0x17 && flvTag.data[1] == 0x00 &&
75 flvTag.data[2] == 0x00 && flvTag.data[3] == 0x00) {
83 if (flvTag.data[0] == 0xaf && flvTag.data[1] == 0x00) {
90 if (headerUpdate && fileHeader.size>0) {
91 int len = fileHeader.size;
92 if (metaData.type==TAG_SCRIPTDATA) len += metaData.packetSize;
93 if (avcHeader.type == TAG_VIDEO) len += avcHeader.packetSize;
94 if (aacHeader.type == TAG_AUDIO) len += aacHeader.packetSize;
95 MemoryStream mem = MemoryStream(ch->headPack.data, len);
96 mem.write(fileHeader.data, fileHeader.size);
97 if (metaData.type == TAG_SCRIPTDATA) mem.write(metaData.packet, metaData.packetSize);
98 if (avcHeader.type == TAG_VIDEO) mem.write(avcHeader.packet, avcHeader.packetSize);
99 if (aacHeader.type == TAG_AUDIO) mem.write(aacHeader.packet, aacHeader.packetSize);
101 ch->info.bitrate = bitrate;
103 ch->headPack.type = ChanPacket::T_HEAD;
104 ch->headPack.len = mem.pos;
105 ch->headPack.pos = ch->streamPos;
106 ch->newPacket(ch->headPack);
108 ch->streamPos += ch->headPack.len;
113 MemoryStream mem = MemoryStream(flvTag.packet, flvTag.packetSize);
115 int rlen = flvTag.packetSize;
119 if (rl > ChanMgr::MAX_METAINT)
120 rl = ChanMgr::MAX_METAINT;
122 pack.init(ChanPacket::T_DATA, pack.data, rl, ch->streamPos);
123 mem.read(pack.data, pack.len);
125 ch->checkReadDelay(pack.len);
126 ch->streamPos += pack.len;