content/media/fmp4/demuxer/audio_decoder_config.cc

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "mp4_demuxer/audio_decoder_config.h"
michael@0 6
michael@0 7 #include <sstream>
michael@0 8 #include <string.h>
michael@0 9
michael@0 10 namespace mp4_demuxer {
michael@0 11
michael@0 12 static int SampleFormatToBitsPerChannel(SampleFormat sample_format) {
michael@0 13 switch (sample_format) {
michael@0 14 case kUnknownSampleFormat:
michael@0 15 return 0;
michael@0 16 case kSampleFormatU8:
michael@0 17 return 8;
michael@0 18 case kSampleFormatS16:
michael@0 19 case kSampleFormatPlanarS16:
michael@0 20 return 16;
michael@0 21 case kSampleFormatS32:
michael@0 22 case kSampleFormatF32:
michael@0 23 case kSampleFormatPlanarF32:
michael@0 24 return 32;
michael@0 25 case kSampleFormatMax:
michael@0 26 break;
michael@0 27 }
michael@0 28
michael@0 29 //NOTREACHED() << "Invalid sample format provided: " << sample_format;
michael@0 30 return 0;
michael@0 31 }
michael@0 32
michael@0 33 AudioDecoderConfig::AudioDecoderConfig()
michael@0 34 : codec_(kUnknownAudioCodec),
michael@0 35 sample_format_(kUnknownSampleFormat),
michael@0 36 bits_per_channel_(0),
michael@0 37 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED),
michael@0 38 samples_per_second_(0),
michael@0 39 bytes_per_frame_(0),
michael@0 40 is_encrypted_(false) {
michael@0 41 }
michael@0 42
michael@0 43 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec,
michael@0 44 SampleFormat sample_format,
michael@0 45 ChannelLayout channel_layout,
michael@0 46 int samples_per_second,
michael@0 47 const uint8_t* extra_data,
michael@0 48 size_t extra_data_size,
michael@0 49 bool is_encrypted) {
michael@0 50 Initialize(codec, sample_format, channel_layout, samples_per_second,
michael@0 51 extra_data, extra_data_size, is_encrypted);
michael@0 52 }
michael@0 53
michael@0 54 void AudioDecoderConfig::Initialize(AudioCodec codec,
michael@0 55 SampleFormat sample_format,
michael@0 56 ChannelLayout channel_layout,
michael@0 57 int samples_per_second,
michael@0 58 const uint8_t* extra_data,
michael@0 59 size_t extra_data_size,
michael@0 60 bool is_encrypted) {
michael@0 61 CHECK((extra_data_size != 0) == (extra_data != NULL));
michael@0 62
michael@0 63 codec_ = codec;
michael@0 64 channel_layout_ = channel_layout;
michael@0 65 samples_per_second_ = samples_per_second;
michael@0 66 sample_format_ = sample_format;
michael@0 67 bits_per_channel_ = SampleFormatToBitsPerChannel(sample_format);
michael@0 68 extra_data_.assign(extra_data, extra_data + extra_data_size);
michael@0 69 is_encrypted_ = is_encrypted;
michael@0 70
michael@0 71 int channels = ChannelLayoutToChannelCount(channel_layout_);
michael@0 72 bytes_per_frame_ = channels * bits_per_channel_ / 8;
michael@0 73 }
michael@0 74
michael@0 75 AudioDecoderConfig::~AudioDecoderConfig() {}
michael@0 76
michael@0 77 bool AudioDecoderConfig::IsValidConfig() const {
michael@0 78 return codec_ != kUnknownAudioCodec &&
michael@0 79 channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
michael@0 80 bits_per_channel_ > 0 &&
michael@0 81 bits_per_channel_ <= kMaxBitsPerSample &&
michael@0 82 samples_per_second_ > 0 &&
michael@0 83 samples_per_second_ <= kMaxSampleRate &&
michael@0 84 sample_format_ != kUnknownSampleFormat;
michael@0 85 }
michael@0 86
michael@0 87 bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
michael@0 88 return ((codec() == config.codec()) &&
michael@0 89 (bits_per_channel() == config.bits_per_channel()) &&
michael@0 90 (channel_layout() == config.channel_layout()) &&
michael@0 91 (samples_per_second() == config.samples_per_second()) &&
michael@0 92 (extra_data_size() == config.extra_data_size()) &&
michael@0 93 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
michael@0 94 extra_data_size())) &&
michael@0 95 (is_encrypted() == config.is_encrypted()) &&
michael@0 96 (sample_format() == config.sample_format()));
michael@0 97 }
michael@0 98
michael@0 99 std::string AudioDecoderConfig::AsHumanReadableString() const {
michael@0 100 std::ostringstream s;
michael@0 101 s << "codec: " << codec()
michael@0 102 << " bits/channel: " << bits_per_channel()
michael@0 103 << " samples/s: " << samples_per_second()
michael@0 104 << " has extra data? " << (extra_data() ? "true" : "false")
michael@0 105 << " encrypted? " << (is_encrypted() ? "true" : "false");
michael@0 106 return s.str();
michael@0 107 }
michael@0 108
michael@0 109 } // namespace mp4_demuxer

mercurial