diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 21:49:49 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 21:49:49 +0000 |
commit | 38259a7a83545e07681d921564468844c7b03337 (patch) | |
tree | ceddb850f76be8ee565d9cc2d3d34d7ae445a1d7 /media | |
parent | 6b33da129646087bbc173a72c84e0690e91740de (diff) | |
download | chromium_src-38259a7a83545e07681d921564468844c7b03337.zip chromium_src-38259a7a83545e07681d921564468844c7b03337.tar.gz chromium_src-38259a7a83545e07681d921564468844c7b03337.tar.bz2 |
BufferedDataSource to support server without range request support
This patch will enable BufferedDataSource to support servers with
no range request support. It will start a probe request of 1 byte
size besides the regular request. If the server does not support
range request, we will turn on the is_streamed flag of FFmpeg and
will not do any seeking.
BUG=17628
TEST=test_shell_tests --gtest_filter=BufferedDataSource.*
Review URL: http://codereview.chromium.org/160076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/filter_host.h | 3 | ||||
-rw-r--r-- | media/base/filters.h | 5 | ||||
-rw-r--r-- | media/base/mock_filter_host.h | 1 | ||||
-rw-r--r-- | media/base/mock_filters.h | 2 | ||||
-rw-r--r-- | media/base/pipeline.h | 4 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 12 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 6 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.cc | 6 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.h | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer_unittest.cc | 6 | ||||
-rw-r--r-- | media/filters/ffmpeg_glue.cc | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_glue.h | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_glue_unittest.cc | 8 | ||||
-rw-r--r-- | media/filters/file_data_source.cc | 5 | ||||
-rw-r--r-- | media/filters/file_data_source.h | 2 |
15 files changed, 48 insertions, 18 deletions
diff --git a/media/base/filter_host.h b/media/base/filter_host.h index 5e70797..65aeebb 100644 --- a/media/base/filter_host.h +++ b/media/base/filter_host.h @@ -53,6 +53,9 @@ class FilterHost { // Sets the size of the video output in pixel units. virtual void SetVideoSize(size_t width, size_t height) = 0; + // Sets the flag to indicate that we are doing streaming. + virtual void SetStreaming(bool streaming) = 0; + protected: virtual ~FilterHost() {} }; diff --git a/media/base/filters.h b/media/base/filters.h index 8fdfe011..3faede5 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -174,8 +174,9 @@ class DataSource : public MediaFilter { // retrieved. virtual bool GetSize(int64* size_out) = 0; - // Returns true if this data source supports random seeking. - virtual bool IsSeekable() = 0; + // Returns true if we are performing streaming. In this case seeking is + // not possible. + virtual bool IsStreaming() = 0; }; diff --git a/media/base/mock_filter_host.h b/media/base/mock_filter_host.h index 8bab1b5..a7150c2 100644 --- a/media/base/mock_filter_host.h +++ b/media/base/mock_filter_host.h @@ -36,6 +36,7 @@ class MockFilterHost : public FilterHost { MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); MOCK_METHOD1(SetBufferedBytes, void(int64 buffered_bytes)); MOCK_METHOD2(SetVideoSize, void(size_t width, size_t height)); + MOCK_METHOD1(SetStreaming, void(bool streamed)); private: DISALLOW_COPY_AND_ASSIGN(MockFilterHost); diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 7954aa9..d3546c4 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -102,7 +102,7 @@ class MockDataSource : public DataSource { MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data, DataSource::ReadCallback* callback)); MOCK_METHOD1(GetSize, bool(int64* size_out)); - MOCK_METHOD0(IsSeekable, bool()); + MOCK_METHOD0(IsStreaming, bool()); protected: virtual ~MockDataSource() {} diff --git a/media/base/pipeline.h b/media/base/pipeline.h index c0286e5..b54d442 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -147,6 +147,10 @@ class Pipeline : public base::RefCountedThreadSafe<Pipeline> { // or the video has not been rendered yet, the width and height will be 0. virtual void GetVideoSize(size_t* width_out, size_t* height_out) const = 0; + // If this method returns true, that means the data source is a streaming + // data source. Seeking may not be possible. + virtual bool IsStreaming() const = 0; + // Gets the current error status for the pipeline. If the pipeline is // operating correctly, this will return OK. virtual PipelineError GetError() const = 0; diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index a09c2c7..10ab9a3 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -237,6 +237,11 @@ void PipelineImpl::GetVideoSize(size_t* width_out, size_t* height_out) const { *height_out = video_height_; } +bool PipelineImpl::IsStreaming() const { + AutoLock auto_lock(lock_); + return streaming_; +} + PipelineError PipelineImpl::GetError() const { AutoLock auto_lock(lock_); return error_; @@ -249,6 +254,7 @@ void PipelineImpl::ResetState() { duration_ = kZero; buffered_time_ = kZero; buffered_bytes_ = 0; + streaming_ = false; total_bytes_ = 0; video_width_ = 0; video_height_ = 0; @@ -343,6 +349,12 @@ void PipelineImpl::SetVideoSize(size_t width, size_t height) { video_height_ = height; } +void PipelineImpl::SetStreaming(bool streaming) { + DCHECK(IsRunning()); + AutoLock auto_lock(lock_); + streaming_ = streaming; +} + void PipelineImpl::InsertRenderedMimeType(const std::string& major_mime_type) { DCHECK(IsRunning()); AutoLock auto_lock(lock_); diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index 02c8bce..e83822d 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -81,6 +81,7 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual int64 GetBufferedBytes() const; virtual int64 GetTotalBytes() const; virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; + virtual bool IsStreaming() const; virtual PipelineError GetError() const; private: @@ -129,6 +130,7 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual void SetTotalBytes(int64 total_bytes); virtual void SetBufferedBytes(int64 buffered_bytes); virtual void SetVideoSize(size_t width, size_t height); + virtual void SetStreaming(bool streamed); // Method called during initialization to insert a mime type into the // |rendered_mime_types_| set. @@ -267,6 +269,10 @@ class PipelineImpl : public Pipeline, public FilterHost { size_t video_width_; size_t video_height_; + // Sets by the filters to indicate whether the data source is a streaming + // source. + bool streaming_; + // Current volume level (from 0.0f to 1.0f). This value is set immediately // via SetVolume() and a task is dispatched on the message loop to notify the // filters. diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index 189aac4..4ad463a 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -345,8 +345,10 @@ bool FFmpegDemuxer::GetSize(int64* size_out) { return data_source_->GetSize(size_out); } -bool FFmpegDemuxer::IsStreamed() { - return false; +bool FFmpegDemuxer::IsStreaming() { + DCHECK(data_source_); + + return data_source_->IsStreaming(); } void FFmpegDemuxer::InitializeTask(DataSource* data_source, diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index 0777855..c897ca4 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -136,7 +136,7 @@ class FFmpegDemuxer : public Demuxer, virtual bool GetPosition(int64* position_out); virtual bool SetPosition(int64 position); virtual bool GetSize(int64* size_out); - virtual bool IsStreamed(); + virtual bool IsStreaming(); private: // Only allow a factory to create this class. diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index e8c9df7..ccd0611 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -776,12 +776,14 @@ TEST_F(FFmpegDemuxerTest, ProtocolGetSize) { EXPECT_EQ(1024, size); } -TEST_F(FFmpegDemuxerTest, ProtocolIsStreamed) { +TEST_F(FFmpegDemuxerTest, ProtocolIsStreaming) { { SCOPED_TRACE(""); InitializeDemuxer(); } - EXPECT_FALSE(demuxer_->IsStreamed()); + EXPECT_CALL(*data_source_, IsStreaming()) + .WillOnce(Return(false)); + EXPECT_FALSE(demuxer_->IsStreaming()); } } // namespace media diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc index 135b3bb..35e35c91 100644 --- a/media/filters/ffmpeg_glue.cc +++ b/media/filters/ffmpeg_glue.cc @@ -22,7 +22,7 @@ int OpenContext(URLContext* h, const char* filename, int flags) { h->priv_data = protocol; h->flags = URL_RDONLY; - h->is_streamed = protocol->IsStreamed(); + h->is_streamed = protocol->IsStreaming(); return 0; } diff --git a/media/filters/ffmpeg_glue.h b/media/filters/ffmpeg_glue.h index 228c964..bc39ab2 100644 --- a/media/filters/ffmpeg_glue.h +++ b/media/filters/ffmpeg_glue.h @@ -62,7 +62,7 @@ class FFmpegURLProtocol { virtual bool GetSize(int64* size_out) = 0; // Returns false if this protocol supports random seeking. - virtual bool IsStreamed() = 0; + virtual bool IsStreaming() = 0; private: DISALLOW_COPY_AND_ASSIGN(FFmpegURLProtocol); diff --git a/media/filters/ffmpeg_glue_unittest.cc b/media/filters/ffmpeg_glue_unittest.cc index 904f6a5..303a8ba 100644 --- a/media/filters/ffmpeg_glue_unittest.cc +++ b/media/filters/ffmpeg_glue_unittest.cc @@ -26,7 +26,7 @@ class MockProtocol : public FFmpegURLProtocol { MOCK_METHOD1(GetPosition, bool(int64* position_out)); MOCK_METHOD1(SetPosition, bool(int64 position)); MOCK_METHOD1(GetSize, bool(int64* size_out)); - MOCK_METHOD0(IsStreamed, bool()); + MOCK_METHOD0(IsStreaming, bool()); private: DISALLOW_COPY_AND_ASSIGN(MockProtocol); @@ -45,8 +45,8 @@ class FFmpegGlueTest : public ::testing::Test { // Helper to open a URLContext pointing to the given mocked protocol. // Callers are expected to close the context at the end of their test. virtual void OpenContext(MockProtocol* protocol, URLContext* context) { - // IsStreamed() is called when opening. - EXPECT_CALL(*protocol, IsStreamed()).WillOnce(Return(true)); + // IsStreaming() is called when opening. + EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); // Add the protocol to the glue layer and open a context. std::string key = FFmpegGlue::get()->AddProtocol(protocol); @@ -144,7 +144,7 @@ TEST_F(FFmpegGlueTest, OpenClose) { // Create our protocol and add them to the glue layer. scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( new StrictMock<Destroyable<MockProtocol> >()); - EXPECT_CALL(*protocol, IsStreamed()).WillOnce(Return(true)); + EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); std::string key = glue->AddProtocol(protocol.get()); // Prepare FFmpeg URLContext structure. diff --git a/media/filters/file_data_source.cc b/media/filters/file_data_source.cc index a6c381c..b14ad9f 100644 --- a/media/filters/file_data_source.cc +++ b/media/filters/file_data_source.cc @@ -101,9 +101,8 @@ bool FileDataSource::GetSize(int64* size_out) { return (NULL != file_); } -bool FileDataSource::IsSeekable() { - // A file data source is always seekable. - return true; +bool FileDataSource::IsStreaming() { + return false; } } // namespace media diff --git a/media/filters/file_data_source.h b/media/filters/file_data_source.h index 760b7c5..164e74c 100644 --- a/media/filters/file_data_source.h +++ b/media/filters/file_data_source.h @@ -31,7 +31,7 @@ class FileDataSource : public DataSource { virtual void Read(int64 position, size_t size, uint8* data, ReadCallback* read_callback); virtual bool GetSize(int64* size_out); - virtual bool IsSeekable(); + virtual bool IsStreaming(); private: // Only allow factories and tests to create this object. |