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

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

Issue 256583006: Fix possible buffer emission during an abort. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CR comments. Created 6 years, 7 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
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
319 if (!has_audio && !has_video) { 319 if (!has_audio && !has_video) {
320 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); 320 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO);
321 } 321 }
322 322
323 return demuxer_->AddId(source_id, type, codecs, 323 return demuxer_->AddId(source_id, type, codecs,
324 use_legacy_frame_processor_); 324 use_legacy_frame_processor_);
325 } 325 }
326 326
327 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) {
328 std::vector<std::string> codecs;
329 std::string type;
330 codecs.push_back("mp4a.40.2");
331 codecs.push_back("avc1.640028");
332 type = "video/mp2t";
333 return demuxer_->AddId(source_id, type, codecs,
334 use_legacy_frame_processor_);
335 }
336
327 void AppendData(const uint8* data, size_t length) { 337 void AppendData(const uint8* data, size_t length) {
328 AppendData(kSourceId, data, length); 338 AppendData(kSourceId, data, length);
329 } 339 }
330 340
331 void AppendCluster(const std::string& source_id, 341 void AppendCluster(const std::string& source_id,
332 scoped_ptr<Cluster> cluster) { 342 scoped_ptr<Cluster> cluster) {
333 AppendData(source_id, cluster->data(), cluster->size()); 343 AppendData(source_id, cluster->data(), cluster->size());
334 } 344 }
335 345
336 void AppendCluster(scoped_ptr<Cluster> cluster) { 346 void AppendCluster(scoped_ptr<Cluster> cluster) {
(...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2718 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { 2728 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) {
2719 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2729 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2720 2730
2721 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2731 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2722 // Append only part of the cluster data. 2732 // Append only part of the cluster data.
2723 AppendData(cluster->data(), cluster->size() - 13); 2733 AppendData(cluster->data(), cluster->size() - 13);
2724 2734
2725 // Confirm we're in the middle of parsing a media segment. 2735 // Confirm we're in the middle of parsing a media segment.
2726 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 2736 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
2727 2737
2728 demuxer_->Abort(kSourceId); 2738 demuxer_->Abort(kSourceId,
2739 append_window_start_for_next_append_,
2740 append_window_end_for_next_append_,
2741 &timestamp_offset_map_[kSourceId]);
2742
2729 // After Abort(), parsing should no longer be in the middle of a media 2743 // After Abort(), parsing should no longer be in the middle of a media
2730 // segment. 2744 // segment.
2731 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); 2745 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2732 } 2746 }
2733 2747
2748 #if defined(USE_PROPRIETARY_CODECS)
2749 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
2750 TEST_P(ChunkDemuxerTest, EmitBuffersDuringAbort) {
2751 EXPECT_CALL(*this, DemuxerOpened());
2752 demuxer_->Initialize(
2753 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true);
2754 EXPECT_EQ(AddIdForMp2tSource(kSourceId), ChunkDemuxer::kOk);
wolenetz 2014/05/06 00:04:32 nit: swap parameters to EXPECT_EQ please
damienv1 2014/05/06 00:29:00 Done.
2755
2756 // For info:
2757 // DTS/PTS derived using dvbsnoop -s ts -if bear-1280x720.ts -tssubdecode
2758 // Video: first PES:
2759 // PTS: 126912 (0x0001efc0) [= 90 kHz-Timestamp: 0:00:01.4101]
2760 // DTS: 123909 (0x0001e405) [= 90 kHz-Timestamp: 0:00:01.3767]
2761 // Audio: first PES:
2762 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000]
2763 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767]
2764 // Video: last PES:
2765 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128]
2766 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794]
2767 // Audio: last PES:
2768 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309]
2769
2770 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts");
2771 AppendData(kSourceId, buffer->data(), buffer->data_size());
2772
2773 // Confirm we're in the middle of parsing a media segment.
2774 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
2775
2776 // Abort on the Mpeg2 TS parser triggers the emission of the last video
2777 // buffer which is pending in the stream parser.
2778 Ranges<base::TimeDelta> range_before_abort =
2779 demuxer_->GetBufferedRanges(kSourceId);
2780 demuxer_->Abort(kSourceId,
2781 append_window_start_for_next_append_,
2782 append_window_end_for_next_append_,
2783 &timestamp_offset_map_[kSourceId]);
2784 Ranges<base::TimeDelta> range_after_abort =
2785 demuxer_->GetBufferedRanges(kSourceId);
2786
2787 ASSERT_EQ(range_before_abort.size(), 1u);
2788 ASSERT_EQ(range_after_abort.size(), 1u);
2789 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0));
2790 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0));
2791 }
2792 #endif
2793 #endif
2794
2734 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { 2795 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
2735 // TODO(wolenetz): Also test 'unknown' sized clusters. 2796 // TODO(wolenetz): Also test 'unknown' sized clusters.
2736 // See http://crbug.com/335676. 2797 // See http://crbug.com/335676.
2737 const uint8 kBuffer[] = { 2798 const uint8 kBuffer[] = {
2738 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 2799 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3)
2739 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 2800 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1)
2740 }; 2801 };
2741 2802
2742 // This array indicates expected return value of IsParsingMediaSegment() 2803 // This array indicates expected return value of IsParsingMediaSegment()
2743 // following each incrementally appended byte in |kBuffer|. 2804 // following each incrementally appended byte in |kBuffer|.
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
3213 // Verify that audio & video streams continue to return expected values. 3274 // Verify that audio & video streams continue to return expected values.
3214 CheckExpectedBuffers(audio_stream, "160 180"); 3275 CheckExpectedBuffers(audio_stream, "160 180");
3215 CheckExpectedBuffers(video_stream, "180 210"); 3276 CheckExpectedBuffers(video_stream, "180 210");
3216 } 3277 }
3217 3278
3218 // TODO(wolenetz): Enable testing of new frame processor based on this flag, 3279 // TODO(wolenetz): Enable testing of new frame processor based on this flag,
3219 // once the new processor has landed. See http://crbug.com/249422. 3280 // once the new processor has landed. See http://crbug.com/249422.
3220 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); 3281 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true));
3221 3282
3222 } // namespace media 3283 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698