diff --git a/headers/os/codec/MetaData.h b/headers/os/codec/MetaData.h new file mode 100644 index 0000000000..5d2e31622d --- /dev/null +++ b/headers/os/codec/MetaData.h @@ -0,0 +1,93 @@ +/* + * Copyright 2018, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _META_DATA_H +#define _META_DATA_H + +#include + + +namespace BPrivate { +namespace media { + + +enum MetaDataKeys { + // Playback capabilities + CanPause = 0x1000, // bool + CanSeekBackward, // bool + CanSeekForward, // bool + CanSeek, // bool + + // Bitrates + AudioBitRate, // uint32 (bps) + VideoBitRate, // uint32 (bps) + AudioSampleRate, // uint32 (hz) + VideoFrameRate, // uint32 (hz) + + // RFC2046 and RFC4281 + MimeType, // BString + AudioCodec, // BString + VideoCodec, // BString + VideoHeight, // uint32 + VideoWidth, // uint32 + NumTracks, // uint32 + DrmCrippled, // bool + + // General use attributes + Title, // BString + Comment, // BString + Copyright, // BString + Album, // BString + Artist, // BString + Author, // BString + Composer, // BString + Genre, // BString + // TODO: what we would use for encoded dates? + // Date, // date + Duration, // uint32 (ms) + Rating, // BString + // TODO: BBitmap? uint8 array? + //AlbumArt, // + CDTrackNum, // uint32 + CDTrackMax // uint32 +}; + + +class BMetaData { +public: + BMetaData(); + ~BMetaData(); + + // Woah. It seems we need BValue there. + status_t SetString(uint32 key, const BString& value); + status_t SetBool(uint32 key, bool value); + status_t SetUInt32(uint32 key, uint32 value); + + status_t FindString(uint32 key, BString* value) const; + status_t FindBool(uint32 key, bool* value) const; + status_t FindUInt32(uint32 key, uint32* value) const; + + status_t RemoveValue(uint32 key); + + // Clean up all keys + void Reset(); + + status_t FromMessage(const BMessage& msg); + const BMessage& ToMessage(); + +private: + // TODO: padding + BMessage* fMessage; + + BMetaData(const BMetaData&); + BMetaData& operator=(const BMetaData&); +}; + +} // namespace media +} // namespace BPrivate + +using namespace BPrivate::media; + +#endif // _META_DATA_H diff --git a/src/kits/codec/Jamfile b/src/kits/codec/Jamfile index 4dc01791aa..5afb253a75 100644 --- a/src/kits/codec/Jamfile +++ b/src/kits/codec/Jamfile @@ -17,6 +17,9 @@ for architectureObject in [ MultiArchSubDirSetup ] { AdapterIO.cpp MediaIO.cpp + # Support API + MetaData.cpp + # Codec Plugin API ChunkCache.cpp DecoderPlugin.cpp diff --git a/src/kits/codec/MetaData.cpp b/src/kits/codec/MetaData.cpp new file mode 100644 index 0000000000..aa067760e5 --- /dev/null +++ b/src/kits/codec/MetaData.cpp @@ -0,0 +1,97 @@ +/* + * Copyright 2018, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include + +#include +#include + + +// TODO: probably we can do better +const char* +key_to_string(uint32 key) +{ + char buf[sizeof(char) * sizeof(uint32) * 4 + 1]; + if (buf) { + sprintf(buf, "%"B_PRId32, key); + } + BString ret(buf); + ret.Prepend("codec:metadata:"); + return ret.String(); +} + + +BMetaData::BMetaData() + : + fMessage(NULL) +{ + fMessage = new BMessage(); +} + + +BMetaData::~BMetaData() +{ + delete fMessage; +} + + +status_t +BMetaData::SetString(uint32 key, const BString& value) +{ + return fMessage->AddString(key_to_string(key), value); +} + + +status_t +BMetaData::SetBool(uint32 key, bool value) +{ + return fMessage->AddBool(key_to_string(key), value); +} + + +status_t +BMetaData::SetUInt32(uint32 key, uint32 value) +{ + return fMessage->AddUInt32(key_to_string(key), value); +} + + +status_t +BMetaData::FindString(uint32 key, BString* value) const +{ + return fMessage->FindString(key_to_string(key), value); +} + + +status_t +BMetaData::FindBool(uint32 key, bool* value) const +{ + return fMessage->FindBool(key_to_string(key), value); +} + + +status_t +BMetaData::FindUInt32(uint32 key, uint32* value) const +{ + return fMessage->FindUInt32(key_to_string(key), value); +} + + +status_t +BMetaData::RemoveValue(uint32 key) +{ + return fMessage->RemoveName(key_to_string(key)); +} + + +// Clean up all keys +void +BMetaData::Reset() +{ + delete fMessage; + fMessage = new BMessage(); +}