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:
+49
-47
@@ -13,69 +13,71 @@ namespace BPrivate {
|
|||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
|
|
||||||
enum MetaDataKeys {
|
// Playback capabilities
|
||||||
// Playback capabilities
|
extern const char* kCanPause; // bool
|
||||||
CanPause = 0x1000, // bool
|
extern const char* kCanSeekBackward; // bool
|
||||||
CanSeekBackward, // bool
|
extern const char* kCanSeekForward; // bool
|
||||||
CanSeekForward, // bool
|
extern const char* kCanSeek; // bool
|
||||||
CanSeek, // bool
|
|
||||||
|
|
||||||
// Bitrates
|
// Bitrates
|
||||||
AudioBitRate, // uint32 (bps)
|
extern const char* kAudioBitRate; // uint32 (bps)
|
||||||
VideoBitRate, // uint32 (bps)
|
extern const char* kVideoBitRate; // uint32 (bps)
|
||||||
AudioSampleRate, // uint32 (hz)
|
extern const char* kAudioSampleRate; // uint32 (hz)
|
||||||
VideoFrameRate, // uint32 (hz)
|
extern const char* kVideoFrameRate; // uint32 (hz)
|
||||||
|
|
||||||
// RFC2046 and RFC4281
|
// RFC2046 and RFC4281
|
||||||
MimeType, // BString
|
extern const char* kMimeType; // BString
|
||||||
AudioCodec, // BString
|
extern const char* kAudioCodec; // BString
|
||||||
VideoCodec, // BString
|
extern const char* kVideoCodec; // BString
|
||||||
VideoHeight, // uint32
|
extern const char* kVideoHeight; // uint32
|
||||||
VideoWidth, // uint32
|
extern const char* kVideoWidth; // uint32
|
||||||
NumTracks, // uint32
|
extern const char* kNumTracks; // uint32
|
||||||
DrmCrippled, // bool
|
extern const char* kDrmCrippled; // bool
|
||||||
|
|
||||||
// General use attributes
|
// General use attributes
|
||||||
Title, // BString
|
extern const char* kTitle; // BString
|
||||||
Comment, // BString
|
extern const char* kComment; // BString
|
||||||
Copyright, // BString
|
extern const char* kCopyright; // BString
|
||||||
Album, // BString
|
extern const char* kAlbum; // BString
|
||||||
Artist, // BString
|
extern const char* kArtist; // BString
|
||||||
Author, // BString
|
extern const char* kAuthor; // BString
|
||||||
Composer, // BString
|
extern const char* kComposer; // BString
|
||||||
Genre, // BString
|
extern const char* kGenre; // BString
|
||||||
// TODO: what we would use for encoded dates?
|
// TODO: what we would use for encoded dates?
|
||||||
// Date, // date
|
// Date, // date
|
||||||
Duration, // uint32 (ms)
|
extern const char* kDuration; // uint32 (ms)
|
||||||
Rating, // BString
|
extern const char* kRating; // BString
|
||||||
// TODO: BBitmap? uint8 array?
|
// TODO: BBitmap? uint8 array?
|
||||||
//AlbumArt, //
|
//AlbumArt,
|
||||||
CDTrackNum, // uint32
|
extern const char* kCDTrackNum; // uint32
|
||||||
CDTrackMax // uint32
|
extern const char* kCDTrackMax; // uint32
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BMetaData {
|
class BMetaData {
|
||||||
public:
|
public:
|
||||||
BMetaData();
|
BMetaData();
|
||||||
|
BMetaData(const BMessage& msg);
|
||||||
|
|
||||||
~BMetaData();
|
~BMetaData();
|
||||||
|
|
||||||
// Woah. It seems we need BValue there.
|
// Woah. It seems we need BValue there.
|
||||||
status_t SetString(uint32 key, const BString& value);
|
bool SetString(const char* key, const BString& value);
|
||||||
status_t SetBool(uint32 key, bool value);
|
bool SetBool(const char* key, bool value);
|
||||||
status_t SetUInt32(uint32 key, uint32 value);
|
bool SetUInt32(const char* key, uint32 value);
|
||||||
|
|
||||||
status_t FindString(uint32 key, BString* value) const;
|
bool GetString(const char* key, BString* value) const;
|
||||||
status_t FindBool(uint32 key, bool* value) const;
|
bool GetBool(const char* key, bool* value) const;
|
||||||
status_t FindUInt32(uint32 key, uint32* value) const;
|
bool GetUInt32(const char* key, uint32* value) const;
|
||||||
|
|
||||||
status_t RemoveValue(uint32 key);
|
bool RemoveValue(const char* key);
|
||||||
|
|
||||||
// Clean up all keys
|
// Clean up all keys
|
||||||
void Reset();
|
void MakeEmpty();
|
||||||
|
bool IsEmpty();
|
||||||
|
|
||||||
status_t FromMessage(const BMessage& msg);
|
// Retain ownership of the object, be careful with that
|
||||||
const BMessage& ToMessage();
|
// that's why we need to introduce smart pointers!
|
||||||
|
BMessage* Message();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO: padding
|
// TODO: padding
|
||||||
|
|||||||
+76
-37
@@ -10,19 +10,38 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define P BPrivate::media::
|
||||||
|
|
||||||
// TODO: probably we can do better
|
const char* P kCanPause = "canpause";
|
||||||
const char*
|
const char* P kCanSeekBackward = "canseekbackward";
|
||||||
key_to_string(uint32 key)
|
const char* P kCanSeekForward = "canseekforward";
|
||||||
{
|
const char* P kCanSeek = "canseek";
|
||||||
char buf[sizeof(char) * sizeof(uint32) * 4 + 1];
|
|
||||||
if (buf) {
|
const char* P kAudioBitRate = "audiobitrate";
|
||||||
sprintf(buf, "%" B_PRId32, key);
|
const char* P kVideoBitRate = "videobitrate";
|
||||||
}
|
const char* P kAudioSampleRate = "audiosamplerate";
|
||||||
BString ret(buf);
|
const char* P kVideoFrameRate = "videoframerate";
|
||||||
ret.Prepend("codec:metadata:");
|
|
||||||
return ret.String();
|
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()
|
BMetaData::BMetaData()
|
||||||
@@ -33,65 +52,85 @@ BMetaData::BMetaData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMetaData::BMetaData(const BMessage& msg)
|
||||||
|
:
|
||||||
|
fMessage(NULL)
|
||||||
|
{
|
||||||
|
fMessage = new BMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BMetaData::~BMetaData()
|
BMetaData::~BMetaData()
|
||||||
{
|
{
|
||||||
delete fMessage;
|
delete fMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
BMetaData::SetString(uint32 key, const BString& value)
|
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
|
bool
|
||||||
BMetaData::SetBool(uint32 key, bool value)
|
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
|
bool
|
||||||
BMetaData::SetUInt32(uint32 key, uint32 value)
|
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
|
bool
|
||||||
BMetaData::FindString(uint32 key, BString* value) const
|
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
|
bool
|
||||||
BMetaData::FindBool(uint32 key, bool* value) const
|
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
|
bool
|
||||||
BMetaData::FindUInt32(uint32 key, uint32* value) const
|
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
|
bool
|
||||||
BMetaData::RemoveValue(uint32 key)
|
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
|
void
|
||||||
BMetaData::Reset()
|
BMetaData::MakeEmpty()
|
||||||
{
|
{
|
||||||
delete fMessage;
|
fMessage->MakeEmpty();
|
||||||
fMessage = new BMessage();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BMetaData::IsEmpty()
|
||||||
|
{
|
||||||
|
return fMessage->IsEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMessage*
|
||||||
|
BMetaData::Message()
|
||||||
|
{
|
||||||
|
return fMessage;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user