Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / formats / mp4 / aac.cc
index fedb33f..45cc129 100644 (file)
@@ -9,39 +9,9 @@
 #include "base/logging.h"
 #include "media/base/bit_reader.h"
 #include "media/formats/mp4/rcheck.h"
-
-// The following conversion table is extracted from ISO 14496 Part 3 -
-// Table 1.16 - Sampling Frequency Index.
-static const int kFrequencyMap[] = {
-  96000, 88200, 64000, 48000, 44100, 32000, 24000,
-  22050, 16000, 12000, 11025, 8000, 7350
-};
+#include "media/formats/mpeg/adts_constants.h"
 
 namespace media {
-
-static ChannelLayout ConvertChannelConfigToLayout(uint8 channel_config) {
-  switch (channel_config) {
-    case 1:
-      return CHANNEL_LAYOUT_MONO;
-    case 2:
-      return CHANNEL_LAYOUT_STEREO;
-    case 3:
-      return CHANNEL_LAYOUT_SURROUND;
-    case 4:
-      return CHANNEL_LAYOUT_4_0;
-    case 5:
-      return CHANNEL_LAYOUT_5_0;
-    case 6:
-      return CHANNEL_LAYOUT_5_1;
-    case 8:
-      return CHANNEL_LAYOUT_7_1;
-    default:
-      break;
-  }
-
-  return CHANNEL_LAYOUT_UNSUPPORTED;
-}
-
 namespace mp4 {
 
 AAC::AAC()
@@ -122,24 +92,25 @@ bool AAC::Parse(const std::vector<uint8>& data) {
   }
 
   if (frequency_ == 0) {
-    RCHECK(frequency_index_ < arraysize(kFrequencyMap));
-    frequency_ = kFrequencyMap[frequency_index_];
+    RCHECK(frequency_index_ < kADTSFrequencyTableSize);
+    frequency_ = kADTSFrequencyTable[frequency_index_];
   }
 
   if (extension_frequency_ == 0 && extension_frequency_index != 0xff) {
-    RCHECK(extension_frequency_index < arraysize(kFrequencyMap));
-    extension_frequency_ = kFrequencyMap[extension_frequency_index];
+    RCHECK(extension_frequency_index < kADTSFrequencyTableSize);
+    extension_frequency_ = kADTSFrequencyTable[extension_frequency_index];
   }
 
   // When Parametric Stereo is on, mono will be played as stereo.
-  if (ps_present && channel_config_ == 1)
+  if (ps_present && channel_config_ == 1) {
     channel_layout_ = CHANNEL_LAYOUT_STEREO;
-  else
-    channel_layout_ = ConvertChannelConfigToLayout(channel_config_);
+  } else {
+    RCHECK(channel_config_ < kADTSChannelLayoutTableSize);
+    channel_layout_ = kADTSChannelLayoutTable[channel_config_];
+  }
 
-  return frequency_ != 0 && channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
-      profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf &&
-      channel_config_ <= 7;
+  return frequency_ != 0 && channel_layout_ != CHANNEL_LAYOUT_NONE &&
+         profile_ >= 1 && profile_ <= 4;
 }
 
 int AAC::GetOutputSamplesPerSecond(bool sbr_in_mimetype) const {
@@ -168,7 +139,7 @@ ChannelLayout AAC::GetChannelLayout(bool sbr_in_mimetype) const {
 }
 
 bool AAC::ConvertEsdsToADTS(std::vector<uint8>* buffer) const {
-  size_t size = buffer->size() + kADTSHeaderSize;
+  size_t size = buffer->size() + kADTSHeaderMinSize;
 
   DCHECK(profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf &&
          channel_config_ <= 7);
@@ -179,7 +150,7 @@ bool AAC::ConvertEsdsToADTS(std::vector<uint8>* buffer) const {
 
   std::vector<uint8>& adts = *buffer;
 
-  adts.insert(buffer->begin(), kADTSHeaderSize, 0);
+  adts.insert(buffer->begin(), kADTSHeaderMinSize, 0);
   adts[0] = 0xff;
   adts[1] = 0xf1;
   adts[2] = ((profile_ - 1) << 6) + (frequency_index_ << 2) +