From 7cd3a2490b94cecc15ce451c8d1c97c04dc852bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 17 Sep 2010 08:04:26 +0000 Subject: [PATCH] Implemented an API to get arbitrary meta-data about BMediaFiles and about BMediaTracks in BMessages. As an example, one can get chapter meta-data or the language name of an audio-track. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38685 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/media/MediaFile.h | 7 +++++++ headers/os/media/MediaTrack.h | 7 +++++++ headers/private/media/MediaExtractor.h | 4 ++++ headers/private/media/ReaderPlugin.h | 4 ++++ src/kits/media/MediaExtractor.cpp | 20 ++++++++++++++++++++ src/kits/media/MediaFile.cpp | 15 ++++++++++++++- src/kits/media/MediaTrack.cpp | 15 +++++++++++++++ src/kits/media/ReaderPlugin.cpp | 18 ++++++++++++++++++ 8 files changed, 89 insertions(+), 1 deletion(-) diff --git a/headers/os/media/MediaFile.h b/headers/os/media/MediaFile.h index d0a25facc1..c4f579e484 100644 --- a/headers/os/media/MediaFile.h +++ b/headers/os/media/MediaFile.h @@ -24,6 +24,7 @@ namespace BPrivate { // forward declarations class BMediaTrack; +class BMessage; class BParameterWeb; class BView; @@ -79,6 +80,12 @@ public: status_t GetFileFormatInfo( media_file_format* mfi) const; + // Returns in _data hierarchical meta-data about the stream. + // The fields in the message shall follow a defined naming-scheme, + // such that applications can find the same information in different + // types of files. + status_t GetMetaData(BMessage* _data) const; + // // These functions are for read-only access to a media file. // The data is read using the BMediaTrack object. diff --git a/headers/os/media/MediaTrack.h b/headers/os/media/MediaTrack.h index 8dde09bed7..91131e8acd 100644 --- a/headers/os/media/MediaTrack.h +++ b/headers/os/media/MediaTrack.h @@ -16,6 +16,7 @@ namespace BPrivate { namespace media { class MediaWriter; } } +class BMessage; class BView; class BParameterWeb; @@ -90,6 +91,12 @@ public: int64 CountFrames() const; bigtime_t Duration() const; + // Returns in _data hierarchical meta-data about the track. + // The fields in the message shall follow a defined naming-scheme, + // such that applications can find the same information in different + // types of tracks. + status_t GetMetaData(BMessage* _data) const; + // CurrentFrame and CurrentTime return the current position (expressed in // microseconds) within the track, expressed in frame index and time. diff --git a/headers/private/media/MediaExtractor.h b/headers/private/media/MediaExtractor.h index 7b0db1b54d..942bf5b132 100644 --- a/headers/private/media/MediaExtractor.h +++ b/headers/private/media/MediaExtractor.h @@ -43,6 +43,7 @@ public: void GetFileFormatInfo( media_file_format* fileFormat) const; + status_t GetMetaData(BMessage* _data) const; int32 StreamCount(); @@ -65,6 +66,9 @@ public: status_t CreateDecoder(int32 stream, Decoder** _decoder, media_codec_info* codecInfo); + status_t GetStreamMetaData(int32 stream, + BMessage* _data) const; + private: void _RecycleLastChunk(stream_info& info); static int32 _ExtractorEntry(void* arg); diff --git a/headers/private/media/ReaderPlugin.h b/headers/private/media/ReaderPlugin.h index d7a0be85b4..708d5b76ba 100644 --- a/headers/private/media/ReaderPlugin.h +++ b/headers/private/media/ReaderPlugin.h @@ -23,6 +23,7 @@ public: virtual status_t Sniff(int32* streamCount) = 0; virtual void GetFileFormatInfo(media_file_format* mff) = 0; + virtual status_t GetMetaData(BMessage* _data); virtual status_t AllocateCookie(int32 streamNumber, void** cookie) = 0; @@ -42,6 +43,9 @@ public: const void** chunkBuffer, size_t* chunkSize, media_header* mediaHeader) = 0; + virtual status_t GetStreamMetaData(void* cookie, + BMessage* _data); + BDataIO* Source() const; virtual status_t Perform(perform_code code, void* data); diff --git a/src/kits/media/MediaExtractor.cpp b/src/kits/media/MediaExtractor.cpp index b82dccff77..8b48172484 100644 --- a/src/kits/media/MediaExtractor.cpp +++ b/src/kits/media/MediaExtractor.cpp @@ -178,6 +178,14 @@ MediaExtractor::GetFileFormatInfo(media_file_format* fileFormat) const } +status_t +MediaExtractor::GetMetaData(BMessage* _data) const +{ + CALLED(); + return fReader->GetMetaData(_data); +} + + int32 MediaExtractor::StreamCount() { @@ -376,6 +384,18 @@ MediaExtractor::CreateDecoder(int32 stream, Decoder** _decoder, } +status_t +MediaExtractor::GetStreamMetaData(int32 stream, BMessage* _data) const +{ + const stream_info& info = fStreamInfo[stream]; + + if (info.status != B_OK) + return info.status; + + return fReader->GetStreamMetaData(fStreamInfo[stream].cookie, _data); +} + + void MediaExtractor::_RecycleLastChunk(stream_info& info) { diff --git a/src/kits/media/MediaFile.cpp b/src/kits/media/MediaFile.cpp index 8e85ae9c30..f5fce00905 100644 --- a/src/kits/media/MediaFile.cpp +++ b/src/kits/media/MediaFile.cpp @@ -129,7 +129,6 @@ BMediaFile::InitCheck() const } -// Get info about the underlying file format. status_t BMediaFile::GetFileFormatInfo(media_file_format* mfi) const { @@ -143,6 +142,20 @@ BMediaFile::GetFileFormatInfo(media_file_format* mfi) const } +status_t +BMediaFile::GetMetaData(BMessage* _data) const +{ + if (fExtractor == NULL) + return B_NO_INIT; + if (_data == NULL) + return B_BAD_VALUE; + + _data->MakeEmpty(); + + return fExtractor->GetMetaData(_data); +} + + const char* BMediaFile::Copyright() const { diff --git a/src/kits/media/MediaTrack.cpp b/src/kits/media/MediaTrack.cpp index 5c38f93e84..983b111ca8 100644 --- a/src/kits/media/MediaTrack.cpp +++ b/src/kits/media/MediaTrack.cpp @@ -233,6 +233,21 @@ BMediaTrack::DecodedFormat(media_format *inout_format, uint32 flags) } +status_t +BMediaTrack::GetMetaData(BMessage* _data) const +{ + CALLED(); + if (fExtractor == NULL) + return B_NO_INIT; + if (_data == NULL) + return B_BAD_VALUE; + + _data->MakeEmpty(); + + return fExtractor->GetStreamMetaData(fStream, _data); +} + + int64 BMediaTrack::CountFrames() const { diff --git a/src/kits/media/ReaderPlugin.cpp b/src/kits/media/ReaderPlugin.cpp index 739981f959..455471823e 100644 --- a/src/kits/media/ReaderPlugin.cpp +++ b/src/kits/media/ReaderPlugin.cpp @@ -1,4 +1,7 @@ /* + * Copyright 2009-2010, Stephan Aßmus . + * Distributed under the terms of the MIT License. + * * Copyright 2004, Marcus Overhagen. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -21,6 +24,13 @@ Reader::~Reader() } +status_t +Reader::GetMetaData(BMessage* _data) +{ + return B_NOT_SUPPORTED; +} + + status_t Reader::Seek(void* cookie, uint32 flags, int64* frame, bigtime_t* time) { @@ -35,6 +45,13 @@ Reader::FindKeyFrame(void* cookie, uint32 flags, int64* frame, bigtime_t* time) } +status_t +Reader::GetStreamMetaData(void* cookie, BMessage* _data) +{ + return B_NOT_SUPPORTED; +} + + BDataIO* Reader::Source() const { @@ -55,6 +72,7 @@ Reader::Perform(perform_code code, void* _data) return B_OK; } + void Reader::_ReservedReader1() {} void Reader::_ReservedReader2() {} void Reader::_ReservedReader3() {}