private void VX2ThreadMain(Object Args) { AudioBuffer = new BufferedWaveProvider(new WaveFormat((int)32768, 16, 1)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 1024 * 512; Player = new WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); FileStream fs = File.OpenRead((String)Args); Invoke((Action) delegate { ClientSize = new Size(256, 192); }); double fps = 25; TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(fps)); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(256, 192, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.Moflex3DS); int frame = 0; while (!StopThread) { if (fs.Position >= fs.Length) { fs.Close(); Application.Exit(); break; } if ((frame % 20) == 0)//Audio { byte[] adata = new byte[32768 * 2]; fs.Read(adata, 0, 32768 * 2); AudioBuffer.AddSamples(adata, 0, adata.Length); } int length = (fs.ReadByte() << 0) | (fs.ReadByte() << 8) | (fs.ReadByte() << 16) | (fs.ReadByte() << 24); byte[] data = new byte[length]; fs.Read(data, 0, length); frame++; d.Data = data; d.Offset = 0; Bitmap b = d.DecodeFrame(); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) { ; } } lastval = s.Value; try { pictureBox1.BeginInvoke((Action) delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } fs.Close(); }
private void MOC5ThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); int offs = (int)IOUtil.ReadU32LE(data, 0x4) + 8;//(int)IOUtil.ReadU32LE(data, 0xD8); uint width = IOUtil.ReadU32LE(data, 0x1C); uint height = IOUtil.ReadU32LE(data, 0x20); Invoke((Action) delegate { ClientSize = new Size((int)width, (int)height); }); double fps = IOUtil.ReadU32LE(data, 0xC) / 128d; TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(fps)); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(width, height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.Moflex3DS); d.Data = data; while (!StopThread) { if (offs >= data.Length) { Application.Exit(); break; } uint blocksize = IOUtil.ReadU32LE(data, offs); d.Offset = offs + 8; Bitmap b = d.DecodeFrame(); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) { ; } } lastval = s.Value; try { pictureBox1.BeginInvoke((Action) delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } offs += 4 + (int)(blocksize & ~1); while ((offs % 4) != 0) { offs++; } } }
private void VxThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); MemoryStream m = new MemoryStream(data); VxDemuxer dm = new VxDemuxer(m); Invoke((Action) delegate { ClientSize = new Size((int)dm.Header.Width, (int)dm.Header.Height); }); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(dm.Header.Width, dm.Header.Height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.VxDS); TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(dm.Header.Fps / (double)0x01000000)); while (!StopThread) { uint NrAudioPackets; byte[] framedata = new byte[dm.Header.BiggestFrame];//dm.ReadFrame(out NrAudioPackets); m.Read(framedata, 0, (int)dm.Header.BiggestFrame); d.Data = framedata; d.Offset = 0; Bitmap b = d.DecodeFrame(); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) { ; } } lastval = s.Value; try { pictureBox1.BeginInvoke((Action) delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } }
void d_OnCompleteFrameReceived(MoLiveChunk Chunk, byte[] Data) { if ((Chunk is MoLiveStreamVideo || Chunk is MoLiveStreamVideoWithLayout) && ((PlayingVideoStream == -1) || ((MoLiveStream)Chunk).StreamIndex == PlayingVideoStream)) { if (!sizeset) { Invoke((Action) delegate { ClientSize = new Size((int)((MoLiveStreamVideo)Chunk).Width, (int)((MoLiveStreamVideo)Chunk).Height); }); } sizeset = true; left = !left; if (ddd == null) { ddd = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(((MoLiveStreamVideo)Chunk).Width, ((MoLiveStreamVideo)Chunk).Height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.Moflex3DS); PlayingVideoStream = ((MoLiveStream)Chunk).StreamIndex; if (!(Chunk is MoLiveStreamVideoWithLayout)) { Is3D = false; } else if (((MoLiveStreamVideoWithLayout)Chunk).ImageLayout == MoLiveStreamVideoWithLayout.VideoLayout.Simple2D) { Is3D = false; } else { Is3D = true; } } ddd.Data = Data; ddd.Offset = 0; Bitmap b = ddd.DecodeFrame(); if (!Is3D || left) { TimeSpan ts = TimeSpan.FromMilliseconds((!Is3D ? 1000d : 2000d) / ((double)((MoLiveStreamVideo)Chunk).FpsRate / (double)((MoLiveStreamVideo)Chunk).FpsScale)); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) { ; //milliseconds) ; } } lastval = s.Value; try { pictureBox1.BeginInvoke((Action) delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } } else if (Chunk is MoLiveStreamAudio) { if (AudioBuffer == null) { AudioBuffer = new BufferedWaveProvider(new WaveFormat((int)((MoLiveStreamAudio)Chunk).Frequency, 16, (int)((MoLiveStreamAudio)Chunk).Channel)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 1024 * 512; Player = new WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } switch ((int)((MoLiveStreamAudio)Chunk).CodecId) { case 0: //fastaudio { if (mFastAudioDecoders == null) { mFastAudioDecoders = new FastAudioDecoder[(int)((MoLiveStreamAudio)Chunk).Channel]; for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { mFastAudioDecoders[i] = new FastAudioDecoder(); } } List <short>[] channels = new List <short> [(int)((MoLiveStreamAudio)Chunk).Channel]; for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { channels[i] = new List <short>(); } int offset = 0; int size = 40; while (offset + size < Data.Length) { for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { mFastAudioDecoders[i].Data = Data; mFastAudioDecoders[i].Offset = offset; channels[i].AddRange(mFastAudioDecoders[i].Decode()); offset = mFastAudioDecoders[i].Offset; } } short[][] channelsresult = new short[(int)((MoLiveStreamAudio)Chunk).Channel][]; for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { channelsresult[i] = channels[i].ToArray(); } byte[] result = InterleaveChannels(channelsresult); AudioBuffer.AddSamples(result, 0, result.Length); } break; case 1: //IMA-ADPCM { IMAADPCMDecoder[] decoders = new IMAADPCMDecoder[(int)((MoLiveStreamAudio)Chunk).Channel]; List <short>[] channels = new List <short> [(int)((MoLiveStreamAudio)Chunk).Channel]; for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { decoders[i] = new IMAADPCMDecoder(); decoders[i].GetWaveData(Data, 4 * i, 4); channels[i] = new List <short>(); } int offset = 4 * (int)((MoLiveStreamAudio)Chunk).Channel; int size = 128 * (int)((MoLiveStreamAudio)Chunk).Channel; while (offset + size < Data.Length) { for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { channels[i].AddRange(decoders[i].GetWaveData(Data, offset, 128)); offset += 128; } } short[][] channelsresult = new short[(int)((MoLiveStreamAudio)Chunk).Channel][]; for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++) { channelsresult[i] = channels[i].ToArray(); } byte[] result = InterleaveChannels(channelsresult); AudioBuffer.AddSamples(result, 0, result.Length); } break; case 2: //PCM16 { AudioBuffer.AddSamples(Data, 0, Data.Length - (Data.Length % ((int)((MoLiveStreamAudio)Chunk).Channel * 2))); } break; } } }
private void ModsThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); ModsDemuxer dm = new ModsDemuxer(new MemoryStream(data)); if ((dm.Header.AudioCodec == 1 || dm.Header.AudioCodec == 2 || dm.Header.AudioCodec == 3) && dm.Header.NbChannel > 0 && dm.Header.Frequency > 0) { AudioBuffer = new BufferedWaveProvider(new WaveFormat((int)dm.Header.Frequency, 16, dm.Header.NbChannel)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 1024 * 512; Player = new WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } Invoke((Action) delegate { ClientSize = new Size((int)dm.Header.Width, (int)dm.Header.Height); }); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(dm.Header.Width, dm.Header.Height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.ModsDS); TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(dm.Header.Fps / (double)0x01000000)); int CurChannel = 0; List <short>[] channels = new List <short> [dm.Header.NbChannel]; IMAADPCMDecoder[] decoders = new IMAADPCMDecoder[dm.Header.NbChannel]; SxDecoder[] sxd = new SxDecoder[dm.Header.NbChannel]; FastAudioDecoder[] fad = new FastAudioDecoder[dm.Header.NbChannel]; bool[] isinit = new bool[dm.Header.NbChannel]; for (int i = 0; i < dm.Header.NbChannel; i++) { channels[i] = new List <short>(); decoders[i] = new IMAADPCMDecoder(); sxd[i] = new SxDecoder(); fad[i] = new FastAudioDecoder(); isinit[i] = false; } while (!StopThread) { uint NrAudioPackets; bool IsKeyFrame; byte[] framedata = dm.ReadFrame(out NrAudioPackets, out IsKeyFrame); if (framedata == null) { break; } d.Data = framedata; d.Offset = 0; Bitmap b = d.DecodeFrame(); if (NrAudioPackets > 0 && AudioBuffer != null) { int Offset = d.Offset - 2; if (dm.Header.TagId == 0x334E && (IOUtil.ReadU16LE(framedata, 0) & 0x8000) != 0) { Offset += 4; } if (dm.Header.AudioCodec == 3) { if (IsKeyFrame) { for (int i = 0; i < dm.Header.NbChannel; i++) { channels[i] = new List <short>(); decoders[i] = new IMAADPCMDecoder(); sxd[i] = new SxDecoder(); isinit[i] = false; } } for (int i = 0; i < NrAudioPackets; i++) { channels[CurChannel].AddRange(decoders[CurChannel].GetWaveData(framedata, Offset, 128 + (!isinit[CurChannel] ? 4 : 0))); Offset += 128 + (!isinit[CurChannel] ? 4 : 0); isinit[CurChannel] = true; CurChannel++; if (CurChannel >= dm.Header.NbChannel) { CurChannel = 0; } } } else if (dm.Header.AudioCodec == 1) { for (int i = 0; i < NrAudioPackets; i++) { if (!isinit[CurChannel]) { sxd[CurChannel].Codebook = dm.AudioCodebooks[CurChannel]; } isinit[CurChannel] = true; sxd[CurChannel].Data = framedata; sxd[CurChannel].Offset = Offset; channels[CurChannel].AddRange(sxd[CurChannel].Decode()); Offset = sxd[CurChannel].Offset; CurChannel++; if (CurChannel >= dm.Header.NbChannel) { CurChannel = 0; } } } else if (dm.Header.AudioCodec == 2) { for (int i = 0; i < NrAudioPackets; i++) { fad[CurChannel].Data = framedata; fad[CurChannel].Offset = Offset; channels[CurChannel].AddRange(fad[CurChannel].Decode()); Offset = fad[CurChannel].Offset; CurChannel++; if (CurChannel >= dm.Header.NbChannel) { CurChannel = 0; } } } int smallest = int.MaxValue; for (int i = 0; i < dm.Header.NbChannel; i++) { if (channels[i].Count < smallest) { smallest = channels[i].Count; } } if (smallest > 0) { //Gather samples short[][] samps = new short[dm.Header.NbChannel][]; for (int i = 0; i < dm.Header.NbChannel; i++) { samps[i] = new short[smallest]; channels[i].CopyTo(0, samps[i], 0, smallest); channels[i].RemoveRange(0, smallest); } byte[] result = InterleaveChannels(samps); AudioBuffer.AddSamples(result, 0, result.Length); } } if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) { ; } } lastval = s.Value; try { pictureBox1.BeginInvoke((Action) delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } }
private void VxThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); MemoryStream m = new MemoryStream(data); VxDemuxer dm = new VxDemuxer(m); Invoke((Action)delegate { ClientSize = new Size((int)dm.Header.Width, (int)dm.Header.Height); }); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(dm.Header.Width, dm.Header.Height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.VxDS); TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(dm.Header.Fps / (double)0x01000000)); while (!StopThread) { uint NrAudioPackets; byte[] framedata = new byte[dm.Header.BiggestFrame];//dm.ReadFrame(out NrAudioPackets); m.Read(framedata, 0, (int)dm.Header.BiggestFrame); d.Data = framedata; d.Offset = 0; Bitmap b = d.DecodeFrame(); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) ; } lastval = s.Value; try { pictureBox1.BeginInvoke((Action)delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } }
private void ModsThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); ModsDemuxer dm = new ModsDemuxer(new MemoryStream(data)); if ((dm.Header.AudioCodec == 1 || dm.Header.AudioCodec == 2 || dm.Header.AudioCodec == 3) && dm.Header.NbChannel > 0 && dm.Header.Frequency > 0) { AudioBuffer = new BufferedWaveProvider(new WaveFormat((int)dm.Header.Frequency, 16, dm.Header.NbChannel)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 1024 * 512; Player = new WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } Invoke((Action)delegate { ClientSize = new Size((int)dm.Header.Width, (int)dm.Header.Height); }); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(dm.Header.Width, dm.Header.Height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.ModsDS); TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(dm.Header.Fps / (double)0x01000000)); int CurChannel = 0; List<short>[] channels = new List<short>[dm.Header.NbChannel]; IMAADPCMDecoder[] decoders = new IMAADPCMDecoder[dm.Header.NbChannel]; SxDecoder[] sxd = new SxDecoder[dm.Header.NbChannel]; FastAudioDecoder[] fad = new FastAudioDecoder[dm.Header.NbChannel]; bool[] isinit = new bool[dm.Header.NbChannel]; for (int i = 0; i < dm.Header.NbChannel; i++) { channels[i] = new List<short>(); decoders[i] = new IMAADPCMDecoder(); sxd[i] = new SxDecoder(); fad[i] = new FastAudioDecoder(); isinit[i] = false; } while (!StopThread) { uint NrAudioPackets; bool IsKeyFrame; byte[] framedata = dm.ReadFrame(out NrAudioPackets, out IsKeyFrame); if (framedata == null) break; d.Data = framedata; d.Offset = 0; Bitmap b = d.DecodeFrame(); if (NrAudioPackets > 0 && AudioBuffer != null) { int Offset = d.Offset - 2; if (dm.Header.TagId == 0x334E && (IOUtil.ReadU16LE(framedata, 0) & 0x8000) != 0) Offset += 4; if (dm.Header.AudioCodec == 3) { if (IsKeyFrame) { for (int i = 0; i < dm.Header.NbChannel; i++) { channels[i] = new List<short>(); decoders[i] = new IMAADPCMDecoder(); sxd[i] = new SxDecoder(); isinit[i] = false; } } for (int i = 0; i < NrAudioPackets; i++) { channels[CurChannel].AddRange(decoders[CurChannel].GetWaveData(framedata, Offset, 128 + (!isinit[CurChannel] ? 4 : 0))); Offset += 128 + (!isinit[CurChannel] ? 4 : 0); isinit[CurChannel] = true; CurChannel++; if (CurChannel >= dm.Header.NbChannel) CurChannel = 0; } } else if (dm.Header.AudioCodec == 1) { for (int i = 0; i < NrAudioPackets; i++) { if (!isinit[CurChannel]) sxd[CurChannel].Codebook = dm.AudioCodebooks[CurChannel]; isinit[CurChannel] = true; sxd[CurChannel].Data = framedata; sxd[CurChannel].Offset = Offset; channels[CurChannel].AddRange(sxd[CurChannel].Decode()); Offset = sxd[CurChannel].Offset; CurChannel++; if (CurChannel >= dm.Header.NbChannel) CurChannel = 0; } } else if (dm.Header.AudioCodec == 2) { for (int i = 0; i < NrAudioPackets; i++) { fad[CurChannel].Data = framedata; fad[CurChannel].Offset = Offset; channels[CurChannel].AddRange(fad[CurChannel].Decode()); Offset = fad[CurChannel].Offset; CurChannel++; if (CurChannel >= dm.Header.NbChannel) CurChannel = 0; } } int smallest = int.MaxValue; for (int i = 0; i < dm.Header.NbChannel; i++) { if (channels[i].Count < smallest) smallest = channels[i].Count; } if (smallest > 0) { //Gather samples short[][] samps = new short[dm.Header.NbChannel][]; for (int i = 0; i < dm.Header.NbChannel; i++) { samps[i] = new short[smallest]; channels[i].CopyTo(0, samps[i], 0, smallest); channels[i].RemoveRange(0, smallest); } byte[] result = InterleaveChannels(samps); AudioBuffer.AddSamples(result, 0, result.Length); } } if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) ; } lastval = s.Value; try { pictureBox1.BeginInvoke((Action)delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } } }
private void MOC5ThreadMain(Object Args) { byte[] data = File.ReadAllBytes((String)Args); int offs = (int)IOUtil.ReadU32LE(data, 0x4) + 8;//(int)IOUtil.ReadU32LE(data, 0xD8); uint width = IOUtil.ReadU32LE(data, 0x1C); uint height = IOUtil.ReadU32LE(data, 0x20); Invoke((Action)delegate { ClientSize = new Size((int)width, (int)height); }); double fps = IOUtil.ReadU32LE(data, 0xC) / 128d; TimeSpan ts = TimeSpan.FromMilliseconds(1000d / (double)(fps)); LibMobiclip.Codec.Mobiclip.MobiclipDecoder d = new LibMobiclip.Codec.Mobiclip.MobiclipDecoder(width, height, LibMobiclip.Codec.Mobiclip.MobiclipDecoder.MobiclipVersion.Moflex3DS); d.Data = data; while (!StopThread) { if (offs >= data.Length) { Application.Exit(); break; } uint blocksize = IOUtil.ReadU32LE(data, offs); d.Offset = offs + 8; Bitmap b = d.DecodeFrame(); if (lastval != 0) { while ((s.Value - lastval) < (long)(ts.TotalSeconds * s.Frequency)) ; } lastval = s.Value; try { pictureBox1.BeginInvoke((Action)delegate { pictureBox1.Image = b; pictureBox1.Invalidate(); }); } catch { } offs += 4 + (int)(blocksize & ~1); while ((offs % 4) != 0) offs++; } }