summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 01:23:46 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 01:23:46 +0000
commit91fa49e706cbb796d6eaa1f6d5c95cc7b277db58 (patch)
treee1bef5ff6e1c3bcf55ee1e49ed1222755549f6c4
parent133a3ba58877c351acfae890f7c75d112c7fb112 (diff)
downloadchromium_src-91fa49e706cbb796d6eaa1f6d5c95cc7b277db58.zip
chromium_src-91fa49e706cbb796d6eaa1f6d5c95cc7b277db58.tar.gz
chromium_src-91fa49e706cbb796d6eaa1f6d5c95cc7b277db58.tar.bz2
Checking in media::MediaFormat class, which describes the output of a filter.
Review URL: http://codereview.chromium.org/13149 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6412 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/base/media.cc3
-rw-r--r--media/base/media_format.cc126
-rw-r--r--media/base/media_format.h86
-rw-r--r--media/build/media.vcproj8
-rw-r--r--media/media_lib.scons1
5 files changed, 223 insertions, 1 deletions
diff --git a/media/base/media.cc b/media/base/media.cc
index 92370bf..91486ee 100644
--- a/media/base/media.cc
+++ b/media/base/media.cc
@@ -4,6 +4,7 @@
#include "media/base/buffers.h"
#include "media/base/filters.h"
+#include "media/base/media_format.h"
namespace media {
@@ -11,4 +12,4 @@ namespace media {
void DoNothing() {
}
-} // namespace media
+} // namespace media
diff --git a/media/base/media_format.cc b/media/base/media_format.cc
new file mode 100644
index 0000000..c675a73
--- /dev/null
+++ b/media/base/media_format.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/media_format.h"
+
+namespace media {
+
+namespace mime_type {
+
+// Represents a URI, typically used to create a DataSourceInterface.
+// Expected keys:
+// kUri String The URI
+const std::wstring kURI(L"text/x-uri");
+
+// Represents a generic byte stream, typically from a DataSourceInterface.
+// Expected keys:
+// None
+const std::wstring kApplicationOctetStream(L"application/octet-stream");
+
+// Represents encoded audio data, typically from an DemuxerStreamInterface.
+// Expected keys:
+// None
+const std::wstring kMPEGAudio(L"audio/mpeg");
+const std::wstring kAACAudio(L"audio/aac");
+
+// Represents encoded video data, typically from a DemuxerStreamInterface.
+// Expected keys:
+// None
+const std::wstring kH264AnnexB(L"video/x-h264-annex-b");
+
+// Represents decoded audio data, typically from an AudioDecoderInterface.
+// Expected keys:
+// kChannels Integer Number of audio channels
+// kSampleRate Integer Audio sample rate (i.e., 44100)
+// kSampleBits Integer Audio bits-per-sample (i.e., 16)
+const std::wstring kRawAudio(L"audio/x-uncompressed");
+
+// Represents decoded video data, typically from a VideoDecoderInterface.
+// Other information, such as surface format (i.e., YV12), stride and planes are
+// included with the buffer itself and is not part of the MediaFormat.
+// Expected keys:
+// kWidth Integer Display width of the surface
+// kHeight Integer Display height of the surface
+const std::wstring kRawVideo(L"video/x-uncompressed");
+
+// Represents FFmpeg encoded packets, typically from an DemuxerStreamInterface.
+// Expected keys:
+// kFfmpegCodecId Integer The FFmpeg CodecID identifying the decoder
+const std::wstring kFFmpegAudio(L"audio/x-ffmpeg");
+const std::wstring kFFmpegVideo(L"video/x-ffmpeg");
+
+} // namespace mime_type
+
+// Common keys.
+const std::wstring MediaFormat::kMimeType(L"MimeType");
+const std::wstring MediaFormat::kURI(L"Uri");
+const std::wstring MediaFormat::kSurfaceFormat(L"SurfaceFormat");
+const std::wstring MediaFormat::kSampleRate(L"SampleRate");
+const std::wstring MediaFormat::kSampleBits(L"SampleBits");
+const std::wstring MediaFormat::kChannels(L"Channels");
+const std::wstring MediaFormat::kWidth(L"Width");
+const std::wstring MediaFormat::kHeight(L"Height");
+const std::wstring MediaFormat::kFfmpegCodecId(L"FfmpegCodecId");
+
+MediaFormat::MediaFormat() {
+}
+
+MediaFormat::~MediaFormat() {
+ Clear();
+}
+
+bool MediaFormat::Contains(const std::wstring& key) const {
+ return value_map_.find(key) != value_map_.end();
+}
+
+void MediaFormat::Clear() {
+ for (ValueMap::iterator iter(value_map_.begin());
+ iter != value_map_.end(); iter = value_map_.erase(iter))
+ delete iter->second;
+}
+
+void MediaFormat::SetAsBoolean(const std::wstring& key, bool in_value) {
+ value_map_[key] = Value::CreateBooleanValue(in_value);
+}
+
+void MediaFormat::SetAsInteger(const std::wstring& key, int in_value) {
+ value_map_[key] = Value::CreateIntegerValue(in_value);
+}
+
+void MediaFormat::SetAsReal(const std::wstring& key, double in_value) {
+ value_map_[key] = Value::CreateRealValue(in_value);
+}
+
+void MediaFormat::SetAsString(const std::wstring& key,
+ const std::wstring& in_value) {
+ value_map_[key] = Value::CreateStringValue(in_value);
+}
+
+bool MediaFormat::GetAsBoolean(const std::wstring& key, bool* out_value) const {
+ Value* value = GetValue(key);
+ return value != NULL && value->GetAsBoolean(out_value);
+}
+
+bool MediaFormat::GetAsInteger(const std::wstring& key, int* out_value) const {
+ Value* value = GetValue(key);
+ return value != NULL && value->GetAsInteger(out_value);
+}
+
+bool MediaFormat::GetAsReal(const std::wstring& key, double* out_value) const {
+ Value* value = GetValue(key);
+ return value != NULL && value->GetAsReal(out_value);
+}
+
+bool MediaFormat::GetAsString(const std::wstring& key,
+ std::wstring* out_value) const {
+ Value* value = GetValue(key);
+ return value != NULL && value->GetAsString(out_value);
+}
+
+Value* MediaFormat::GetValue(const std::wstring& key) const {
+ ValueMap::const_iterator value_iter = value_map_.find(key);
+ return (value_iter == value_map_.end()) ? NULL : value_iter->second;
+}
+
+} // namespace media
diff --git a/media/base/media_format.h b/media/base/media_format.h
new file mode 100644
index 0000000..d1303a2
--- /dev/null
+++ b/media/base/media_format.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_MEDIA_FORMAT_H_
+#define MEDIA_BASE_MEDIA_FORMAT_H_
+
+#include "base/values.h"
+
+namespace media {
+
+// Common MIME types.
+namespace mime_type {
+extern const std::wstring kURI;
+extern const std::wstring kApplicationOctetStream;
+extern const std::wstring kMPEGAudio;
+extern const std::wstring kAACAudio;
+extern const std::wstring kH264AnnexB;
+extern const std::wstring kUncompressedAudio;
+extern const std::wstring kUncompressedVideo;
+extern const std::wstring kFFmpegAudio;
+extern const std::wstring kFFmpegVideo;
+} // namespace mime_type
+
+// MediaFormat is used to describe the output of a MediaFilterInterface to
+// determine whether a downstream filter can accept the output from an upstream
+// filter. In general, every MediaFormat contains a MIME type describing
+// its output as well as additional key-values describing additional details.
+//
+// For example, an audio decoder could output audio/x-uncompressed and include
+// additional key-values such as the number of channels and the sample rate.
+// An audio renderer would use this information to properly initialize the
+// audio hardware before playback started.
+//
+// It's also perfectly acceptable to create your own MIME types and standards
+// to allow communication between two filters that goes beyond the basics
+// described here. For example, you could write a video decoder that outputs
+// a MIME type video/x-special for which your video renderer knows it's some
+// special form of decompressed video output that regular video renderers
+// couldn't handle.
+class MediaFormat {
+ public:
+ // Common keys.
+ static const std::wstring kMimeType;
+ static const std::wstring kURI;
+ static const std::wstring kSurfaceFormat;
+ static const std::wstring kSampleRate;
+ static const std::wstring kSampleBits;
+ static const std::wstring kChannels;
+ static const std::wstring kWidth;
+ static const std::wstring kHeight;
+ static const std::wstring kFfmpegCodecId;
+
+ MediaFormat();
+ ~MediaFormat();
+
+ // Basic map operations.
+ bool empty() const { return value_map_.empty(); }
+
+ bool Contains(const std::wstring& key) const;
+
+ void Clear();
+
+ // Value accessors.
+ void SetAsBoolean(const std::wstring& key, bool in_value);
+ void SetAsInteger(const std::wstring& key, int in_value);
+ void SetAsReal(const std::wstring& key, double in_value);
+ void SetAsString(const std::wstring& key, const std::wstring& in_value);
+
+ bool GetAsBoolean(const std::wstring& key, bool* out_value) const;
+ bool GetAsInteger(const std::wstring& key, int* out_value) const;
+ bool GetAsReal(const std::wstring& key, double* out_value) const;
+ bool GetAsString(const std::wstring& key, std::wstring* out_value) const;
+
+ private:
+ // Helper to return a value.
+ Value* GetValue(const std::wstring& key) const;
+
+ ValueMap value_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaFormat);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_MEDIA_FORMAT_H_
diff --git a/media/build/media.vcproj b/media/build/media.vcproj
index fd20b15..641abc2 100644
--- a/media/build/media.vcproj
+++ b/media/build/media.vcproj
@@ -136,6 +136,14 @@
RelativePath="..\base\media.cc"
>
</File>
+ <File
+ RelativePath="..\base\media_format.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\base\media_format.h"
+ >
+ </File>
</Filter>
</Files>
<Globals>
diff --git a/media/media_lib.scons b/media/media_lib.scons
index ba044e6..9f016c4 100644
--- a/media/media_lib.scons
+++ b/media/media_lib.scons
@@ -26,6 +26,7 @@ env.Prepend(
# cross-platform live below.
input_files = [
'base/media.cc',
+ 'base/media_format.cc',
]
if env['PLATFORM'] == 'win32':