/* ======================== idSWFBitStream::ReadMorphGradient ======================== */ void idSWFBitStream::ReadMorphGradient( swfGradient_t& grad ) { grad.numGradients = ReadU8() & 0xF; // the top 4 bits control spread and interpolation mode, but we ignore them for( int i = 0; i < grad.numGradients; i++ ) { grad.gradientRecords[i].startRatio = ReadU8(); ReadColorRGBA( grad.gradientRecords[i].startColor ); grad.gradientRecords[i].endRatio = ReadU8(); ReadColorRGBA( grad.gradientRecords[i].endColor ); } }
void CMapReader::ReadBlockQ(FILE *fp) { m_blockQ = new SBlockQ[m_header.numBlockQ]; memset(m_blockQ, 0, sizeof(SBlockQ)*m_header.numBlockQ); SBlockQ *p = m_blockQ; for(u32 i=0; i<m_header.numBlockQ; i++, p++) { p->un0 = ReadU8(fp); p->un1 = ReadU8(fp); } }
/***************************************************************************** * FUNCTION - ReadMpcTime * DESCRIPTION: IFlashReader implementation ****************************************************************************/ void FlashBlock::ReadMpcTime(MpcTime* pMpcTime) { if (CanRead(9)) { // read data part if (ReadBool(false)) { pMpcTime->SetDate(YEAR, ReadU8((U8)pMpcTime->GetDate(YEAR))+2000); pMpcTime->SetDate(MONTH, ReadU8((U8)pMpcTime->GetDate(MONTH))); pMpcTime->SetDate(DAY, ReadU8((U8)pMpcTime->GetDate(DAY))); pMpcTime->SetDate(DAY_OF_WEEK, ReadU8((U8)pMpcTime->GetDate(DAY_OF_WEEK))); } else { pMpcTime->SetDateInValid(); mReadPos += 4; mReadAvailable -= 4; } // read time part if (ReadBool(false)) { pMpcTime->SetTime(HOURS, ReadU8((U8)pMpcTime->GetTime(HOURS))); pMpcTime->SetTime(MINUTES, ReadU8((U8)pMpcTime->GetTime(MINUTES))); pMpcTime->SetTime(SECONDS, ReadU8((U8)pMpcTime->GetTime(SECONDS))); } else { pMpcTime->SetTimeInValid(); mReadPos += 3; mReadAvailable -= 3; } } }
/* ======================== idSWFBitStream::ReadGradient ======================== */ void idSWFBitStream::ReadGradient( swfGradient_t& grad, bool rgba ) { grad.numGradients = ReadU8() & 0xF; // the top 4 bits control spread and interpolation mode, but we ignore them for( int i = 0; i < grad.numGradients; i++ ) { grad.gradientRecords[i].startRatio = ReadU8(); if( rgba ) { ReadColorRGBA( grad.gradientRecords[i].startColor ); } else { ReadColorRGB( grad.gradientRecords[i].startColor ); } grad.gradientRecords[i].endRatio = grad.gradientRecords[i].startRatio; grad.gradientRecords[i].endColor = grad.gradientRecords[i].startColor; } }
void CMapReader::ReadVertices(FILE *fp) { m_vertices = new SVertex[m_header.numVertices]; memset(m_vertices, 0, sizeof(SVertex)*m_header.numVertices); SVertex *v = m_vertices; for(u32 i=0; i<m_header.numVertices; i++, v++) { v->un0 = ReadU8(fp); v->un1 = ReadU8(fp); v->x = ReadS16(fp); v->y = ReadS16(fp); v->z = ReadS16(fp); v->un2 = ReadU8(fp); v->un3 = ReadU8(fp); } }
/* ======================== idSWFBitStream::ReadEncodedU32 ======================== */ uint32 idSWFBitStream::ReadEncodedU32() { uint32 result = 0; for( int i = 0; i < 5; i++ ) { byte b = ReadU8(); result |= ( b & 0x7F ) << ( 7 * i ); if( ( b & 0x80 ) == 0 ) { return result; } } return result; }
void CMapReader::ReadQuadUVFaces(FILE *fp) { m_quadUVFaces = new SQuadUVFace[m_header.numQuadUVFaces]; memset(m_quadUVFaces, 0, sizeof(SQuadUVFace)*m_header.numQuadUVFaces); SQuadUVFace *f = m_quadUVFaces; for(int i=0; i<m_header.numQuadUVFaces; i++, f++) { f->u0 = ReadU8(fp); f->v0 = ReadU8(fp); f->u1 = ReadU8(fp); f->v1 = ReadU8(fp); f->u2 = ReadU8(fp); f->v2 = ReadU8(fp); f->u3 = ReadU8(fp); f->v3 = ReadU8(fp); f->texture = ReadU16(fp); f->pad[0] = ReadU16(fp); f->pad[1] = ReadU16(fp); f->pad[2] = ReadU16(fp); f->pad[3] = ReadU16(fp); } }
unsigned int BinaryDataReader::ReadBytes(unsigned int _count, unsigned char *_buffer) { if (m_eof) { return 0; } for (unsigned int i = 0; i < _count; ++i) { _buffer[i] = ReadU8(); if (m_offset >= m_dataSize) { m_eof = true; return i + 1; } } return _count; }
//Publish using RTMP_SendPacket() int publish_using_packet(){ RTMP *rtmp=NULL; RTMPPacket *packet=NULL; uint32_t start_time=0; uint32_t now_time=0; //the timestamp of the previous frame long pre_frame_time=0; long lasttime=0; int bNextIsKey=1; uint32_t preTagsize=0; //packet attributes uint32_t type=0; uint32_t datalength=0; uint32_t timestamp=0; uint32_t streamid=0; FILE*fp=NULL; fp=fopen("../live.flv","rb"); if (!fp){ RTMP_LogPrintf("Open File Error.\n"); // CleanupSockets(); return -1; } /* set log level */ //RTMP_LogLevel loglvl=RTMP_LOGDEBUG; //RTMP_LogSetLevel(loglvl); // if (!InitSockets()){ // RTMP_LogPrintf("Init Socket Err\n"); // return -1; // } rtmp=RTMP_Alloc(); RTMP_Init(rtmp); //set connection timeout,default 30s rtmp->Link.timeout=5; if(!RTMP_SetupURL(rtmp,"rtmp://101.251.251.93:1935/myapp/mystream")) { RTMP_Log(RTMP_LOGERROR,"SetupURL Err\n"); RTMP_Free(rtmp); // CleanupSockets(); return -1; } //if unable,the AMF command would be 'play' instead of 'publish' RTMP_EnableWrite(rtmp); if (!RTMP_Connect(rtmp,NULL)){ RTMP_Log(RTMP_LOGERROR,"Connect Err\n"); RTMP_Free(rtmp); // CleanupSockets(); return -1; } if (!RTMP_ConnectStream(rtmp,0)){ RTMP_Log(RTMP_LOGERROR,"ConnectStream Err\n"); RTMP_Close(rtmp); RTMP_Free(rtmp); // CleanupSockets(); return -1; } packet=(RTMPPacket*)malloc(sizeof(RTMPPacket)); RTMPPacket_Alloc(packet,1024*64); RTMPPacket_Reset(packet); packet->m_hasAbsTimestamp = 0; packet->m_nChannel = 0x04; packet->m_nInfoField2 = rtmp->m_stream_id; RTMP_LogPrintf("Start to send data ...\n"); //jump over FLV Header fseek(fp,9,SEEK_SET); //jump over previousTagSizen fseek(fp,4,SEEK_CUR); start_time=RTMP_GetTime(); while(1) { if((((now_time=RTMP_GetTime())-start_time) <(pre_frame_time)) && bNextIsKey){ //wait for 1 sec if the send process is too fast //this mechanism is not very good,need some improvement if(pre_frame_time>lasttime){ RTMP_LogPrintf("TimeStamp:%8lu ms\n",pre_frame_time); lasttime=pre_frame_time; } sleep(1); continue; } //not quite the same as FLV spec if(!ReadU8(&type,fp)) break; if(!ReadU24(&datalength,fp)) break; if(!ReadTime(×tamp,fp)) break; if(!ReadU24(&streamid,fp)) break; if (type!=0x08&&type!=0x09){ //jump over non_audio and non_video frame, //jump over next previousTagSizen at the same time fseek(fp,datalength+4,SEEK_CUR); continue; } if(fread(packet->m_body,1,datalength,fp)!=datalength) break; packet->m_headerType = RTMP_PACKET_SIZE_LARGE; packet->m_nTimeStamp = timestamp; packet->m_packetType = type; packet->m_nBodySize = datalength; pre_frame_time=timestamp; if (!RTMP_IsConnected(rtmp)){ RTMP_Log(RTMP_LOGERROR,"rtmp is not connect\n"); break; } if (!RTMP_SendPacket(rtmp,packet,0)){ RTMP_Log(RTMP_LOGERROR,"Send Error\n"); break; } if(!ReadU32(&preTagsize,fp)) break; if(!PeekU8(&type,fp)) break; if(type==0x09){ if(fseek(fp,11,SEEK_CUR)!=0) break; if(!PeekU8(&type,fp)){ break; } if(type==0x17) bNextIsKey=1; else bNextIsKey=0; fseek(fp,-11,SEEK_CUR); } } RTMP_LogPrintf("\nSend Data Over\n"); if(fp) fclose(fp); if (rtmp!=NULL){ RTMP_Close(rtmp); RTMP_Free(rtmp); rtmp=NULL; } if (packet!=NULL){ RTMPPacket_Free(packet); free(packet); packet=NULL; } // CleanupSockets(); return 0; }