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 <inttypes.h>
10 
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/string_number_conversions.h"
13 #include "packager/base/strings/stringprintf.h"
14 #include "packager/media/base/limits.h"
15 
16 namespace shaka {
17 namespace media {
18 
19 namespace {
20 std::string AudioCodecToString(AudioCodec audio_codec) {
21  switch (audio_codec) {
22  case kCodecAAC:
23  return "AAC";
24  case kCodecAC3:
25  return "AC3";
26  case kCodecDTSC:
27  return "DTSC";
28  case kCodecDTSE:
29  return "DTSE";
30  case kCodecDTSH:
31  return "DTSH";
32  case kCodecDTSL:
33  return "DTSL";
34  case kCodecDTSM:
35  return "DTS-";
36  case kCodecDTSP:
37  return "DTS+";
38  case kCodecEAC3:
39  return "EAC3";
40  case kCodecOpus:
41  return "Opus";
42  case kCodecVorbis:
43  return "Vorbis";
44  default:
45  NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec;
46  return "UnknownAudioCodec";
47  }
48 }
49 } // namespace
50 
52  uint32_t time_scale,
53  uint64_t duration,
54  AudioCodec codec,
55  const std::string& codec_string,
56  const std::string& language,
57  uint8_t sample_bits,
58  uint8_t num_channels,
59  uint32_t sampling_frequency,
60  uint64_t seek_preroll_ns,
61  uint64_t codec_delay_ns,
62  uint32_t max_bitrate,
63  uint32_t avg_bitrate,
64  const uint8_t* extra_data,
65  size_t extra_data_size,
66  bool is_encrypted)
67  : StreamInfo(kStreamAudio,
68  track_id,
69  time_scale,
70  duration,
71  codec_string,
72  language,
73  extra_data,
74  extra_data_size,
75  is_encrypted),
76  codec_(codec),
77  sample_bits_(sample_bits),
78  num_channels_(num_channels),
79  sampling_frequency_(sampling_frequency),
80  seek_preroll_ns_(seek_preroll_ns),
81  codec_delay_ns_(codec_delay_ns),
82  max_bitrate_(max_bitrate),
83  avg_bitrate_(avg_bitrate) {}
84 
85 AudioStreamInfo::~AudioStreamInfo() {}
86 
88  return codec_ != kUnknownAudioCodec && num_channels_ != 0 &&
89  num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
90  sample_bits_ <= limits::kMaxBitsPerSample &&
91  sampling_frequency_ > 0 &&
92  sampling_frequency_ <= limits::kMaxSampleRate;
93 }
94 
95 std::string AudioStreamInfo::ToString() const {
96  std::string str = base::StringPrintf(
97  "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
98  "sampling_frequency: %d\n language: %s\n",
99  StreamInfo::ToString().c_str(), AudioCodecToString(codec_).c_str(),
100  sample_bits_, num_channels_, sampling_frequency_, language().c_str());
101  if (seek_preroll_ns_ != 0) {
102  base::StringAppendF(&str, " seek_preroll_ns: %" PRIu64 "\n",
103  seek_preroll_ns_);
104  }
105  if (codec_delay_ns_ != 0) {
106  base::StringAppendF(&str, " codec_delay_ns: %" PRIu64 "\n",
107  codec_delay_ns_);
108  }
109  return str;
110 }
111 
112 std::string AudioStreamInfo::GetCodecString(AudioCodec codec,
113  uint8_t audio_object_type) {
114  switch (codec) {
115  case kCodecVorbis:
116  return "vorbis";
117  case kCodecOpus:
118  return "opus";
119  case kCodecAAC:
120  return "mp4a.40." + base::UintToString(audio_object_type);
121  case kCodecDTSC:
122  return "dtsc";
123  case kCodecDTSH:
124  return "dtsh";
125  case kCodecDTSL:
126  return "dtsl";
127  case kCodecDTSE:
128  return "dtse";
129  case kCodecDTSP:
130  return "dts+";
131  case kCodecDTSM:
132  return "dts-";
133  case kCodecAC3:
134  return "ac-3";
135  case kCodecEAC3:
136  return "ec-3";
137  default:
138  NOTIMPLEMENTED() << "Codec: " << codec;
139  return "unknown";
140  }
141 }
142 
143 } // namespace media
144 } // namespace shaka
static std::string GetCodecString(AudioCodec codec, uint8_t audio_object_type)
Abstract class holds stream information.
Definition: stream_info.h:26
std::string ToString() const override
bool IsValidConfig() const override
virtual std::string ToString() const
Definition: stream_info.cc:40
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, uint64_t seek_preroll_ns, uint64_t codec_delay_ns, 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.