OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <deque> | 5 #include <deque> |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 virtual ~FFmpegDemuxerTest() { | 53 virtual ~FFmpegDemuxerTest() { |
54 // Call Stop() to shut down internal threads. | 54 // Call Stop() to shut down internal threads. |
55 demuxer_->Stop(NewExpectedCallback()); | 55 demuxer_->Stop(NewExpectedCallback()); |
56 | 56 |
57 // Finish up any remaining tasks. | 57 // Finish up any remaining tasks. |
58 message_loop_.RunAllPending(); | 58 message_loop_.RunAllPending(); |
59 // Release the reference to the demuxer. | 59 // Release the reference to the demuxer. |
60 demuxer_ = NULL; | 60 demuxer_ = NULL; |
61 } | 61 } |
62 | 62 |
63 scoped_refptr<DataSource> CreateDataSource(const std::string& name) { | 63 scoped_refptr<FileDataSource> CreateDataSource(const std::string& name) { |
| 64 return CreateDataSource(name, false); |
| 65 } |
| 66 |
| 67 scoped_refptr<FileDataSource> CreateDataSource(const std::string& name, |
| 68 bool disable_file_size) { |
64 FilePath file_path; | 69 FilePath file_path; |
65 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | 70 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); |
66 | 71 |
67 file_path = file_path.Append(FILE_PATH_LITERAL("media")) | 72 file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
68 .Append(FILE_PATH_LITERAL("test")) | 73 .Append(FILE_PATH_LITERAL("test")) |
69 .Append(FILE_PATH_LITERAL("data")) | 74 .Append(FILE_PATH_LITERAL("data")) |
70 .AppendASCII(name); | 75 .AppendASCII(name); |
71 | 76 |
72 scoped_refptr<FileDataSource> data_source = new FileDataSource(); | 77 scoped_refptr<FileDataSource> data_source = new FileDataSource( |
| 78 disable_file_size); |
73 | 79 |
74 EXPECT_EQ(PIPELINE_OK, data_source->Initialize(file_path.MaybeAsASCII())); | 80 EXPECT_EQ(PIPELINE_OK, data_source->Initialize(file_path.MaybeAsASCII())); |
75 | 81 |
76 return data_source.get(); | 82 return data_source.get(); |
77 } | 83 } |
78 | 84 |
79 MOCK_METHOD1(CheckPoint, void(int v)); | 85 MOCK_METHOD1(CheckPoint, void(int v)); |
80 | 86 |
81 // Initializes FFmpegDemuxer. | 87 // Initializes FFmpegDemuxer. |
82 void InitializeDemuxer(const scoped_refptr<DataSource>& data_source) { | 88 void InitializeDemuxer(const scoped_refptr<DataSource>& data_source) { |
(...skipping 11 matching lines...) Expand all Loading... |
94 std::string location_str; | 100 std::string location_str; |
95 location.Write(true, false, &location_str); | 101 location.Write(true, false, &location_str); |
96 location_str += "\n"; | 102 location_str += "\n"; |
97 SCOPED_TRACE(location_str); | 103 SCOPED_TRACE(location_str); |
98 EXPECT_TRUE(buffer.get() != NULL); | 104 EXPECT_TRUE(buffer.get() != NULL); |
99 EXPECT_EQ(size, buffer->GetDataSize()); | 105 EXPECT_EQ(size, buffer->GetDataSize()); |
100 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), | 106 EXPECT_EQ(base::TimeDelta::FromMicroseconds(timestampInMicroseconds), |
101 buffer->GetTimestamp()); | 107 buffer->GetTimestamp()); |
102 } | 108 } |
103 | 109 |
| 110 // Creates a data source with the given |file_name|. If |disable_file_size| |
| 111 // then the data source pretends it does not know the file size (e.g. often |
| 112 // when streaming video). Uses this data source to initialize a demuxer, then |
| 113 // returns true if the bitrate is valid, false otherwise. |
| 114 bool VideoHasValidBitrate( |
| 115 const std::string& file_name, bool disable_file_size) { |
| 116 scoped_refptr<FileDataSource> data_source = |
| 117 CreateDataSource(file_name, disable_file_size); |
| 118 InitializeDemuxer(data_source); |
| 119 return demuxer_->GetBitrate() > 0; |
| 120 } |
| 121 |
104 // Fixture members. | 122 // Fixture members. |
105 scoped_refptr<FFmpegDemuxer> demuxer_; | 123 scoped_refptr<FFmpegDemuxer> demuxer_; |
106 StrictMock<MockFilterHost> host_; | 124 StrictMock<MockFilterHost> host_; |
107 MessageLoop message_loop_; | 125 MessageLoop message_loop_; |
108 | 126 |
109 int64 current_read_position_; | 127 int64 current_read_position_; |
110 | 128 |
111 private: | 129 private: |
112 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); | 130 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); |
113 }; | 131 }; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 509 |
492 // Third read will get an end-of-file error, which is represented as zero. | 510 // Third read will get an end-of-file error, which is represented as zero. |
493 EXPECT_EQ(0, demuxer->Read(512, kBuffer)); | 511 EXPECT_EQ(0, demuxer->Read(512, kBuffer)); |
494 | 512 |
495 // This read complete signal is generated when demuxer is stopped. | 513 // This read complete signal is generated when demuxer is stopped. |
496 EXPECT_CALL(*demuxer, SignalReadCompleted(DataSource::kReadError)); | 514 EXPECT_CALL(*demuxer, SignalReadCompleted(DataSource::kReadError)); |
497 demuxer->Stop(NewExpectedCallback()); | 515 demuxer->Stop(NewExpectedCallback()); |
498 message_loop_.RunAllPending(); | 516 message_loop_.RunAllPending(); |
499 } | 517 } |
500 | 518 |
| 519 TEST_F(FFmpegDemuxerTest, GetBitrate_SetInContainer) { |
| 520 EXPECT_TRUE(VideoHasValidBitrate("bear.ogv", false)); |
| 521 } |
| 522 |
| 523 TEST_F(FFmpegDemuxerTest, GetBitrate_UnsetInContainer_KnownSize) { |
| 524 EXPECT_TRUE(VideoHasValidBitrate("bear-320x240.webm", false)); |
| 525 } |
| 526 |
| 527 TEST_F(FFmpegDemuxerTest, GetBitrate_SetInContainer_NoFileSize) { |
| 528 EXPECT_TRUE(VideoHasValidBitrate("bear.ogv", true)); |
| 529 } |
| 530 |
| 531 TEST_F(FFmpegDemuxerTest, GetBitrate_UnsetInContainer_NoFileSize) { |
| 532 EXPECT_FALSE(VideoHasValidBitrate("bear-320x240.webm", true)); |
| 533 } |
| 534 |
501 TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) { | 535 TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) { |
502 scoped_refptr<DataSource> data_source = CreateDataSource("bear-320x240.webm"); | 536 scoped_refptr<DataSource> data_source = CreateDataSource("bear-320x240.webm"); |
503 InitializeDemuxer(data_source); | 537 InitializeDemuxer(data_source); |
504 | 538 |
505 InSequence s; | 539 InSequence s; |
506 | 540 |
507 int64 size; | 541 int64 size; |
508 int64 position; | 542 int64 position; |
509 EXPECT_TRUE(demuxer_->GetSize(&size)); | 543 EXPECT_TRUE(demuxer_->GetSize(&size)); |
510 EXPECT_TRUE(demuxer_->GetPosition(&position)); | 544 EXPECT_TRUE(demuxer_->GetPosition(&position)); |
(...skipping 21 matching lines...) Expand all Loading... |
532 | 566 |
533 TEST_F(FFmpegDemuxerTest, ProtocolIsStreaming) { | 567 TEST_F(FFmpegDemuxerTest, ProtocolIsStreaming) { |
534 scoped_refptr<DataSource> data_source = CreateDataSource("bear-320x240.webm"); | 568 scoped_refptr<DataSource> data_source = CreateDataSource("bear-320x240.webm"); |
535 InitializeDemuxer(data_source); | 569 InitializeDemuxer(data_source); |
536 | 570 |
537 EXPECT_FALSE(data_source->IsStreaming()); | 571 EXPECT_FALSE(data_source->IsStreaming()); |
538 EXPECT_FALSE(demuxer_->IsStreaming()); | 572 EXPECT_FALSE(demuxer_->IsStreaming()); |
539 } | 573 } |
540 | 574 |
541 } // namespace media | 575 } // namespace media |
OLD | NEW |