Commit 1afc67e0 authored by Carsten Schlote's avatar Carsten Schlote
Browse files

Initial version of the binding. Migrate some older work to D2.

parent eaca961d
Pipeline #135 failed with stages
in 20 seconds
.dub
docs.json
__dummy.html
mediainfo-d
mediainfo-d.so
mediainfo-d.dylib
mediainfo-d.dll
mediainfo-d.a
mediainfo-d.lib
mediainfo-d-test-*
libmediainfo-d
libmediainfo-d.so
libmediainfo-d.dylib
libmediainfo-d.dll
libmediainfo-d.a
libmediainfo-d.lib
libmediainfo-d-test-*
*.exe
*.o
*.obj
......
{
"description": "D language bindings for then libmediainfo library.",
"license": "bsd-2",
"authors": [
"Carsten Schlote"
],
"name": "mediainfo-d",
"targetType": "autodetect",
"lflags": [
"-lmediainfo"
]
}
/**
* Object oriented wrapper for $(LINK2 http://mediainfo.sourceforge.net/Support/SDK, MediaInfo)
* License:
* This wrapper $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* MediaInfo $(LINK2 http://www.gnu.org/licenses/lgpl-3.0.txt, LGPL 3.0)
* Authors: Johannes Pfau, Carsten Schlote
*/
module mediainfo;
import std.string;
import std.conv;
import std.typecons;
import mediainfodll;
//public alias MediaInfo_stream_t Stream;
//public alias MediaInfo_info_t Info;
///
public class MediaInfoException : Exception
{
public this(string msg)
{
super(msg);
}
}
///
public struct MediaInfo
{
private:
struct Payload
{
void* _payload;
this(void* h)
{
_payload = h;
}
~this()
{
if(_payload)
{
MediaInfo_Delete(_payload);
_payload = null;
}
}
// Should never perform these operations
this(this) { assert(false); }
void opAssign(MediaInfo.Payload rhs) { assert(false); }
}
alias Data = RefCounted!(Payload, RefCountedAutoInitialize.no);
Data _data;
@property void* handle()
{
return _data._payload;
}
public:
/** Use call operator to initialize resource */
static MediaInfo opCall()
{
MediaInfo info;
void* h = MediaInfo_New();
info._data._payload = h;
return info;
}
/**
* Open a file.
* Open a file and collect information about it (technical information and tags)
*
* Parameters:
* fileName = Full name of file to open
*/
void open(string fileName)
{
if(!MediaInfo_Open(handle, toStringz(fileName)))
{
throw new MediaInfoException("Couldn't open file: " ~ fileName);
}
}
/+ /**
* Open a buffer.
* Open a Buffer (Begin and end of the stream) and collect information about it (technical information and tags)
* Params:
* begin = First bytes of the buffer
* begin_size = Size of Begin
* end = Last bytes of the buffer
* end_size = Size of End
* file_size = Total size of the file
*/
void open(ubyte* begin, size_t begin_size, ubyte* end, size_t end_size)
{
if(MediaInfo_Open_Buffer(handle, begin, begin_size, end, end_size))
{
throw new MediaInfoException("Couldn't open file from buffer");
}
}
+/
/**
* Open a stream (Init).
*
* Open a stream and collect information about it (technical information and tags)
*
* Params:
* fileSize = Estimated file size
* fileOffset = Offset of the file (if we don't have the beginning of the file)
*/
size_t openBufferInit(long fileSize = -1, long fileOffset = 0)
{
return MediaInfo_Open_Buffer_Init(handle, fileSize, fileOffset);
}
/**
* Open a stream (Continue).
*
* Open a stream and collect information about it (technical information and tags)
*
* Params:
* buffer = pointer to the stream
* size =Count of bytes to read
*/
size_t openBufferContinue(ubyte* buffer, size_t size)
{
return MediaInfo_Open_Buffer_Continue(handle, buffer, size);
}
/**
* Open a stream (Get the needed file Offset).
*
* Open a stream and collect information about it (technical information and tags)
*
* Returns:
* the needed offset of the file
* File size if no more bytes are needed
*/
long openBufferContinueGoToGet()
{
return MediaInfo_Open_Buffer_Continue_GoTo_Get(handle);
}
/**
* Open a stream (Finalize).
*
* Open a stream and collect information about it (technical information and tags)
*/
size_t openBufferFinalize()
{
return MediaInfo_Open_Buffer_Finalize(handle);
}
/+ /**
* (NOT IMPLEMENTED YET) Save the file
*
* (NOT IMPLEMENTED YET) Save the file opened before with Open() (modifications of tags)
*/
void save()
{
if(MediaInfo_Save(handle))
{
throw new MediaInfoException("Couldn't save file");
}
}
+/
/**
* Close a file.
*
* Close a file opened before with Open() (without saving)
*
* Warning:
* without have saved before, modifications are lost
*/
void close()
{
MediaInfo_Close(handle);
}
/**
* String MediaInfoLib::MediaInfo::Inform ( size_t Reserved = 0 )
* Get all details about a file.
*
* Get all details about a file in one string
*
* Precondition:
* You can change default presentation with Inform_Set()
*/
string inform(size_t reserved = 0)
{
return to!string(MediaInfo_Inform(handle, reserved));
}
/**
* Get a piece of information about a file (parameter is an integer).
*
* Get a piece of information about a file (parameter is an integer)
*
* Params:
* streamKind = Kind of stream (general, video, audio...)
* streamNumber = Stream number in Kind of stream (first, second...)
* parameter = Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...)
* infoKind = Kind of information you want about the parameter (the text, the measure, the help...)
* Returns:
* a string about information you search
* an empty string if there is a problem
*/
string get(MediaInfo_stream_t streamKind, size_t streamNumber, size_t parameter,
MediaInfo_info_t infoKind = MediaInfo_info_t.MediaInfo_Info_Text)
{
return to!string(MediaInfo_GetI(handle, streamKind, streamNumber,
parameter, infoKind));
}
/**
* Get a piece of information about a file (parameter is a string).
*
* Get a piece of information about a file (parameter is a string)
*
* Params:
* streamKind = Kind of stream (general, video, audio...)
* streamNumber = Stream number in Kind of stream (first, second...)
* parameter = Parameter you are looking for in the stream (Codec, width, bitrate...), in string format ("Codec", "Width"...)
* See MediaInfo::Option("Info_Parameters") to have the full list
* infoKind = Kind of information you want about the parameter (the text, the measure, the help...)
* searchKind = Where to look for the parameter
* Returns:
* a string about information you search
* an empty string if there is a problem
*/
string get(MediaInfo_stream_t streamKind, size_t streamNumber,
const(string) parameter, MediaInfo_info_t infoKind = MediaInfo_info_t.MediaInfo_Info_Text,
MediaInfo_info_t searchKind = MediaInfo_info_t.MediaInfo_Info_Name)
{
return to!string(MediaInfo_Get(handle, streamKind, streamNumber, toStringz(parameter),
infoKind, searchKind));
}
/+ /**
* (NOT IMPLEMENTED YET) Set a piece of information about a file (parameter is an int)
*
* (NOT IMPLEMENTED YET) Set a piece of information about a file (parameter is an integer)
*
* Warning:
* Not yet implemented, do not use it
* Params:
* toSet = Piece of information
* streamKind = Kind of stream (general, video, audio...)
* streamNumber = Stream number in Kind of stream (first, second...)
* parameter = Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...)
* oldValue = The old value of the parameter
* if OldValue is empty and ToSet is filled: tag is added
* if OldValue is filled and ToSet is filled: tag is replaced
* if OldValue is filled and ToSet is empty: tag is deleted
*/
void set(const(string) toSet, Stream streamKind, size_t streamNumber,
size_t parameter, const(string) oldValue = "")
{
if(!MediaInfo_SetI(handle, toStringz(toSet), streamKind, streamNumber,
parameter, toStringz(oldValue)))
{
throw new MediaInfoException("Couldn't set parameter");
}
}
/**
* (NOT IMPLEMENTED YET) Set information about a file (parameter is a string)
*
* (NOT IMPLEMENTED YET) Set a piece of information about a file (parameter is a string)
*
* Warning:
* Not yet implemented, do not use it
* Params:
* toSet = Piece of information
* streamKind = Kind of stream (general, video, audio...)
* streamNumber = Stream number in Kind of stream (first, second...)
* parameter = Parameter you are looking for in the stream (Codec, width, bitrate...), in string format
* oldValue = The old value of the parameter
* if OldValue is empty and ToSet is filled: tag is added
* if OldValue is filled and ToSet is filled: tag is replaced
* if OldValue is filled and ToSet is empty: tag is deleted
*/
void set(const(string) toSet, Stream streamKind, size_t streamNumber,
const(string) parameter, const(string) oldValue = "")
{
if(!MediaInfo_Set(handle, toStringz(toSet), streamKind, streamNumber,
toStringz(parameter), toStringz(oldValue)))
{
throw new MediaInfoException("Couldn't set parameter");
}
}
+/
/**
* Output the written size when "File_Duplicate" option is used.
*
* Output the written size when "File_Duplicate" option is used.
*
* Params:
* Value = The unique name of the duplicated stream (begin with "memory://")
* Returns:
* The size of the used buffer
*/
size_t outputBufferGet(const(string) value)
{
return MediaInfo_Output_Buffer_Get(handle, toStringz(value));
}
/**
* Output the written size when "File_Duplicate" option is used.
*
* Output the written size when "File_Duplicate" option is used.
*
* Params:
* Value = The order of calling
* Returns:
* The size of the used buffer
*/
size_t outputBufferGet(size_t pos)
{
return MediaInfo_Output_Buffer_GetI(handle, pos);
}
/**
* Configure or get information about MediaInfoLib
*
* Params:
* Option = The name of option
* Value = The value of option
* Returns:
* Depend of the option: by default "" (nothing) means No, other means Yes
*/
string option(const(string) option, const(string) value = "")
{
return to!string(MediaInfo_Option(handle, toStringz(option), toStringz(value)));
}
/*
static string optionStatic(const(string) option, const(string) value = "")
{
return to!string(MediaInfoA_Option_Static(handle, toStringz(option), toStringz(value)));
}*/
/**
* (NOT IMPLEMENTED YET) Get the state of the library
*
* Return values:
* <1000 No information is available for the file yet
* >=1000_<5000 Only local (into the file) information is available, getting Internet information (titles only) is no finished yet
* 5000 (only if Internet connection is accepted) User interaction is needed (use Option() with "Internet_Title_Get")
* Warning: even there is only one possible, user interaction (or the software) is needed
* >5000<=10000 Only local (into the file) information is available, getting Internet information (all) is no finished yet
* <10000 Done
*/
size_t getState()
{
return MediaInfo_State_Get(handle);
}
/**
* Count of streams of a stream kind (StreamNumber not filled), or count of piece of information in this stream.
*
* Params:
* streamKind = Kind of stream (general, video, audio...)
* streamNumber = Stream number in this kind of stream (first, second...)
*/
size_t getCount(MediaInfo_stream_t streamKind, size_t streamNumber = -1)
{
return MediaInfo_Count_Get(handle, streamKind, streamNumber);
}
}
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Public DLL interface implementation
// Wrapper for MediaInfo Library
// See MediaInfo.h for help
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
extern (C):
import core.stdc.config;
//***************************************************************************
// Platforms (from libzen)
//***************************************************************************
enum __UNIX__ = 1;
enum MEDIAINFODLL_NAME = "libmediainfo.so.0";
/*-------------------------------------------------------------------------*/
/*Char types */
alias MediaInfo_Char = char;
enum MEDIAINFO_Ansi = "A";
/*-------------------------------------------------------------------------*/
/*8-bit int */
alias MediaInfo_int8u = ubyte;
/*-------------------------------------------------------------------------*/
/*64-bit int */
enum MAXTYPE_INT = 64;
alias MediaInfo_int64u = ulong;
/*-------------------------------------------------------------------------*/
/*NULL */
enum NULL = 0;
/*-------------------------------------------------------------------------*/
/** @brief Kinds of Stream */
enum MediaInfo_stream_t
{
MediaInfo_Stream_General = 0,
MediaInfo_Stream_Video = 1,
MediaInfo_Stream_Audio = 2,
MediaInfo_Stream_Text = 3,
MediaInfo_Stream_Other = 4,
MediaInfo_Stream_Image = 5,
MediaInfo_Stream_Menu = 6,
MediaInfo_Stream_Max = 7
}
alias MediaInfo_stream_C = MediaInfo_stream_t;
/** @brief Kinds of Info */
enum MediaInfo_info_t
{
MediaInfo_Info_Name = 0,
MediaInfo_Info_Text = 1,
MediaInfo_Info_Measure = 2,
MediaInfo_Info_Options = 3,
MediaInfo_Info_Name_Text = 4,
MediaInfo_Info_Measure_Text = 5,
MediaInfo_Info_Info = 6,
MediaInfo_Info_HowTo = 7,
MediaInfo_Info_Max = 8
}
alias MediaInfo_info_C = MediaInfo_info_t;
/** @brief Option if InfoKind = Info_Options */
enum MediaInfo_infooptions_t
{
MediaInfo_InfoOption_ShowInInform = 0,
MediaInfo_InfoOption_Reserved = 1,
MediaInfo_InfoOption_ShowInSupported = 2,
MediaInfo_InfoOption_TypeOfValue = 3,
MediaInfo_InfoOption_Max = 4
}
alias MediaInfo_infooptions_C = MediaInfo_infooptions_t;
/** @brief File opening options */
enum MediaInfo_fileoptions_t
{
MediaInfo_FileOption_Nothing = 0x00,
MediaInfo_FileOption_NoRecursive = 0x01,
MediaInfo_FileOption_CloseAll = 0x02,
MediaInfo_FileOption_Max = 0x04
}
alias MediaInfo_fileoptions_C = MediaInfo_fileoptions_t;
/* __cplusplus */
extern __gshared void* MediaInfo_Module;
extern __gshared size_t Module_Count;
alias MEDIAINFO_New = void* function ();
extern __gshared MEDIAINFO_New MediaInfo_New;
alias MEDIAINFOLIST_New = void* function ();
extern __gshared MEDIAINFOLIST_New MediaInfoList_New;
alias MEDIAINFO_Delete = void function (void*);
extern __gshared MEDIAINFO_Delete MediaInfo_Delete;
alias MEDIAINFOLIST_Delete = void function (void*);
extern __gshared MEDIAINFOLIST_Delete MediaInfoList_Delete;
alias MEDIAINFO_Open = c_ulong function (void*, const(MediaInfo_Char)*);
extern __gshared MEDIAINFO_Open MediaInfo_Open;
alias MEDIAINFOLIST_Open = c_ulong function (void*, const(MediaInfo_Char)*, const MediaInfo_fileoptions_C);
extern __gshared MEDIAINFOLIST_Open MediaInfoList_Open;
alias MEDIAINFO_Open_Buffer_Init = c_ulong function (void*, MediaInfo_int64u File_Size, MediaInfo_int64u File_Offset);
extern __gshared MEDIAINFO_Open_Buffer_Init MediaInfo_Open_Buffer_Init;
alias MEDIAINFO_Open_Buffer_Continue = c_ulong function (void*, MediaInfo_int8u* Buffer, size_t Buffer_Size);
extern __gshared MEDIAINFO_Open_Buffer_Continue MediaInfo_Open_Buffer_Continue;
alias MEDIAINFO_Open_Buffer_Continue_GoTo_Get = ulong function (void*);
extern __gshared MEDIAINFO_Open_Buffer_Continue_GoTo_Get MediaInfo_Open_Buffer_Continue_GoTo_Get;
alias MEDIAINFO_Open_Buffer_Finalize = c_ulong function (void*);
extern __gshared MEDIAINFO_Open_Buffer_Finalize MediaInfo_Open_Buffer_Finalize;
alias MEDIAINFO_Open_NextPacket = c_ulong function (void*);
extern __gshared MEDIAINFO_Open_NextPacket MediaInfo_Open_NextPacket;
alias MEDIAINFO_Close = void function (void*);
extern __gshared MEDIAINFO_Close MediaInfo_Close;
alias MEDIAINFOLIST_Close = void function (void*, size_t);
extern __gshared MEDIAINFOLIST_Close MediaInfoList_Close;
alias MEDIAINFO_Inform = const(char)* function (void*, size_t Reserved);
extern __gshared MEDIAINFO_Inform MediaInfo_Inform;
alias MEDIAINFOLIST_Inform = const(char)* function (void*, size_t, size_t Reserved);
extern __gshared MEDIAINFOLIST_Inform MediaInfoList_Inform;
alias MEDIAINFO_GetI = const(char)* function (void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
extern __gshared MEDIAINFO_GetI MediaInfo_GetI;
alias MEDIAINFOLIST_GetI = const(char)* function (void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, size_t Parameter, MediaInfo_info_C KindOfInfo);
extern __gshared MEDIAINFOLIST_GetI MediaInfoList_GetI;
alias MEDIAINFO_Get = const(char)* function (void*, MediaInfo_stream_C StreamKind, size_t StreamNumber, const(MediaInfo_Char)* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch);
extern __gshared MEDIAINFO_Get MediaInfo_Get;
alias MEDIAINFOLIST_Get = const(char)* function (void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber, const(MediaInfo_Char)* Parameter, MediaInfo_info_C KindOfInfo, MediaInfo_info_C KindOfSearch);
extern __gshared MEDIAINFOLIST_Get MediaInfoList_Get;
alias MEDIAINFO_Output_Buffer_Get = c_ulong function (void*, const(MediaInfo_Char)* Parameter);
extern __gshared MEDIAINFO_Output_Buffer_Get MediaInfo_Output_Buffer_Get;
alias MEDIAINFO_Output_Buffer_GetI = c_ulong function (void*, size_t Pos);
extern __gshared MEDIAINFO_Output_Buffer_GetI MediaInfo_Output_Buffer_GetI;
alias MEDIAINFO_Option = const(char)* function (void*, const(MediaInfo_Char)* Parameter, const(MediaInfo_Char)* Value);
extern __gshared MEDIAINFO_Option MediaInfo_Option;
alias MEDIAINFOLIST_Option = const(char)* function (void*, const(MediaInfo_Char)* Parameter, const(MediaInfo_Char)* Value);
extern __gshared MEDIAINFOLIST_Option MediaInfoList_Option;
alias MEDIAINFO_State_Get = c_ulong function (void*);
extern __gshared MEDIAINFO_State_Get MediaInfo_State_Get;
alias MEDIAINFOLIST_State_Get = c_ulong function (void*);
extern __gshared MEDIAINFOLIST_State_Get MediaInfoList_State_Get;
alias MEDIAINFO_Count_Get = c_ulong function (void*, MediaInfo_stream_C StreamKind, size_t StreamNumber);
extern __gshared MEDIAINFO_Count_Get MediaInfo_Count_Get;
alias MEDIAINFOLIST_Count_Get = c_ulong function (void*, size_t, MediaInfo_stream_C StreamKind, size_t StreamNumber);
extern __gshared MEDIAINFOLIST_Count_Get MediaInfoList_Count_Get;
alias MEDIAINFO_Count_Get_Files = c_ulong function (void*);
extern __gshared MEDIAINFO_Count_Get_Files MediaInfo_Count_Get_Files;
alias MEDIAINFOLIST_Count_Get_Files = c_ulong function (void*);
extern __gshared MEDIAINFOLIST_Count_Get_Files MediaInfoList_Count_Get_Files;
/* Load library */
// get full app path and delete app name
/* MACOSX*/
/* Load methods */
// Unload DLL with errors
size_t MediaInfoDLL_Load ();
size_t MediaInfoDLL_IsLoaded ();
void MediaInfoDLL_UnLoad ();
/*__cplusplus*/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
//DLL C++ wrapper for C functions
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//MediaInfo_Char types
// Legacy
//Legacy
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/// @brief Kinds of Stream
///< StreamKind = General
///< StreamKind = Video
///< StreamKind = Audio
///< StreamKind = Text
///< StreamKind = Other
///< StreamKind = Image
///< StreamKind = Menu
/// @brief Kind of information
///< InfoKind = Unique name of parameter
///< InfoKind = Value of parameter
///< InfoKind = Unique name of measure unit of parameter
///< InfoKind = See infooptions_t
///< InfoKind = Translated name of parameter
///< InfoKind = Translated name of measure unit
///< InfoKind = More information about the parameter
///< InfoKind = Information : how data is found
/// Get(...)[infooptions_t] return a string like "YNYN..." \n
/// Use this enum to know at what correspond the Y (Yes) or N (No)
/// If Get(...)[0]==Y, then :
/// @brief Option if InfoKind = Info_Options
///< Show this parameter in Inform()
///<
///< Internal use only (info : Must be showed in Info_Capacities() )
///< Value return by a standard Get() can be : T (Text), I (Integer, warning up to 64 bits), F (Float), D (Date), B (Binary datas coded Base64) (Numbers are in Base 10)
/// @brief File opening options
///< Do not browse folders recursively
///< Close all files before open
//---------------------------------------------------------------------------
//File