content/media/fmp4/demuxer/audio_decoder_config.cc

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial