DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
audio_stream_info.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/base/audio_stream_info.h"
8 
9 #include "packager/base/logging.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/base/strings/stringprintf.h"
12 #include "packager/media/base/limits.h"
13 
14 namespace edash_packager {
15 namespace media {
16 
17 namespace {
18 std::string AudioCodecToString(AudioCodec audio_codec) {
19  switch (audio_codec) {
20  case kCodecAAC:
21  return "AAC";
22  case kCodecMP3:
23  return "MP3";
24  case kCodecPCM:
25  return "PCM";
26  case kCodecVorbis:
27  return "Vorbis";
28  case kCodecFLAC:
29  return "FLAC";
30  case kCodecAMR_NB:
31  return "AMR_NB";
32  case kCodecAMR_WB:
33  return "AMR_WB";
34  case kCodecPCM_MULAW:
35  return "PCM_MULAW";
36  case kCodecGSM_MS:
37  return "GSM_MS";
38  case kCodecPCM_S16BE:
39  return "PCM_S16BE";
40  case kCodecPCM_S24BE:
41  return "PCM_S24BE";
42  case kCodecOpus:
43  return "Opus";
44  case kCodecEAC3:
45  return "EAC3";
46  case kCodecDTSC:
47  return "DTSC";
48  case kCodecDTSH:
49  return "DTSH";
50  case kCodecDTSL:
51  return "DTSL";
52  case kCodecDTSE:
53  return "DTSE";
54  case kCodecDTSP:
55  return "DTS+";
56  case kCodecDTSM:
57  return "DTS-";
58  default:
59  NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec;
60  return "UnknownAudioCodec";
61  }
62 }
63 } // namespace
64 
66  uint32_t time_scale,
67  uint64_t duration,
68  AudioCodec codec,
69  const std::string& codec_string,
70  const std::string& language,
71  uint8_t sample_bits,
72  uint8_t num_channels,
73  uint32_t sampling_frequency,
74  const uint8_t* extra_data,
75  size_t extra_data_size,
76  bool is_encrypted)
77  : StreamInfo(kStreamAudio,
78  track_id,
79  time_scale,
80  duration,
81  codec_string,
82  language,
83  extra_data,
84  extra_data_size,
85  is_encrypted),
86  codec_(codec),
87  sample_bits_(sample_bits),
88  num_channels_(num_channels),
89  sampling_frequency_(sampling_frequency) {
90 }
91 
92 AudioStreamInfo::~AudioStreamInfo() {}
93 
95  return codec_ != kUnknownAudioCodec && num_channels_ != 0 &&
96  num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
97  sample_bits_ <= limits::kMaxBitsPerSample &&
98  sampling_frequency_ > 0 &&
99  sampling_frequency_ <= limits::kMaxSampleRate;
100 }
101 
102 std::string AudioStreamInfo::ToString() const {
103  return base::StringPrintf(
104  "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
105  "sampling_frequency: %d\n language: %s\n",
106  StreamInfo::ToString().c_str(), AudioCodecToString(codec_).c_str(),
107  sample_bits_, num_channels_, sampling_frequency_, language().c_str());
108 }
109 
110 std::string AudioStreamInfo::GetCodecString(AudioCodec codec,
111  uint8_t audio_object_type) {
112  switch (codec) {
113  case kCodecVorbis:
114  return "vorbis";
115  case kCodecOpus:
116  return "opus";
117  case kCodecAAC:
118  return "mp4a.40." + base::UintToString(audio_object_type);
119  case kCodecDTSC:
120  return "dtsc";
121  case kCodecDTSH:
122  return "dtsh";
123  case kCodecDTSL:
124  return "dtsl";
125  case kCodecDTSE:
126  return "dtse";
127  case kCodecDTSP:
128  return "dts+";
129  case kCodecDTSM:
130  return "dts-";
131  default:
132  NOTIMPLEMENTED() << "Codec: " << codec;
133  return "unknown";
134  }
135 }
136 
137 } // namespace media
138 } // namespace edash_packager
std::string ToString() const override
Abstract class holds stream information.
Definition: stream_info.h:26
AudioStreamInfo(int track_id, uint32_t time_scale, uint64_t duration, AudioCodec codec, const std::string &codec_string, const std::string &language, uint8_t sample_bits, uint8_t num_channels, uint32_t sampling_frequency, const uint8_t *extra_data, size_t extra_data_size, bool is_encrypted)
Construct an initialized audio stream info object.
virtual std::string ToString() const
Definition: stream_info.cc:40
static std::string GetCodecString(AudioCodec codec, uint8_t audio_object_type)