Example #1
0
//出力用TSデータを送る
//戻り値:
// TRUE(成功)、FALSE(失敗)
//引数:
// data		[IN]TSデータ
// size		[IN]dataのサイズ
BOOL COneServiceUtil::AddTSBuff(
	BYTE* data,
	DWORD size
	)
{
	BOOL ret = TRUE;
	if( this->SID == 0xFFFF || this->sendTcp != NULL || this->sendUdp != NULL){
		//全サービス扱い
		ret = WriteData(data, size);
		for( DWORD i=0; i<size; i+=188 ){
			CTSPacketUtil packet;
			if( packet.Set188TS(data + i, 188) == TRUE ){
				if( packet.PID == this->pmtPID ){
					DWORD err = createPmt.AddData(&packet);
				}
			}
		}
	}else{
		if( size > this->buffSize ){
			SAFE_DELETE_ARRAY(this->buff);
			this->buff = new BYTE[size*2];
			this->buffSize = size*2;
		}
		this->buffWriteSize = 0;

		for( DWORD i=0; i<size; i+=188 ){
			CTSPacketUtil packet;
			if( packet.Set188TS(data + i, 188) == TRUE ){
				if( packet.PID == 0x0000 ){
					//PAT
					BYTE* patBuff = NULL;
					DWORD patBuffSize = 0;
					if( createPat.GetPacket(&patBuff, &patBuffSize) == TRUE ){
						memcpy(this->buff + this->buffWriteSize, patBuff, patBuffSize);
						this->buffWriteSize+=patBuffSize;
					}
				}else if( packet.PID == this->pmtPID ){
					//PMT
					DWORD err = createPmt.AddData(&packet);
					if( err == NO_ERR || err == ERR_NO_CHAGE ){
						BYTE* pmtBuff = NULL;
						DWORD pmtBuffSize = 0;
						if( createPmt.GetPacket(&pmtBuff, &pmtBuffSize) == TRUE ){
							memcpy(this->buff + this->buffWriteSize, pmtBuff, pmtBuffSize);
							this->buffWriteSize+=pmtBuffSize;
						}else{
							_OutputDebugString(L"createPmt.GetPacket Err");
							//そのまま
							memcpy(this->buff + this->buffWriteSize, data+i, 188);
							this->buffWriteSize+=188;
						}
					}else if( err == FALSE ){
						_OutputDebugString(L"createPmt.AddData Err");
						//そのまま
						memcpy(this->buff + this->buffWriteSize, data+i, 188);
						this->buffWriteSize+=188;
					}
				}else{
					//その他
					if( packet.PID < 0x0030 ){
						//そのまま
						memcpy(this->buff + this->buffWriteSize, data+i, 188);
						this->buffWriteSize+=188;
					}else{
						if( createPmt.IsNeedPID(packet.PID) == TRUE ){
							//PMTで定義されてる
							memcpy(this->buff + this->buffWriteSize, data+i, 188);
							this->buffWriteSize+=188;
						}else{
							//EMMなら必要
							map<WORD,WORD>::iterator itr;
							itr = this->emmPIDMap.find(packet.PID);
							if( itr != this->emmPIDMap.end() ){
								memcpy(this->buff + this->buffWriteSize, data+i, 188);
								this->buffWriteSize+=188;
							}
						}
					}
				}
			}
		}

		WriteData(this->buff, this->buffWriteSize);
	}

	if( this->pittariStart == TRUE ){
		if( this->lastPMTVer == 0xFFFF ){
			this->lastPMTVer = createPmt.GetVersion();
		}else if(this->lastPMTVer != createPmt.GetVersion()){
			//ぴったり開始
			StratPittariRec();
			this->lastPMTVer = createPmt.GetVersion();
		}
		if( this->epgUtil != NULL ){
			EPG_EVENT_INFO* epgInfo;
			if( this->epgUtil->GetEpgInfo( this->pittariONID, this->pittariTSID, this->pittariSID, FALSE, &epgInfo ) == NO_ERR ){
				if( epgInfo->event_id == this->pittariEventID ){
					//ぴったり開始
					StratPittariRec();
					this->pittariStart = FALSE;
					this->pittariEndChk = TRUE;
				}
			}
		}
	}
	if( this->pittariEndChk == TRUE ){
		if( this->epgUtil != NULL ){
			EPG_EVENT_INFO* epgInfo;
			if( this->epgUtil->GetEpgInfo( this->pittariONID, this->pittariTSID, this->pittariSID, FALSE, &epgInfo ) == NO_ERR ){
				if( epgInfo->event_id != this->pittariEventID ){
					//ぴったり終了
					StopPittariRec();
					this->pittariEndChk = FALSE;
				}
			}
		}
	}

	return ret;
}
Example #2
0
void CDecodeUtil::AddTSData(BYTE* data)
{
	{
		CTSPacketUtil tsPacket;
		if( tsPacket.Set188TS(data, 188) == TRUE ){
			if( tsPacket.PID == 0x1FFF ){
				return;
			}
			CTSBuffUtil* buffUtil = NULL;

			map<WORD, CTSBuffUtil>::iterator itr;
			itr = this->buffUtilMap.find( tsPacket.PID );
			if( itr == this->buffUtilMap.end() ){
				//まだPIDがないので新規
				buffUtil = &this->buffUtilMap.insert(std::make_pair(tsPacket.PID, CTSBuffUtil())).first->second;
			}else{
				buffUtil = &itr->second;
			}
			if( buffUtil->Add188TS(&tsPacket) == TRUE ){
				BYTE* section = NULL;
				DWORD sectionSize = 0;
				while( buffUtil->GetSectionBuff( &section, &sectionSize ) == TRUE ){
					if( buffUtil->IsPES() == TRUE ){
						continue;
					}
					CPSITable* table;
					BOOL ret;
					switch( CTableUtil::Decode(section, sectionSize, &table) ){
					case CTableUtil::TYPE_PAT:
						ret = CheckPAT(tsPacket.PID, static_cast<CPATTable*>(table));
						break;
					case CTableUtil::TYPE_NIT:
						ret = CheckNIT(tsPacket.PID, static_cast<CNITTable*>(table));
						break;
					case CTableUtil::TYPE_SDT:
						ret = CheckSDT(tsPacket.PID, static_cast<CSDTTable*>(table));
						break;
					case CTableUtil::TYPE_TOT:
						ret = CheckTOT(tsPacket.PID, static_cast<CTOTTable*>(table));
						break;
					case CTableUtil::TYPE_TDT:
						ret = CheckTDT(tsPacket.PID, static_cast<CTDTTable*>(table));
						break;
					case CTableUtil::TYPE_EIT:
						ret = CheckEIT(tsPacket.PID, static_cast<CEITTable*>(table));
						break;
					case CTableUtil::TYPE_BIT:
						ret = CheckBIT(tsPacket.PID, static_cast<CBITTable*>(table));
						break;
					case CTableUtil::TYPE_SIT:
						ret = CheckSIT(tsPacket.PID, static_cast<CSITTable*>(table));
						break;
					case CTableUtil::TYPE_NONE:
						if( section[0] == 0 ){
							_OutputDebugString(L"★pid 0x%04X\r\n", tsPacket.PID);
						}
						ret = TRUE;
						break;
					default:
						ret = FALSE;
						break;
					}
					if( ret == FALSE ){
						delete table;
					}
				}
			}
		}
	}
}
Example #3
0
DWORD CTSSrcFilter::AddTS(BYTE* data, DWORD size)
{
	DWORD addVideo = 0;
	for( DWORD i=0; i<size; i+=188 ){
		CTSPacketUtil packet;
		if( packet.Set188TS(data + i, 188) == TRUE ){
			if( packet.transport_scrambling_control == 0 ){
				//PMT
				map<WORD, CPMTUtil*>::iterator itrPmt;
				if( packet.payload_unit_start_indicator == 1 && packet.data_byteSize > 0){
					BYTE pointer = packet.data_byte[0];
					if( pointer+1 < packet.data_byteSize ){
						if( packet.data_byte[1+pointer] == 0x02 ){
							//PMT
							map<WORD, CPMTUtil*>::iterator itrPmt;
							itrPmt = this->pmtUtilMap.find(packet.PID);
							if( itrPmt == this->pmtUtilMap.end() ){
								CPMTUtil* util = new CPMTUtil;
								this->pmtUtilMap.insert(pair<WORD, CPMTUtil*>(packet.PID, util));
								if( util->AddPacket(&packet) == TRUE ){
									CheckPID();
								}
							}else{
								if( itrPmt->second->AddPacket(&packet) == TRUE ){
									CheckPID();
								}
							}
						}
					}
				}else{
					//PMTの2パケット目かチェック
					map<WORD, CPMTUtil*>::iterator itrPmt;
					itrPmt = this->pmtUtilMap.find(packet.PID);
					if( itrPmt != this->pmtUtilMap.end() ){
						if( itrPmt->second->AddPacket(&packet) == TRUE ){
							CheckPID();
						}
					}
				}
				if( packet.PID == videoPID ){
					videoBuff.Add188TS(&packet);
					BYTE* buff = NULL;
					DWORD buffSize = 0;
					BOOL ret = videoBuff.GetSectionBuff(&buff, &buffSize);
					if( ret == TRUE ){
						CPESHeadInfo info;
						info.SetData(buff, buffSize);
						LONGLONG pts = 0;
						LONGLONG time = 0;
						if( info.PTS_DTS_flags == 3 ){
							if(this->startTSV == 0){
								this->startTSV = info.DTS;
							}
							if( this->startTS == 0 ){
								this->startTS = this->startTSV;
							}
							pts = info.DTS;
						}else if( info.PTS_DTS_flags == 2 ){
							if(this->startTSV == 0){
								this->startTSV = info.PTS;
							}
							if( this->startTS == 0 ){
								this->startTS = this->startTSV;
							}
							pts = info.PTS;
						}
						if( this->startTSV > pts ){
							pts += 0x1FFFFFFFF;
						}
						time = ((pts-this->startTS)/90)*10000;
						if( info.PES_packet_data_byte_size > 0 && time >= 0){
							this->m_pVideoPin->AddData(info.PES_packet_data_byte, info.PES_packet_data_byte_size, time);
							addVideo++;
						}
					}
				}else if( packet.PID == audioPID ){
					audioBuff.Add188TS(&packet);
					BYTE* buff = NULL;
					DWORD buffSize = 0;
					BOOL ret = audioBuff.GetSectionBuff(&buff, &buffSize);
					if( ret == TRUE ){
						CPESHeadInfo info;
						info.SetData(buff, buffSize);
						LONGLONG pts = 0;
						LONGLONG time = 0;
						if( info.PTS_DTS_flags == 3 ){
							if(this->startTSA == 0){
								this->startTSA = info.DTS;
							}
							if( this->startTS == 0 ){
								this->startTS = this->startTSV;
							}
							pts = info.DTS;
						}else if( info.PTS_DTS_flags == 2 ){
							if(this->startTSA == 0){
								this->startTSA = info.PTS;
							}
							if( this->startTS == 0 ){
								this->startTS = this->startTSV;
							}
							pts = info.PTS;
						}
						if( this->startTSA > pts ){
							pts += 0x1FFFFFFFF;
						}
						time = ((pts-this->startTS)/90)*10000;
						if( info.PES_packet_data_byte_size > 0 && time >= 0){
							this->m_pAudioPin->AddData(info.PES_packet_data_byte, info.PES_packet_data_byte_size, time);
						}
					}
				}
			}
		}
	}
	return addVideo;
}
Example #4
0
UINT WINAPI CTimeShiftUtil::ReadThread(LPVOID param)
{
	CoInitialize(NULL);
	CTimeShiftUtil* sys = (CTimeShiftUtil*)param;
	BYTE buff[188*256];
	CPacketInit packetInit;

	{
		CBlockLock lock(&sys->ioLock);
		sys->readFile = CreateFile(sys->filePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
		                           NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
		if( sys->readFile == INVALID_HANDLE_VALUE ){
			return FALSE;
		}
		sys->seekFile = CreateFile(sys->filePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
		                           NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if( sys->seekFile == INVALID_HANDLE_VALUE ){
			CloseHandle(sys->readFile);
			sys->readFile = INVALID_HANDLE_VALUE;
			return FALSE;
		}
	}

	__int64 initTime = -1;
	__int64 base = -1;
	DWORD initTick = 0;
	vector<WORD> pcrPidList;
	DWORD errCount = 0;

	for(;;){
		{
			__int64 wait = 0;
			if( base >= 0 ){
				//レート調整
				wait = ((base + 0x200000000LL - initTime) & 0x1FFFFFFFFLL) / 90 - (GetTickCount() - initTick);
				base = -1;
			}else if( errCount > 0 ){
				//終端監視中
				wait = 200;
			}
			for( ; wait > 0 && sys->readStopFlag == FALSE; wait -= 20 ){
				Sleep(20);
			}
			if( sys->readStopFlag ){
				break;
			}
		}
		CBlockLock lock(&sys->ioLock);

		LARGE_INTEGER liMove = {};
		if( SetFilePointerEx(sys->readFile, liMove, &liMove, FILE_CURRENT) == FALSE ){
			break;
		}
		if( liMove.QuadPart != sys->currentFilePos ){
			//シークされた
			if( sys->currentFilePos >= sys->GetAvailableFileSize() ){
				//有効なデータの終端に達した
				if( sys->fileMode || ++errCount > 50 ){
					break;
				}
				continue;
			}
			liMove.QuadPart = sys->currentFilePos;
			if( SetFilePointerEx(sys->readFile, liMove, NULL, FILE_BEGIN) == FALSE ){
				break;
			}
			packetInit.ClearBuff();
			initTime = -1;
		}
		DWORD readSize;
		if( ReadFile(sys->readFile, buff, sizeof(buff), &readSize, NULL) == FALSE ||
		    readSize < (sys->fileMode ? 1 : sizeof(buff)) ){
			//ファイル終端に達した
			if( sys->fileMode || ++errCount > 50 ){
				break;
			}
			liMove.QuadPart = sys->currentFilePos;
			if( SetFilePointerEx(sys->readFile, liMove, NULL, FILE_BEGIN) == FALSE ){
				break;
			}
			continue;
		}
		BYTE* data;
		DWORD dataSize;
		if( packetInit.GetTSData(buff, readSize, &data, &dataSize) == FALSE || dataSize <= 0 ){
			if( sys->fileMode == FALSE && sys->currentFilePos + (__int64)sizeof(buff) > sys->GetAvailableFileSize() ){
				//無効なデータ領域を読んでいる可能性がある
				if( ++errCount > 50 ){
					break;
				}
				liMove.QuadPart = sys->currentFilePos;
				if( SetFilePointerEx(sys->readFile, liMove, NULL, FILE_BEGIN) == FALSE ){
					break;
				}
			}else{
				//不正なデータを読み飛ばす
				sys->currentFilePos += readSize;
				errCount = 0;
			}
			continue;
		}
		sys->currentFilePos += readSize;
		errCount = 0;

		for( DWORD i = 0; i < dataSize; i += 188 ){
			CTSPacketUtil packet;
			if( packet.Set188TS(data + i, 188) ){
				if( packet.adaptation_field_length > 0 && packet.PCR_flag == 1 ){
					//最初に3回PCRが出現したPIDをPCR_PIDとする
					//PCR_PIDが現れることなく5回別のPCRが出現すればPCR_PIDを変更する
					if( packet.PID != sys->PCR_PID ){
						pcrPidList.push_back(packet.PID);
						if( std::count(pcrPidList.begin(), pcrPidList.end(), packet.PID) >= (sys->PCR_PID == 0xFFFF ? 3 : 5) ){
							sys->PCR_PID = packet.PID;
							initTime = -1;
						}
					}
					if( packet.PID == sys->PCR_PID ){
						pcrPidList.clear();
						base = packet.program_clock_reference_base;
						if( initTime < 0 ){
							initTime = base;
							initTick = GetTickCount();
						}
					}
				}
			}
		}
		if( sys->sendUdpIP.empty() == false ){
			sys->sendUdp.SendData(data, dataSize);
		}
		if( sys->sendTcpIP.empty() == false ){
			sys->sendTcp.SendData(data, dataSize);
		}
	}

	CBlockLock lock(&sys->ioLock);
	CloseHandle(sys->seekFile);
	sys->seekFile = INVALID_HANDLE_VALUE;
	CloseHandle(sys->readFile);
	sys->readFile = INVALID_HANDLE_VALUE;

	if( sys->readStopFlag == FALSE ){
		return 0;
	}
	//無効PAT送って次回送信時にリセットされるようにする
	BYTE endBuff[188*512];
	memset(endBuff, 0xFF, 188*512);
	map<WORD, CCreatePATPacket::PROGRAM_PID_INFO> PIDMap;
	CCreatePATPacket patUtil;
	patUtil.SetParam(1, &PIDMap);
	BYTE* patBuff;
	DWORD patSize=0;
	patUtil.GetPacket(&patBuff, &patSize);

	memcpy(endBuff, patBuff, patSize);
	for( int i=patSize; i<188*512; i+=188){
		endBuff[i] = 0x47;
		endBuff[i+1] = 0x1F;
		endBuff[i+2] = 0xFF;
		endBuff[i+3] = 0x10;
	}

	if( sys->sendUdpIP.empty() == false ){
		sys->sendUdp.SendData(endBuff, 188*512);
	}
	if( sys->sendTcpIP.empty() == false ){
		sys->sendTcp.SendData(endBuff, 188*512);
	}

	CoUninitialize();
	return 0;
}
Example #5
0
UINT WINAPI CTimeShiftUtil::ReadThread(LPVOID param)
{
	CoInitialize(NULL);
	CTimeShiftUtil* sys = (CTimeShiftUtil*)param;
	BYTE buff[188*256];
	CPacketInit packetInit;

	HANDLE file = CreateFile( sys->filePath.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( file == INVALID_HANDLE_VALUE ){
		return FALSE;
	}

	DWORD lenH = 0;
	DWORD lenL = GetFileSize(file, &lenH);
	__int64 totlaFileSize = ((__int64)lenH)<<32 | lenL;
	if( totlaFileSize < sys->currentFilePos ){
		sys->currentFilePos = totlaFileSize;
	}
	sys->totalFileSize = totlaFileSize;

	LONG setH = (LONG)(sys->currentFilePos>>32);
	LONG setL = (LONG)(sys->currentFilePos & 0x00000000FFFFFFFF);
	SetFilePointer(file, setL, &setH, FILE_BEGIN);

	__int64 initTime = -1;
	__int64 initTick = 0;

	DWORD errCount = 0;
	__int64 pcr_offset = 0;
	__int64 tick_offset = 0;

	for(;;){
		if( ::WaitForSingleObject(sys->readStopEvent, 0) != WAIT_TIMEOUT ){
			//キャンセルされた
			break;
		}
		__int64 totalReadSize = sys->currentFilePos;
		DWORD readSize = 0;
		DWORD buffSize = 188*256;
		if( sys->availableFileSize != -1 && sys->fileMode == FALSE ){
			if( totalReadSize + buffSize > sys->availableFileSize ){
				buffSize = (DWORD)(sys->availableFileSize-totalReadSize);
			}
		}
		if( totalReadSize + buffSize > sys->totalFileSize && sys->fileMode == FALSE){
			//ファイルサイズ変わっていってるはずなので開き直す
			CloseHandle(file);
			file = CreateFile( sys->filePath.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
			if( file == INVALID_HANDLE_VALUE ){
				return FALSE;
			}
			setH = (LONG)(sys->currentFilePos>>32);
			setL = (LONG)(sys->currentFilePos & 0x00000000FFFFFFFF);
			SetFilePointer(file, setL, &setH, FILE_BEGIN);

			lenH = 0;
			lenL = GetFileSize(file, &lenH);
			__int64 newSize = ((__int64)lenH)<<32 | lenL;

			sys->totalFileSize = newSize;
			Sleep(50);
			errCount++;
			if( errCount > (1000/50)*10){
				//10秒間ファイルサイズの更新ないから終端のはず
				CloseHandle(file);
				return FALSE;
			}
			continue;
		}
		BOOL ret = ReadFile( file, buff, buffSize, &readSize, NULL );
		if( ret == FALSE || readSize < buffSize){
			if( sys->fileMode == TRUE ){
				//ファイルモードだからエラーは終端のはず
				CloseHandle(file);
				return FALSE;
			}else{
				Sleep(50);
				errCount++;
				if( errCount > (1000/50)*10){
					//10秒間ファイルサイズの更新ないから終端のはず
					CloseHandle(file);
					return FALSE;
				}
			}
		}else{
			errCount = 0;
		}
		if( readSize == 0 ){
			Sleep(50);
			continue;
		}
		BYTE* data = NULL;
		DWORD dataSize = 0;
		__int64 base = -1;
		if( packetInit.GetTSData(buff, readSize, &data, &dataSize) == TRUE ){
			if( sys->LockBuff() == TRUE ){
				for( DWORD i=0; i<dataSize; i+=188 ){
					CTSPacketUtil packet;
					if( packet.Set188TS(data + i, 188) == TRUE ){
						if( packet.transport_scrambling_control == 0 ){
							//PMT
							if( packet.payload_unit_start_indicator == 1 && packet.data_byteSize > 0){
								BYTE pointer = packet.data_byte[0];
								if( pointer+1 < packet.data_byteSize ){
									if( packet.data_byte[1+pointer] == 0x02 ){
										//PMT
										map<WORD, CPMTUtil*>::iterator itrPmt;
										itrPmt = sys->pmtUtilMap.find(packet.PID);
										if( itrPmt == sys->pmtUtilMap.end() ){
											CPMTUtil* util = new CPMTUtil;
											sys->pmtUtilMap.insert(pair<WORD, CPMTUtil*>(packet.PID, util));
											if( util->AddPacket(&packet) == TRUE ){
												if( sys->PCR_PID != util->PCR_PID ){
													//チャンネル変わった?
													initTime = -1;
													initTick = 0;
												}
												sys->PCR_PID = util->PCR_PID;
											}
										}else{
											if( itrPmt->second->AddPacket(&packet) == TRUE ){
												if( sys->PCR_PID != itrPmt->second->PCR_PID ){
													//チャンネル変わった?
													initTime = -1;
													initTick = 0;
												}
												sys->PCR_PID = itrPmt->second->PCR_PID;
											}
										}
									}
								}
							}else{
								//PMTの2パケット目かチェック
								map<WORD, CPMTUtil*>::iterator itrPmt;
								itrPmt = sys->pmtUtilMap.find(packet.PID);
								if( itrPmt != sys->pmtUtilMap.end() ){
									if( itrPmt->second->AddPacket(&packet) == TRUE ){
										if( sys->PCR_PID != itrPmt->second->PCR_PID ){
											//チャンネル変わった?
											initTime = -1;
											initTick = 0;
										}
										sys->PCR_PID = itrPmt->second->PCR_PID;
									}
								}
							}

							if( packet.adaptation_field_length > 0 && packet.PCR_flag == 1 ){
								if( sys->PCR_PID == 0xFFFF ){
									//最初に捕まえたPCRを暫定的に使う
									initTime = -1;
									sys->PCR_PID = packet.PID;
								}
								if( sys->PCR_PID == packet.PID ){
									base = (__int64)packet.program_clock_reference_base/90;
									if( initTime == -1 ){
										initTime = base;
										initTick = GetTickCount();
									}
								}
							}
						}
					}
				}
				sys->UnLockBuff();

				if( sys->sendUdp != NULL ){
					sys->sendUdp->SendData(data, dataSize);
				}
				if( sys->sendTcp != NULL ){
					sys->sendTcp->SendData(data, dataSize);
				}
			}
			sys->currentFilePos += readSize;
		}
		

		for(;;){
			if( initTime != -1 && base != -1){
				if( base+pcr_offset<initTime ){
					//PCR巻き戻った?
					pcr_offset = 0x1FFFFFFFF;
				}
				__int64 tick = GetTickCount();
				if( tick+tick_offset<initTick ){
					tick_offset = 0xFFFFFFFF;
				}
				if( (base+pcr_offset)-initTime >tick+tick_offset-initTick+100){
					if( ::WaitForSingleObject(sys->readStopEvent, 20) != WAIT_TIMEOUT ){
						//キャンセルされた
						goto Err_End;
					}
				}else{
					break;
				}
			}else{
				break;
			}
		}
	}
Example #6
0
//出力用TSデータを送る
//戻り値:
// TRUE(成功)、FALSE(失敗)
//引数:
// data		[IN]TSデータ
// size		[IN]dataのサイズ
BOOL COneServiceUtil::AddTSBuff(
	BYTE* data,
	DWORD size
	)
{
	BOOL ret = TRUE;
	if( this->SID == 0xFFFF || this->sendTcp != NULL || this->sendUdp != NULL){
		//全サービス扱い
		if( data != NULL ){
			ret = WriteData(data, size);
		}
		for( DWORD i=0; i<size; i+=188 ){
			CTSPacketUtil packet;
			if( packet.Set188TS(data + i, 188) == TRUE ){
				if( packet.PID == this->pmtPID ){
					DWORD err = createPmt.AddData(&packet);
				}
			}
		}
	}else{
		this->buff.clear();

		for( DWORD i=0; i<size; i+=188 ){
			CTSPacketUtil packet;
			if( packet.Set188TS(data + i, 188) == TRUE ){
				if( packet.PID == 0x0000 ){
					//PAT
					BYTE* patBuff = NULL;
					DWORD patBuffSize = 0;
					if( createPat.GetPacket(&patBuff, &patBuffSize) == TRUE ){
						if( packet.payload_unit_start_indicator == 1 ){
							this->buff.insert(this->buff.end(), patBuff, patBuff + patBuffSize);
						}
					}
				}else if( packet.PID == this->pmtPID ){
					//PMT
					DWORD err = createPmt.AddData(&packet);
					if( err == NO_ERR || err == ERR_NO_CHAGE ){
						BYTE* pmtBuff = NULL;
						DWORD pmtBuffSize = 0;
						if( createPmt.GetPacket(&pmtBuff, &pmtBuffSize) == TRUE ){
							this->buff.insert(this->buff.end(), pmtBuff, pmtBuff + pmtBuffSize);
						}else{
							_OutputDebugString(L"createPmt.GetPacket Err");
							//そのまま
							this->buff.insert(this->buff.end(), data + i, data + i + 188);
						}
					}else if( err == FALSE ){
						_OutputDebugString(L"createPmt.AddData Err");
						//そのまま
						this->buff.insert(this->buff.end(), data + i, data + i + 188);
					}
				}else{
					//その他
					if( packet.PID < 0x0030 ){
						//そのまま
						this->buff.insert(this->buff.end(), data + i, data + i + 188);
					}else{
						if( createPmt.IsNeedPID(packet.PID) == TRUE ){
							//PMTで定義されてる
							this->buff.insert(this->buff.end(), data + i, data + i + 188);
						}else{
							//EMMなら必要
							map<WORD,WORD>::iterator itr;
							itr = this->emmPIDMap.find(packet.PID);
							if( itr != this->emmPIDMap.end() ){
								this->buff.insert(this->buff.end(), data + i, data + i + 188);
							}
						}
					}
				}
			}
		}

		if( this->buff.empty() == false ){
			ret = WriteData(&this->buff.front(), (DWORD)this->buff.size());
		}
	}

	if( this->pittariStart == TRUE ){
		if( this->lastPMTVer == 0xFFFF ){
			this->lastPMTVer = createPmt.GetVersion();
		}else if(this->lastPMTVer != createPmt.GetVersion()){
			//ぴったり開始
			StratPittariRec();
			this->lastPMTVer = createPmt.GetVersion();
		}
		if( this->epgUtil != NULL ){
			EPG_EVENT_INFO* epgInfo;
			if( this->epgUtil->GetEpgInfo( this->pittariONID, this->pittariTSID, this->pittariSID, FALSE, &epgInfo ) == NO_ERR ){
				if( epgInfo->event_id == this->pittariEventID ){
					//ぴったり開始
					StratPittariRec();
					this->pittariStart = FALSE;
					this->pittariEndChk = TRUE;
				}
			}
		}
	}
	if( this->pittariEndChk == TRUE ){
		if( this->epgUtil != NULL ){
			EPG_EVENT_INFO* epgInfo;
			if( this->epgUtil->GetEpgInfo( this->pittariONID, this->pittariTSID, this->pittariSID, FALSE, &epgInfo ) == NO_ERR ){
				if( epgInfo->event_id != this->pittariEventID ){
					//ぴったり終了
					StopPittariRec();
					this->pittariEndChk = FALSE;
				}
			}
		}
	}

	return ret;
}
Example #7
0
void CDecodeUtil::AddTSData(BYTE* data)
{
	{
		CTSPacketUtil tsPacket;
		if( tsPacket.Set188TS(data, 188) == TRUE ){
			if( tsPacket.PID == 0x1FFF ){
				return;
			}
			CTSBuffUtil* buffUtil = NULL;

			map<WORD, CTSBuffUtil*>::iterator itr;
			itr = this->buffUtilMap.find( tsPacket.PID );
			if( itr == this->buffUtilMap.end() ){
				//まだPIDがないので新規
				buffUtil = new CTSBuffUtil;
				this->buffUtilMap.insert(pair<WORD, CTSBuffUtil*>(tsPacket.PID, buffUtil));
			}else{
				buffUtil = itr->second;
			}
			if( buffUtil->Add188TS(&tsPacket) == TRUE ){
				BYTE* section = NULL;
				DWORD sectionSize = 0;
				while( buffUtil->GetSectionBuff( &section, &sectionSize ) == TRUE ){
					if( buffUtil->IsPES() == TRUE ){
						continue;
					}
					CTableUtil tableUtil;

					vector<TABLE_DATA*> tableList;
					DWORD decodeReadSize = 0;
					if( tableUtil.Decode(section, sectionSize, &tableList, &decodeReadSize) == TRUE ){
						for( size_t j=0; j<tableList.size(); j++ ){
							if( tableList[j]->PATTable != NULL ){
								if( CheckPAT(tsPacket.PID, tableList[j]->PATTable) == TRUE ){
									tableList[j]->PATTable = NULL;
								}
							}else if( tableList[j]->CATTable != NULL ){
								if( CheckCAT(tsPacket.PID, tableList[j]->CATTable) == TRUE ){
									tableList[j]->CATTable = NULL;
								}
							}else if( tableList[j]->PMTTable != NULL ){
								if( CheckPMT(tsPacket.PID, tableList[j]->PMTTable) == TRUE ){
									tableList[j]->PMTTable = NULL;
								}
							}else if( tableList[j]->NITTable != NULL ){
								if( CheckNIT(tsPacket.PID, tableList[j]->NITTable) == TRUE ){
									tableList[j]->NITTable = NULL;
								}
							}else if( tableList[j]->SDTTable != NULL ){
								if( CheckSDT(tsPacket.PID, tableList[j]->SDTTable) == TRUE ){
									tableList[j]->SDTTable = NULL;
								}
							}else if( tableList[j]->TOTTable != NULL ){
								if( CheckTOT(tsPacket.PID, tableList[j]->TOTTable) == TRUE ){
									tableList[j]->TOTTable = NULL;
								}
							}else if( tableList[j]->TDTTable != NULL ){
								if( CheckTDT(tsPacket.PID, tableList[j]->TDTTable) == TRUE ){
									tableList[j]->TDTTable = NULL;
								}
							}else if( tableList[j]->EITTable != NULL ){
								if( CheckEIT(tsPacket.PID, tableList[j]->EITTable) == TRUE ){
									tableList[j]->EITTable = NULL;
								}
							}else if( tableList[j]->CDTTable != NULL ){
								if( CheckCDT(tsPacket.PID, tableList[j]->CDTTable) == TRUE ){
									tableList[j]->CDTTable = NULL;
								}
							}else if( tableList[j]->SDTTTable != NULL ){
								if( CheckSDTT(tsPacket.PID, tableList[j]->SDTTTable) == TRUE ){
									tableList[j]->SDTTTable = NULL;
								}
							}else if( tableList[j]->BITTable != NULL ){
								if( CheckBIT(tsPacket.PID, tableList[j]->BITTable) == TRUE ){
									tableList[j]->BITTable = NULL;
								}
							}else if( tableList[j]->SITTable != NULL ){
								if( CheckSIT(tsPacket.PID, tableList[j]->SITTable) == TRUE ){
									tableList[j]->SITTable = NULL;
								}
							}else if( tableList[j]->EITTable_SD != NULL ){
								if( CheckEIT_SD(tsPacket.PID, tableList[j]->EITTable_SD) == TRUE ){
									tableList[j]->EITTable_SD = NULL;
								}
							}else if( tableList[j]->EITTable_SD2 != NULL ){
								if( CheckEIT_SD2(tsPacket.PID, tableList[j]->EITTable_SD2) == TRUE ){
									tableList[j]->EITTable_SD2 = NULL;
								}
							}
							SAFE_DELETE(tableList[j]);
						}
					}else{
						if( section[0] == 0 ){
							_OutputDebugString(L"★pid 0x%04X\r\n", tsPacket.PID);
						}
					}
				}
			}
		}
	}
}