Codec Kit: Initial BMetaData implementation

This commit is contained in:
Barrett17
2018-11-18 16:57:12 +01:00
parent b4d8bbd540
commit 1f2ddf2fd0
3 changed files with 193 additions and 0 deletions
+93
View File
@@ -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 <Message.h>
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
+3
View File
@@ -17,6 +17,9 @@ for architectureObject in [ MultiArchSubDirSetup ] {
AdapterIO.cpp
MediaIO.cpp
# Support API
MetaData.cpp
# Codec Plugin API
ChunkCache.cpp
DecoderPlugin.cpp
+97
View File
@@ -0,0 +1,97 @@
/*
* Copyright 2018, Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <MetaData.h>
#include <String.h>
#include <stdio.h>
#include <stdlib.h>
// 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();
}