📄 javacode.txt
字号:
/// <summary>
/// Non-thread-safe read a single int from the stream
/// </summary>
/// <param name="FourCC">Output int</param>
public unsafe void ReadOneInt(out int FourCC)
{
try {
int readsize = m_stream.Read(m_fourBytes, 0, DWORDSIZE);
if (DWORDSIZE != readsize) {
throw new RiffParserException("Unable to read. Corrupt RIFF file " + FileName);
}
fixed (byte* bp = &m_fourBytes[0]) {
FourCC = *((int*)bp);
}
}
catch (Exception ex)
{
throw new RiffParserException("Problem accessing RIFF file " + FileName, ex);
}
}
/// <summary>
/// Skip the specified number of bytes
/// </summary>
/// <param name="skipBytes">Number of bytes to skip</param>
public void SkipData(int skipBytes)
{
try {
m_stream.Seek(skipBytes, SeekOrigin.Current);
}
catch (Exception ex)
{
throw new RiffParserException("Problem seeking in file " + FileName, ex);
}
}
/// <summary>
/// Read the specified length into the byte array at the specified
/// offset in the array
/// </summary>
/// <param name="data">Array of bytes to read into</param>
/// <param name="offset">Offset in the array to start from</param>
/// <param name="length">Number of bytes to read</param>
/// <returns>Number of bytes actually read</returns>
public int ReadData(Byte[] data, int offset, int length)
{
try {
return m_stream.Read(data, offset, length);
}
catch (Exception ex)
{
throw new RiffParserException("Problem reading data in file " + FileName, ex);
}
}
/// <summary>
/// Close the RIFF file
/// </summary>
public void CloseFile()
{
if (null != m_stream)
{
m_stream.Close();
m_stream = null;
}
}
#endregion
#region FourCC conversion methods
public static string FromFourCC(int FourCC)
{
char[] chars = new char[4];
chars[0] = (char)(FourCC & 0xFF);
chars[1] = (char)((FourCC >> 8) & 0xFF);
chars[2] = (char)((FourCC >> 16) & 0xFF);
chars[3] = (char)((FourCC >> 24) & 0xFF);
return new string(chars);
}
public static int ToFourCC(string FourCC)
{
if (FourCC.Length != 4)
{
throw new Exception("FourCC strings must be 4 characters long " + FourCC);
}
int result = ((int)FourCC[3]) << 24
| ((int)FourCC[2]) << 16
| ((int)FourCC[1]) << 8
| ((int)FourCC[0]);
return result;
}
public static int ToFourCC(char[] FourCC)
{
if (FourCC.Length != 4)
{
throw new Exception("FourCC char arrays must be 4 characters long " + new string(FourCC));
}
int result = ((int)FourCC[3]) << 24
| ((int)FourCC[2]) << 16
| ((int)FourCC[1]) << 8
| ((int)FourCC[0]);
return result;
}
public static int ToFourCC(char c0, char c1, char c2, char c3)
{
int result = ((int)c3) << 24
| ((int)c2) << 16
| ((int)c1) << 8
| ((int)c0);
return result;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace AviReader
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AVIMAINHEADER
{ // 'avih'
public int dwMicroSecPerFrame;
public int dwMaxBytesPerSec;
public int dwPaddingGranularity;
public int dwFlags;
public int dwTotalFrames;
public int dwInitialFrames;
public int dwStreams;
public int dwSuggestedBufferSize;
public int dwWidth;
public int dwHeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public int[] dwReserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AVIEXTHEADER
{ // 'dmlh'
public int dwGrandFrames; // total number of frames in the file
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 244)]
public int[] dwFuture; // to be defined later
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct RECT
{
public short left;
public short top;
public short right;
public short bottom;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AVISTREAMHEADER
{ // 'strh'
public int fccType; // stream type codes
public int fccHandler;
public int dwFlags;
public short wPriority;
public short wLanguage;
public int dwInitialFrames;
public int dwScale;
public int dwRate; // dwRate/dwScale is stream tick rate in ticks/sec
public int dwStart;
public int dwLength;
public int dwSuggestedBufferSize;
public int dwQuality;
public int dwSampleSize;
public RECT rcFrame;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AVIOLDINDEXENTRY
{
public int dwChunkId;
public int dwFlags;
public int dwOffset; // offset of riff chunk header for the data
public int dwSize; // size of the data (excluding riff header size)
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TIMECODE
{
public short wFrameRate;
public short wFrameFract;
public int cFrames;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TIMECODEDATA
{
TIMECODE time;
public int dwSMPTEflags;
public int dwUser;
}
class AviRiffData
{
#region AVI constants
// AVIMAINHEADER flags
public static readonly int AVIF_HASINDEX = 0x00000010; // Index at end of file?
public static readonly int AVIF_MUSTUSEINDEX = 0x00000020;
public static readonly int AVIF_ISINTERLEAVED = 0x00000100;
public static readonly int AVIF_TRUSTCKTYPE = 0x00000800; // Use CKType to find key frames
public static readonly int AVIF_WASCAPTUREFILE = 0x00010000;
public static readonly int AVIF_COPYRIGHTED = 0x00020000;
// AVISTREAMINFO flags
public static readonly int AVISF_DISABLED = 0x00000001;
public static readonly int AVISF_VIDEO_PALCHANGES = 0x00010000;
// AVIOLDINDEXENTRY flags
public static readonly int AVIIF_LIST = 0x00000001;
public static readonly int AVIIF_KEYFRAME = 0x00000010;
public static readonly int AVIIF_NO_TIME = 0x00000100;
public static readonly int AVIIF_COMPRESSOR = 0x0FFF0000; // unused?
// TIMECODEDATA flags
public static readonly int TIMECODE_SMPTE_BINARY_GROUP = 0x07;
public static readonly int TIMECODE_SMPTE_COLOR_FRAME = 0x08;
// AVI stream FourCC codes
public static readonly int streamtypeVIDEO = RiffParser.ToFourCC("vids");
public static readonly int streamtypeAUDIO = RiffParser.ToFourCC("auds");
public static readonly int streamtypeMIDI = RiffParser.ToFourCC("mids");
public static readonly int streamtypeTEXT = RiffParser.ToFourCC("txts");
// AVI section FourCC codes
public static readonly int ckidMainAVIHeader = RiffParser.ToFourCC("avih");
public static readonly int ckidODML = RiffParser.ToFourCC("odml");
public static readonly int ckidAVIExtHeader = RiffParser.ToFourCC("dmlh");
public static readonly int ckidStreamList = RiffParser.ToFourCC("strl");
public static readonly int ckidAVIStreamHeader = RiffParser.ToFourCC("strh");
public static readonly int ckidStreamFormat = RiffParser.ToFourCC("strf");
public static readonly int ckidAVIOldIndex = RiffParser.ToFourCC("idx1");
#endregion
}
}
using System;
using System.Collections;
using System.Text;
/// <copyright>
/// Giora Tamir (giora@gtamir.com), 2005
/// </copyright>
namespace RiffParserDemo2
{
/// <summary>
/// Summary description for DecodeHeader.
/// </summary>
public class DecodeHeader
{
#region private members
private RiffParser m_parser;
private double m_frameRate;
private int m_maxBitRate;
private int m_totalFrames;
private int m_numStreams;
private int m_width;
private int m_height;
private string m_isft;
private double m_vidDataRate;
private string m_vidHandler;
private double m_audDataRate;
private string m_audHandler;
private int m_numChannels;
private int m_samplesPerSec;
private int m_bitsPerSec;
private int m_bitsPerSample;
#endregion
#region public members
/// <summary>
/// Access the internal parser object
/// </summary>
public RiffParser Parser
{
get
{
return m_parser;
}
}
public string FrameRate
{
get
{
double rate = 0.0;
if (m_frameRate > 0.0) rate = 1000000.0 / m_frameRate;
return String.Format("{0:N2} Frames/Sec", rate);
}
}
public string MaxBitRate
{
get
{
return String.Format("{0:N} Kb/Sec", m_maxBitRate / 128);
}
}
public string TotalFrames
{
get
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -