DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations 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 kCodecAC3:
23  return "AC3";
24  case kCodecDTSC:
25  return "DTSC";
26  case kCodecDTSE:
27  return "DTSE";
28  case kCodecDTSH:
29  return "DTSH";
30  case kCodecDTSL:
31  return "DTSL";
32  case kCodecDTSM:
33  return "DTS-";
34  case kCodecDTSP:
35  return "DTS+";
36  case kCodecEAC3:
37  return "EAC3";
38  case kCodecOpus:
39  return "Opus";
40  case kCodecVorbis:
41  return "Vorbis";
42  default:
43  NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec;
44  return "UnknownAudioCodec";
45  }
46 }
47 } // namespace
48 
50  uint32_t time_scale,
51  uint64_t duration,
52  AudioCodec codec,
53  const std::string& codec_string,
54  const std::string& language,
55  uint8_t sample_bits,
56  uint8_t num_channels,
57  uint32_t sampling_frequency,
58  uint32_t max_bitrate,
59  uint32_t avg_bitrate,
60  const uint8_t* extra_data,
61  size_t extra_data_size,
62  bool is_encrypted)
63  : StreamInfo(kStreamAudio,
64  track_id,
65  time_scale,
66  duration,
67  codec_string,
68  language,
69  extra_data,
70  extra_data_size,
71  is_encrypted),
72  codec_(codec),
73  sample_bits_(sample_bits),
74  num_channels_(num_channels),
75  sampling_frequency_(sampling_frequency),
76  max_bitrate_(max_bitrate),
77  avg_bitrate_(avg_bitrate) {}
78 
79 AudioStreamInfo::~AudioStreamInfo() {}
80 
82  return codec_ != kUnknownAudioCodec && num_channels_ != 0 &&
83  num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
84  sample_bits_ <= limits::kMaxBitsPerSample &&
85  sampling_frequency_ > 0 &&
86  sampling_frequency_ <= limits::kMaxSampleRate;
87 }
88 
89 std::string AudioStreamInfo::ToString() const {
90  return base::StringPrintf(
91  "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
92  "sampling_frequency: %d\n language: %s\n",
93  StreamInfo::ToString().c_str(), AudioCodecToString(codec_).c_str(),
94  sample_bits_, num_channels_, sampling_frequency_, language().c_str());
95 }
96 
97 std::string AudioStreamInfo::GetCodecString(AudioCodec codec,
98  uint8_t audio_object_type) {
99  switch (codec) {
100  case kCodecVorbis:
101  return "vorbis";
102  case kCodecOpus:
103  return "opus";
104  case kCodecAAC:
105  return "mp4a.40." + base::UintToString(audio_object_type);
106  case kCodecDTSC:
107  return "dtsc";
108  case kCodecDTSH:
109  return "dtsh";
110  case kCodecDTSL:
111  return "dtsl";
112  case kCodecDTSE:
113  return "dtse";
114  case kCodecDTSP:
115  return "dts+";
116  case kCodecDTSM:
117  return "dts-";
118  case kCodecAC3:
119  return "ac-3";
120  case kCodecEAC3:
121  return "ec-3";
122  default:
123  NOTIMPLEMENTED() << "Codec: " << codec;
124  return "unknown";
125  }
126 }
127 
128 } // namespace media
129 } // 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, uint32_t max_bitrate, uint32_t avg_bitrate, 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)