1
// MediaInfoDLL - All info about media files, for DLL
2 // Copyright (C) 2002-2009 Jerome Martinez, Zen@MediaArea.net
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // MediaInfoDLL - All info about media files, for DLL
15 // Copyright (C) 2002-2009 Jerome Martinez, Zen@MediaArea.net
16 // Copyright (C) 2014 marukochan, lunarshaddow
18 // This library is free software; you can redistribute it and/or
19 // modify it under the terms of the GNU Lesser General Public
20 // License as published by the Free Software Foundation; either
21 // version 2.1 of the License, or (at your option) any later version.
23 // This library is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public
29 // License along with this library; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 // Microsoft Visual C# wrapper for MediaInfo Library
36 // See MediaInfo.h for help
38 // To make it working, you must put MediaInfo.Dll
39 // in the executable folder
41 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
44 using System
.Runtime
.InteropServices
;
46 namespace MediaInfoLib
48 public enum StreamKind
70 public enum InfoOptions
78 public enum InfoFileOptions
80 FileOption_Nothing
= 0x00,
81 FileOption_NoRecursive
= 0x01,
82 FileOption_CloseAll
= 0x02,
87 public class MediaInfo
89 //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
90 [DllImport("MediaInfo.dll")]
91 private static extern IntPtr
MediaInfo_New();
92 [DllImport("MediaInfo.dll")]
93 private static extern void MediaInfo_Delete(IntPtr Handle
);
94 [DllImport("MediaInfo.dll")]
95 private static extern IntPtr
MediaInfo_Open(IntPtr Handle
, [MarshalAs(UnmanagedType
.LPWStr
)] string FileName
);
96 [DllImport("MediaInfo.dll")]
97 private static extern IntPtr
MediaInfoA_Open(IntPtr Handle
, IntPtr FileName
);
98 [DllImport("MediaInfo.dll")]
99 private static extern IntPtr
MediaInfo_Open_Buffer_Init(IntPtr Handle
, Int64 File_Size
, Int64 File_Offset
);
100 [DllImport("MediaInfo.dll")]
101 private static extern IntPtr
MediaInfoA_Open(IntPtr Handle
, Int64 File_Size
, Int64 File_Offset
);
102 [DllImport("MediaInfo.dll")]
103 private static extern IntPtr
MediaInfo_Open_Buffer_Continue(IntPtr Handle
, IntPtr Buffer
, IntPtr Buffer_Size
);
104 [DllImport("MediaInfo.dll")]
105 private static extern IntPtr
MediaInfoA_Open_Buffer_Continue(IntPtr Handle
, Int64 File_Size
, byte[] Buffer
, IntPtr Buffer_Size
);
106 [DllImport("MediaInfo.dll")]
107 private static extern Int64
MediaInfo_Open_Buffer_Continue_GoTo_Get(IntPtr Handle
);
108 [DllImport("MediaInfo.dll")]
109 private static extern Int64
MediaInfoA_Open_Buffer_Continue_GoTo_Get(IntPtr Handle
);
110 [DllImport("MediaInfo.dll")]
111 private static extern IntPtr
MediaInfo_Open_Buffer_Finalize(IntPtr Handle
);
112 [DllImport("MediaInfo.dll")]
113 private static extern IntPtr
MediaInfoA_Open_Buffer_Finalize(IntPtr Handle
);
114 [DllImport("MediaInfo.dll")]
115 private static extern void MediaInfo_Close(IntPtr Handle
);
116 [DllImport("MediaInfo.dll")]
117 private static extern IntPtr
MediaInfo_Inform(IntPtr Handle
, IntPtr Reserved
);
118 [DllImport("MediaInfo.dll")]
119 private static extern IntPtr
MediaInfoA_Inform(IntPtr Handle
, IntPtr Reserved
);
120 [DllImport("MediaInfo.dll")]
121 private static extern IntPtr
MediaInfo_GetI(IntPtr Handle
, IntPtr StreamKind
, IntPtr StreamNumber
, IntPtr Parameter
, IntPtr KindOfInfo
);
122 [DllImport("MediaInfo.dll")]
123 private static extern IntPtr
MediaInfoA_GetI(IntPtr Handle
, IntPtr StreamKind
, IntPtr StreamNumber
, IntPtr Parameter
, IntPtr KindOfInfo
);
124 [DllImport("MediaInfo.dll")]
125 private static extern IntPtr
MediaInfo_Get(IntPtr Handle
, IntPtr StreamKind
, IntPtr StreamNumber
, [MarshalAs(UnmanagedType
.LPWStr
)] string Parameter
, IntPtr KindOfInfo
, IntPtr KindOfSearch
);
126 [DllImport("MediaInfo.dll")]
127 private static extern IntPtr
MediaInfoA_Get(IntPtr Handle
, IntPtr StreamKind
, IntPtr StreamNumber
, IntPtr Parameter
, IntPtr KindOfInfo
, IntPtr KindOfSearch
);
128 [DllImport("MediaInfo.dll")]
129 private static extern IntPtr
MediaInfo_Option(IntPtr Handle
, [MarshalAs(UnmanagedType
.LPWStr
)] string Option
, [MarshalAs(UnmanagedType
.LPWStr
)] string Value
);
130 [DllImport("MediaInfo.dll")]
131 private static extern IntPtr
MediaInfoA_Option(IntPtr Handle
, IntPtr Option
, IntPtr Value
);
132 [DllImport("MediaInfo.dll")]
133 private static extern IntPtr
MediaInfo_State_Get(IntPtr Handle
);
134 [DllImport("MediaInfo.dll")]
135 private static extern IntPtr
MediaInfo_Count_Get(IntPtr Handle
, IntPtr StreamKind
, IntPtr StreamNumber
);
140 Handle
= MediaInfo_New();
141 if (Environment
.OSVersion
.ToString().IndexOf("Windows") == -1)
146 ~
MediaInfo() { MediaInfo_Delete(Handle); }
147 public int Open(String FileName
)
151 IntPtr FileName_Ptr
= Marshal
.StringToHGlobalAnsi(FileName
);
152 int ToReturn
= (int)MediaInfoA_Open(Handle
, FileName_Ptr
);
153 Marshal
.FreeHGlobal(FileName_Ptr
);
157 return (int)MediaInfo_Open(Handle
, FileName
);
159 public int Open_Buffer_Init(Int64 File_Size
, Int64 File_Offset
)
161 return (int)MediaInfo_Open_Buffer_Init(Handle
, File_Size
, File_Offset
);
163 public int Open_Buffer_Continue(IntPtr Buffer
, IntPtr Buffer_Size
)
165 return (int)MediaInfo_Open_Buffer_Continue(Handle
, Buffer
, Buffer_Size
);
167 public Int64
Open_Buffer_Continue_GoTo_Get()
169 return (int)MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle
);
171 public int Open_Buffer_Finalize()
173 return (int)MediaInfo_Open_Buffer_Finalize(Handle
);
175 public void Close() { MediaInfo_Close(Handle); }
176 public String
Inform()
179 return Marshal
.PtrToStringAnsi(MediaInfoA_Inform(Handle
, (IntPtr
)0));
181 return Marshal
.PtrToStringUni(MediaInfo_Inform(Handle
, (IntPtr
)0));
183 public String
Get(StreamKind StreamKind
, int StreamNumber
, String Parameter
, InfoKind KindOfInfo
, InfoKind KindOfSearch
)
187 IntPtr Parameter_Ptr
= Marshal
.StringToHGlobalAnsi(Parameter
);
188 String ToReturn
= Marshal
.PtrToStringAnsi(MediaInfoA_Get(Handle
, (IntPtr
)StreamKind
, (IntPtr
)StreamNumber
, Parameter_Ptr
, (IntPtr
)KindOfInfo
, (IntPtr
)KindOfSearch
));
189 Marshal
.FreeHGlobal(Parameter_Ptr
);
193 return Marshal
.PtrToStringUni(MediaInfo_Get(Handle
, (IntPtr
)StreamKind
, (IntPtr
)StreamNumber
, Parameter
, (IntPtr
)KindOfInfo
, (IntPtr
)KindOfSearch
));
195 public String
Get(StreamKind StreamKind
, int StreamNumber
, int Parameter
, InfoKind KindOfInfo
)
198 return Marshal
.PtrToStringAnsi(MediaInfoA_GetI(Handle
, (IntPtr
)StreamKind
, (IntPtr
)StreamNumber
, (IntPtr
)Parameter
, (IntPtr
)KindOfInfo
));
200 return Marshal
.PtrToStringUni(MediaInfo_GetI(Handle
, (IntPtr
)StreamKind
, (IntPtr
)StreamNumber
, (IntPtr
)Parameter
, (IntPtr
)KindOfInfo
));
202 public String
Option(String Option
, String Value
)
206 IntPtr Option_Ptr
= Marshal
.StringToHGlobalAnsi(Option
);
207 IntPtr Value_Ptr
= Marshal
.StringToHGlobalAnsi(Value
);
208 String ToReturn
= Marshal
.PtrToStringAnsi(MediaInfoA_Option(Handle
, Option_Ptr
, Value_Ptr
));
209 Marshal
.FreeHGlobal(Option_Ptr
);
210 Marshal
.FreeHGlobal(Value_Ptr
);
214 return Marshal
.PtrToStringUni(MediaInfo_Option(Handle
, Option
, Value
));
216 public int State_Get() { return (int)MediaInfo_State_Get(Handle); }
217 public int Count_Get(StreamKind StreamKind
, int StreamNumber
) { return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
218 private IntPtr Handle
;
219 private bool MustUseAnsi
;
221 //Default values, if you know how to set default values in C#, say me
222 public String
Get(StreamKind StreamKind
, int StreamNumber
, String Parameter
, InfoKind KindOfInfo
) { return Get(StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); }
223 public String
Get(StreamKind StreamKind
, int StreamNumber
, String Parameter
) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); }
224 public String
Get(StreamKind StreamKind
, int StreamNumber
, int Parameter
) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text); }
225 public String
Option(String Option_
) { return Option(Option_, ""); }
226 public int Count_Get(StreamKind StreamKind
) { return Count_Get(StreamKind, -1); }
230 public class MediaInfoList
232 //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
233 [DllImport("MediaInfo.dll")]
234 private static extern IntPtr
MediaInfoList_New();
235 [DllImport("MediaInfo.dll")]
236 private static extern void MediaInfoList_Delete(IntPtr Handle
);
237 [DllImport("MediaInfo.dll")]
238 private static extern IntPtr
MediaInfoList_Open(IntPtr Handle
, [MarshalAs(UnmanagedType
.LPWStr
)] string FileName
, IntPtr Options
);
239 [DllImport("MediaInfo.dll")]
240 private static extern void MediaInfoList_Close(IntPtr Handle
, IntPtr FilePos
);
241 [DllImport("MediaInfo.dll")]
242 private static extern IntPtr
MediaInfoList_Inform(IntPtr Handle
, IntPtr FilePos
, IntPtr Reserved
);
243 [DllImport("MediaInfo.dll")]
244 private static extern IntPtr
MediaInfoList_GetI(IntPtr Handle
, IntPtr FilePos
, IntPtr StreamKind
, IntPtr StreamNumber
, IntPtr Parameter
, IntPtr KindOfInfo
);
245 [DllImport("MediaInfo.dll")]
246 private static extern IntPtr
MediaInfoList_Get(IntPtr Handle
, IntPtr FilePos
, IntPtr StreamKind
, IntPtr StreamNumber
, [MarshalAs(UnmanagedType
.LPWStr
)] string Parameter
, IntPtr KindOfInfo
, IntPtr KindOfSearch
);
247 [DllImport("MediaInfo.dll")]
248 private static extern IntPtr
MediaInfoList_Option(IntPtr Handle
, [MarshalAs(UnmanagedType
.LPWStr
)] string Option
, [MarshalAs(UnmanagedType
.LPWStr
)] string Value
);
249 [DllImport("MediaInfo.dll")]
250 private static extern IntPtr
MediaInfoList_State_Get(IntPtr Handle
);
251 [DllImport("MediaInfo.dll")]
252 private static extern IntPtr
MediaInfoList_Count_Get(IntPtr Handle
, IntPtr FilePos
, IntPtr StreamKind
, IntPtr StreamNumber
);
255 public MediaInfoList() { Handle = MediaInfoList_New(); }
256 ~
MediaInfoList() { MediaInfoList_Delete(Handle); }
257 public int Open(String FileName
, InfoFileOptions Options
) { return (int)MediaInfoList_Open(Handle, FileName, (IntPtr)Options); }
258 public void Close(int FilePos
) { MediaInfoList_Close(Handle, (IntPtr)FilePos); }
259 public String
Inform(int FilePos
) { return Marshal.PtrToStringUni(MediaInfoList_Inform(Handle, (IntPtr)FilePos, (IntPtr)0)); }
260 public String
Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
, String Parameter
, InfoKind KindOfInfo
, InfoKind KindOfSearch
) { return Marshal.PtrToStringUni(MediaInfoList_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)); }
261 public String
Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
, int Parameter
, InfoKind KindOfInfo
) { return Marshal.PtrToStringUni(MediaInfoList_GetI(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)); }
262 public String
Option(String Option
, String Value
) { return Marshal.PtrToStringUni(MediaInfoList_Option(Handle, Option, Value)); }
263 public int State_Get() { return (int)MediaInfoList_State_Get(Handle); }
264 public int Count_Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
) { return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
265 private IntPtr Handle
;
267 //Default values, if you know how to set default values in C#, say me
268 public void Open(String FileName
) { Open(FileName, 0); }
269 public void Close() { Close(-1); }
270 public String
Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
, String Parameter
, InfoKind KindOfInfo
) { return Get(FilePos, StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); }
271 public String
Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
, String Parameter
) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); }
272 public String
Get(int FilePos
, StreamKind StreamKind
, int StreamNumber
, int Parameter
) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text); }
273 public String
Option(String Option_
) { return Option(Option_, ""); }
274 public int Count_Get(int FilePos
, StreamKind StreamKind
) { return Count_Get(FilePos, StreamKind, -1); }