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 "media/audio/audio_parameters.h" | 8 #include "media/audio/audio_parameters.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
10 #include "media/video/capture/video_capture_types.h" | 10 #include "media/video/capture/video_capture_types.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 void ParamTraits<AudioParameters>::Log(const AudioParameters& p, | 52 void ParamTraits<AudioParameters>::Log(const AudioParameters& p, |
53 std::string* l) { | 53 std::string* l) { |
54 l->append(base::StringPrintf("<AudioParameters>")); | 54 l->append(base::StringPrintf("<AudioParameters>")); |
55 } | 55 } |
56 | 56 |
57 void ParamTraits<VideoCaptureParams>::Write(Message* m, | 57 void ParamTraits<VideoCaptureParams>::Write(Message* m, |
58 const VideoCaptureParams& p) { | 58 const VideoCaptureParams& p) { |
59 m->WriteInt(p.width); | 59 m->WriteInt(p.width); |
60 m->WriteInt(p.height); | 60 m->WriteInt(p.height); |
61 m->WriteInt(p.frame_per_second); | 61 m->WriteInt(p.frame_rate); |
62 m->WriteInt(static_cast<int>(p.session_id)); | 62 m->WriteInt(static_cast<int>(p.session_id)); |
63 m->WriteInt(static_cast<int>(p.frame_size_type)); | 63 m->WriteInt(static_cast<int>(p.frame_size_type)); |
64 } | 64 } |
65 | 65 |
66 bool ParamTraits<VideoCaptureParams>::Read(const Message* m, | 66 bool ParamTraits<VideoCaptureParams>::Read(const Message* m, |
67 PickleIterator* iter, | 67 PickleIterator* iter, |
68 VideoCaptureParams* r) { | 68 VideoCaptureParams* r) { |
69 int session_id, frame_size_type; | 69 int session_id, frame_size_type; |
70 if (!m->ReadInt(iter, &r->width) || | 70 if (!m->ReadInt(iter, &r->width) || |
71 !m->ReadInt(iter, &r->height) || | 71 !m->ReadInt(iter, &r->height) || |
72 !m->ReadInt(iter, &r->frame_per_second) || | 72 !m->ReadInt(iter, &r->frame_rate) || |
73 !m->ReadInt(iter, &session_id) || | 73 !m->ReadInt(iter, &session_id) || |
74 !m->ReadInt(iter, &frame_size_type)) | 74 !m->ReadInt(iter, &frame_size_type)) |
75 return false; | 75 return false; |
76 | 76 |
77 r->session_id = static_cast<VideoCaptureSessionId>(session_id); | 77 r->session_id = static_cast<VideoCaptureSessionId>(session_id); |
78 r->frame_size_type = | 78 r->frame_size_type = |
79 static_cast<media::VideoCaptureResolutionType>( | 79 static_cast<media::VideoCaptureResolutionType>( |
80 frame_size_type); | 80 frame_size_type); |
81 | 81 if (!r->IsValid()) |
82 // TODO(wjia): Replace with IsValid() method on VideoCaptureParams. | |
83 if (r->width <= 0 || r->height <= 0 || r->frame_per_second <= 0 || | |
84 r->frame_per_second > media::limits::kMaxFramesPerSecond || | |
85 r->width > media::limits::kMaxDimension || | |
86 r->height > media::limits::kMaxDimension || | |
87 r->width * r->height > media::limits::kMaxCanvas || | |
88 r->frame_size_type < 0 || | |
89 r->frame_size_type >= media::MaxVideoCaptureResolutionType) { | |
90 return false; | 82 return false; |
91 } | |
92 | |
93 return true; | 83 return true; |
94 } | 84 } |
95 | 85 |
96 void ParamTraits<VideoCaptureParams>::Log(const VideoCaptureParams& p, | 86 void ParamTraits<VideoCaptureParams>::Log(const VideoCaptureParams& p, |
97 std::string* l) { | 87 std::string* l) { |
98 l->append(base::StringPrintf("<VideoCaptureParams>")); | 88 l->append(base::StringPrintf("<VideoCaptureParams>")); |
99 } | 89 } |
100 | 90 |
101 } | 91 } |
OLD | NEW |