Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1359)

Unified Diff: media/filters/opus_audio_decoder.cc

Issue 104873011: Add support for setting OPUS header gain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/opus_audio_decoder.cc
diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc
index e3567209f1a83063e484af89f9222bc693dbe445..6762c9bb6bacbf5e6365fea43770ab1244f355e7 100644
--- a/media/filters/opus_audio_decoder.cc
+++ b/media/filters/opus_audio_decoder.cc
@@ -24,8 +24,9 @@
namespace media {
-static uint16 ReadLE16(const uint8* data, size_t data_size, int read_offset) {
- uint16 value = 0;
+template <typename T>
+static T ReadLE16(const uint8* data, size_t data_size, int read_offset) {
+ T value = 0;
DCHECK_LE(read_offset + sizeof(value), data_size);
memcpy(&value, data + read_offset, sizeof(value));
return base::ByteSwapToLE16(value);
@@ -157,6 +158,9 @@ static const int kOpusExtraDataChannelsOffset = 9;
// Offset to the pre-skip value in the Opus extra data.
static const int kOpusExtraDataSkipSamplesOffset = 10;
+// Offset to the gain value in the Opus extra data.
+static const int kOpusExtraDataGainOffset = 16;
+
// Offset to the channel mapping byte in the Opus extra data.
static const int kOpusExtraDataChannelMappingOffset = 18;
@@ -179,16 +183,18 @@ struct OpusExtraData {
skip_samples(0),
channel_mapping(0),
num_streams(0),
- num_coupled(0) {
+ num_coupled(0),
+ gain_db(0) {
memcpy(stream_map,
kDefaultOpusChannelLayout,
kMaxChannelsWithDefaultLayout);
}
int channels;
- int skip_samples;
+ uint16_t skip_samples;
int channel_mapping;
int num_streams;
int num_coupled;
+ int16_t gain_db;
uint8 stream_map[kMaxVorbisChannels];
};
@@ -212,7 +218,9 @@ static bool ParseOpusExtraData(const uint8* data, int data_size,
}
extra_data->skip_samples =
- ReadLE16(data, data_size, kOpusExtraDataSkipSamplesOffset);
+ ReadLE16<uint16_t>(data, data_size, kOpusExtraDataSkipSamplesOffset);
+ extra_data->gain_db =
+ ReadLE16<int16_t>(data, data_size, kOpusExtraDataGainOffset);
acolwell GONE FROM CHROMIUM 2013/12/16 21:37:08 nit: How about just putting a static_cast<int16_t>
DaleCurtis 2013/12/16 22:21:04 Nice catch, I've reverted this in place of just us
extra_data->channel_mapping = *(data + kOpusExtraDataChannelMappingOffset);
@@ -502,6 +510,13 @@ bool OpusAudioDecoder::ConfigureDecoder() {
return false;
}
+ status = opus_multistream_decoder_ctl(
+ opus_decoder_, OPUS_SET_GAIN(opus_extra_data.gain_db));
+ if (status != OPUS_OK) {
+ DLOG(WARNING) << "Failed to set OPUS header gain. status="
+ << opus_strerror(status);
acolwell GONE FROM CHROMIUM 2013/12/16 21:37:08 nit: Shouldn't we return false here since this is
DaleCurtis 2013/12/16 22:21:04 While the docs don't make it clear, errors will be
vignesh 2013/12/16 22:24:51 We do strict checking on other fields (like codec_
DaleCurtis 2013/12/16 22:28:02 The bounds are int16_min -> int16_max, it's enforc
+ }
+
channel_layout_ = config.channel_layout();
samples_per_second_ = config.samples_per_second();
output_timestamp_helper_.reset(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698