2015-10-08 21:48:07 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/media/formats/webm/webm_audio_client.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 23:12:10 +00:00
|
|
|
#include "packager/base/logging.h"
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/media/formats/webm/webm_constants.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 23:12:10 +00:00
|
|
|
namespace {
|
|
|
|
// Timestamps are represented in double in WebM. Convert to uint64_t in us.
|
|
|
|
const uint32_t kWebMTimeScale = 1000000u;
|
|
|
|
} // namespace
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
WebMAudioClient::WebMAudioClient() {
|
2015-10-08 21:48:07 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebMAudioClient::~WebMAudioClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebMAudioClient::Reset() {
|
|
|
|
channels_ = -1;
|
|
|
|
samples_per_second_ = -1;
|
|
|
|
output_samples_per_second_ = -1;
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:12:10 +00:00
|
|
|
scoped_refptr<AudioStreamInfo> WebMAudioClient::GetAudioStreamInfo(
|
|
|
|
int64_t track_num,
|
2015-10-14 22:46:23 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::vector<uint8_t>& codec_private,
|
2016-05-05 22:26:48 +00:00
|
|
|
int64_t seek_preroll,
|
|
|
|
int64_t codec_delay,
|
2015-10-14 23:12:10 +00:00
|
|
|
const std::string& language,
|
|
|
|
bool is_encrypted) {
|
2015-10-08 21:48:07 +00:00
|
|
|
AudioCodec audio_codec = kUnknownAudioCodec;
|
|
|
|
if (codec_id == "A_VORBIS") {
|
|
|
|
audio_codec = kCodecVorbis;
|
|
|
|
} else if (codec_id == "A_OPUS") {
|
|
|
|
audio_codec = kCodecOpus;
|
|
|
|
} else {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Unsupported audio codec_id " << codec_id;
|
2015-10-14 23:12:10 +00:00
|
|
|
return scoped_refptr<AudioStreamInfo>();
|
2015-10-08 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (samples_per_second_ <= 0)
|
2015-10-14 23:12:10 +00:00
|
|
|
return scoped_refptr<AudioStreamInfo>();
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
// Set channel layout default if a Channels element was not present.
|
|
|
|
if (channels_ == -1)
|
|
|
|
channels_ = 1;
|
|
|
|
|
2015-10-14 23:12:10 +00:00
|
|
|
uint32_t sampling_frequency = samples_per_second_;
|
2015-10-08 21:48:07 +00:00
|
|
|
// Always use 48kHz for OPUS. See the "Input Sample Rate" section of the
|
|
|
|
// spec: http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11
|
|
|
|
if (audio_codec == kCodecOpus) {
|
2015-10-14 23:12:10 +00:00
|
|
|
sampling_frequency = 48000;
|
2015-10-08 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* extra_data = NULL;
|
2015-10-08 21:48:07 +00:00
|
|
|
size_t extra_data_size = 0;
|
|
|
|
if (codec_private.size() > 0) {
|
|
|
|
extra_data = &codec_private[0];
|
|
|
|
extra_data_size = codec_private.size();
|
|
|
|
}
|
|
|
|
|
2016-05-09 18:55:14 +00:00
|
|
|
const uint8_t kSampleSizeInBits = 16u;
|
2015-10-14 23:12:10 +00:00
|
|
|
return scoped_refptr<AudioStreamInfo>(new AudioStreamInfo(
|
|
|
|
track_num, kWebMTimeScale, 0, audio_codec,
|
|
|
|
AudioStreamInfo::GetCodecString(audio_codec, 0), language,
|
2016-05-05 22:26:48 +00:00
|
|
|
kSampleSizeInBits, channels_, sampling_frequency,
|
|
|
|
seek_preroll < 0 ? 0 : seek_preroll, codec_delay < 0 ? 0 : codec_delay, 0,
|
|
|
|
0, extra_data, extra_data_size, is_encrypted));
|
2015-10-08 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
bool WebMAudioClient::OnUInt(int id, int64_t val) {
|
2015-10-08 21:48:07 +00:00
|
|
|
if (id == kWebMIdChannels) {
|
|
|
|
if (channels_ != -1) {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Multiple values for id " << std::hex << id
|
|
|
|
<< " specified. (" << channels_ << " and " << val << ")";
|
2015-10-08 21:48:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
channels_ = val;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebMAudioClient::OnFloat(int id, double val) {
|
|
|
|
double* dst = NULL;
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case kWebMIdSamplingFrequency:
|
|
|
|
dst = &samples_per_second_;
|
|
|
|
break;
|
|
|
|
case kWebMIdOutputSamplingFrequency:
|
|
|
|
dst = &output_samples_per_second_;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (*dst != -1) {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Multiple values for id " << std::hex << id << " specified ("
|
|
|
|
<< *dst << " and " << val << ")";
|
2015-10-08 21:48:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|