OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/formats/webm/webm_audio_client.h" | 5 #include "media/formats/webm/webm_audio_client.h" |
6 | 6 |
7 #include "media/base/audio_decoder_config.h" | 7 #include "media/base/audio_decoder_config.h" |
8 #include "media/base/channel_layout.h" | 8 #include "media/base/channel_layout.h" |
9 #include "media/formats/webm/webm_constants.h" | 9 #include "media/formats/webm/webm_constants.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 channels_ = -1; | 22 channels_ = -1; |
23 samples_per_second_ = -1; | 23 samples_per_second_ = -1; |
24 output_samples_per_second_ = -1; | 24 output_samples_per_second_ = -1; |
25 } | 25 } |
26 | 26 |
27 bool WebMAudioClient::InitializeConfig( | 27 bool WebMAudioClient::InitializeConfig( |
28 const std::string& codec_id, const std::vector<uint8>& codec_private, | 28 const std::string& codec_id, const std::vector<uint8>& codec_private, |
29 int64 seek_preroll, int64 codec_delay, bool is_encrypted, | 29 int64 seek_preroll, int64 codec_delay, bool is_encrypted, |
30 AudioDecoderConfig* config) { | 30 AudioDecoderConfig* config) { |
31 DCHECK(config); | 31 DCHECK(config); |
| 32 SampleFormat sample_format = kSampleFormatPlanarF32; |
32 | 33 |
33 AudioCodec audio_codec = kUnknownAudioCodec; | 34 AudioCodec audio_codec = kUnknownAudioCodec; |
34 if (codec_id == "A_VORBIS") { | 35 if (codec_id == "A_VORBIS") { |
35 audio_codec = kCodecVorbis; | 36 audio_codec = kCodecVorbis; |
36 } else if (codec_id == "A_OPUS") { | 37 } else if (codec_id == "A_OPUS") { |
37 audio_codec = kCodecOpus; | 38 audio_codec = kCodecOpus; |
38 } else { | 39 } else { |
39 MEDIA_LOG(log_cb_) << "Unsupported audio codec_id " << codec_id; | 40 MEDIA_LOG(log_cb_) << "Unsupported audio codec_id " << codec_id; |
40 return false; | 41 return false; |
41 } | 42 } |
(...skipping 11 matching lines...) Expand all Loading... |
53 MEDIA_LOG(log_cb_) << "Unsupported channel count " << channels_; | 54 MEDIA_LOG(log_cb_) << "Unsupported channel count " << channels_; |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 int samples_per_second = samples_per_second_; | 58 int samples_per_second = samples_per_second_; |
58 if (output_samples_per_second_ > 0) | 59 if (output_samples_per_second_ > 0) |
59 samples_per_second = output_samples_per_second_; | 60 samples_per_second = output_samples_per_second_; |
60 | 61 |
61 // Always use 48kHz for OPUS. See the "Input Sample Rate" section of the | 62 // Always use 48kHz for OPUS. See the "Input Sample Rate" section of the |
62 // spec: http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 | 63 // spec: http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 |
63 if (audio_codec == kCodecOpus) | 64 if (audio_codec == kCodecOpus) { |
64 samples_per_second = 48000; | 65 samples_per_second = 48000; |
| 66 sample_format = kSampleFormatF32; |
| 67 } |
65 | 68 |
66 const uint8* extra_data = NULL; | 69 const uint8* extra_data = NULL; |
67 size_t extra_data_size = 0; | 70 size_t extra_data_size = 0; |
68 if (codec_private.size() > 0) { | 71 if (codec_private.size() > 0) { |
69 extra_data = &codec_private[0]; | 72 extra_data = &codec_private[0]; |
70 extra_data_size = codec_private.size(); | 73 extra_data_size = codec_private.size(); |
71 } | 74 } |
72 | 75 |
73 // Convert |codec_delay| from nanoseconds into frames. | 76 // Convert |codec_delay| from nanoseconds into frames. |
74 int codec_delay_in_frames = 0; | 77 int codec_delay_in_frames = 0; |
75 if (codec_delay != -1) { | 78 if (codec_delay != -1) { |
76 codec_delay_in_frames = | 79 codec_delay_in_frames = |
77 0.5 + | 80 0.5 + |
78 samples_per_second * (static_cast<double>(codec_delay) / | 81 samples_per_second * (static_cast<double>(codec_delay) / |
79 base::Time::kNanosecondsPerSecond); | 82 base::Time::kNanosecondsPerSecond); |
80 } | 83 } |
81 | 84 |
82 config->Initialize( | 85 config->Initialize( |
83 audio_codec, | 86 audio_codec, |
84 (audio_codec == kCodecOpus) ? kSampleFormatS16 : kSampleFormatPlanarF32, | 87 sample_format, |
85 channel_layout, | 88 channel_layout, |
86 samples_per_second, | 89 samples_per_second, |
87 extra_data, | 90 extra_data, |
88 extra_data_size, | 91 extra_data_size, |
89 is_encrypted, | 92 is_encrypted, |
90 true, | 93 true, |
91 base::TimeDelta::FromMicroseconds( | 94 base::TimeDelta::FromMicroseconds( |
92 (seek_preroll != -1 ? seek_preroll : 0) / 1000), | 95 (seek_preroll != -1 ? seek_preroll : 0) / 1000), |
93 codec_delay_in_frames); | 96 codec_delay_in_frames); |
94 return config->IsValidConfig(); | 97 return config->IsValidConfig(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 MEDIA_LOG(log_cb_) << "Multiple values for id " << std::hex << id | 132 MEDIA_LOG(log_cb_) << "Multiple values for id " << std::hex << id |
130 << " specified (" << *dst << " and " << val << ")"; | 133 << " specified (" << *dst << " and " << val << ")"; |
131 return false; | 134 return false; |
132 } | 135 } |
133 | 136 |
134 *dst = val; | 137 *dst = val; |
135 return true; | 138 return true; |
136 } | 139 } |
137 | 140 |
138 } // namespace media | 141 } // namespace media |
OLD | NEW |