From 7f22d253db482ab30b9a66987d08ed7d0ec07f6c Mon Sep 17 00:00:00 2001 From: "cevans@chromium.org" Date: Thu, 24 Jan 2013 23:26:37 +0000 Subject: Merge 177277 > Introduce IPC validation to the media::VideoCaptureParams type. > > BUG=167199 > > R=jam@chromium.org,dalecurtis@chromium.org > Review URL: https://codereview.chromium.org/11888015 TBR=cevans@chromium.org Review URL: https://codereview.chromium.org/11896103 git-svn-id: svn://svn.chromium.org/chrome/branches/1364/src@178691 0039d316-1c4b-4281-b951-d872f2087c98 --- content/common/media/audio_messages.h | 2 +- content/common/media/audio_param_traits.cc | 51 --------------- content/common/media/audio_param_traits.h | 27 -------- content/common/media/media_param_traits.cc | 93 +++++++++++++++++++++++++++ content/common/media/media_param_traits.h | 37 +++++++++++ content/common/media/video_capture_messages.h | 7 -- content/content_common.gypi | 4 +- 7 files changed, 133 insertions(+), 88 deletions(-) delete mode 100644 content/common/media/audio_param_traits.cc delete mode 100644 content/common/media/audio_param_traits.h create mode 100644 content/common/media/media_param_traits.cc create mode 100644 content/common/media/media_param_traits.h (limited to 'content') diff --git a/content/common/media/audio_messages.h b/content/common/media/audio_messages.h index e78cfdd..cac43d1 100644 --- a/content/common/media/audio_messages.h +++ b/content/common/media/audio_messages.h @@ -11,7 +11,7 @@ #include "base/shared_memory.h" #include "base/sync_socket.h" #include "content/common/content_export.h" -#include "content/common/media/audio_param_traits.h" +#include "content/common/media/media_param_traits.h" #include "ipc/ipc_message_macros.h" #include "media/audio/audio_buffers_state.h" #include "media/audio/audio_input_ipc.h" diff --git a/content/common/media/audio_param_traits.cc b/content/common/media/audio_param_traits.cc deleted file mode 100644 index 215bd71..0000000 --- a/content/common/media/audio_param_traits.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/common/media/audio_param_traits.h" - -#include "base/stringprintf.h" -#include "media/audio/audio_parameters.h" - -using media::AudioParameters; -using media::ChannelLayout; - -namespace IPC { - -void ParamTraits::Write(Message* m, - const AudioParameters& p) { - m->WriteInt(static_cast(p.format())); - m->WriteInt(static_cast(p.channel_layout())); - m->WriteInt(p.sample_rate()); - m->WriteInt(p.bits_per_sample()); - m->WriteInt(p.frames_per_buffer()); - m->WriteInt(p.channels()); -} - -bool ParamTraits::Read(const Message* m, - PickleIterator* iter, - AudioParameters* r) { - int format, channel_layout, sample_rate, bits_per_sample, - frames_per_buffer, channels; - - if (!m->ReadInt(iter, &format) || - !m->ReadInt(iter, &channel_layout) || - !m->ReadInt(iter, &sample_rate) || - !m->ReadInt(iter, &bits_per_sample) || - !m->ReadInt(iter, &frames_per_buffer) || - !m->ReadInt(iter, &channels)) - return false; - r->Reset(static_cast(format), - static_cast(channel_layout), - sample_rate, bits_per_sample, frames_per_buffer); - if (!r->IsValid()) - return false; - return true; -} - -void ParamTraits::Log(const AudioParameters& p, - std::string* l) { - l->append(base::StringPrintf("")); -} - -} diff --git a/content/common/media/audio_param_traits.h b/content/common/media/audio_param_traits.h deleted file mode 100644 index 6910906..0000000 --- a/content/common/media/audio_param_traits.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_COMMON_MEDIA_AUDIO_AUDIO_PARAM_TRAITS_H_ -#define CONTENT_COMMON_MEDIA_AUDIO_AUDIO_PARAM_TRAITS_H_ - -#include "ipc/ipc_message.h" -#include "ipc/ipc_param_traits.h" - -namespace media { -class AudioParameters; -} - -namespace IPC { - -template <> -struct ParamTraits { - typedef media::AudioParameters param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -} // namespace IPC - -#endif // CONTENT_COMMON_MEDIA_AUDIO_AUDIO_PARAM_TRAITS_H_ diff --git a/content/common/media/media_param_traits.cc b/content/common/media/media_param_traits.cc new file mode 100644 index 0000000..85ef57c --- /dev/null +++ b/content/common/media/media_param_traits.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/common/media/media_param_traits.h" + +#include "base/stringprintf.h" +#include "media/audio/audio_parameters.h" +#include "media/base/limits.h" +#include "media/video/capture/video_capture_types.h" + +using media::AudioParameters; +using media::ChannelLayout; +using media::VideoCaptureParams; +using media::VideoCaptureSessionId; + +namespace IPC { + +void ParamTraits::Write(Message* m, + const AudioParameters& p) { + m->WriteInt(static_cast(p.format())); + m->WriteInt(static_cast(p.channel_layout())); + m->WriteInt(p.sample_rate()); + m->WriteInt(p.bits_per_sample()); + m->WriteInt(p.frames_per_buffer()); + m->WriteInt(p.channels()); +} + +bool ParamTraits::Read(const Message* m, + PickleIterator* iter, + AudioParameters* r) { + int format, channel_layout, sample_rate, bits_per_sample, + frames_per_buffer, channels; + + if (!m->ReadInt(iter, &format) || + !m->ReadInt(iter, &channel_layout) || + !m->ReadInt(iter, &sample_rate) || + !m->ReadInt(iter, &bits_per_sample) || + !m->ReadInt(iter, &frames_per_buffer) || + !m->ReadInt(iter, &channels)) + return false; + r->Reset(static_cast(format), + static_cast(channel_layout), + sample_rate, bits_per_sample, frames_per_buffer); + if (!r->IsValid()) + return false; + return true; +} + +void ParamTraits::Log(const AudioParameters& p, + std::string* l) { + l->append(base::StringPrintf("")); +} + +void ParamTraits::Write(Message* m, + const VideoCaptureParams& p) { + m->WriteInt(p.width); + m->WriteInt(p.height); + m->WriteInt(p.frame_per_second); + m->WriteInt(static_cast(p.session_id)); +} + +bool ParamTraits::Read(const Message* m, + PickleIterator* iter, + VideoCaptureParams* r) { + int session_id; + + if (!m->ReadInt(iter, &r->width) || + !m->ReadInt(iter, &r->height) || + !m->ReadInt(iter, &r->frame_per_second) || + !m->ReadInt(iter, &session_id)) + return false; + + r->session_id = static_cast(session_id); + + // TODO(wjia): Replace with IsValid() method on VideoCaptureParams. + if (r->width <= 0 || r->height <= 0 || r->frame_per_second <= 0 || + r->frame_per_second > media::limits::kMaxFramesPerSecond || + r->width > media::limits::kMaxDimension || + r->height > media::limits::kMaxDimension || + r->width * r->height > media::limits::kMaxCanvas) { + return false; + } + + return true; +} + +void ParamTraits::Log(const VideoCaptureParams& p, + std::string* l) { + l->append(base::StringPrintf("")); +} + +} diff --git a/content/common/media/media_param_traits.h b/content/common/media/media_param_traits.h new file mode 100644 index 0000000..94ce9ca --- /dev/null +++ b/content/common/media/media_param_traits.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMMON_MEDIA_MEDIA_PARAM_TRAITS_H_ +#define CONTENT_COMMON_MEDIA_MEDIA_PARAM_TRAITS_H_ + +#include "ipc/ipc_message.h" +#include "ipc/ipc_param_traits.h" + +namespace media { +class AudioParameters; +struct VideoCaptureParams; +} + +namespace IPC { + +template <> +struct ParamTraits { + typedef media::AudioParameters param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits { + typedef media::VideoCaptureParams param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + + +} // namespace IPC + +#endif // CONTENT_COMMON_MEDIA_MEDIA_PARAM_TRAITS_H_ diff --git a/content/common/media/video_capture_messages.h b/content/common/media/video_capture_messages.h index 7e167e2..9ea9a43 100644 --- a/content/common/media/video_capture_messages.h +++ b/content/common/media/video_capture_messages.h @@ -15,13 +15,6 @@ IPC_ENUM_TRAITS(content::VideoCaptureState) -IPC_STRUCT_TRAITS_BEGIN(media::VideoCaptureParams) - IPC_STRUCT_TRAITS_MEMBER(width) - IPC_STRUCT_TRAITS_MEMBER(height) - IPC_STRUCT_TRAITS_MEMBER(frame_per_second) - IPC_STRUCT_TRAITS_MEMBER(session_id) -IPC_STRUCT_TRAITS_END() - // Notify the renderer process about the state update such as // Start/Pause/Stop. IPC_MESSAGE_CONTROL2(VideoCaptureMsg_StateChanged, diff --git a/content/content_common.gypi b/content/content_common.gypi index 56158a6..22a8e70 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -293,8 +293,8 @@ 'common/mac/font_loader.h', 'common/mac/font_loader.mm', 'common/media/audio_messages.h', - 'common/media/audio_param_traits.cc', - 'common/media/audio_param_traits.h', + 'common/media/media_param_traits.cc', + 'common/media/media_param_traits.h', 'common/media/media_player_messages.h', 'common/media/media_stream_messages.h', 'common/media/media_stream_options.cc', -- cgit v1.1