Beispiel #1
0
static void ClearInput(codec* p)
{
	PacketFormatClear(&p->In.Format);
	PacketFormatClear(&p->Out.Format);
	p->Out.Process = DummyProcess;
	p->In.Process = DummyProcess;
}
Beispiel #2
0
static int Init(ape* p)
{
	format_stream* s;
	p->Format.HeaderLoaded = 1;
	p->Format.TimeStamps = 0;
	if (!Load(p))
		return ERR_NOT_SUPPORTED;
	p->Samples = 0;
	s = Format_AddStream(&p->Format,sizeof(format_stream));
	if (s)
	{
		PacketFormatClear(&s->Format);
		s->Format.Type = PACKET_AUDIO;
		s->Format.Format.Audio.Format = AUDIOFMT_PCM;
		s->Format.Format.Audio.Bits = p->Decoder->GetInfo(APE_INFO_BITS_PER_SAMPLE, 0, 0);
		s->Format.Format.Audio.SampleRate = p->Decoder->GetInfo(APE_INFO_SAMPLE_RATE, 0, 0);
		s->Format.Format.Audio.Channels = p->Decoder->GetInfo(APE_INFO_CHANNELS, 0, 0);
		PacketFormatDefault(&s->Format);
		s->Format.ByteRate = p->Decoder->GetInfo(APE_INFO_AVERAGE_BITRATE, 0, 0) * 125;
		s->Fragmented = 1;
		s->DisableDrop = 1;
		p->Format.Duration = (tick_t)(((int64_t)p->Decoder->GetInfo(APE_INFO_LENGTH_MS, 0, 0) / 1000) * TICKSPERSEC);
		Format_PrepairStream(&p->Format,s);
		p->SampleRate = s->Format.Format.Audio.SampleRate;
		p->SampleSize = p->Decoder->GetInfo(APE_INFO_BYTES_PER_SAMPLE, 0, 0) * s->Format.Format.Audio.Channels;
	}
	//p->blockSize = p->Decoder->GetInfo(APE_INFO_BLOCK_ALIGN, 0, 0);
	p->BufferLen = p->SampleSize * 1024;//p->blockSize  * 1024; /////??????
	p->Buffer = (uint8_t*)malloc(p->SampleSize*p->BufferLen);
	if (!p->Buffer)
		  return ERR_OUT_OF_MEMORY;
	return ERR_NONE;
}
Beispiel #3
0
static int UpdateInput(codecidct* p)
{
	int Result = ERR_NONE;
	
	Flush(p);

	if (!PacketFormatMatch(p->Node.Class, &p->In.Format))
		PacketFormatClear(&p->In.Format);

	memset(&p->IDCT.Format,0,sizeof(video));
	if (p->UpdateInput)
		Result = p->UpdateInput(p);

	if (Result != ERR_NONE)
		PacketFormatClear(&p->In.Format);

	if (p->In.Format.Type != PACKET_VIDEO && p->IDCT.Ptr)
		p->IDCT.Ptr->Set(p->IDCT.Ptr,IDCT_FORMAT,NULL,0);

	return Result;
}
Beispiel #4
0
int RawAudioInit(rawaudio* p)
{
	format_stream* s = Format_AddStream(&p->Format,sizeof(format_stream));
	p->Head = 0;
	if (s)
	{
		PacketFormatClear(&s->Format);
		s->Format.Type = PACKET_AUDIO;
		s->Format.Audio.Format = p->Type;
		s->PacketBurst = 1;
		s->Fragmented = 1;
		s->DisableDrop = 1;
		Format_PrepairStream(&p->Format,s);

		if (s->Comment.Node)
		{
			format_reader* Reader = p->Format.Reader;
			// id3v1
			char Buffer[ID3TAG1SIZE];
			char Head[ID3TAGQUERYSIZE];
			filepos_t Save = Reader->Input->Seek(Reader->Input,0,SEEK_CUR);
			if (Save>=0 && Reader->Input->Seek(Reader->Input,-(int)sizeof(Buffer),SEEK_END)>=0)
			{
				if (Reader->Input->Read(Reader->Input,Buffer,sizeof(Buffer)) == sizeof(Buffer))
					Id3TagParse(Buffer,sizeof(Buffer),&s->Comment);

				Reader->Input->Seek(Reader->Input,Save,SEEK_SET);
			}

			// id3v2
			if (Reader->Read(Reader,Head,sizeof(Head))==sizeof(Head))
			{
				int TagSize = Id3TagQuery(Head,sizeof(Head));
				if (TagSize > 0)
				{
					void* Buffer = malloc(TagSize);
					if (Buffer)
					{
						int Len = Reader->Read(Reader,Buffer,TagSize);
						Id3TagParse(Buffer,Len,&s->Comment);
						free(Buffer);
					}
					p->Head = TagSize;
				}
			}

			Reader->Seek(Reader,p->Head,SEEK_SET);
		}
	}

	p->SeekPos = p->Head;
	return ERR_NONE;
}
Beispiel #5
0
static int UpdateInput(nulloutput* p)
{
	p->Total = 0;
	p->Dropped = 0;
	if ((p->Format.Type == PACKET_SUBTITLE) ||
		(p->Format.Type == PACKET_VIDEO && (p->Node.Class != NULLVIDEO_ID || Compressed(&p->Format.Format.Video.Pixel))) ||
	    (p->Format.Type == PACKET_AUDIO && (p->Node.Class != NULLAUDIO_ID || p->Format.Format.Audio.Format != AUDIOFMT_PCM)))
	{
		PacketFormatClear(&p->Format);
		return ERR_INVALID_DATA;
	}
	return ERR_NONE;
}
Beispiel #6
0
static void AudioTrack(format_stream* s,TrackInfo* Info,int Format,bool_t PacketBased)
{
	PacketFormatClear(&s->Format);
	s->Format.Type = PACKET_AUDIO;
	s->Format.Format.Audio.Format = Format;
	Info->AV.Audio.Channels;
	s->Format.Format.Audio.Channels = Info->AV.Audio.Channels; //Mod2010:
	s->Format.Format.Audio.SampleRate = mkv_TruncFloat(Info->AV.Audio.SamplingFreq); //Mod2010:
	s->Format.Format.Audio.Bits = Info->AV.Audio.BitDepth; //Mod2010:
	s->Fragmented = !PacketBased;
	if (PacketBased)
		s->Format.Format.Audio.Flags |= PCM_PACKET_BASED;
	PacketFormatDefault(&s->Format);
}
Beispiel #7
0
void Format_FreeSubTitle(format_base* p,format_stream* s)
{
	format_subtitleitem* i;
	format_subtitleitem* Last=NULL;
	for (i=((format_subtitle*)s)->List;i;i=i->Next)
		if (i->Allocated)
		{
			free(Last);
			Last = i; 
		}
	free(Last);

	PacketFormatClear(&s->Format);
	free(s);
}
Beispiel #8
0
static int Init(rawimage* p)
{
	format_stream* s = Format_AddStream(&p->Format,sizeof(format_stream));
	if (s)
	{
		PacketFormatClear(&s->Format);
		s->Format.Type = PACKET_VIDEO;
		s->Format.Format.Video.Pixel.Flags = PF_FOURCC; //|PF_NOPREROTATE;
		s->Format.Format.Video.Pixel.FourCC = p->FourCC;
		s->PacketBurst = 1;
		s->DisableDrop = 1;
		Format_PrepairStream(&p->Format,s);
	}
	p->Total = 0;
	p->Format.HeaderLoaded = 1;
	p->Format.TimeStamps = 0;
	return ERR_NONE;
}
Beispiel #9
0
static bool_t SpeexHeader(ogg* p, oggstream* s, const char* Data, int Length )
{
	if (Length<80 && strncmp(Data,"Speex   ",8)!=0)
		return 0;

	PacketFormatClear(&s->Stream.Format);
	s->Stream.Format.Type = PACKET_AUDIO;
	s->Stream.Format.Format.Audio.Format = AUDIOFMT_SPEEX;
	s->Stream.Format.Format.Audio.Channels = INT32LE(*(int32_t*)(Data+48));
	s->Stream.Format.ByteRate = INT32LE(*(int32_t*)(Data+52))/8;
	s->Stream.Format.Format.Audio.SampleRate = INT32LE(*(int32_t*)(Data+36));

	s->MediaRateDen = TICKSPERSEC;
	s->MediaRateNum = s->Stream.Format.Format.Audio.SampleRate;
	s->Native = 1;

	if (PacketFormatExtra(&s->Stream.Format,Length))
		memcpy(s->Stream.Format.Extra,Data,s->Stream.Format.ExtraLength);

	return 1;
}
Beispiel #10
0
static int UpdateInput( audio_template* p )
{
	free(p->Buffer);
	p->Buffer = NULL;

	if (p->Codec.In.Format.Type == PACKET_AUDIO)
	{
		PacketFormatClear(&p->Codec.Out.Format);
		p->Codec.Out.Format.Type = PACKET_AUDIO;
		p->Codec.Out.Format.Format.Audio.Format = AUDIOFMT_PCM;
		p->Codec.Out.Format.Format.Audio.Bits = 16;
		p->Codec.Out.Format.Format.Audio.FracBits = 15;
		p->Codec.Out.Format.Format.Audio.Channels = 2;
		p->Codec.Out.Format.Format.Audio.SampleRate = 44100;

		p->Buffer = (int16_t*) malloc(BUFFERSIZE*2*sizeof(int16_t));
		if (!p->Buffer)
			return ERR_OUT_OF_MEMORY;
	}

	return ERR_NONE;
}
Beispiel #11
0
static int Init(asap* p)
{
	format_stream* s;

	p->Format.HeaderLoaded = 1;
	p->Format.TimeStamps = 0;
	p->Format.Duration = 60*5*TICKSPERSEC;
	p->Total = Scale(p->Format.Duration,SAMPLE_RATE,TICKSPERSEC);

	ASAP_Initialize(SAMPLE_RATE, AUDIO_FORMAT_S16_NE, 3);

	if (!Load(p))
		return ERR_NOT_SUPPORTED;

	p->Buffer = malloc(BUFFER_SIZE);
	if (!p->Buffer)
		return ERR_OUT_OF_MEMORY;

	s = Format_AddStream(&p->Format,sizeof(format_stream));
	if (!s)
		return ERR_OUT_OF_MEMORY;

	PacketFormatClear(&s->Format);
	s->Format.Type = PACKET_AUDIO;
	s->Format.Format.Audio.Format = AUDIOFMT_PCM;
	s->Format.Format.Audio.Bits = 16;
	s->Format.Format.Audio.SampleRate = SAMPLE_RATE;
	s->Format.Format.Audio.Channels = ASAP_GetChannels();
	PacketFormatDefault(&s->Format);

	s->Fragmented = 1;
	s->DisableDrop = 1;
	p->SamplePerBuffer = BUFFER_SIZE/2/s->Format.Format.Audio.Channels;

	Format_PrepairStream(&p->Format,s);
	return ERR_NONE;
}
Beispiel #12
0
static bool_t VorbisHeader(ogg* p,oggstream* s)
{
	tchar_t URL[MAXPATH];

	if (vorbis_synthesis_headerin(&s->Info,&s->Comment,&s->OggPacket)<0)
		return 0;

	PacketFormatClear(&s->Stream.Format);
	s->Stream.Format.Type = PACKET_AUDIO;
	s->Stream.Format.Format.Audio.Channels = s->Info.channels;
	s->Stream.Format.Format.Audio.SampleRate = s->Info.rate;
	s->Stream.Format.ByteRate = s->Info.bitrate_nominal >> 3;

	if (p->Format.Reader->Input->Get(p->Format.Reader->Input,STREAM_URL,URL,sizeof(URL))==ERR_NONE &&
		CheckExts(URL,T("ogg:A")) != 0)
		s->Stream.Format.Format.Audio.Format = AUDIOFMT_VORBIS_INTERNAL_AUDIO;
	else
		s->Stream.Format.Format.Audio.Format = AUDIOFMT_VORBIS_INTERNAL_VIDEO;

	s->Vorbis = 1;
	s->MediaRateDen = TICKSPERSEC;
	s->MediaRateNum = s->Info.rate;
	return 1;
}
Beispiel #13
0
static int Init(tta* p)
{
  int ret;
	format_stream* s;

	p->Format.HeaderLoaded = 1;
	p->Format.TimeStamps = 0;
	
  p->Decoder.Reader = p->Format.Reader;
  ret = open_tta_file(&p->Decoder, 0);
  if (ret != 0)
    return ERR_INVALID_DATA;

  ret = player_init(&p->Decoder);
  if (ret != 0)
    return ERR_INVALID_DATA;

	p->Samples = 0;

	s = Format_AddStream(&p->Format,sizeof(format_stream));
	if (s)
	{
		PacketFormatClear(&s->Format);
		s->Format.Type = PACKET_AUDIO;
		s->Format.Format.Audio.Format = AUDIOFMT_PCM;
		s->Format.Format.Audio.Bits = p->Decoder.BPS;
		s->Format.Format.Audio.SampleRate = p->Decoder.SAMPLERATE;
		s->Format.Format.Audio.Channels = p->Decoder.NCH;
		PacketFormatDefault(&s->Format);
		s->Format.ByteRate = (int)p->Decoder.BITRATE * 125;

		s->PacketBurst = 1;
		s->Fragmented = 1;
		s->DisableDrop = 1;
		p->Format.Duration = (tick_t)(((int64_t)p->Decoder.DATALENGTH * TICKSPERSEC) / s->Format.Format.Audio.SampleRate);

		Format_PrepairStream(&p->Format,s);

		if (p->Format.Comment.Node)
		{
      // id3v1
      format_reader* Reader = p->Format.Reader;
      char Buffer[ID3V1_SIZE];
      filepos_t Save = Reader->Input->Seek(Reader->Input,0,SEEK_CUR);
      if (Save>=0 && Reader->Input->Seek(Reader->Input,-(int)sizeof(Buffer),SEEK_END)>=0)
      {
        if (Reader->Input->Read(Reader->Input,Buffer,sizeof(Buffer)) == sizeof(Buffer))
          ID3v1_Parse(Buffer,&p->Format.Comment);

        Reader->Input->Seek(Reader->Input,Save,SEEK_SET);
      }
		}

    p->SampleRate = s->Format.Format.Audio.SampleRate;
    p->SampleSize = p->Decoder.BSIZE * s->Format.Format.Audio.Channels;
	}

  p->BufferLen = PCM_BUFFER_LENGTH;
  p->Buffer = (uint8_t*)malloc(p->SampleSize*p->BufferLen);
  if (!p->Buffer)
    return ERR_OUT_OF_MEMORY;

	return ERR_NONE;
}
Beispiel #14
0
static bool_t BuildOutputFormat(ffmpeg_video* p)
{
	int pix_fmt = p->Context->pix_fmt;
	if (pix_fmt<0)
		pix_fmt = PIX_FMT_YUV420P; // is this needed?

	PacketFormatClear(&p->Codec.Out.Format);
	p->Codec.Out.Format.Type = PACKET_VIDEO;

	switch (pix_fmt)
	{
	case PIX_FMT_YUV410P:
		p->Codec.Out.Format.Format.Video.Pixel.Flags = PF_YUV410;
		break;
	case PIX_FMT_YUV420P:
		p->Codec.Out.Format.Format.Video.Pixel.Flags = PF_YUV420;
		break;
	case PIX_FMT_BGR24:
		DefaultRGB(&p->Codec.Out.Format.Format.Video.Pixel,24,8,8,8,0,0,0);
		break;;
	case PIX_FMT_RGB32:
		DefaultRGB(&p->Codec.Out.Format.Format.Video.Pixel,32,8,8,8,0,0,0);
		break;
	case PIX_FMT_RGB555:
		DefaultRGB(&p->Codec.Out.Format.Format.Video.Pixel,16,5,5,5,0,0,0);
		break;
	case PIX_FMT_PAL8:
		p->Codec.Out.Format.Format.Video.Pixel.Flags = PF_PALETTE;
		p->Codec.Out.Format.Format.Video.Pixel.BitCount = 8;
		p->Codec.Out.Format.Format.Video.Pixel.Palette = p->Codec.In.Format.Format.Video.Pixel.Palette;
		break;
	default:
		return 0;
	}

	p->Aspect = p->Context->sample_aspect_ratio;
	p->Codec.Out.Format.Format.Video.Aspect = p->Codec.In.Format.Format.Video.Aspect;
	if (p->Context->sample_aspect_ratio.num>0 && !p->Codec.Out.Format.Format.Video.Aspect)
		p->Codec.Out.Format.Format.Video.Aspect = Scale(ASPECT_ONE,p->Context->sample_aspect_ratio.num,p->Context->sample_aspect_ratio.den);

	p->Codec.In.Format.Format.Video.Width = p->Codec.Out.Format.Format.Video.Width = p->Context->width;
	p->Codec.In.Format.Format.Video.Height = p->Codec.Out.Format.Format.Video.Height = p->Context->height;
	
	if (p->Picture->linesize[0])
		p->Codec.Out.Format.Format.Video.Pitch = p->Picture->linesize[0];
	else
		DefaultPitch(&p->Codec.Out.Format.Format.Video);

	p->PixelFormat = p->Context->pix_fmt;

	if (p->Context->bit_rate > 0 && p->Context->bit_rate < 100000000)
		p->Codec.In.Format.ByteRate = p->Context->bit_rate/8;
	if (p->Context->time_base.num > 0)
	{
		p->Codec.In.Format.PacketRate.Num = p->Context->time_base.den;
		p->Codec.In.Format.PacketRate.Den = p->Context->time_base.num;
		p->FrameTime = Scale(TICKSPERSEC,p->Codec.In.Format.PacketRate.Den,p->Codec.In.Format.PacketRate.Num);
	}
	else
		p->FrameTime = TIME_UNKNOWN;

	//ShowMessage("","%d %d %d",p->Context->pix_fmt,p->Context->width,p->Context->height);
	return 1;
}
Beispiel #15
0
static int UpdateInput(waveout_base* p)
{
	if (p->Done)
		p->Done(p);

	p->Total = 0;
	p->Dropped = 0;

	if (p->Input.Type == PACKET_AUDIO)
	{
		int Result;
		int Try;

		if (p->Input.Audio.Format != AUDIOFMT_PCM) 
		{
			PacketFormatClear(&p->Input);
			return ERR_INVALID_DATA;
		}

		if (p->Input.Audio.Channels == 0)
			return ERR_NONE;

		AlignRate(&p->Input.Audio.SampleRate,8000);
		AlignRate(&p->Input.Audio.SampleRate,11025);
		AlignRate(&p->Input.Audio.SampleRate,16000);
		AlignRate(&p->Input.Audio.SampleRate,22050);
		AlignRate(&p->Input.Audio.SampleRate,44100);

		PacketFormatClear(&p->Output);
		p->Output.Type = PACKET_AUDIO;
		p->Output.Audio = p->Input.Audio;
		p->Output.Audio.Flags = 0;
		p->Dither = 0;

		if (p->Stereo==1)
			p->Output.Audio.Flags |= PCM_SWAPEDSTEREO;
		else
		if (p->Stereo>1)
		{
			p->Output.Audio.Channels = 1;
			if (p->Stereo==3)
				p->Output.Audio.Flags |= PCM_ONLY_LEFT;
			if (p->Stereo==4)
				p->Output.Audio.Flags |= PCM_ONLY_RIGHT;
		}

		switch (p->Quality)
		{
		case 0: // low quality for very poor devices
			p->Output.Audio.Bits = 8;
			p->Output.Audio.FracBits = 7;
			p->Output.Audio.Channels = 1;
			p->Output.Audio.SampleRate = 22050;
			break;

		case 1: // no dither and only standard samplerate
			if (p->Output.Audio.Bits > 8)
			{
				p->Output.Audio.Bits = 16;
				p->Output.Audio.FracBits = 15;
			}
			else
			{
				p->Output.Audio.Bits = 8;
				p->Output.Audio.FracBits = 7;
			}
			if (p->Output.Audio.SampleRate >= 44100)
				p->Output.Audio.SampleRate = 44100;
			else
				p->Output.Audio.SampleRate = 22050;
			break;

		default:
		case 2: // original samplerate 
			if (p->Output.Audio.Bits > 8)
			{
				p->Output.Audio.Bits = 16;
				p->Output.Audio.FracBits = 15;
			}
			else
			{
				p->Output.Audio.Bits = 8;
				p->Output.Audio.FracBits = 7;
			}
			p->Dither = 1;
			break;
		}

		for (Try=0;Try<5;++Try)
		{
			if (p->Output.Audio.Bits <= 8)
				p->Output.Audio.Flags |= PCM_UNSIGNED;

			Result = p->Init(p);
			if (Result == ERR_NONE)
				break;

			if (p->Done)
				p->Done(p);

			if (Try==0)
			{
				if (p->Output.Audio.SampleRate > 36000)
					p->Output.Audio.SampleRate = 44100;
				else
					++Try;
			}
			if (Try==1)
			{
				if (p->Output.Audio.SampleRate != 22050)
					p->Output.Audio.SampleRate = 22050;
				else
					++Try;
			}
			if (Try==2)
			{
				if (p->Output.Audio.Channels > 1)
					p->Output.Audio.Channels = 1;
				else
					++Try;
			}
			if (Try==3)
			{
				if (p->Output.Audio.Bits != 8)
				{
					p->Output.Audio.Bits = 8;
					p->Output.Audio.FracBits = 7;
				}
				else
					++Try;
			}
		}

		if (Try==5)
		{
			PacketFormatClear(&p->Input);
			if (Result == ERR_DEVICE_ERROR)
				ShowError(p->Node.Class,ERR_ID,Result);
			return Result;
		}
	}
	else
	if (p->Input.Type != PACKET_NONE)
		return ERR_INVALID_DATA;

	return ERR_NONE;
}
Beispiel #16
0
static bool_t OGMHeader(ogg* p, oggstream* s, const char* Data, int Length )
{
	int i;
	if (Length<40 || (*Data & PACKET_TYPE_BITS) != PACKET_TYPE_HEADER)
		return 0;

	if (strncmp(Data+1, "Direct Show Samples embedded in Ogg", 35) == 0)
	{
		// old header

		if (INT32LE(*(int32_t*)(Data+96)) == 0x05589F80)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_VIDEO;
			s->Stream.Format.Format.Video.Width = INT32LE(*(int32_t*)(Data+176));
			s->Stream.Format.Format.Video.Height = INT32LE(*(int32_t*)(Data+180));
			s->Stream.Format.Format.Video.Pixel.FourCC = INT32LE(*(int32_t*)(Data+68));
			s->Stream.Format.Format.Video.Pixel.BitCount = INT16LE(*(int16_t*)(Data+182));

			i = INT16LE(*(int16_t*)(Data+136));	// extrasize
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+142,s->Stream.Format.ExtraLength);

			s->MediaRateDen = INT64LE(*(int32_t*)(Data+164))*TICKSPERSEC;
			s->MediaRateNum = 10000000;
			s->DefaultLen = 1;

			FrameRate(&s->Stream.Format.PacketRate,s->MediaRateNum,s->MediaRateDen/TICKSPERSEC);
			return 1;
		}

		if (INT32LE(*(int32_t*)(Data+96)) == 0x05589F81)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_AUDIO;
			s->Stream.Format.Format.Audio.Format = INT16LE(*(int16_t*)(Data+124));
			s->Stream.Format.Format.Audio.Channels = INT16LE(*(int16_t*)(Data+126));
			s->Stream.Format.Format.Audio.BlockAlign = INT16LE(*(int16_t*)(Data+136));
			s->Stream.Format.Format.Audio.Bits = INT16LE(*(int16_t*)(Data+138));
			s->Stream.Format.Format.Audio.SampleRate = INT32LE(*(int32_t*)(Data+128));
			s->Stream.Format.ByteRate = INT32LE(*(int32_t*)(p+132));

			i = INT16LE(*(int16_t*)(Data+136));	// extrasize
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+142,s->Stream.Format.ExtraLength);

			s->MediaRateDen = TICKSPERSEC;
			s->MediaRateNum = INT32LE(*(int32_t*)(Data+128));
			s->DefaultLen = 1;
			return 1;
		}
	}
	else
	if (Length >= sizeof(ogm_header)+1)
	{
		ogm_header Head;
		memcpy(&Head,Data+1,sizeof(Head));

		// new header
		if (strncmp(Head.streamtype, MT_Video, strlen(MT_Video)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_VIDEO;
			s->Stream.Format.Format.Video.Width = INT32LE(Head.format.video.width);
			s->Stream.Format.Format.Video.Height = INT32LE(Head.format.video.height);
			s->Stream.Format.Format.Video.Pixel.FourCC = INT32LE(*(int32_t*)Head.subtype);
			s->Stream.Format.Format.Video.Pixel.BitCount = INT16LE(Head.bits_per_sample);

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			FrameRate(&s->Stream.Format.PacketRate,s->MediaRateNum,s->MediaRateDen/TICKSPERSEC);
			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}
		
		if (strncmp(Head.streamtype, MT_Audio, strlen(MT_Audio)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_AUDIO;
			s->Stream.Format.Format.Audio.Format = 0;
			for (i=0;i<4;++i)
				if (Head.subtype[i])
					s->Stream.Format.Format.Audio.Format = s->Stream.Format.Format.Audio.Format*16+Hex(Head.subtype[i]);
			s->Stream.Format.Format.Audio.Channels = INT16LE(Head.format.audio.channels);
			s->Stream.Format.Format.Audio.Bits = INT16LE(Head.bits_per_sample);
			s->Stream.Format.Format.Audio.BlockAlign = INT16LE(Head.format.audio.blockalign);
			s->Stream.Format.ByteRate = INT32LE(Head.format.audio.avgbytespersec);
			s->Stream.Format.Format.Audio.SampleRate = (int)INT64LE(Head.samples_per_unit);

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}

		if (strncmp(Data+1, MT_Text,  strlen(MT_Text)) == 0)
		{
			PacketFormatClear(&s->Stream.Format);
			s->Stream.Format.Type = PACKET_SUBTITLE;
			s->Stream.Format.Format.Subtitle.FourCC = SUBTITLE_OEM; //???

			s->MediaRateDen = INT64LE(Head.time_unit)*TICKSPERSEC;
			s->MediaRateNum = INT64LE(Head.samples_per_unit) * 10000000;
			s->DefaultLen = INT32LE(Head.default_len);

			i = Length - (sizeof(ogm_header)+1);
			if (i && PacketFormatExtra(&s->Stream.Format,i))
				memcpy(s->Stream.Format.Extra,Data+1+sizeof(ogm_header),s->Stream.Format.ExtraLength);
			return 1;
		}
	}

	return 0;
}
Beispiel #17
0
static int ReadPacket(flv* p, format_reader* Reader, format_packet* Packet)
{
	format_stream* s;
    int		i, type, size, TimeStamp, flags, is_audio;
	int64_t next;
	bool_t	isNewStream = 0;
	filepos_t	startfilepos;
	
	startfilepos = Reader->FilePos;

	for (;;) 
	{
		Reader->Skip(Reader, 4);//prvious type size
		type = Reader->Read8(Reader);
		size = ReadBE24(Reader);
		TimeStamp = ReadBE24(Reader);
		if (Reader->Eof(Reader))
		{
			return ERR_END_OF_FILE;
		}

		// Reserved
		Reader->Skip(Reader, 4);

		flags = 0;

		if (size == 0)
			continue;

		next = size + Reader->FilePos;

		if (type == FLV_TAG_TYPE_AUDIO)
		{
			is_audio = 1;
			flags = Reader->Read8(Reader);
			size--;
			p->bHasA = 1;
		} 
		else if (type == FLV_TAG_TYPE_VIDEO)
		{
			is_audio = 0;
			flags = Reader->Read8(Reader);
			size--;
			p->bHasV = 1;
		}
		else if (type == FLV_TAG_TYPE_META && size > 13+1+4)
		{
			if(flv_read_metabody(p,Reader, next)<0)
			{
				Reader->Seek(Reader,(filepos_t)next,SEEK_SET);
			}
			continue;
		}
		else
		{
			// Skip the packet
			Reader->Skip(Reader, size);
			continue;
		}

		// Now find stream
		s = NULL;
		for (i=0;i<p->Format.StreamCount;++i)
		{
			if (p->Format.Streams[i]->Id == is_audio)
			{
				s = p->Format.Streams[i];
				break;
			}
		}

		if (!s)
		{
			s = Format_AddStream(&p->Format,sizeof(format_stream));
	        if (!s)
		        return ERR_OUT_OF_MEMORY;

			s->Id = is_audio;
			isNewStream = 1;

			s->Format.PacketRate.Den = 24;
			s->Format.PacketRate.Num = 1000;
		}

		break;
	}

    if(is_audio)
	{
		if (isNewStream)
		{
			int bInited = 0;

			PacketFormatClear(&s->Format);
			s->Format.Type = PACKET_AUDIO;
			s->Format.Format.Audio.Channels = (flags&1)+1;
			if((flags >> 4) == 5)
				s->Format.Format.Audio.SampleRate = 8000;
			else
				s->Format.Format.Audio.SampleRate = (44100<<((flags>>2)&3))>>3;

			switch(flags >> 4)
			{/* 0: uncompressed 1: ADPCM 2: mp3 5: Nellymoser 8kHz mono 6: Nellymoser */
			case FLV_CODECID_PCM:
				s->Format.Format.Audio.Format = AUDIOFMT_PCM;
				if (!(flags&2))
				{
					s->Format.Format.Audio.Bits = 8;
					s->Format.Format.Audio.FracBits = 7;
					bInited = 1;
				}
				break;
			case FLV_CODECID_ADPCM:
				s->Format.Format.Audio.Format = AUDIOFMT_ADPCM_SWF;
				break;
			case FLV_CODECID_MP3: 
				s->Format.Format.Audio.Format = AUDIOFMT_MP3;
				break;
			case FLV_CODECID_PCM_LE:
				s->Format.Format.Audio.Format = AUDIOFMT_PCM;
				if (!(flags&2))
				{
					s->Format.Format.Audio.Bits = 8;
					s->Format.Format.Audio.FracBits = 7;
					bInited = 1;
				}
				break;
			case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
				s->Format.Format.Audio.SampleRate = 8000;
			case FLV_CODECID_NELLYMOSER:
				s->Format.Format.Audio.Format = AUDIOFMT_NELLYMOSER;
				break;
			case FLV_CODECID_AAC:
				{
					format_stream* s;
					int type = Reader->Read8(Reader);
					size--;
					if(type == 0)
					{
						s = p->Format.Streams[p->Format.StreamCount-1];

						if (PacketFormatExtra(&s->Format,size))
							Reader->Read(Reader,s->Format.Extra,size);
					}
					s->Format.Format.Audio.Format = AUDIOFMT_AAC;
					Format_PrepairStream(&p->Format, s);

				}
				return ERR_NONE;
			case FLV_CODECID_SPEEX:
				s->Format.Format.Audio.Format = AUDIOFMT_SPEEX;
				s->Format.Format.Audio.SampleRate = 16000;
				break;
			default:
				return ERR_NOT_SUPPORTED;
			}
			if(!bInited)
			{
				s->Format.Format.Audio.Bits = 16;
				s->Format.Format.Audio.FracBits = 15;
			}
			s->Format.ByteRate = s->Format.Format.Audio.SampleRate * s->Format.Format.Audio.Channels * 2;
			Format_PrepairStream(&p->Format,s);
		}
    }
Beispiel #18
0
static void Delete(codecidct* p)
{
	PacketFormatClear(&p->In.Format);
	if (p->UpdateInput)
		p->UpdateInput(p);
}