content/media/fmp4/demuxer/audio_decoder_config.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
michael@0 6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
michael@0 7
michael@0 8 #include <vector>
michael@0 9
michael@0 10 #include "mp4_demuxer/basictypes.h"
michael@0 11 #include "mp4_demuxer/channel_layout.h"
michael@0 12
michael@0 13 namespace mp4_demuxer {
michael@0 14
michael@0 15 enum AudioCodec {
michael@0 16 // These values are histogrammed over time; do not change their ordinal
michael@0 17 // values. When deleting a codec replace it with a dummy value; when adding a
michael@0 18 // codec, do so at the bottom before kAudioCodecMax.
michael@0 19 kUnknownAudioCodec = 0,
michael@0 20 kCodecAAC,
michael@0 21 kCodecMP3,
michael@0 22 kCodecPCM,
michael@0 23 kCodecVorbis,
michael@0 24 kCodecFLAC,
michael@0 25 kCodecAMR_NB,
michael@0 26 kCodecAMR_WB,
michael@0 27 kCodecPCM_MULAW,
michael@0 28 kCodecGSM_MS,
michael@0 29 kCodecPCM_S16BE,
michael@0 30 kCodecPCM_S24BE,
michael@0 31 kCodecOpus,
michael@0 32 // DO NOT ADD RANDOM AUDIO CODECS!
michael@0 33 //
michael@0 34 // The only acceptable time to add a new codec is if there is production code
michael@0 35 // that uses said codec in the same CL.
michael@0 36
michael@0 37 // Must always be last!
michael@0 38 kAudioCodecMax
michael@0 39 };
michael@0 40
michael@0 41 enum SampleFormat {
michael@0 42 // These values are histogrammed over time; do not change their ordinal
michael@0 43 // values. When deleting a sample format replace it with a dummy value; when
michael@0 44 // adding a sample format, do so at the bottom before kSampleFormatMax.
michael@0 45 kUnknownSampleFormat = 0,
michael@0 46 kSampleFormatU8, // Unsigned 8-bit w/ bias of 128.
michael@0 47 kSampleFormatS16, // Signed 16-bit.
michael@0 48 kSampleFormatS32, // Signed 32-bit.
michael@0 49 kSampleFormatF32, // Float 32-bit.
michael@0 50 kSampleFormatPlanarS16, // Signed 16-bit planar.
michael@0 51 kSampleFormatPlanarF32, // Float 32-bit planar.
michael@0 52
michael@0 53 // Must always be last!
michael@0 54 kSampleFormatMax
michael@0 55 };
michael@0 56
michael@0 57 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
michael@0 58 // |bits_per_channel|, we should switch over since bits are generally confusing
michael@0 59 // to work with.
michael@0 60 class AudioDecoderConfig {
michael@0 61 public:
michael@0 62 // Constructs an uninitialized object. Clients should call Initialize() with
michael@0 63 // appropriate values before using.
michael@0 64 AudioDecoderConfig();
michael@0 65
michael@0 66 // Constructs an initialized object. It is acceptable to pass in NULL for
michael@0 67 // |extra_data|, otherwise the memory is copied.
michael@0 68 AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
michael@0 69 ChannelLayout channel_layout, int samples_per_second,
michael@0 70 const uint8_t* extra_data, size_t extra_data_size,
michael@0 71 bool is_encrypted);
michael@0 72
michael@0 73 ~AudioDecoderConfig();
michael@0 74
michael@0 75 // Resets the internal state of this object.
michael@0 76 void Initialize(AudioCodec codec, SampleFormat sample_format,
michael@0 77 ChannelLayout channel_layout, int samples_per_second,
michael@0 78 const uint8_t* extra_data, size_t extra_data_size,
michael@0 79 bool is_encrypted);
michael@0 80
michael@0 81 // Returns true if this object has appropriate configuration values, false
michael@0 82 // otherwise.
michael@0 83 bool IsValidConfig() const;
michael@0 84
michael@0 85 // Returns true if all fields in |config| match this config.
michael@0 86 // Note: The contents of |extra_data_| are compared not the raw pointers.
michael@0 87 bool Matches(const AudioDecoderConfig& config) const;
michael@0 88
michael@0 89 AudioCodec codec() const { return codec_; }
michael@0 90 int bits_per_channel() const { return bits_per_channel_; }
michael@0 91 ChannelLayout channel_layout() const { return channel_layout_; }
michael@0 92 int samples_per_second() const { return samples_per_second_; }
michael@0 93 SampleFormat sample_format() const { return sample_format_; }
michael@0 94 int bytes_per_frame() const { return bytes_per_frame_; }
michael@0 95
michael@0 96 // Optional byte data required to initialize audio decoders such as Vorbis
michael@0 97 // codebooks.
michael@0 98 const uint8_t* extra_data() const {
michael@0 99 return extra_data_.empty() ? NULL : &extra_data_[0];
michael@0 100 }
michael@0 101 size_t extra_data_size() const { return extra_data_.size(); }
michael@0 102
michael@0 103 // Whether the audio stream is potentially encrypted.
michael@0 104 // Note that in a potentially encrypted audio stream, individual buffers
michael@0 105 // can be encrypted or not encrypted.
michael@0 106 bool is_encrypted() const { return is_encrypted_; }
michael@0 107
michael@0 108 std::string AsHumanReadableString() const;
michael@0 109
michael@0 110 private:
michael@0 111 AudioCodec codec_;
michael@0 112 SampleFormat sample_format_;
michael@0 113 int bits_per_channel_;
michael@0 114 ChannelLayout channel_layout_;
michael@0 115 int samples_per_second_;
michael@0 116 int bytes_per_frame_;
michael@0 117 std::vector<uint8_t> extra_data_;
michael@0 118 bool is_encrypted_;
michael@0 119
michael@0 120 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
michael@0 121 // generated copy constructor and assignment operator. Since the extra data is
michael@0 122 // typically small, the performance impact is minimal.
michael@0 123 };
michael@0 124
michael@0 125 } // namespace mp4_demuxer
michael@0 126
michael@0 127 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_

mercurial