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

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

Issue 1260193005: Fix incorrect opus seek preroll and flaky pre-skip removal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test cases. Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/md5.h" 9 #include "base/md5.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // Tells gtest how to print our DecoderTestData structure. 58 // Tells gtest how to print our DecoderTestData structure.
59 std::ostream& operator<<(std::ostream& os, const DecoderTestData& data) { 59 std::ostream& operator<<(std::ostream& os, const DecoderTestData& data) {
60 return os << data.filename; 60 return os << data.filename;
61 } 61 }
62 62
63 // Marks negative timestamp buffers for discard or transfers FFmpeg's built in 63 // Marks negative timestamp buffers for discard or transfers FFmpeg's built in
64 // discard metadata in favor of setting DiscardPadding on the DecoderBuffer. 64 // discard metadata in favor of setting DiscardPadding on the DecoderBuffer.
65 // Allows better testing of AudioDiscardHelper usage. 65 // Allows better testing of AudioDiscardHelper usage.
66 static void SetDiscardPadding(AVPacket* packet, 66 static void SetDiscardPadding(AVPacket* packet,
67 bool first_packet,
68 const AVStream* stream,
67 const scoped_refptr<DecoderBuffer> buffer, 69 const scoped_refptr<DecoderBuffer> buffer,
68 double samples_per_second) { 70 double samples_per_second) {
69 // Discard negative timestamps. 71 // Discard negative timestamps.
70 if (buffer->timestamp() + buffer->duration() < base::TimeDelta()) { 72 if (buffer->timestamp() + buffer->duration() < base::TimeDelta()) {
71 buffer->set_discard_padding( 73 buffer->set_discard_padding(
72 std::make_pair(kInfiniteDuration(), base::TimeDelta())); 74 std::make_pair(kInfiniteDuration(), base::TimeDelta()));
73 return; 75 return;
74 } 76 }
75 if (buffer->timestamp() < base::TimeDelta()) { 77 if (buffer->timestamp() < base::TimeDelta()) {
76 buffer->set_discard_padding( 78 buffer->set_discard_padding(
77 std::make_pair(-buffer->timestamp(), base::TimeDelta())); 79 std::make_pair(-buffer->timestamp(), base::TimeDelta()));
78 return; 80 return;
79 } 81 }
80 82
81 // If the timestamp is positive, try to use FFmpeg's discard data. 83 // If the timestamp is positive, try to use FFmpeg's discard data.
84 int skip_samples = 0;
82 int skip_samples_size = 0; 85 int skip_samples_size = 0;
83 const uint32* skip_samples_ptr = 86 const uint32* skip_samples_ptr =
84 reinterpret_cast<const uint32*>(av_packet_get_side_data( 87 reinterpret_cast<const uint32*>(av_packet_get_side_data(
85 packet, AV_PKT_DATA_SKIP_SAMPLES, &skip_samples_size)); 88 packet, AV_PKT_DATA_SKIP_SAMPLES, &skip_samples_size));
86 if (skip_samples_size < 4) 89 if (skip_samples_size >= 4)
90 skip_samples = base::ByteSwapToLE32(*skip_samples_ptr);
91 else if (first_packet && stream->codec->delay)
92 skip_samples = stream->codec->delay;
93 else
87 return; 94 return;
95
88 buffer->set_discard_padding(std::make_pair( 96 buffer->set_discard_padding(std::make_pair(
89 base::TimeDelta::FromSecondsD(base::ByteSwapToLE32(*skip_samples_ptr) / 97 base::TimeDelta::FromSecondsD(skip_samples / samples_per_second),
90 samples_per_second),
91 base::TimeDelta())); 98 base::TimeDelta()));
92 } 99 }
93 100
94 class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> { 101 class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> {
95 public: 102 public:
96 AudioDecoderTest() 103 AudioDecoderTest()
97 : pending_decode_(false), 104 : pending_decode_(false),
98 pending_reset_(false), 105 pending_reset_(false),
99 last_decode_status_(AudioDecoder::kDecodeError) { 106 last_decode_status_(AudioDecoder::kDecodeError) {
100 switch (GetParam().decoder_type) { 107 switch (GetParam().decoder_type) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 188
182 scoped_refptr<DecoderBuffer> buffer = 189 scoped_refptr<DecoderBuffer> buffer =
183 DecoderBuffer::CopyFrom(packet.data, packet.size); 190 DecoderBuffer::CopyFrom(packet.data, packet.size);
184 buffer->set_timestamp(ConvertFromTimeBase( 191 buffer->set_timestamp(ConvertFromTimeBase(
185 reader_->GetAVStreamForTesting()->time_base, packet.pts)); 192 reader_->GetAVStreamForTesting()->time_base, packet.pts));
186 buffer->set_duration(ConvertFromTimeBase( 193 buffer->set_duration(ConvertFromTimeBase(
187 reader_->GetAVStreamForTesting()->time_base, packet.duration)); 194 reader_->GetAVStreamForTesting()->time_base, packet.duration));
188 if (packet.flags & AV_PKT_FLAG_KEY) 195 if (packet.flags & AV_PKT_FLAG_KEY)
189 buffer->set_is_key_frame(true); 196 buffer->set_is_key_frame(true);
190 197
191 // Don't set discard padding for Opus, it already has discard behavior set 198 SetDiscardPadding(&packet, buffer->timestamp() == start_timestamp_,
192 // based on the codec delay in the AudioDecoderConfig. 199 reader_->GetAVStreamForTesting(), buffer,
193 if (GetParam().decoder_type == FFMPEG) 200 GetParam().samples_per_second);
194 SetDiscardPadding(&packet, buffer, GetParam().samples_per_second);
195 201
196 // DecodeBuffer() shouldn't need the original packet since it uses the copy. 202 // DecodeBuffer() shouldn't need the original packet since it uses the copy.
197 av_free_packet(&packet); 203 av_free_packet(&packet);
198 DecodeBuffer(buffer); 204 DecodeBuffer(buffer);
199 } 205 }
200 206
201 void Reset() { 207 void Reset() {
202 ASSERT_FALSE(pending_reset_); 208 ASSERT_FALSE(pending_reset_);
203 pending_reset_ = true; 209 pending_reset_ = true;
204 decoder_->Reset( 210 decoder_->Reset(
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 }; 537 };
532 538
533 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest, 539 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest,
534 AudioDecoderTest, 540 AudioDecoderTest,
535 testing::ValuesIn(kFFmpegTests)); 541 testing::ValuesIn(kFFmpegTests));
536 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest, 542 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest,
537 FFmpegAudioDecoderBehavioralTest, 543 FFmpegAudioDecoderBehavioralTest,
538 testing::ValuesIn(kFFmpegBehavioralTest)); 544 testing::ValuesIn(kFFmpegBehavioralTest));
539 545
540 } // namespace media 546 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698