Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/common/media/media_param_traits.h" | 5 #include "content/common/media/media_param_traits.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "ipc/ipc_message_utils.h" | |
| 8 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
| 9 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
| 10 #include "media/base/video_capture_types.h" | 11 #include "media/base/video_capture_types.h" |
| 12 #include "ui/gfx/ipc/gfx_param_traits.h" | |
| 11 | 13 |
| 12 using media::AudioParameters; | 14 using media::AudioParameters; |
| 13 using media::ChannelLayout; | 15 using media::ChannelLayout; |
| 14 using media::VideoCaptureFormat; | 16 using media::VideoCaptureFormat; |
| 15 using media::VideoPixelFormat; | |
| 16 | 17 |
| 17 namespace IPC { | 18 namespace IPC { |
| 18 | 19 |
| 20 IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelFormat, media::PIXEL_FORMAT_MAX - 1) | |
| 21 IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelStorage, media::PIXEL_STORAGE_MAX) | |
|
dcheng
2015/06/25 02:02:18
See https://codereview.chromium.org/1210743003/ fo
mcasas
2015/06/25 13:51:03
Done.
| |
| 22 | |
| 19 void ParamTraits<AudioParameters>::Write(Message* m, | 23 void ParamTraits<AudioParameters>::Write(Message* m, |
| 20 const AudioParameters& p) { | 24 const AudioParameters& p) { |
| 21 m->WriteInt(static_cast<int>(p.format())); | 25 m->WriteInt(static_cast<int>(p.format())); |
| 22 m->WriteInt(static_cast<int>(p.channel_layout())); | 26 m->WriteInt(static_cast<int>(p.channel_layout())); |
| 23 m->WriteInt(p.sample_rate()); | 27 m->WriteInt(p.sample_rate()); |
| 24 m->WriteInt(p.bits_per_sample()); | 28 m->WriteInt(p.bits_per_sample()); |
| 25 m->WriteInt(p.frames_per_buffer()); | 29 m->WriteInt(p.frames_per_buffer()); |
| 26 m->WriteInt(p.channels()); | 30 m->WriteInt(p.channels()); |
| 27 m->WriteInt(p.effects()); | 31 m->WriteInt(p.effects()); |
| 28 } | 32 } |
| 29 | 33 |
| 30 bool ParamTraits<AudioParameters>::Read(const Message* m, | 34 bool ParamTraits<AudioParameters>::Read(const Message* m, |
| 31 base::PickleIterator* iter, | 35 base::PickleIterator* iter, |
| 32 AudioParameters* r) { | 36 AudioParameters* r) { |
| 33 int format, channel_layout, sample_rate, bits_per_sample, | 37 int format, channel_layout, sample_rate, bits_per_sample, |
| 34 frames_per_buffer, channels, effects; | 38 frames_per_buffer, channels, effects; |
| 35 | 39 |
| 36 if (!iter->ReadInt(&format) || | 40 if (!iter->ReadInt(&format) || |
| 37 !iter->ReadInt(&channel_layout) || | 41 !iter->ReadInt(&channel_layout) || |
| 38 !iter->ReadInt(&sample_rate) || | 42 !iter->ReadInt(&sample_rate) || |
| 39 !iter->ReadInt(&bits_per_sample) || | 43 !iter->ReadInt(&bits_per_sample) || |
| 40 !iter->ReadInt(&frames_per_buffer) || | 44 !iter->ReadInt(&frames_per_buffer) || |
| 41 !iter->ReadInt(&channels) || | 45 !iter->ReadInt(&channels) || |
| 42 !iter->ReadInt(&effects)) | 46 !iter->ReadInt(&effects)) { |
| 43 return false; | 47 return false; |
| 48 } | |
| 44 | 49 |
| 45 AudioParameters params(static_cast<AudioParameters::Format>(format), | 50 AudioParameters params(static_cast<AudioParameters::Format>(format), |
| 46 static_cast<ChannelLayout>(channel_layout), channels, | 51 static_cast<ChannelLayout>(channel_layout), channels, |
| 47 sample_rate, bits_per_sample, frames_per_buffer, effects); | 52 sample_rate, bits_per_sample, frames_per_buffer, effects); |
| 48 *r = params; | 53 *r = params; |
| 49 if (!r->IsValid()) | 54 return r->IsValid(); |
| 50 return false; | |
| 51 return true; | |
| 52 } | 55 } |
| 53 | 56 |
| 54 void ParamTraits<AudioParameters>::Log(const AudioParameters& p, | 57 void ParamTraits<AudioParameters>::Log(const AudioParameters& p, |
| 55 std::string* l) { | 58 std::string* l) { |
| 56 l->append(base::StringPrintf("<AudioParameters>")); | 59 l->append(base::StringPrintf("<AudioParameters>")); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void ParamTraits<VideoCaptureFormat>::Write(Message* m, | 62 void ParamTraits<VideoCaptureFormat>::Write(Message* m, |
| 60 const VideoCaptureFormat& p) { | 63 const VideoCaptureFormat& p) { |
| 61 // Crash during Send rather than have a failure at the message handler. | 64 // Crash during Send rather than have a failure at the message handler. |
| 62 m->WriteInt(p.frame_size.width()); | 65 m->WriteInt(p.frame_size.width()); |
| 63 m->WriteInt(p.frame_size.height()); | 66 m->WriteInt(p.frame_size.height()); |
| 64 m->WriteFloat(p.frame_rate); | 67 m->WriteFloat(p.frame_rate); |
| 65 m->WriteInt(static_cast<int>(p.pixel_format)); | 68 m->WriteInt(static_cast<int>(p.pixel_format)); |
| 69 m->WriteInt(static_cast<int>(p.pixel_storage)); | |
|
dcheng
2015/06/25 02:02:18
Btw, these should probably be WriteParam() as well
mcasas
2015/06/25 13:51:03
Done.
| |
| 66 } | 70 } |
| 67 | 71 |
| 68 bool ParamTraits<VideoCaptureFormat>::Read(const Message* m, | 72 bool ParamTraits<VideoCaptureFormat>::Read(const Message* m, |
| 69 base::PickleIterator* iter, | 73 base::PickleIterator* iter, |
| 70 VideoCaptureFormat* r) { | 74 VideoCaptureFormat* r) { |
| 71 int frame_size_width, frame_size_height, pixel_format; | 75 if (!ReadParam(m, iter, &r->frame_size) || |
| 72 if (!iter->ReadInt(&frame_size_width) || | 76 !ReadParam(m, iter, &r->frame_rate) || |
| 73 !iter->ReadInt(&frame_size_height) || | 77 !ReadParam(m, iter, &r->pixel_format) || |
| 74 !iter->ReadFloat(&r->frame_rate) || | 78 !ReadParam(m, iter, &r->pixel_storage)) { |
| 75 !iter->ReadInt(&pixel_format)) | |
| 76 return false; | 79 return false; |
| 77 | 80 } |
| 78 r->frame_size.SetSize(frame_size_width, frame_size_height); | 81 return r->IsValid(); |
| 79 r->pixel_format = static_cast<VideoPixelFormat>(pixel_format); | |
| 80 if (!r->IsValid()) | |
| 81 return false; | |
| 82 return true; | |
| 83 } | 82 } |
| 84 | 83 |
| 85 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p, | 84 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p, |
| 86 std::string* l) { | 85 std::string* l) { |
| 87 l->append(base::StringPrintf("<VideoCaptureFormat>")); | 86 l->append(base::StringPrintf("<VideoCaptureFormat>")); |
| 88 } | 87 } |
| 89 | 88 |
| 90 } | 89 } |
| OLD | NEW |