summaryrefslogtreecommitdiffstats
path: root/media/base/data_source.h
diff options
context:
space:
mode:
authoracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 17:14:25 +0000
committeracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 17:14:25 +0000
commit236119cf32eb61f4b775ba573ecf46a1c504e7a3 (patch)
tree9a292fdefecf37aa48d448f3f7706ab5521e4d33 /media/base/data_source.h
parent7046bfcb6c8f46d0693c129d52de27bc68042af7 (diff)
downloadchromium_src-236119cf32eb61f4b775ba573ecf46a1c504e7a3.zip
chromium_src-236119cf32eb61f4b775ba573ecf46a1c504e7a3.tar.gz
chromium_src-236119cf32eb61f4b775ba573ecf46a1c504e7a3.tar.bz2
Removing DataSource from Filter hierarchy and refactoring FilterHost into DemuxerHost & DataSourceHost.
Over the last year, several refactorings have caused DataSource to have almost nothing in common with the Filter interface. This change removes it from the Filter class hierarchy and splits up the FilterHost interface so that DataSource, Demuxer, and Filter have their own host interfaces. Splitting FilterHost improves encapsulation and makes it easier to reason about which host methods are required by different parts of the code. BUG= TEST=media_unittests Review URL: http://codereview.chromium.org/8936014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/data_source.h')
-rw-r--r--media/base/data_source.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/media/base/data_source.h b/media/base/data_source.h
new file mode 100644
index 0000000..9de147e
--- /dev/null
+++ b/media/base/data_source.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 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_DATA_SOURCE_H_
+#define MEDIA_BASE_DATA_SOURCE_H_
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
+#include "media/base/preload.h"
+
+namespace media {
+
+class MEDIA_EXPORT DataSourceHost {
+ public:
+ virtual ~DataSourceHost();
+
+ // Set the total size of the media file.
+ virtual void SetTotalBytes(int64 total_bytes) = 0;
+
+ // Sets the total number of bytes that are buffered on the client and ready to
+ // be played.
+ virtual void SetBufferedBytes(int64 buffered_bytes) = 0;
+
+ // Sets the flag to indicate current network activity.
+ virtual void SetNetworkActivity(bool is_downloading_data) = 0;
+};
+
+class MEDIA_EXPORT DataSource : public base::RefCountedThreadSafe<DataSource> {
+ public:
+ typedef base::Callback<void(int64, int64)> StatusCallback;
+ typedef base::Callback<void(size_t)> ReadCallback;
+ static const size_t kReadError;
+
+ DataSource();
+
+ virtual void set_host(DataSourceHost* host);
+
+ // Reads |size| bytes from |position| into |data|. And when the read is done
+ // or failed, |read_callback| is called with the number of bytes read or
+ // kReadError in case of error.
+ // TODO(hclam): should change |size| to int! It makes the code so messy
+ // with size_t and int all over the place..
+ virtual void Read(int64 position, size_t size,
+ uint8* data,
+ const DataSource::ReadCallback& read_callback) = 0;
+
+ // Notifies the DataSource of a change in the current playback rate.
+ virtual void SetPlaybackRate(float playback_rate);
+
+ // Stops the DataSource. Once this is called all future Read() calls will
+ // return an error.
+ virtual void Stop(const base::Closure& callback) = 0;
+
+ // Returns true and the file size, false if the file size could not be
+ // retrieved.
+ virtual bool GetSize(int64* size_out) = 0;
+
+ // Returns true if we are performing streaming. In this case seeking is
+ // not possible.
+ virtual bool IsStreaming() = 0;
+
+ // Alert the DataSource that the video preload value has been changed.
+ virtual void SetPreload(Preload preload) = 0;
+
+ // Notify the DataSource of the bitrate of the media.
+ // Values of |bitrate| <= 0 are invalid and should be ignored.
+ virtual void SetBitrate(int bitrate) = 0;
+
+ protected:
+ // Only allow scoped_refptr<> to delete DataSource.
+ friend class base::RefCountedThreadSafe<DataSource>;
+ virtual ~DataSource();
+
+ DataSourceHost* host();
+
+ private:
+ DataSourceHost* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataSource);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_DATA_SOURCE_H_