summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 01:23:21 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 01:23:21 +0000
commitac7a9e59634dee01ac68d1f8b4f049d68cbbd057 (patch)
treec962e8dcb53c933d782b5f0698a11e4f1896dae4 /media
parent4c967930c379e81f151e0132fe33b5925d1fc144 (diff)
downloadchromium_src-ac7a9e59634dee01ac68d1f8b4f049d68cbbd057.zip
chromium_src-ac7a9e59634dee01ac68d1f8b4f049d68cbbd057.tar.gz
chromium_src-ac7a9e59634dee01ac68d1f8b4f049d68cbbd057.tar.bz2
Returns AVERROR_EOF when FFmpeg is read at the end of file
BUG=18046 TEST=media_unittests --gtest_filter=FFmpegDemuxerTest.ProtocolRead FFmpeg may read over the size of a file. When it happens we should return AVERROR_EOF. Review URL: http://codereview.chromium.org/159679 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22133 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/ffmpeg_demuxer.cc6
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc15
2 files changed, 19 insertions, 2 deletions
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index 4ad463a..00e6531 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -304,6 +304,12 @@ int FFmpegDemuxer::Read(int size, uint8* data) {
if (read_has_failed_)
return AVERROR_IO;
+ // If the read position exceeds the size of the data source. We should return
+ // end-of-file directly.
+ int64 file_size;
+ if (data_source_->GetSize(&file_size) && read_position_ >= file_size)
+ return AVERROR_EOF;
+
// Asynchronous read from data source.
data_source_->Read(read_position_, size, data,
NewCallback(this, &FFmpegDemuxer::OnReadCompleted));
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index ccd0611..044e8ea 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -709,6 +709,8 @@ TEST_F(FFmpegDemuxerTest, ProtocolRead) {
uint8 kBuffer[1];
InSequence s;
// Actions taken in the first read.
+ EXPECT_CALL(*data_source_, GetSize(_))
+ .WillOnce(DoAll(SetArgumentPointee<0>(1024), Return(true)));
EXPECT_CALL(*data_source_, Read(0, 512, kBuffer, NotNull()))
.WillOnce(WithArgs<1, 3>(Invoke(&RunCallback)));
EXPECT_CALL(*demuxer, SignalReadCompleted(512));
@@ -716,25 +718,34 @@ TEST_F(FFmpegDemuxerTest, ProtocolRead) {
.WillOnce(Return(512));
// Second read.
+ EXPECT_CALL(*data_source_, GetSize(_))
+ .WillOnce(DoAll(SetArgumentPointee<0>(1024), Return(true)));
EXPECT_CALL(*data_source_, Read(512, 512, kBuffer, NotNull()))
.WillOnce(WithArgs<1, 3>(Invoke(&RunCallback)));
EXPECT_CALL(*demuxer, SignalReadCompleted(512));
EXPECT_CALL(*demuxer, WaitForRead())
.WillOnce(Return(512));
- // Called during SetPosition().
+ // Third read will fail because it exceeds the file size.
EXPECT_CALL(*data_source_, GetSize(_))
.WillOnce(DoAll(SetArgumentPointee<0>(1024), Return(true)));
// This read complete signal is generated when demuxer is stopped.
EXPECT_CALL(*demuxer, SignalReadCompleted(DataSource::kReadError));
+ // First read.
EXPECT_EQ(512, demuxer->Read(512, kBuffer));
int64 position;
EXPECT_TRUE(demuxer->GetPosition(&position));
EXPECT_EQ(512, position);
+
+ // Second read.
EXPECT_EQ(512, demuxer->Read(512, kBuffer));
- EXPECT_FALSE(demuxer->SetPosition(1024));
+ EXPECT_TRUE(demuxer->GetPosition(&position));
+ EXPECT_EQ(1024, position);
+
+ // Third read will get an end-of-file error.
+ EXPECT_EQ(AVERROR_EOF, demuxer->Read(512, kBuffer));
demuxer->Stop();
}