DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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  default:
47  NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec;
48  return "UnknownAudioCodec";
49  }
50 }
51 } // namespace
52 
54  uint32_t time_scale,
55  uint64_t duration,
56  AudioCodec codec,
57  const std::string& codec_string,
58  const std::string& language,
59  uint8_t sample_bits,
60  uint8_t num_channels,
61  uint32_t sampling_frequency,
62  const uint8_t* extra_data,
63  size_t extra_data_size,
64  bool is_encrypted)
65  : StreamInfo(kStreamAudio,
66  track_id,
67  time_scale,
68  duration,
69  codec_string,
70  language,
71  extra_data,
72  extra_data_size,
73  is_encrypted),
74  codec_(codec),
75  sample_bits_(sample_bits),
76  num_channels_(num_channels),
77  sampling_frequency_(sampling_frequency) {
78 }
79 
80 AudioStreamInfo::~AudioStreamInfo() {}
81 
83  return codec_ != kUnknownAudioCodec && num_channels_ != 0 &&
84  num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
85  sample_bits_ <= limits::kMaxBitsPerSample &&
86  sampling_frequency_ > 0 &&
87  sampling_frequency_ <= limits::kMaxSampleRate;
88 }
89 
90 std::string AudioStreamInfo::ToString() const {
91  return base::StringPrintf(
92  "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
93  "sampling_frequency: %d\n language: %s\n",
94  StreamInfo::ToString().c_str(), AudioCodecToString(codec_).c_str(),
95  sample_bits_, num_channels_, sampling_frequency_, language().c_str());
96 }
97 
98 std::string AudioStreamInfo::GetCodecString(AudioCodec codec,
99  uint8_t audio_object_type) {
100  switch (codec) {
101  case kCodecVorbis:
102  return "vorbis";
103  case kCodecOpus:
104  return "opus";
105  case kCodecAAC:
106  return "mp4a.40." + base::UintToString(audio_object_type);
107  default:
108  NOTIMPLEMENTED() << "Codec: " << codec;
109  return "unknown";
110  }
111 }
112 
113 } // namespace media
114 } // namespace edash_packager
Abstract class holds stream information.
Definition: stream_info.h:25
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
virtual std::string ToString() const OVERRIDE
virtual bool IsValidConfig() const OVERRIDE
static std::string GetCodecString(AudioCodec codec, uint8_t audio_object_type)