|
Packit |
c32a2d |
/*
|
|
Packit |
c32a2d |
mpg123clr: MPEG Audio Decoder library Common Language Runtime version.
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
copyright 2009-2011 by Malcolm Boczek - free software under the terms of the LGPL 2.1
|
|
Packit |
c32a2d |
mpg123clr.dll is a derivative work of libmpg123 - all original mpg123 licensing terms apply.
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
All rights to this work freely assigned to the mpg123 project.
|
|
Packit |
c32a2d |
*/
|
|
Packit |
c32a2d |
/*
|
|
Packit |
c32a2d |
libmpg123: MPEG Audio Decoder library
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
copyright 1995-2011 by the mpg123 project - free software under the terms of the LGPL 2.1
|
|
Packit |
c32a2d |
see COPYING and AUTHORS files in distribution or http://mpg123.org
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
*/
|
|
Packit |
c32a2d |
/*
|
|
Packit |
c32a2d |
1.8.1.0 04-Aug-09 Initial release.
|
|
Packit |
c32a2d |
1.9.0.0 16-Sep-09 1.9.0 Update - add enc_from_id3, store_utf8
|
|
Packit |
c32a2d |
1.9.0.0 24-Sep-09 Function names harmonized with libmpg123 (mb)
|
|
Packit |
c32a2d |
1.13.0.0 13-Jan-11 release match - added strlen (mb)
|
|
Packit |
c32a2d |
*/
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
#pragma once
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
#pragma warning(disable : 4635)
|
|
Packit |
c32a2d |
#include "mpg123.h"
|
|
Packit |
c32a2d |
#pragma warning(default : 4635)
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
#include <string>
|
|
Packit |
c32a2d |
#include <iostream>
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
#include <vcclr.h>
|
|
Packit |
c32a2d |
using namespace std;
|
|
Packit |
c32a2d |
using namespace System;
|
|
Packit |
c32a2d |
using namespace System::Runtime::InteropServices;
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
namespace mpg123clr
|
|
Packit |
c32a2d |
{
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
// Recommended usage when creating reference type on the managed heap (not using stack semantics
|
|
Packit |
c32a2d |
// for reference types...) [see Destructors and Finalizers in Visual C++]
|
|
Packit |
c32a2d |
//
|
|
Packit |
c32a2d |
// A ^ myA = gcnew A;
|
|
Packit |
c32a2d |
// try
|
|
Packit |
c32a2d |
// {
|
|
Packit |
c32a2d |
// use myA
|
|
Packit |
c32a2d |
// }
|
|
Packit |
c32a2d |
// finally
|
|
Packit |
c32a2d |
// {
|
|
Packit |
c32a2d |
// delete myA;
|
|
Packit |
c32a2d |
// }
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Wrapper for mpg123_string.
|
|
Packit |
c32a2d |
///<para>mpg123str can be used as both (publicly) an instance object and (privately) a reference object.
|
|
Packit |
c32a2d |
/// Construction and Finalizer operations perform differently depending on the instance type...
|
|
Packit |
c32a2d |
///</para>
|
|
Packit |
c32a2d |
///<para>Instanced: i.e. new mpg123str();
|
|
Packit |
c32a2d |
/// Normal operation of any object. Construction initializes memory and Destruction frees memory.
|
|
Packit |
c32a2d |
///</para>
|
|
Packit |
c32a2d |
///<para>Referenced: i.e. new mpg123str(sb);
|
|
Packit |
c32a2d |
/// Construction and Destruction have no effect on the referenced object, mpg123str objects may be freely
|
|
Packit |
c32a2d |
/// made and deleted without affecting the referenced object.
|
|
Packit |
c32a2d |
///</para>
|
|
Packit |
c32a2d |
///<para>However!
|
|
Packit |
c32a2d |
///</para>
|
|
Packit |
c32a2d |
///<para>All methods operate on the referenced object (and NOT a copy of the object), the underlying mpg123_string
|
|
Packit |
c32a2d |
/// is directly modified in situ. Therefore the referenced object can be initialized and disposed by
|
|
Packit |
c32a2d |
/// explicitly calling Init() and Free().</para>
|
|
Packit |
c32a2d |
///<para>The length of strings is limited to a 32bit value due to limitations of the CLI marshaler.
|
|
Packit |
c32a2d |
///</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
[StructLayout(LayoutKind::Sequential, CharSet=CharSet::Ansi)]
|
|
Packit |
c32a2d |
public ref struct mpg123str
|
|
Packit |
c32a2d |
{
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
public:
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>text_encoding enumeration.</summary>
|
|
Packit |
c32a2d |
enum class text_encoding
|
|
Packit |
c32a2d |
{
|
|
Packit |
c32a2d |
text_unknown = mpg123_text_unknown, /// Unkown encoding... mpg123_id3_encoding can return that on invalid codes.
|
|
Packit |
c32a2d |
text_utf8 = mpg123_text_utf8, /// UTF-8
|
|
Packit |
c32a2d |
text_latin1 = mpg123_text_latin1, /// ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings.
|
|
Packit |
c32a2d |
text_icy = mpg123_text_icy, /// ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such.
|
|
Packit |
c32a2d |
text_cp1252 = mpg123_text_cp1252, /// Really CP-1252 without any guessing.
|
|
Packit |
c32a2d |
text_utf16 = mpg123_text_utf16, /// Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules.
|
|
Packit |
c32a2d |
/// When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when
|
|
Packit |
c32a2d |
/// you don't mess with the reserved code points. If you want to decode little endian data
|
|
Packit |
c32a2d |
/// without BOM you need to prepend 0xff 0xfe yourself.
|
|
Packit |
c32a2d |
text_utf16bom = mpg123_text_utf16bom, /// Just an alias for UTF-16, ID3v2 has this as distinct code.
|
|
Packit |
c32a2d |
text_utf16be = mpg123_text_utf16be, /// Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality,
|
|
Packit |
c32a2d |
/// BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123
|
|
Packit |
c32a2d |
/// One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16
|
|
Packit |
c32a2d |
/// types (we expect a BOM before real data there), not so for utf16be!
|
|
Packit |
c32a2d |
text_max = mpg123_text_max /// Placeholder for the maximum encoding value.
|
|
Packit |
c32a2d |
};
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>id3_enc enumeration.</summary>
|
|
Packit |
c32a2d |
enum class id3_enc
|
|
Packit |
c32a2d |
{
|
|
Packit |
c32a2d |
id3_latin1 = mpg123_id3_latin1, /// Note: This sometimes can mean anything in practice...
|
|
Packit |
c32a2d |
id3_utf16bom = mpg123_id3_utf16bom, /// UTF16, UCS-2 ... it's all the same for practical purposes.
|
|
Packit |
c32a2d |
id3_utf16be = mpg123_id3_utf16be, /// Big-endian UTF-16, BOM see note for mpg123_text_utf16be.
|
|
Packit |
c32a2d |
id3_utf8 = mpg123_id3_utf8, /// Our lovely overly ASCII-compatible 8 byte encoding for the world.
|
|
Packit |
c32a2d |
id3_enc_max = mpg123_id3_enc_max /// Placeholder to check valid range of encoding byte.
|
|
Packit |
c32a2d |
};
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
private:
|
|
Packit |
c32a2d |
mpg123_string* sb;
|
|
Packit |
c32a2d |
bool instanced;
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
internal:
|
|
Packit |
c32a2d |
///<summary>Reference Constructor. Does nothing to referenced mpg123_string structure.
|
|
Packit |
c32a2d |
///<para>Reference objects may be freely created and deleted without affecting the underlying mpg123_string object.
|
|
Packit |
c32a2d |
/// However, operations on the referenced object do modify the object in-situ (i.e. 'this' is not a 'copy'), and
|
|
Packit |
c32a2d |
/// the referenced object may be explicitly initialized and disposed by calling the appropriate methods. (Init() and Free())</para>
|
|
Packit |
c32a2d |
///<para>Recommended usage: using(mpg123str obj = new mpg123str(sb)){ use obj here }</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
mpg123str(mpg123_string* sb);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Internal Constructor.
|
|
Packit |
c32a2d |
///<para>Only used on empty fields.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
mpg123str(const char* str);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
protected:
|
|
Packit |
c32a2d |
///<summary>Finalizer.
|
|
Packit |
c32a2d |
///<para>Cleanly handles mpg123_free_string of instanced mpg123_string object.</para>
|
|
Packit |
c32a2d |
///<para>Does not dispose referenced mpg123_string object. Referenced objects may be explicitly disposed by using Free().</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
/// Implementation of CLR Finalize().
|
|
Packit |
c32a2d |
!mpg123str(void);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
public:
|
|
Packit |
c32a2d |
///<summary>Constructor, also initializes underlying mpg123_string structure.
|
|
Packit |
c32a2d |
///<para>Instanced objects automatically dispose of underlying mpg123_string object.</para>
|
|
Packit |
c32a2d |
///<para>Recommended usage: using(mpg123str obj = new mpg123str(sb)){ use obj here }</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
mpg123str(void);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Destructor. Used for final object deletion.
|
|
Packit |
c32a2d |
///<para>Instance objects call the finalizer for clean disposal of internal mpg123_string object.</para>
|
|
Packit |
c32a2d |
///<para>Reference objects may be freely deleted without affecting the underlying mpg123_string object.
|
|
Packit |
c32a2d |
/// However, the referenced object may be explicitly disposed by calling Free()</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
// Implementation of CLR Dispose().
|
|
Packit |
c32a2d |
// ~Destructor and !Finalizer are the prescribed implementation of Dispose() and Finalize().
|
|
Packit |
c32a2d |
// See Destructors and Finalizers in Visual C++
|
|
Packit |
c32a2d |
~mpg123str(void);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Append a C# string to this mpg123str.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="s">String to be appended.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_add_string(String ^ s);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Append a C# substring to this mpg123str.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="s">String to be appended.</param>
|
|
Packit |
c32a2d |
///<param name="from">String offset to copy from.</param>
|
|
Packit |
c32a2d |
///<param name="count">Number of characters to copy. (a null byte is always appended)</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_add_substring(String ^ s, int from, int count);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Copy the contents of this string to another.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="to">Where to copy this string to.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_copy_string(mpg123str^ to);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Free-up mempory for an existing mpg123_string.
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
void __clrcall mpg123_free_string(void);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Increase size of a mpg123_string if necessary (it may stay larger).
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="newSize">Required size.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_grow_string(int newSize);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Change the size of a mpg123_string.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="newSize">Required size.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_resize_string(int newSize);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Create and allocate memory for a new mpg123_string.
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
void __clrcall mpg123_init_string(void);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Set the contents to a C# string.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="s">String to be applied.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_set_string(String ^ s);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Set the contents to a C# substring.
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="s">String to be applied.</param>
|
|
Packit |
c32a2d |
///<param name="from">String offset to copy from.</param>
|
|
Packit |
c32a2d |
///<param name="count">Number of characters to copy. (a null byte is always appended)</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success.</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_set_substring(String ^ s, int from, int count);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Count characters in a mpg123 string (non-null bytes or UTF-8 characters).
|
|
Packit |
c32a2d |
///<para>Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.</para>
|
|
Packit |
c32a2d |
///<para>Returns the character count.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="utf8">Flag to tell if the string is in utf8 encoding.</param>
|
|
Packit |
c32a2d |
///<returns>Character count.</returns>
|
|
Packit |
c32a2d |
long long __clrcall mpg123_strlen(bool utf8);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Get the number of used bytes. (including closing zero byte).
|
|
Packit |
c32a2d |
///<para>Property returns the number of used bytes.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<value>The number of used bytes.</value>
|
|
Packit |
c32a2d |
property int Fill{int __clrcall get();} // property
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Get the number of bytes allocated.
|
|
Packit |
c32a2d |
///<para>Property returns the number of bytes allocated.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<value>The number of bytes allocated.</value>
|
|
Packit |
c32a2d |
property int Size{int __clrcall get();} // property
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Get a C# string representation of the mpg123str.
|
|
Packit |
c32a2d |
///<para>Property returns C# string text.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<value>C# string text.</value>
|
|
Packit |
c32a2d |
property String^ Text{String^ __clrcall get();}
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
// 1.9.0.0 +add
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Convert ID3 encoding byte to mpg123 encoding index.
|
|
Packit |
c32a2d |
///<para>Returns the text_encoding enum of the converted value.</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="id3_enc_byte">The ID3 encoding byte to be converted.</param>
|
|
Packit |
c32a2d |
///<returns>The text_encoding enum of the converted value.</returns>
|
|
Packit |
c32a2d |
static text_encoding __clrcall mpg123_enc_from_id3(unsigned char id3_enc_byte);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
///<summary>Store text data in string, after converting to UTF-8 from indicated encoding.
|
|
Packit |
c32a2d |
///<para>A prominent error can be that you provided an unknown encoding value, or this build of libmpg123 lacks support for certain encodings (ID3 or ICY stuff missing).
|
|
Packit |
c32a2d |
/// Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).</para>
|
|
Packit |
c32a2d |
///<para>CLR - e.g. UnicodeEncoding(true, true) works with utf16be.</para>
|
|
Packit |
c32a2d |
///<para>Returns 0 on error, 1 on success (on error, mpg123_free_string is called on sb).</para>
|
|
Packit |
c32a2d |
///</summary>
|
|
Packit |
c32a2d |
///<param name="enc">Mpg123 text encoding value.</param>
|
|
Packit |
c32a2d |
///<param name="source">Source buffer with plain unsigned bytes.</param>
|
|
Packit |
c32a2d |
///<param name="source_size">Number of bytes in the source buffer.</param>
|
|
Packit |
c32a2d |
///<returns>0 on error, 1 on success (on error, mpg123_free_string is called on sb).</returns>
|
|
Packit |
c32a2d |
int __clrcall mpg123_store_utf8(text_encoding enc, const unsigned char *source, size_t source_size);
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
// 1.9.0.0 -add
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
};
|
|
Packit |
c32a2d |
|
|
Packit |
c32a2d |
}
|