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; }
static int UpdateInput( ffmpeg_video* p ) { if (p->Context) avcodec_close(p->Context); av_free(p->Context); av_free(p->Picture); p->Context = NULL; p->Picture = NULL; BufferClear(&p->Buffer); if (p->Codec.In.Format.Type == PACKET_VIDEO) { AVCodec *Codec; const codecinfo *i; for (i=Info;i->Id;++i) if (i->Id == p->Codec.Node.Class) break; if (!i->Id) return ERR_INVALID_DATA; Codec = avcodec_find_decoder(i->CodecId); if (!Codec) return ERR_INVALID_DATA; p->Context = avcodec_alloc_context(); p->Picture = avcodec_alloc_frame(); if (!p->Context || !p->Picture) return ERR_OUT_OF_MEMORY; if ((p->Codec.In.Format.Format.Video.Pixel.Flags & PF_FRAGMENTED) && (Codec->capabilities & CODEC_CAP_TRUNCATED)) p->Context->flags|= CODEC_FLAG_TRUNCATED; UpdateSettings(p); p->Context->palctrl = NULL; p->Context->bit_rate = 0; p->Context->extradata = p->Codec.In.Format.Extra; p->Context->extradata_size = p->Codec.In.Format.ExtraLength; p->Context->width = p->Codec.In.Format.Format.Video.Width; p->Context->height = p->Codec.In.Format.Format.Video.Height; p->Context->bits_per_coded_sample = p->Codec.In.Format.Format.Video.Pixel.BitCount; if (p->Codec.In.Format.Format.Video.Pixel.Palette && p->Codec.In.Format.Format.Video.Pixel.BitCount<=8) { int i,n = 1 << p->Codec.In.Format.Format.Video.Pixel.BitCount; for (i=0;i<n;++i) p->Palette.palette[i] = INT32LE(p->Codec.In.Format.Format.Video.Pixel.Palette[i].v); p->Palette.palette_changed = 1; p->Context->palctrl = &p->Palette; } p->CodecId = i->CodecId; if (avcodec_open(p->Context,Codec)<0) { // avoid calling avcodec_close at next UpdateInput av_free(p->Context); p->Context = NULL; return ERR_INVALID_DATA; } if (!BuildOutputFormat(p)) return ERR_INVALID_DATA; p->SkipToKey = 1; p->DropToKey = 1; p->Dropping = 0; } return ERR_NONE; }
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; }