diff options
author | dcheng <dcheng@chromium.org> | 2015-06-30 13:14:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-30 20:16:05 +0000 |
commit | 3c49f49b2c6d873fb5b23abc52cde08de7909b88 (patch) | |
tree | afa62066e73848a32f9940bba8fc62db3b193abc /media/audio | |
parent | 025bd4f976cb10e6a903c86d2ea19ad05d0f6830 (diff) | |
download | chromium_src-3c49f49b2c6d873fb5b23abc52cde08de7909b88.zip chromium_src-3c49f49b2c6d873fb5b23abc52cde08de7909b88.tar.gz chromium_src-3c49f49b2c6d873fb5b23abc52cde08de7909b88.tar.bz2 |
Use safer IPC serializations in media_param_traits.cc
The custom serialization routines for these classes used base::Pickle's
serialization/deserialization routines directly rather than using the
type-deducing ReadParam/WriteParam helpers. These helpers have the bonus
of using any pre-existing ParamTraits defined for the type, so the
custom serialization doesn't have to remember to check that enum values
are in range, etc.
BUG=504205
Review URL: https://codereview.chromium.org/1211273005
Cr-Commit-Position: refs/heads/master@{#336861}
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/alsa/alsa_output_unittest.cc | 11 | ||||
-rw-r--r-- | media/audio/android/audio_android_unittest.cc | 2 | ||||
-rw-r--r-- | media/audio/audio_parameters.cc | 6 | ||||
-rw-r--r-- | media/audio/audio_parameters.h | 8 | ||||
-rw-r--r-- | media/audio/cras/cras_input_unittest.cc | 13 |
5 files changed, 5 insertions, 35 deletions
diff --git a/media/audio/alsa/alsa_output_unittest.cc b/media/audio/alsa/alsa_output_unittest.cc index c9a98c5..8996dbc 100644 --- a/media/audio/alsa/alsa_output_unittest.cc +++ b/media/audio/alsa/alsa_output_unittest.cc @@ -235,17 +235,6 @@ TEST_F(AlsaPcmOutputStreamTest, ConstructedState) { mock_manager_.get()); EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream->state()); test_stream->Close(); - - // Bad format. - AudioParameters bad_format_params( - AudioParameters::AUDIO_LAST_FORMAT, kTestChannelLayout, kTestSampleRate, - kTestBitsPerSample, kTestFramesPerPacket); - test_stream = new AlsaPcmOutputStream(kTestDeviceName, - bad_format_params, - &mock_alsa_wrapper_, - mock_manager_.get()); - EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream->state()); - test_stream->Close(); } TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc index b8ebccf..64b3b4b 100644 --- a/media/audio/android/audio_android_unittest.cc +++ b/media/audio/android/audio_android_unittest.cc @@ -60,8 +60,6 @@ static std::string FormatToString(AudioParameters::Format format) { return std::string("AUDIO_PCM_LOW_LATENCY"); case AudioParameters::AUDIO_FAKE: return std::string("AUDIO_FAKE"); - case AudioParameters::AUDIO_LAST_FORMAT: - return std::string("AUDIO_LAST_FORMAT"); default: return std::string(); } diff --git a/media/audio/audio_parameters.cc b/media/audio/audio_parameters.cc index c9dcdeb..872413f 100644 --- a/media/audio/audio_parameters.cc +++ b/media/audio/audio_parameters.cc @@ -68,12 +68,8 @@ void AudioParameters::Reset(Format format, ChannelLayout channel_layout, } bool AudioParameters::IsValid() const { - return (format_ >= AUDIO_PCM_LINEAR) && - (format_ < AUDIO_LAST_FORMAT) && - (channels_ > 0) && - (channels_ <= media::limits::kMaxChannels) && + return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) && (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && - (channel_layout_ <= CHANNEL_LAYOUT_MAX) && (sample_rate_ >= media::limits::kMinSampleRate) && (sample_rate_ <= media::limits::kMaxSampleRate) && (bits_per_sample_ > 0) && diff --git a/media/audio/audio_parameters.h b/media/audio/audio_parameters.h index 9267232..3820d8c 100644 --- a/media/audio/audio_parameters.h +++ b/media/audio/audio_parameters.h @@ -33,10 +33,10 @@ class MEDIA_EXPORT AudioParameters { // TODO(miu): Rename this enum to something that correctly reflects its // semantics, such as "TransportScheme." enum Format { - AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. - AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. - AUDIO_FAKE, // Creates a fake AudioOutputStream object. - AUDIO_LAST_FORMAT // Only used for validation of format. + AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. + AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. + AUDIO_FAKE, // Creates a fake AudioOutputStream object. + AUDIO_FORMAT_LAST = AUDIO_FAKE, // Only used for validation of format. }; enum { diff --git a/media/audio/cras/cras_input_unittest.cc b/media/audio/cras/cras_input_unittest.cc index 4352b58..6c5a40c 100644 --- a/media/audio/cras/cras_input_unittest.cc +++ b/media/audio/cras/cras_input_unittest.cc @@ -151,19 +151,6 @@ TEST_F(CrasInputStreamTest, BadBitsPerSample) { test_stream->Close(); } -TEST_F(CrasInputStreamTest, BadFormat) { - AudioParameters bad_format_params(AudioParameters::AUDIO_LAST_FORMAT, - kTestChannelLayout, - kTestSampleRate, - kTestBitsPerSample, - kTestFramesPerPacket); - CrasInputStream* test_stream = new CrasInputStream( - bad_format_params, mock_manager_.get(), - AudioManagerBase::kDefaultDeviceId); - EXPECT_FALSE(test_stream->Open()); - test_stream->Close(); -} - TEST_F(CrasInputStreamTest, BadSampleRate) { AudioParameters bad_rate_params(kTestFormat, kTestChannelLayout, |