OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "mojo/services/media/common/cpp/linear_transform.h" | 9 #include "mojo/services/media/common/cpp/linear_transform.h" |
10 #include "services/media/audio/audio_output_manager.h" | 10 #include "services/media/audio/audio_output_manager.h" |
11 #include "services/media/audio/audio_server_impl.h" | 11 #include "services/media/audio/audio_server_impl.h" |
12 #include "services/media/audio/audio_track_impl.h" | 12 #include "services/media/audio/audio_track_impl.h" |
13 #include "services/media/audio/audio_track_to_output_link.h" | 13 #include "services/media/audio/audio_track_to_output_link.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace media { | 16 namespace media { |
17 namespace audio { | 17 namespace audio { |
18 | 18 |
19 constexpr size_t AudioTrackImpl::PTS_FRACTIONAL_BITS; | 19 constexpr size_t AudioTrackImpl::PTS_FRACTIONAL_BITS; |
20 | 20 |
21 // TODO(johngro): If there is ever a better way to do this type of static-table | 21 // TODO(johngro): If there is ever a better way to do this type of static-table |
22 // initialization using mojom generated structs, we should switch to it. | 22 // initialization using mojom generated structs, we should switch to it. |
23 static const struct { | 23 static const struct { |
24 LpcmSampleFormat sample_format; | 24 LpcmSampleFormat sample_format; |
25 uint8_t min_samples_per_frame; | 25 BoolRange interleaved; |
26 uint8_t max_samples_per_frame; | 26 uint8_t min_channels; |
| 27 uint8_t max_channels; |
27 uint32_t min_frames_per_second; | 28 uint32_t min_frames_per_second; |
28 uint32_t max_frames_per_second; | 29 uint32_t max_frames_per_second; |
29 } kSupportedLpcmTypeSets[] = { | 30 } kSupportedLpcmTypeSets[] = { |
30 { | 31 { |
31 .sample_format = LpcmSampleFormat::UNSIGNED_8, | 32 .sample_format = LpcmSampleFormat::UNSIGNED_8, |
32 .min_samples_per_frame = 1, | 33 .interleaved = BoolRange::TRUE, |
33 .max_samples_per_frame = 2, | 34 .min_channels = 1, |
| 35 .max_channels = 2, |
34 .min_frames_per_second = 1000, | 36 .min_frames_per_second = 1000, |
35 .max_frames_per_second = 48000, | 37 .max_frames_per_second = 48000, |
36 }, | 38 }, |
37 { | 39 { |
38 .sample_format = LpcmSampleFormat::SIGNED_16, | 40 .sample_format = LpcmSampleFormat::SIGNED_16, |
39 .min_samples_per_frame = 1, | 41 .interleaved = BoolRange::TRUE, |
40 .max_samples_per_frame = 2, | 42 .min_channels = 1, |
| 43 .max_channels = 2, |
41 .min_frames_per_second = 1000, | 44 .min_frames_per_second = 1000, |
42 .max_frames_per_second = 48000, | 45 .max_frames_per_second = 48000, |
43 }, | 46 }, |
44 }; | 47 }; |
45 | 48 |
46 AudioTrackImpl::AudioTrackImpl(InterfaceRequest<AudioTrack> iface, | 49 AudioTrackImpl::AudioTrackImpl(InterfaceRequest<AudioTrack> iface, |
47 AudioServerImpl* owner) | 50 AudioServerImpl* owner) |
48 : owner_(owner), | 51 : owner_(owner), |
49 binding_(this), | 52 binding_(this), |
50 pipe_(this, owner) { | 53 pipe_(this, owner) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const MediaTypeSetPtr& mts = | 87 const MediaTypeSetPtr& mts = |
85 (desc->supported_media_types[i] = MediaTypeSet::New()); | 88 (desc->supported_media_types[i] = MediaTypeSet::New()); |
86 | 89 |
87 mts->scheme = MediaTypeScheme::LPCM; | 90 mts->scheme = MediaTypeScheme::LPCM; |
88 mts->details = MediaTypeSetDetails::New(); | 91 mts->details = MediaTypeSetDetails::New(); |
89 | 92 |
90 const auto& s = kSupportedLpcmTypeSets[i]; | 93 const auto& s = kSupportedLpcmTypeSets[i]; |
91 LpcmMediaTypeSetDetailsPtr lpcm_detail = LpcmMediaTypeSetDetails::New(); | 94 LpcmMediaTypeSetDetailsPtr lpcm_detail = LpcmMediaTypeSetDetails::New(); |
92 | 95 |
93 lpcm_detail->sample_format = s.sample_format; | 96 lpcm_detail->sample_format = s.sample_format; |
94 lpcm_detail->min_samples_per_frame = s.min_samples_per_frame; | 97 lpcm_detail->interleaved = s.interleaved; |
95 lpcm_detail->max_samples_per_frame = s.max_samples_per_frame; | 98 lpcm_detail->min_channels = s.min_channels; |
| 99 lpcm_detail->max_channels = s.max_channels; |
96 lpcm_detail->min_frames_per_second = s.min_frames_per_second; | 100 lpcm_detail->min_frames_per_second = s.min_frames_per_second; |
97 lpcm_detail->max_frames_per_second = s.max_frames_per_second; | 101 lpcm_detail->max_frames_per_second = s.max_frames_per_second; |
98 mts->details->set_lpcm(lpcm_detail.Pass()); | 102 mts->details->set_lpcm(lpcm_detail.Pass()); |
99 } | 103 } |
100 | 104 |
101 cbk.Run(desc.Pass()); | 105 cbk.Run(desc.Pass()); |
102 } | 106 } |
103 | 107 |
104 void AudioTrackImpl::Configure(AudioTrackConfigurationPtr configuration, | 108 void AudioTrackImpl::Configure(AudioTrackConfigurationPtr configuration, |
105 InterfaceRequest<MediaPipe> req, | 109 InterfaceRequest<MediaPipe> req, |
(...skipping 12 matching lines...) Expand all Loading... |
118 } | 122 } |
119 | 123 |
120 // Search our supported configuration sets to find one compatible with this | 124 // Search our supported configuration sets to find one compatible with this |
121 // request. | 125 // request. |
122 auto& cfg = configuration->media_type->details->get_lpcm(); | 126 auto& cfg = configuration->media_type->details->get_lpcm(); |
123 size_t i; | 127 size_t i; |
124 for (i = 0; i < arraysize(kSupportedLpcmTypeSets); ++i) { | 128 for (i = 0; i < arraysize(kSupportedLpcmTypeSets); ++i) { |
125 const auto& cfg_set = kSupportedLpcmTypeSets[i]; | 129 const auto& cfg_set = kSupportedLpcmTypeSets[i]; |
126 | 130 |
127 if ((cfg->sample_format == cfg_set.sample_format) && | 131 if ((cfg->sample_format == cfg_set.sample_format) && |
128 (cfg->samples_per_frame >= cfg_set.min_samples_per_frame) && | 132 (cfg_set.interleaved == BoolRange::EITHER || |
129 (cfg->samples_per_frame <= cfg_set.max_samples_per_frame) && | 133 cfg->interleaved == (cfg_set.interleaved == BoolRange::TRUE)) && |
| 134 (cfg->channels >= cfg_set.min_channels) && |
| 135 (cfg->channels <= cfg_set.max_channels) && |
130 (cfg->frames_per_second >= cfg_set.min_frames_per_second) && | 136 (cfg->frames_per_second >= cfg_set.min_frames_per_second) && |
131 (cfg->frames_per_second <= cfg_set.max_frames_per_second)) { | 137 (cfg->frames_per_second <= cfg_set.max_frames_per_second)) { |
132 break; | 138 break; |
133 } | 139 } |
134 } | 140 } |
135 | 141 |
136 if (i >= arraysize(kSupportedLpcmTypeSets)) { | 142 if (i >= arraysize(kSupportedLpcmTypeSets)) { |
137 cbk.Run(MediaResult::UNSUPPORTED_CONFIG); | 143 cbk.Run(MediaResult::UNSUPPORTED_CONFIG); |
138 return; | 144 return; |
139 } | 145 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 179 |
174 case LpcmSampleFormat::SIGNED_24_IN_32: | 180 case LpcmSampleFormat::SIGNED_24_IN_32: |
175 bytes_per_frame_ = 4; | 181 bytes_per_frame_ = 4; |
176 break; | 182 break; |
177 | 183 |
178 default: | 184 default: |
179 DCHECK(false); | 185 DCHECK(false); |
180 bytes_per_frame_ = 2; | 186 bytes_per_frame_ = 2; |
181 break; | 187 break; |
182 } | 188 } |
183 bytes_per_frame_ *= cfg->samples_per_frame; | 189 bytes_per_frame_ *= cfg->channels; |
184 | 190 |
185 // Overflow trying to convert from frames to bytes? | 191 // Overflow trying to convert from frames to bytes? |
186 uint64_t requested_frames = configuration->max_frames; | 192 uint64_t requested_frames = configuration->max_frames; |
187 if (requested_frames > | 193 if (requested_frames > |
188 (std::numeric_limits<size_t>::max() / bytes_per_frame_)) { | 194 (std::numeric_limits<size_t>::max() / bytes_per_frame_)) { |
189 cbk.Run(MediaResult::INSUFFICIENT_RESOURCES); | 195 cbk.Run(MediaResult::INSUFFICIENT_RESOURCES); |
190 return; | 196 return; |
191 } | 197 } |
192 | 198 |
193 size_t requested_bytes = (requested_frames * bytes_per_frame_); | 199 size_t requested_bytes = (requested_frames * bytes_per_frame_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 for (const auto& output : outputs_) { | 271 for (const auto& output : outputs_) { |
266 DCHECK(output); | 272 DCHECK(output); |
267 output->FlushPendingQueue(); | 273 output->FlushPendingQueue(); |
268 } | 274 } |
269 cbk.Run(MediaResult::OK); | 275 cbk.Run(MediaResult::OK); |
270 } | 276 } |
271 | 277 |
272 } // namespace audio | 278 } // namespace audio |
273 } // namespace media | 279 } // namespace media |
274 } // namespace mojo | 280 } // namespace mojo |
OLD | NEW |