BMetaData: Finalize implementation
* Use string keys. I am still convinced we need BValue. * Use boolean instead of status_t in return, this is much more handy in pratical use given that there's no really a status to check.
This commit is contained in:
parent
c5287be1f3
commit
f722040584
@ -13,69 +13,71 @@ namespace BPrivate {
|
||||
namespace media {
|
||||
|
||||
|
||||
enum MetaDataKeys {
|
||||
// Playback capabilities
|
||||
CanPause = 0x1000, // bool
|
||||
CanSeekBackward, // bool
|
||||
CanSeekForward, // bool
|
||||
CanSeek, // bool
|
||||
// Playback capabilities
|
||||
extern const char* kCanPause; // bool
|
||||
extern const char* kCanSeekBackward; // bool
|
||||
extern const char* kCanSeekForward; // bool
|
||||
extern const char* kCanSeek; // bool
|
||||
|
||||
// Bitrates
|
||||
AudioBitRate, // uint32 (bps)
|
||||
VideoBitRate, // uint32 (bps)
|
||||
AudioSampleRate, // uint32 (hz)
|
||||
VideoFrameRate, // uint32 (hz)
|
||||
// Bitrates
|
||||
extern const char* kAudioBitRate; // uint32 (bps)
|
||||
extern const char* kVideoBitRate; // uint32 (bps)
|
||||
extern const char* kAudioSampleRate; // uint32 (hz)
|
||||
extern const char* kVideoFrameRate; // uint32 (hz)
|
||||
|
||||
// RFC2046 and RFC4281
|
||||
MimeType, // BString
|
||||
AudioCodec, // BString
|
||||
VideoCodec, // BString
|
||||
VideoHeight, // uint32
|
||||
VideoWidth, // uint32
|
||||
NumTracks, // uint32
|
||||
DrmCrippled, // bool
|
||||
// RFC2046 and RFC4281
|
||||
extern const char* kMimeType; // BString
|
||||
extern const char* kAudioCodec; // BString
|
||||
extern const char* kVideoCodec; // BString
|
||||
extern const char* kVideoHeight; // uint32
|
||||
extern const char* kVideoWidth; // uint32
|
||||
extern const char* kNumTracks; // uint32
|
||||
extern const char* kDrmCrippled; // 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
|
||||
};
|
||||
// General use attributes
|
||||
extern const char* kTitle; // BString
|
||||
extern const char* kComment; // BString
|
||||
extern const char* kCopyright; // BString
|
||||
extern const char* kAlbum; // BString
|
||||
extern const char* kArtist; // BString
|
||||
extern const char* kAuthor; // BString
|
||||
extern const char* kComposer; // BString
|
||||
extern const char* kGenre; // BString
|
||||
// TODO: what we would use for encoded dates?
|
||||
// Date, // date
|
||||
extern const char* kDuration; // uint32 (ms)
|
||||
extern const char* kRating; // BString
|
||||
// TODO: BBitmap? uint8 array?
|
||||
//AlbumArt,
|
||||
extern const char* kCDTrackNum; // uint32
|
||||
extern const char* kCDTrackMax; // uint32
|
||||
|
||||
|
||||
class BMetaData {
|
||||
public:
|
||||
BMetaData();
|
||||
BMetaData(const BMessage& msg);
|
||||
|
||||
~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);
|
||||
bool SetString(const char* key, const BString& value);
|
||||
bool SetBool(const char* key, bool value);
|
||||
bool SetUInt32(const char* 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;
|
||||
bool GetString(const char* key, BString* value) const;
|
||||
bool GetBool(const char* key, bool* value) const;
|
||||
bool GetUInt32(const char* key, uint32* value) const;
|
||||
|
||||
status_t RemoveValue(uint32 key);
|
||||
bool RemoveValue(const char* key);
|
||||
|
||||
// Clean up all keys
|
||||
void Reset();
|
||||
void MakeEmpty();
|
||||
bool IsEmpty();
|
||||
|
||||
status_t FromMessage(const BMessage& msg);
|
||||
const BMessage& ToMessage();
|
||||
// Retain ownership of the object, be careful with that
|
||||
// that's why we need to introduce smart pointers!
|
||||
BMessage* Message();
|
||||
|
||||
private:
|
||||
// TODO: padding
|
||||
|
@ -10,19 +10,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define P BPrivate::media::
|
||||
|
||||
// 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();
|
||||
}
|
||||
const char* P kCanPause = "canpause";
|
||||
const char* P kCanSeekBackward = "canseekbackward";
|
||||
const char* P kCanSeekForward = "canseekforward";
|
||||
const char* P kCanSeek = "canseek";
|
||||
|
||||
const char* P kAudioBitRate = "audiobitrate";
|
||||
const char* P kVideoBitRate = "videobitrate";
|
||||
const char* P kAudioSampleRate = "audiosamplerate";
|
||||
const char* P kVideoFrameRate = "videoframerate";
|
||||
|
||||
const char* P kMimeType = "mime";
|
||||
const char* P kAudioCodec = "audiocodec";
|
||||
const char* P kVideoCodec = "videocodec";
|
||||
const char* P kVideoHeight = "videoheight";
|
||||
const char* P kVideoWidth = "videowidth";
|
||||
const char* P kNumTracks = "numtracks";
|
||||
const char* P kDrmCrippled = "drmcrippled";
|
||||
|
||||
const char* P kTitle = "title";
|
||||
const char* P kComment = "comment";
|
||||
const char* P kCopyright = "copyright";
|
||||
const char* P kAlbum = "album";
|
||||
const char* P kArtist = "artist";
|
||||
const char* P kAuthor = "author";
|
||||
const char* P kComposer = "composer";
|
||||
const char* P kGenre = "genre";
|
||||
const char* P kDuration = "duration";
|
||||
const char* P kRating = "rating";
|
||||
const char* P kCDTrackNum = "cdtracknumber";
|
||||
const char* P kCDTrackMax = "cdtrackmax";
|
||||
|
||||
|
||||
BMetaData::BMetaData()
|
||||
@ -33,65 +52,85 @@ BMetaData::BMetaData()
|
||||
}
|
||||
|
||||
|
||||
BMetaData::BMetaData(const BMessage& msg)
|
||||
:
|
||||
fMessage(NULL)
|
||||
{
|
||||
fMessage = new BMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
BMetaData::~BMetaData()
|
||||
{
|
||||
delete fMessage;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::SetString(uint32 key, const BString& value)
|
||||
bool
|
||||
BMetaData::SetString(const char* key, const BString& value)
|
||||
{
|
||||
return fMessage->AddString(key_to_string(key), value);
|
||||
return fMessage->SetString(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::SetBool(uint32 key, bool value)
|
||||
bool
|
||||
BMetaData::SetBool(const char* key, bool value)
|
||||
{
|
||||
return fMessage->AddBool(key_to_string(key), value);
|
||||
return fMessage->SetBool(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::SetUInt32(uint32 key, uint32 value)
|
||||
bool
|
||||
BMetaData::SetUInt32(const char* key, uint32 value)
|
||||
{
|
||||
return fMessage->AddUInt32(key_to_string(key), value);
|
||||
return fMessage->SetUInt32(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::FindString(uint32 key, BString* value) const
|
||||
bool
|
||||
BMetaData::GetString(const char* key, BString* value) const
|
||||
{
|
||||
return fMessage->FindString(key_to_string(key), value);
|
||||
return fMessage->FindString(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::FindBool(uint32 key, bool* value) const
|
||||
bool
|
||||
BMetaData::GetBool(const char* key, bool* value) const
|
||||
{
|
||||
return fMessage->FindBool(key_to_string(key), value);
|
||||
return fMessage->FindBool(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::FindUInt32(uint32 key, uint32* value) const
|
||||
bool
|
||||
BMetaData::GetUInt32(const char* key, uint32* value) const
|
||||
{
|
||||
return fMessage->FindUInt32(key_to_string(key), value);
|
||||
return fMessage->FindUInt32(key, value) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMetaData::RemoveValue(uint32 key)
|
||||
bool
|
||||
BMetaData::RemoveValue(const char* key)
|
||||
{
|
||||
return fMessage->RemoveName(key_to_string(key));
|
||||
return fMessage->RemoveName(key) == B_OK ? true : false;
|
||||
}
|
||||
|
||||
|
||||
// Clean up all keys
|
||||
void
|
||||
BMetaData::Reset()
|
||||
BMetaData::MakeEmpty()
|
||||
{
|
||||
delete fMessage;
|
||||
fMessage = new BMessage();
|
||||
fMessage->MakeEmpty();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BMetaData::IsEmpty()
|
||||
{
|
||||
return fMessage->IsEmpty();
|
||||
}
|
||||
|
||||
|
||||
BMessage*
|
||||
BMetaData::Message()
|
||||
{
|
||||
return fMessage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user