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