📄 repid.c
字号:
{
HasThePID=1;
break;
}
}
if(!HasThePID)
{
PID_Info[PortNo].PID_Map[PIDIndex].OldPrgNo = PMT_Head->Program_number;
PID_Info[PortNo].PID_Map[PIDIndex].OldPID = CA_Head->CA_PID;
PID_Info[PortNo].PID_Map[PIDIndex].StreamType = STREAM_TYPE_ECM;
PID_Info[PortNo].PID_Map[PIDIndex].SetPrgNo = PID_Info[PortNo].PID_Map[PIDIndex].NewPrgNo = PrgNo;
PID_Info[PortNo].PID_Map[PIDIndex].SetPID = PID_Info[PortNo].PID_Map[PIDIndex].NewPID = PID++;
PID_Info[PortNo].PIDs++;
PIDIndex=PID_Info[PortNo].PIDs;
}
else
{
PID_Info[PortNo].PID_Map[PIDIndex].OldPrgNo = PMT_Head->Program_number;
PID_Info[PortNo].PID_Map[PIDIndex].OldPID = CA_Head->CA_PID;
PID_Info[PortNo].PID_Map[PIDIndex].StreamType = STREAM_TYPE_ECM;
PID_Info[PortNo].PID_Map[PIDIndex].SetPrgNo = PID_Info[PortNo].PID_Map[PIDIndex].NewPrgNo = PrgNo;
PID_Info[PortNo].PID_Map[PIDIndex].SetPID = PID_Info[PortNo].PID_Map[PIDIndex].NewPID = PID_Info[PortNo].PID_Map[k].NewPID;
PID_Info[PortNo].PIDs++;
PIDIndex=PID_Info[PortNo].PIDs;
}
}
EsRest-=CA_Head->Descriptor_length + 2;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head + CA_Head->Descriptor_length + 2);
}
/************************************************************/
Rest-=(sizeof(ES_INFO_Tag) + ES_Head->ES_info_length);
ES_Head=(ES_INFO_Tag *)((unsigned char *)ES_Head + sizeof(ES_INFO_Tag) + ES_Head->ES_info_length);
}
range=PID_Info[PortNo].PIDs;
/*--------------------------------------------------------------*/
/* 从PMT的section中得到所有PCR PID并得到其新的PID */
/*--------------------------------------------------------------*/
PMT_Head=(PMT_SECTION_TAG *)PID_Info[PortNo].PMT[i].PMT_Section;
PCR_PID=PID_Info[PortNo].PID_Map[PIDIndex].OldPID=PMT_Head->PCR_PID;
/*--------------------------------------------------------------*/
/* 用户通道的PCR PID不需要重新映射 */
/*--------------------------------------------------------------*/
if(PCR_PID!=0x1FFF)
{
Found=0;
/*----------------------------------------------------------*/
/* 如果PCR的老PID和某基本流的老PID相同, */
/* 则新PID也要和其新PID相同 */
/*----------------------------------------------------------*/
for(j=PID_Info[PortNo].PMTs;j<range;j++)
{
if(PID_Info[PortNo].PID_Map[j].OldPID==PCR_PID)
{
Found=1;
break;
}
}
if(Found)
PID_Info[PortNo].PID_Map[PIDIndex].SetPID=PID_Info[PortNo].PID_Map[PIDIndex].NewPID=PID_Info[PortNo].PID_Map[j].NewPID;
else
PID_Info[PortNo].PID_Map[PIDIndex].SetPID=PID_Info[PortNo].PID_Map[PIDIndex].NewPID=PID++;
}
else
{
PID_Info[PortNo].PID_Map[PIDIndex].SetPID=PID_Info[PortNo].PID_Map[PIDIndex].NewPID=0x1FFF;
}
PID_Info[PortNo].PID_Map[PIDIndex].OldPrgNo =PMT_Head->Program_number;
PID_Info[PortNo].PID_Map[PIDIndex].SetPrgNo =PID_Info[PortNo].PID_Map[PIDIndex].NewPrgNo =PrgNo;
PID_Info[PortNo].PID_Map[PIDIndex].StreamType=STREAM_TYPE_PCR;
PID_Info[PortNo].PIDs++;
PIDIndex++;
}
}
/*为SDT添加新的描述符*/
unsigned long ConvertSDT(void)
{
int i,j,k;
unsigned short volatile SectionLength,TotalServiceLength,ServiceLength;
unsigned char volatile ServiceIndex;
unsigned short volatile DescLength,OriginDescLength;
SDT_SECTION_TAG *SDT_Section_Head;
SDT_ELEMENT_TAG *SDT_Element_Head;
SERVICE_DESCRIPTOR_TAG *Descriptor_Head, *New_Descriptor_Head;
unsigned char volatile ProviderInfoLength,DescriptorInfoLength;
short volatile Diff;
short volatile Rest;
unsigned char volatile Mdfied;
unsigned char volatile MdfIndex;
unsigned char volatile FoundSDT;
unsigned char Buf[1024];
unsigned short Offset;
unsigned char volatile HasDesc;
unsigned char volatile SDTIndex;
unsigned char volatile PortNo;
unsigned short volatile OldPrgNo;
for(i=0;i<8;i++)
SDT_Service_Info[i].ServiceCount=0;
/*--------------------------------------------------------------------*/
/* 如果某个被修改的节目没有SDT描述,就给它加一个SDT的描述 */
/*--------------------------------------------------------------------*/
for(i=0;i<New_Description.MdfCount;i++)
{
PortNo = New_Description.New_Desc[i].PortNo;
OldPrgNo = New_Description.New_Desc[i].OldPrgNo;
HasDesc=0;
for(j=0;j<SDT_Info[PortNo].SectionCount;j++)
{
/*--------------------------------------------------------------------------*/
/* 一个大BUG,应该搜索所有的描述,而不只是开头的那个 */
/* 修改:2001-11-06 */
/*--------------------------------------------------------------------------*/
SDT_Section_Head=(SDT_SECTION_TAG *)SDT_Info[PortNo].PortSections[j].Section;
Rest=SDT_Section_Head->Section_Length-(sizeof(SDT_SECTION_TAG) - 3);
SDT_Element_Head=(SDT_ELEMENT_TAG *)((unsigned char *)SDT_Section_Head + sizeof(SDT_SECTION_TAG));
while(Rest>4)
{
DescLength=SDT_Element_Head->Descriptors_loop_length;
if(SDT_Element_Head->Service_id==OldPrgNo)
{
HasDesc=1;
break;
}
else
{
SDT_Element_Head=(SDT_ELEMENT_TAG *)((unsigned char *)SDT_Element_Head + sizeof(SDT_Element_Head) + DescLength + 1);
Rest-=sizeof(SDT_Element_Head) + DescLength + 1;
}
}
}
if(HasDesc==0)
{
/*-----------------------------------------------------------*/
/* 没有SDT描述,生成一个 */
/*-----------------------------------------------------------*/
SDTIndex=SDT_Service_Info[PortNo].ServiceCount;
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Head.Service_id=OldPrgNo;
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Head.Descriptors_loop_length=1 + sizeof(SERVICE_DESCRIPTOR_TAG)- 1 + New_Description.New_Desc[i].Provider_Length + 1 + New_Description.New_Desc[i].Description_Length;
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Head.Free_CA_mode=0;
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Head.REE=0xFC;
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Head.Running_status=0x04;
New_Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)Buf;
New_Descriptor_Head->Descriptor_tag=0x48;
New_Descriptor_Head->Descriptor_length=sizeof(SERVICE_DESCRIPTOR_TAG) -2 + New_Description.New_Desc[i].Provider_Length + 1 + New_Description.New_Desc[i].Description_Length;
New_Descriptor_Head->Service_type=0x01;
New_Descriptor_Head->Service_provider_name_length=New_Description.New_Desc[i].Provider_Length;
MemCopy((unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG)),(unsigned char *)New_Description.New_Desc[i].Provider_Info,New_Description.New_Desc[i].Provider_Length);
*(unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + New_Description.New_Desc[i].Provider_Length)=New_Description.New_Desc[i].Description_Length;
MemCopy((unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + New_Description.New_Desc[i].Provider_Length + 1),(unsigned char *)New_Description.New_Desc[i].Description_Info,New_Description.New_Desc[i].Description_Length);
if(SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Desc!=NULL)
MemFree(SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Desc);
SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Desc=(unsigned char *)MemAlloc(RNG2ID,"ConvertSDT",New_Descriptor_Head->Descriptor_length + 2);
if(SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Desc == NULL)
return;
MemCopy((unsigned char *)(SDT_Service_Info[PortNo].PortService[SDTIndex].Service_Desc),(unsigned char *)New_Descriptor_Head, New_Descriptor_Head->Descriptor_length + 2);
SDT_Service_Info[PortNo].ServiceCount++;
}
}
/*--------------------------------------------------------------------*/
/* 根据SDT_Info 生成SDT_Service_Info */
/* 以便生成新的SDT */
/*--------------------------------------------------------------------*/
for(i=0;i<8;i++)
{
for(j=0;j<SDT_Info[i].SectionCount;j++)
{
SDT_Section_Head=(SDT_SECTION_TAG *)SDT_Info[i].PortSections[j].Section;
TotalServiceLength=0;
SectionLength=SDT_Section_Head->Section_Length;
SDT_Element_Head=(SDT_ELEMENT_TAG *)((unsigned char *)SDT_Section_Head + sizeof(SDT_SECTION_TAG));
while(TotalServiceLength<(SectionLength- 4 - (sizeof(SDT_SECTION_TAG) - 3)))
{
/*--------------------------------------------------------------------------*/
/* 该节目的描述是否被修改 */
/*--------------------------------------------------------------------------*/
Mdfied=0;
for(k=0;k<New_Description.MdfCount;k++)
{
if((New_Description.New_Desc[k].PortNo==i)&&(New_Description.New_Desc[k].OldPrgNo==SDT_Element_Head->Service_id))
{
/*===================================================================*/
/* 是否是对原节目描述的修改 */
/* 存在问题,如果同一个端口,相同的节目号,但不是同一个节目,就会错误*/
/* 的修改节目描述 */
/*===================================================================*/
Mdfied=1;
MdfIndex=k;
break;
}
}
ServiceIndex=SDT_Service_Info[i].ServiceCount;
OriginDescLength=DescLength=SDT_Element_Head->Descriptors_loop_length;
/*------------------------------------------------------------------------*/
/* 计算描述新的长度 */
/*------------------------------------------------------------------------*/
if(Mdfied==1)
{
Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)((unsigned char *)SDT_Element_Head + sizeof(SDT_ELEMENT_TAG));
FoundSDT=0;
Rest=SDT_Element_Head->Descriptors_loop_length;
while(Rest>0)
{
ProviderInfoLength=Descriptor_Head->Service_provider_name_length;
DescriptorInfoLength=*(unsigned char *)((unsigned char *)Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + Descriptor_Head->Service_provider_name_length);
if(Descriptor_Head->Descriptor_tag==0x48)
{
FoundSDT=1;
break;
}
/*----------------------------------------------------------------------------------*/
/* modified by johnnyling 2003-09-16 */
/*----------------------------------------------------------------------------------*/
/*
Rest-= sizeof(SERVICE_DESCRIPTOR_TAG) + ProviderInfoLength + DescriptorInfoLength +1;
Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)((unsigned char *)Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + Descriptor_Head->Service_provider_name_length + DescriptorInfoLength + 1);
*/
Rest-= (Descriptor_Head->Descriptor_length + 2);
Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)((unsigned char *)Descriptor_Head + Descriptor_Head->Descriptor_length + 2);
}
if(FoundSDT==0)
{
ProviderInfoLength=0;
DescriptorInfoLength=0;
DescLength += sizeof(SERVICE_DESCRIPTOR_TAG) + 1 + New_Description.New_Desc[MdfIndex].Provider_Length + New_Description.New_Desc[MdfIndex].Description_Length;
}
else
{
DescLength+=New_Description.New_Desc[MdfIndex].Description_Length + New_Description.New_Desc[MdfIndex].Provider_Length - ProviderInfoLength - DescriptorInfoLength;
}
}
if(SDT_Service_Info[i].PortService[ServiceIndex].Service_Desc!=NULL)
MemFree(SDT_Service_Info[i].PortService[ServiceIndex].Service_Desc);
SDT_Service_Info[i].PortService[ServiceIndex].Service_Desc=(unsigned char *)MemAlloc(RNG2ID,"NewSDT",DescLength);
if(SDT_Service_Info[i].PortService[ServiceIndex].Service_Desc!=NULL)
{
SDT_Service_Info[i].PortService[ServiceIndex].Service_Head.Service_id =SDT_Element_Head->Service_id;
SDT_Service_Info[i].PortService[ServiceIndex].Service_Head.REE =SDT_Element_Head->REE;
SDT_Service_Info[i].PortService[ServiceIndex].Service_Head.Running_status =SDT_Element_Head->Running_status;
SDT_Service_Info[i].PortService[ServiceIndex].Service_Head.Free_CA_mode =SDT_Element_Head->Free_CA_mode;
SDT_Service_Info[i].PortService[ServiceIndex].Service_Head.Descriptors_loop_length =SDT_Element_Head->Descriptors_loop_length;
/*-------------------------------------------------------------------------------------*/
/* 修改SDT的描述信息 */
/*-------------------------------------------------------------------------------------*/
if(Mdfied==1)
{
Offset=0;
Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)((unsigned char *)SDT_Element_Head + sizeof(SDT_ELEMENT_TAG));
FoundSDT=0;
Rest=SDT_Element_Head->Descriptors_loop_length;
while(Rest>0)
{
ProviderInfoLength=Descriptor_Head->Service_provider_name_length;
DescriptorInfoLength=*(unsigned char *)((unsigned char *)Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + Descriptor_Head->Service_provider_name_length);
if(Descriptor_Head->Descriptor_tag==0x48)
{
FoundSDT=1;
Diff=New_Description.New_Desc[MdfIndex].Provider_Length + New_Description.New_Desc[MdfIndex].Description_Length - ProviderInfoLength - DescriptorInfoLength;
New_Descriptor_Head=(SERVICE_DESCRIPTOR_TAG *)Buf;
New_Descriptor_Head->Descriptor_tag = 0x48;
New_Descriptor_Head->Descriptor_length = sizeof(SERVICE_DESCRIPTOR_TAG)- 2 + New_Description.New_Desc[MdfIndex].Provider_Length + 1 + New_Description.New_Desc[MdfIndex].Description_Length;
New_Descriptor_Head->Service_type = Descriptor_Head->Service_type;
New_Descriptor_Head->Service_provider_name_length = New_Description.New_Desc[MdfIndex].Provider_Length;
MemCopy((unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG)),(unsigned char *)New_Description.New_Desc[MdfIndex].Provider_Info,New_Description.New_Desc[MdfIndex].Provider_Length);
*(unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + New_Description.New_Desc[MdfIndex].Provider_Length)=New_Description.New_Desc[MdfIndex].Description_Length;
MemCopy((unsigned char *)((unsigned char *)New_Descriptor_Head + sizeof(SERVICE_DESCRIPTOR_TAG) + New_Description.New_Desc[MdfIndex].Provider_Length + 1),(unsigned char *)New_Description.New_Desc[MdfIndex].Description_Info,New_Description.New_Desc[MdfIndex].Description_Length);
MemCopy((unsigned char *)(SDT_Service_Info[i].PortService[ServiceIndex].Service_Desc + Offset),(unsigned char *)New_Descriptor_Head, New_Descriptor_Head->Descriptor_length + 2);
Offset+=New_Descriptor_Head->Descriptor_length + 2;
}
else
{
/*-------------------------------------------------------------------*/
/* 不是Service Descriptor,直接拷贝
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -