Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: media/filters/chunk_demuxer_unittest.cc

Issue 10829108: Cap sourceBuffered() on duration and truncate duration on EoS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated test Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "media/base/audio_decoder_config.h" 6 #include "media/base/audio_decoder_config.h"
7 #include "media/base/decoder_buffer.h" 7 #include "media/base/decoder_buffer.h"
8 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
9 #include "media/base/mock_demuxer_host.h" 9 #include "media/base/mock_demuxer_host.h"
10 #include "media/base/test_data_util.h" 10 #include "media/base/test_data_util.h"
(...skipping 29 matching lines...) Expand all
40 kVideoTrackSizeWidth; 40 kVideoTrackSizeWidth;
41 41
42 static const int kVideoTrackNum = 1; 42 static const int kVideoTrackNum = 1;
43 static const int kAudioTrackNum = 2; 43 static const int kAudioTrackNum = 2;
44 44
45 static const int kAudioBlockDuration = 23; 45 static const int kAudioBlockDuration = 23;
46 static const int kVideoBlockDuration = 33; 46 static const int kVideoBlockDuration = 33;
47 47
48 static const char* kSourceId = "SourceId"; 48 static const char* kSourceId = "SourceId";
49 static const char* kDefaultFirstClusterRange = "{ [0,46) }"; 49 static const char* kDefaultFirstClusterRange = "{ [0,46) }";
50 static const int kDefaultFirstClusterDuration = 66;
51 static const int kDefaultSecondClusterDuration = 132;
acolwell GONE FROM CHROMIUM 2012/08/01 17:09:45 nit: Duration is misleading here. The cluster isn'
vrk (LEFT CHROMIUM) 2012/08/02 18:23:00 Done.
50 52
51 base::TimeDelta kDefaultDuration() { 53 base::TimeDelta kDefaultDuration() {
52 return base::TimeDelta::FromMilliseconds(201224); 54 return base::TimeDelta::FromMilliseconds(201224);
53 } 55 }
54 56
55 // Write an integer into buffer in the form of vint that spans 8 bytes. 57 // Write an integer into buffer in the form of vint that spans 8 bytes.
56 // The data pointed by |buffer| should be at least 8 bytes long. 58 // The data pointed by |buffer| should be at least 8 bytes long.
57 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF. 59 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF.
58 static void WriteInt64(uint8* buffer, int64 number) { 60 static void WriteInt64(uint8* buffer, int64 number) {
59 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF)); 61 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF));
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 &video_read_done_1)); 1095 &video_read_done_1));
1094 1096
1095 end_of_stream_helper_1.RequestReads(); 1097 end_of_stream_helper_1.RequestReads();
1096 end_of_stream_helper_2.RequestReads(); 1098 end_of_stream_helper_2.RequestReads();
1097 1099
1098 EXPECT_TRUE(audio_read_done_1); 1100 EXPECT_TRUE(audio_read_done_1);
1099 EXPECT_TRUE(video_read_done_1); 1101 EXPECT_TRUE(video_read_done_1);
1100 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); 1102 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false);
1101 end_of_stream_helper_2.CheckIfReadDonesWereCalled(false); 1103 end_of_stream_helper_2.CheckIfReadDonesWereCalled(false);
1102 1104
1105 EXPECT_CALL(host_, SetDuration(
1106 base::TimeDelta::FromMilliseconds(kVideoBlockDuration)));
1103 demuxer_->EndOfStream(PIPELINE_OK); 1107 demuxer_->EndOfStream(PIPELINE_OK);
1104 1108
1105 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); 1109 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true);
1106 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); 1110 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true);
1107 } 1111 }
1108 1112
1109 // Make sure that all Read() calls after we get an EndOfStream() 1113 // Make sure that all Read() calls after we get an EndOfStream()
1110 // call return an "end of stream" buffer. 1114 // call return an "end of stream" buffer.
1111 TEST_F(ChunkDemuxerTest, TestReadsAfterEndOfStream) { 1115 TEST_F(ChunkDemuxerTest, TestReadsAfterEndOfStream) {
1112 ASSERT_TRUE(InitDemuxer(true, true, false)); 1116 ASSERT_TRUE(InitDemuxer(true, true, false));
(...skipping 19 matching lines...) Expand all
1132 video->Read(base::Bind(&OnReadDone, 1136 video->Read(base::Bind(&OnReadDone,
1133 base::TimeDelta::FromMilliseconds(0), 1137 base::TimeDelta::FromMilliseconds(0),
1134 &video_read_done_1)); 1138 &video_read_done_1));
1135 1139
1136 end_of_stream_helper_1.RequestReads(); 1140 end_of_stream_helper_1.RequestReads();
1137 1141
1138 EXPECT_TRUE(audio_read_done_1); 1142 EXPECT_TRUE(audio_read_done_1);
1139 EXPECT_TRUE(video_read_done_1); 1143 EXPECT_TRUE(video_read_done_1);
1140 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); 1144 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false);
1141 1145
1146 EXPECT_CALL(host_, SetDuration(
1147 base::TimeDelta::FromMilliseconds(kVideoBlockDuration)));
1142 EXPECT_TRUE(demuxer_->EndOfStream(PIPELINE_OK)); 1148 EXPECT_TRUE(demuxer_->EndOfStream(PIPELINE_OK));
1143 1149
1144 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); 1150 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true);
1145 1151
1146 // Request a few more reads and make sure we immediately get 1152 // Request a few more reads and make sure we immediately get
1147 // end of stream buffers. 1153 // end of stream buffers.
1148 end_of_stream_helper_2.RequestReads(); 1154 end_of_stream_helper_2.RequestReads();
1149 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); 1155 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true);
1150 1156
1151 end_of_stream_helper_3.RequestReads(); 1157 end_of_stream_helper_3.RequestReads();
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 scoped_ptr<Cluster> cluster_a( 1696 scoped_ptr<Cluster> cluster_a(
1691 GenerateSingleStreamCluster(0, 90, kAudioTrackNum, 90)); 1697 GenerateSingleStreamCluster(0, 90, kAudioTrackNum, 90));
1692 scoped_ptr<Cluster> cluster_v( 1698 scoped_ptr<Cluster> cluster_v(
1693 GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 100)); 1699 GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 100));
1694 1700
1695 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); 1701 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size()));
1696 ASSERT_TRUE(AppendData(cluster_v->data(), cluster_v->size())); 1702 ASSERT_TRUE(AppendData(cluster_v->data(), cluster_v->size()));
1697 1703
1698 CheckExpectedRanges("{ [0,90) }"); 1704 CheckExpectedRanges("{ [0,90) }");
1699 1705
1706 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(100)));
1700 demuxer_->EndOfStream(PIPELINE_OK); 1707 demuxer_->EndOfStream(PIPELINE_OK);
1701 1708
1702 CheckExpectedRanges("{ [0,100) }"); 1709 CheckExpectedRanges("{ [0,100) }");
1703 } 1710 }
1704 1711
1705 TEST_F(ChunkDemuxerTest, TestDifferentStreamTimecodes) { 1712 TEST_F(ChunkDemuxerTest, TestDifferentStreamTimecodes) {
1706 ASSERT_TRUE(InitDemuxer(true, true, false)); 1713 ASSERT_TRUE(InitDemuxer(true, true, false));
1707 1714
1708 scoped_refptr<DemuxerStream> audio = 1715 scoped_refptr<DemuxerStream> audio =
1709 demuxer_->GetStream(DemuxerStream::AUDIO); 1716 demuxer_->GetStream(DemuxerStream::AUDIO);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 1813
1807 ASSERT_TRUE(AppendData(audio_id, cluster_a1->data(), cluster_a1->size())); 1814 ASSERT_TRUE(AppendData(audio_id, cluster_a1->data(), cluster_a1->size()));
1808 ASSERT_TRUE(AppendData(video_id, cluster_v1->data(), cluster_v1->size())); 1815 ASSERT_TRUE(AppendData(video_id, cluster_v1->data(), cluster_v1->size()));
1809 ASSERT_TRUE(AppendData(video_id, cluster_v3->data(), cluster_v3->size())); 1816 ASSERT_TRUE(AppendData(video_id, cluster_v3->data(), cluster_v3->size()));
1810 1817
1811 CheckExpectedRanges(audio_id, "{ [0,35) }"); 1818 CheckExpectedRanges(audio_id, "{ [0,35) }");
1812 CheckExpectedRanges(video_id, "{ [0,10) [30,50) }"); 1819 CheckExpectedRanges(video_id, "{ [0,10) [30,50) }");
1813 1820
1814 // Make sure that end of stream fails because there is a gap between 1821 // Make sure that end of stream fails because there is a gap between
1815 // the current position(0) and the end of the appended data. 1822 // the current position(0) and the end of the appended data.
1823 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(50)));
1816 ASSERT_FALSE(demuxer_->EndOfStream(PIPELINE_OK)); 1824 ASSERT_FALSE(demuxer_->EndOfStream(PIPELINE_OK));
1817 1825
1818 // Seek to an time that is inside the last ranges for both streams 1826 // Seek to an time that is inside the last ranges for both streams
1819 // and verify that the EndOfStream() is successful. 1827 // and verify that the EndOfStream() is successful.
1820 demuxer_->StartWaitingForSeek(); 1828 demuxer_->StartWaitingForSeek();
1821 demuxer_->Seek(base::TimeDelta::FromMilliseconds(30), 1829 demuxer_->Seek(base::TimeDelta::FromMilliseconds(30),
1822 NewExpectedStatusCB(PIPELINE_OK)); 1830 NewExpectedStatusCB(PIPELINE_OK));
1823 1831
1824 ASSERT_TRUE(demuxer_->EndOfStream(PIPELINE_OK)); 1832 ASSERT_TRUE(demuxer_->EndOfStream(PIPELINE_OK));
1825 1833
(...skipping 30 matching lines...) Expand all
1856 1864
1857 ASSERT_TRUE(InitDemuxer(true, true, false)); 1865 ASSERT_TRUE(InitDemuxer(true, true, false));
1858 1866
1859 scoped_ptr<Cluster> cluster_a(kDefaultFirstCluster()); 1867 scoped_ptr<Cluster> cluster_a(kDefaultFirstCluster());
1860 scoped_ptr<Cluster> cluster_b(kDefaultSecondCluster()); 1868 scoped_ptr<Cluster> cluster_b(kDefaultSecondCluster());
1861 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); 1869 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size()));
1862 1870
1863 demuxer_->StartWaitingForSeek(); 1871 demuxer_->StartWaitingForSeek();
1864 1872
1865 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); 1873 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size()));
1874 EXPECT_CALL(host_, SetDuration(
1875 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterDuration)));
1866 demuxer_->EndOfStream(PIPELINE_OK); 1876 demuxer_->EndOfStream(PIPELINE_OK);
1867 1877
1868 demuxer_->Seek(base::TimeDelta::FromSeconds(0), 1878 demuxer_->Seek(base::TimeDelta::FromSeconds(0),
1869 NewExpectedStatusCB(PIPELINE_OK)); 1879 NewExpectedStatusCB(PIPELINE_OK));
1870 1880
1871 scoped_refptr<DemuxerStream> audio = 1881 scoped_refptr<DemuxerStream> audio =
1872 demuxer_->GetStream(DemuxerStream::AUDIO); 1882 demuxer_->GetStream(DemuxerStream::AUDIO);
1873 scoped_refptr<DemuxerStream> video = 1883 scoped_refptr<DemuxerStream> video =
1874 demuxer_->GetStream(DemuxerStream::VIDEO); 1884 demuxer_->GetStream(DemuxerStream::VIDEO);
1875 1885
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2136 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2127 // Append only part of the cluster data. 2137 // Append only part of the cluster data.
2128 ASSERT_TRUE(AppendData(cluster->data(), cluster->size() - 13)); 2138 ASSERT_TRUE(AppendData(cluster->data(), cluster->size() - 13));
2129 2139
2130 // Setting a timestamp should fail because we're in the middle of a cluster. 2140 // Setting a timestamp should fail because we're in the middle of a cluster.
2131 ASSERT_FALSE(demuxer_->SetTimestampOffset(kSourceId, 25)); 2141 ASSERT_FALSE(demuxer_->SetTimestampOffset(kSourceId, 25));
2132 } 2142 }
2133 2143
2134 TEST_F(ChunkDemuxerTest, TestDurationChange) { 2144 TEST_F(ChunkDemuxerTest, TestDurationChange) {
2135 ASSERT_TRUE(InitDemuxer(true, true, false)); 2145 ASSERT_TRUE(InitDemuxer(true, true, false));
2146 static const int kStreamDuration = kDefaultDuration().InMilliseconds();
2136 2147
2137 // Add data leading up to the currently set duration. 2148 // Add data leading up to the currently set duration.
2138 scoped_ptr<Cluster> first_cluster = GenerateCluster( 2149 scoped_ptr<Cluster> first_cluster = GenerateCluster(
2139 kDefaultDuration().InMilliseconds() - kAudioBlockDuration, 2150 kStreamDuration - kAudioBlockDuration,
2140 kDefaultDuration().InMilliseconds() - kVideoBlockDuration, 2); 2151 kStreamDuration - kVideoBlockDuration, 2);
2141 ASSERT_TRUE(AppendData(first_cluster->data(), first_cluster->size())); 2152 ASSERT_TRUE(AppendData(first_cluster->data(), first_cluster->size()));
2142 2153
2154 std::stringstream first_range;
2155 first_range << "{ [" << kStreamDuration - kVideoBlockDuration << "," <<
2156 kStreamDuration << ") }";
2157 CheckExpectedRanges(kSourceId, first_range.str());
acolwell GONE FROM CHROMIUM 2012/08/01 17:09:45 Just explicitly put the strings here and below. I'
vrk (LEFT CHROMIUM) 2012/08/02 18:23:00 Done, and I agree I think it's clearer this way.
2158
2159 // Add data at the currently set duration. The duration should not increase.
2160 scoped_ptr<Cluster> second_cluster = GenerateCluster(
2161 kDefaultDuration().InMilliseconds(), 2);
2162 ASSERT_TRUE(AppendData(second_cluster->data(), second_cluster->size()));
2163
2164 // Range should not be affected.
2165 CheckExpectedRanges(kSourceId, first_range.str());
2166
2143 // Now add data past the duration and expect a new duration to be signalled. 2167 // Now add data past the duration and expect a new duration to be signalled.
2144 scoped_ptr<Cluster> second_cluster = GenerateCluster( 2168 static const int kNewStreamDuration =
2145 kDefaultDuration().InMilliseconds(), 4); 2169 kStreamDuration + kAudioBlockDuration * 2;
2170 scoped_ptr<Cluster> third_cluster = GenerateCluster(
2171 kStreamDuration + kAudioBlockDuration,
2172 kStreamDuration + kVideoBlockDuration, 2);
2146 EXPECT_CALL(host_, SetDuration( 2173 EXPECT_CALL(host_, SetDuration(
2147 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2174 base::TimeDelta::FromMilliseconds(kNewStreamDuration)));
2148 kAudioBlockDuration * 2))); 2175 ASSERT_TRUE(AppendData(third_cluster->data(), third_cluster->size()));
2149 ASSERT_TRUE(AppendData(second_cluster->data(), second_cluster->size())); 2176
2177 // See that the range has increased appropriately.
2178 std::stringstream second_range;
2179 second_range << "{ [" << kStreamDuration - kVideoBlockDuration << "," <<
2180 kNewStreamDuration << ") }";
2181 CheckExpectedRanges(kSourceId, second_range.str());
2150 } 2182 }
2151 2183
2152 TEST_F(ChunkDemuxerTest, TestDurationChangeTimestampOffset) { 2184 TEST_F(ChunkDemuxerTest, TestDurationChangeTimestampOffset) {
2153 ASSERT_TRUE(InitDemuxer(true, true, false)); 2185 ASSERT_TRUE(InitDemuxer(true, true, false));
2154 2186
2155 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, 2187 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId,
2156 kDefaultDuration().InSecondsF())); 2188 kDefaultDuration().InSecondsF()));
2157 scoped_ptr<Cluster> cluster = GenerateCluster(0, 4); 2189 scoped_ptr<Cluster> cluster = GenerateCluster(0, 4);
2158 2190
2159 EXPECT_CALL(host_, SetDuration( 2191 EXPECT_CALL(host_, SetDuration(
2160 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2192 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2161 kAudioBlockDuration * 2))); 2193 kAudioBlockDuration * 2)));
2162 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); 2194 ASSERT_TRUE(AppendData(cluster->data(), cluster->size()));
2163 } 2195 }
2164 2196
2197 TEST_F(ChunkDemuxerTest, TestEndOfStreamTruncateDuration) {
2198 ASSERT_TRUE(InitDemuxer(true, true, false));
2199
2200 scoped_ptr<Cluster> cluster_a(kDefaultFirstCluster());
2201 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size()));
2202
2203 EXPECT_CALL(host_, SetDuration(
2204 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterDuration)));
2205 demuxer_->EndOfStream(PIPELINE_OK);
2206 }
2207
2165 } // namespace media 2208 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698