Alex Bikfalvi
SimStream Documentation
StreamSourceMpeg.cpp
00001 #include "Headers.h" 00002 #include "StreamSourceMpeg.h" 00003 00004 CStreamSourceMpegFrameTemplate::CStreamSourceMpegFrameTemplate( 00005 EFrameType type, 00006 __uint32 size, 00007 char anchorP, 00008 char anchorB 00009 ) 00010 { 00011 this->type = type; 00012 this->size = size; 00013 this->anchorP = anchorP; 00014 this->anchorB = anchorB; 00015 } 00016 00017 CStreamSourceMpeg::CStreamSourceMpeg( 00018 CChannel* channel, 00019 __byte gopDistanceItoI, 00020 __byte gopDistanceItoP, 00021 __byte segmentSize 00022 ) : CStreamSource(channel) 00023 { 00024 assert(gopDistanceItoI > 0); 00025 assert(gopDistanceItoP > 0); 00026 assert(gopDistanceItoI >= gopDistanceItoP); 00027 00028 this->gopDistanceItoI = gopDistanceItoI; 00029 this->gopDistanceItoP = gopDistanceItoP; 00030 this->segmentSize = segmentSize; 00031 00032 // Generate frame template 00033 this->gopTemplate = new CStreamSourceMpegFrameTemplate[this->gopDistanceItoI]; 00034 00035 // I frame 00036 this->gopTemplate[0] = CStreamSourceMpegFrameTemplate( 00037 FRAME_I, 00038 (__uint32)ceil(this->channel->Bw()/this->channel->Fps()), 00039 0, 00040 0); 00041 00042 // P frames 00043 for(char indexP = this->gopDistanceItoP; indexP < this->gopDistanceItoI; indexP += this->gopDistanceItoP) 00044 { 00045 this->gopTemplate[indexP] = CStreamSourceMpegFrameTemplate( 00046 FRAME_P, 00047 (__uint32)ceil(this->channel->Bw()/this->channel->Fps()), 00048 -((char)this->gopDistanceItoP), // Previous anchor 00049 0); 00050 } 00051 00052 // B frames 00053 for(char indexP = 0; indexP < this->gopDistanceItoI; indexP += this->gopDistanceItoP) 00054 { 00055 for(char indexB = indexP + 1; indexB < indexP + this->gopDistanceItoP; indexB++) 00056 { 00057 this->gopTemplate[indexB] = CStreamSourceMpegFrameTemplate( 00058 FRAME_B, 00059 (__uint32)ceil(this->channel->Bw()/this->channel->Fps()), 00060 -((char)(indexB - indexP)), // Previous anchor 00061 (indexP + this->gopDistanceItoP - indexB) // Next anchor 00062 ); 00063 } 00064 } 00065 } 00066 00067 CStreamSourceMpeg::~CStreamSourceMpeg() 00068 { 00069 delete[] this->gopTemplate; 00070 } 00071 00072 CStreamFrame CStreamSourceMpeg::Fetch(__uint32 index) 00073 { 00074 // Generate frame 00075 00076 // Calculate GOP index 00077 __uint32 idx = index % this->gopDistanceItoI; 00078 00079 return CStreamFrame( 00080 this->channel->Id(), 00081 this->gopTemplate[idx].type, 00082 index, 00083 this->gopTemplate[idx].anchorP, 00084 this->gopTemplate[idx].anchorB, 00085 this->gopTemplate[idx].size, 00086 index / this->segmentSize, 00087 index % this->segmentSize, 00088 this->segmentSize 00089 ); 00090 }
Last updated: February 8, 2011