Import Cobalt 19.master.0.205881
diff --git a/src/content/browser/speech/audio_buffer.cc b/src/content/browser/speech/audio_buffer.cc
new file mode 100644
index 0000000..1038ac9
--- /dev/null
+++ b/src/content/browser/speech/audio_buffer.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/speech/audio_buffer.h"
+
+#include "base/logging.h"
+
+namespace content {
+
+AudioChunk::AudioChunk(int bytes_per_sample)
+    : bytes_per_sample_(bytes_per_sample) {
+}
+
+AudioChunk::AudioChunk(size_t length, int bytes_per_sample)
+    : data_string_(length, '\0'), bytes_per_sample_(bytes_per_sample) {
+  DCHECK_EQ(length % bytes_per_sample, 0U);
+}
+
+AudioChunk::AudioChunk(const uint8_t* data, size_t length, int bytes_per_sample)
+    : data_string_(reinterpret_cast<const char*>(data), length),
+      bytes_per_sample_(bytes_per_sample) {
+  DCHECK_EQ(length % bytes_per_sample, 0U);
+}
+
+bool AudioChunk::IsEmpty() const {
+  return data_string_.empty();
+}
+
+size_t AudioChunk::NumSamples() const {
+  return data_string_.size() / bytes_per_sample_;
+}
+
+const std::string& AudioChunk::AsString() const {
+  return data_string_;
+}
+
+int16_t AudioChunk::GetSample16(size_t index) const {
+  DCHECK(index < (data_string_.size() / sizeof(int16_t)));
+  return SamplesData16()[index];
+}
+
+const int16_t* AudioChunk::SamplesData16() const {
+  return reinterpret_cast<const int16_t*>(data_string_.data());
+}
+
+AudioBuffer::AudioBuffer(int bytes_per_sample)
+    : bytes_per_sample_(bytes_per_sample) {
+  DCHECK(bytes_per_sample == 1 ||
+         bytes_per_sample == 2 ||
+         bytes_per_sample == 4);
+}
+
+AudioBuffer::~AudioBuffer() {
+  Clear();
+}
+
+void AudioBuffer::Enqueue(const uint8_t* data, size_t length) {
+  chunks_.push_back(new AudioChunk(data, length, bytes_per_sample_));
+}
+
+scoped_refptr<AudioChunk> AudioBuffer::DequeueSingleChunk() {
+  DCHECK(!chunks_.empty());
+  scoped_refptr<AudioChunk> chunk(chunks_.front());
+  chunks_.pop_front();
+  return chunk;
+}
+
+scoped_refptr<AudioChunk> AudioBuffer::DequeueAll() {
+  size_t resulting_length = 0;
+  ChunksContainer::const_iterator it;
+  // In order to improve performance, calulate in advance the total length
+  // and then copy the chunks.
+  for (it = chunks_.begin(); it != chunks_.end(); ++it) {
+    resulting_length += (*it)->AsString().length();
+  }
+  scoped_refptr<AudioChunk> chunk(
+      new AudioChunk(resulting_length, bytes_per_sample_));
+  uint8_t* dest = chunk->writable_data();
+  for (it = chunks_.begin(); it != chunks_.end(); ++it) {
+    memcpy(dest, (*it)->AsString().data(), (*it)->AsString().length());
+    dest += (*it)->AsString().length();
+  }
+  Clear();
+  return chunk;
+}
+
+void AudioBuffer::Clear() {
+  chunks_.clear();
+}
+
+bool AudioBuffer::IsEmpty() const {
+  return chunks_.empty();
+}
+
+}  // namespace content
diff --git a/src/content/browser/speech/audio_buffer.h b/src/content/browser/speech/audio_buffer.h
new file mode 100644
index 0000000..1231fa4
--- /dev/null
+++ b/src/content/browser/speech/audio_buffer.h
@@ -0,0 +1,84 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
+#define CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+
+#include "base/containers/circular_deque.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+// Models a chunk derived from an AudioBuffer.
+class CONTENT_EXPORT AudioChunk :
+    public base::RefCountedThreadSafe<AudioChunk> {
+ public:
+  explicit AudioChunk(int bytes_per_sample);
+  // Creates a chunk of |length| bytes, initialized to zeros.
+  AudioChunk(size_t length, int bytes_per_sample);
+  AudioChunk(const uint8_t* data, size_t length, int bytes_per_sample);
+
+  bool IsEmpty() const;
+  int bytes_per_sample() const { return bytes_per_sample_; }
+  size_t NumSamples() const;
+  const std::string& AsString() const;
+  int16_t GetSample16(size_t index) const;
+  const int16_t* SamplesData16() const;
+  uint8_t* writable_data() {
+    return reinterpret_cast<uint8_t*>(&data_string_[0]);
+  }
+
+ private:
+  friend class base::RefCountedThreadSafe<AudioChunk>;
+  ~AudioChunk() {}
+
+  std::string data_string_;
+  const int bytes_per_sample_;
+
+  DISALLOW_COPY_AND_ASSIGN(AudioChunk);
+};
+
+// Models an audio buffer. The current implementation relies on on-demand
+// allocations of AudioChunk(s) (which uses a string as storage).
+class AudioBuffer {
+ public:
+  explicit AudioBuffer(int bytes_per_sample);
+  ~AudioBuffer();
+
+  // Enqueues a copy of |length| bytes of |data| buffer.
+  void Enqueue(const uint8_t* data, size_t length);
+
+  // Dequeues, in FIFO order, a single chunk respecting the length of the
+  // corresponding Enqueue call (in a nutshell: multiple Enqueue calls followed
+  // by DequeueSingleChunk calls will return the individual chunks without
+  // merging them).
+  scoped_refptr<AudioChunk> DequeueSingleChunk();
+
+  // Dequeues all previously enqueued chunks, merging them in a single chunk.
+  scoped_refptr<AudioChunk> DequeueAll();
+
+  // Removes and frees all the enqueued chunks.
+  void Clear();
+
+  // Checks whether the buffer is empty.
+  bool IsEmpty() const;
+
+ private:
+  using ChunksContainer = base::circular_deque<scoped_refptr<AudioChunk>>;
+  ChunksContainer chunks_;
+  const int bytes_per_sample_;
+
+  DISALLOW_COPY_AND_ASSIGN(AudioBuffer);
+};
+
+}  // namespace content
+
+#endif  // CONTENT_BROWSER_SPEECH_AUDIO_BUFFER_H_
diff --git a/src/content/browser/speech/chunked_byte_buffer.cc b/src/content/browser/speech/chunked_byte_buffer.cc
index 8ac9c92..5e3f70c 100644
--- a/src/content/browser/speech/chunked_byte_buffer.cc
+++ b/src/content/browser/speech/chunked_byte_buffer.cc
@@ -7,22 +7,16 @@
 #include <algorithm>
 #include <utility>
 
-#include "base/basictypes.h"
+#include "base/big_endian.h"
+#include "base/lazy_instance.h"
 #include "base/logging.h"
 
 namespace {
 
 static const size_t kHeaderLength = sizeof(uint32_t);
 
-COMPILE_ASSERT(sizeof(size_t) >= kHeaderLength,
-               chunked_byte_buffer_not_supported_on_this_architecture);
-
-uint32_t ReadBigEndian32(const uint8_t* buffer) {
-  return (static_cast<uint32_t>(buffer[3])) |
-         (static_cast<uint32_t>(buffer[2]) << 8) |
-         (static_cast<uint32_t>(buffer[1]) << 16) |
-         (static_cast<uint32_t>(buffer[0]) << 24);
-}
+static_assert(sizeof(size_t) >= kHeaderLength,
+              "chunked byte buffer not supported on this architecture");
 
 }  // namespace
 
@@ -42,7 +36,7 @@
   const uint8_t* next_data = start;
 
   while (remaining_bytes > 0) {
-    DCHECK(partial_chunk_ != NULL);
+    DCHECK(partial_chunk_ != nullptr);
     size_t insert_length = 0;
     bool header_completed = false;
     bool content_completed = false;
@@ -78,7 +72,7 @@
       DCHECK_EQ(partial_chunk_->header.size(), kHeaderLength);
       if (partial_chunk_->ExpectedContentLength() == 0) {
         // Handle zero-byte chunks.
-        chunks_.push_back(partial_chunk_.release());
+        chunks_.push_back(std::move(partial_chunk_));
         partial_chunk_.reset(new Chunk());
       } else {
         partial_chunk_->content->reserve(
@@ -87,7 +81,7 @@
     } else if (content_completed) {
       DCHECK_EQ(partial_chunk_->content->size(),
                 partial_chunk_->ExpectedContentLength());
-      chunks_.push_back(partial_chunk_.release());
+      chunks_.push_back(std::move(partial_chunk_));
       partial_chunk_.reset(new Chunk());
     }
   }
@@ -95,7 +89,7 @@
   total_bytes_stored_ += length;
 }
 
-void ChunkedByteBuffer::Append(const std::string& string) {
+void ChunkedByteBuffer::Append(base::StringPiece string) {
   Append(reinterpret_cast<const uint8_t*>(string.data()), string.size());
 }
 
@@ -103,16 +97,16 @@
   return !chunks_.empty();
 }
 
-scoped_ptr<std::vector<uint8_t> > ChunkedByteBuffer::PopChunk() {
+std::unique_ptr<std::vector<uint8_t>> ChunkedByteBuffer::PopChunk() {
   if (chunks_.empty())
-    return scoped_ptr<std::vector<uint8_t> >().Pass();
-  scoped_ptr<Chunk> chunk(*chunks_.begin());
-  chunks_.weak_erase(chunks_.begin());
+    return std::unique_ptr<std::vector<uint8_t>>();
+  std::unique_ptr<Chunk> chunk = std::move(*chunks_.begin());
+  chunks_.erase(chunks_.begin());
   DCHECK_EQ(chunk->header.size(), kHeaderLength);
   DCHECK_EQ(chunk->content->size(), chunk->ExpectedContentLength());
   total_bytes_stored_ -= chunk->content->size();
   total_bytes_stored_ -= kHeaderLength;
-  return chunk->content.Pass();
+  return std::move(chunk->content);
 }
 
 void ChunkedByteBuffer::Clear() {
@@ -128,7 +122,10 @@
 
 size_t ChunkedByteBuffer::Chunk::ExpectedContentLength() const {
   DCHECK_EQ(header.size(), kHeaderLength);
-  return static_cast<size_t>(ReadBigEndian32(&header[0]));
+  uint32_t content_length = 0;
+  base::ReadBigEndian(reinterpret_cast<const char*>(&header[0]),
+                      &content_length);
+  return static_cast<size_t>(content_length);
 }
 
 }  // namespace content
diff --git a/src/content/browser/speech/chunked_byte_buffer.h b/src/content/browser/speech/chunked_byte_buffer.h
index 483ddb9..98bdd92 100644
--- a/src/content/browser/speech/chunked_byte_buffer.h
+++ b/src/content/browser/speech/chunked_byte_buffer.h
@@ -5,12 +5,16 @@
 #ifndef CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_
 #define CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_
 
+#include <stddef.h>
+#include <stdint.h>
+
 #include <memory>
 #include <string>
 #include <vector>
 
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "content/common/content_export.h"
 
 namespace content {
 
@@ -24,7 +28,7 @@
 //
 // E.g. 00 00 00 04 xx xx xx xx 00 00 00 02 yy yy 00 00 00 04 zz zz zz zz
 //      [----- CHUNK 1 -------] [--- CHUNK 2 ---] [------ CHUNK 3 ------]
-class ChunkedByteBuffer {
+class CONTENT_EXPORT ChunkedByteBuffer {
  public:
   ChunkedByteBuffer();
   ~ChunkedByteBuffer();
@@ -33,14 +37,14 @@
   void Append(const uint8_t* start, size_t length);
 
   // Appends bytes contained in the |string| to the buffer.
-  void Append(const std::string& string);
+  void Append(base::StringPiece string);
 
   // Checks whether one or more complete chunks are available in the buffer.
   bool HasChunks() const;
 
   // If enough data is available, reads and removes the first complete chunk
   // from the buffer. Returns a NULL pointer if no complete chunk is available.
-  scoped_ptr<std::vector<uint8_t> > PopChunk();
+  std::unique_ptr<std::vector<uint8_t>> PopChunk();
 
   // Clears all the content of the buffer.
   void Clear();
@@ -54,15 +58,15 @@
     ~Chunk();
 
     std::vector<uint8_t> header;
-    scoped_ptr<std::vector<uint8_t> > content;
+    std::unique_ptr<std::vector<uint8_t>> content;
     size_t ExpectedContentLength() const;
 
    private:
     DISALLOW_COPY_AND_ASSIGN(Chunk);
   };
 
-  ScopedVector<Chunk> chunks_;
-  scoped_ptr<Chunk> partial_chunk_;
+  std::vector<std::unique_ptr<Chunk>> chunks_;
+  std::unique_ptr<Chunk> partial_chunk_;
   size_t total_bytes_stored_;
 
   DISALLOW_COPY_AND_ASSIGN(ChunkedByteBuffer);
diff --git a/src/content/browser/speech/chunked_byte_buffer_unittest.cc b/src/content/browser/speech/chunked_byte_buffer_unittest.cc
index 9b7be0f..099d311 100644
--- a/src/content/browser/speech/chunked_byte_buffer_unittest.cc
+++ b/src/content/browser/speech/chunked_byte_buffer_unittest.cc
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include <stdint.h>
+
 #include <string>
 #include <vector>
 
@@ -40,9 +42,9 @@
   EXPECT_TRUE(buffer.HasChunks());
 
   // Remove and check chunk 1.
-  scoped_ptr<ByteVector> chunk;
-  chunk = buffer.PopChunk().Pass();
-  EXPECT_TRUE(chunk != NULL);
+  std::unique_ptr<ByteVector> chunk;
+  chunk = buffer.PopChunk();
+  EXPECT_TRUE(chunk != nullptr);
   EXPECT_EQ(4U, chunk->size());
   EXPECT_EQ(0, std::char_traits<uint8_t>::compare(kChunks + 4, &(*chunk)[0],
                                                   chunk->size()));
@@ -50,8 +52,8 @@
   EXPECT_TRUE(buffer.HasChunks());
 
   // Read and check chunk 2.
-  chunk = buffer.PopChunk().Pass();
-  EXPECT_TRUE(chunk != NULL);
+  chunk = buffer.PopChunk();
+  EXPECT_TRUE(chunk != nullptr);
   EXPECT_EQ(2U, chunk->size());
   EXPECT_EQ(0, std::char_traits<uint8_t>::compare(kChunks + 12, &(*chunk)[0],
                                                   chunk->size()));
@@ -63,8 +65,8 @@
   EXPECT_EQ(5U, buffer.GetTotalLength());
 
   // Remove and check chunk 3.
-  chunk = buffer.PopChunk().Pass();
-  EXPECT_TRUE(chunk != NULL);
+  chunk = buffer.PopChunk();
+  EXPECT_TRUE(chunk != nullptr);
   EXPECT_EQ(1U, chunk->size());
   EXPECT_EQ((*chunk)[0], kChunks[18]);
   EXPECT_EQ(0U, buffer.GetTotalLength());
diff --git a/src/content/browser/speech/endpointer/endpointer.cc b/src/content/browser/speech/endpointer/endpointer.cc
index e6d9941..87782d6 100644
--- a/src/content/browser/speech/endpointer/endpointer.cc
+++ b/src/content/browser/speech/endpointer/endpointer.cc
@@ -4,15 +4,12 @@
 
 #include "content/browser/speech/endpointer/endpointer.h"
 
-#include "base/time.h"
-
-using base::Time;
+#include "base/time/time.h"
+#include "content/browser/speech/audio_buffer.h"
 
 namespace {
-// Only send |kFrameSize| of audio data to energy endpointer each time.
-// It should be smaller than the samples of audio bus which is passed in
-// |ProcessAudio|.
-const int kFrameSize = 160;
+const int64_t kMicrosecondsPerSecond = base::Time::kMicrosecondsPerSecond;
+const int kFrameRate = 50;  // 1 frame = 20ms of audio.
 }
 
 namespace content {
@@ -22,22 +19,24 @@
       speech_input_complete_silence_length_us_(-1),
       audio_frame_time_us_(0),
       sample_rate_(sample_rate),
-      frame_rate_(sample_rate / kFrameSize) {
+      frame_size_(0) {
   Reset();
 
+  frame_size_ = static_cast<int>(sample_rate / static_cast<float>(kFrameRate));
+
   speech_input_minimum_length_us_ =
-      static_cast<int64_t>(1.7 * Time::kMicrosecondsPerSecond);
+      static_cast<int64_t>(1.7 * kMicrosecondsPerSecond);
   speech_input_complete_silence_length_us_ =
-      static_cast<int64_t>(0.5 * Time::kMicrosecondsPerSecond);
+      static_cast<int64_t>(0.5 * kMicrosecondsPerSecond);
   long_speech_input_complete_silence_length_us_ = -1;
   long_speech_length_us_ = -1;
   speech_input_possibly_complete_silence_length_us_ =
-      1 * Time::kMicrosecondsPerSecond;
+      1 * kMicrosecondsPerSecond;
 
   // Set the default configuration for Push To Talk mode.
   EnergyEndpointerParams ep_config;
-  ep_config.set_frame_period(1.0f / static_cast<float>(frame_rate_));
-  ep_config.set_frame_duration(1.0f / static_cast<float>(frame_rate_));
+  ep_config.set_frame_period(1.0f / static_cast<float>(kFrameRate));
+  ep_config.set_frame_duration(1.0f / static_cast<float>(kFrameRate));
   ep_config.set_endpoint_margin(0.2f);
   ep_config.set_onset_window(0.15f);
   ep_config.set_speech_on_window(0.4f);
@@ -62,7 +61,7 @@
   waiting_for_speech_complete_timeout_ = false;
   speech_previously_detected_ = false;
   speech_input_complete_ = false;
-  audio_frame_time_us_ = 0;  // Reset time for packets sent to endpointer.
+  audio_frame_time_us_ = 0; // Reset time for packets sent to endpointer.
   speech_end_time_us_ = -1;
   speech_start_time_us_ = -1;
 }
@@ -89,8 +88,10 @@
   return energy_endpointer_.Status(time);
 }
 
-EpStatus Endpointer::ProcessAudio(
-    const ShellAudioBus& audio_bus, float* rms_out) {
+#if defined(STARBOARD)
+EpStatus Endpointer::ProcessAudio(const ShellAudioBus& audio_bus, float* rms_out) {
+  // TODO[johnx]: replace ShellAudioData with AudioChunk and deprecate
+  // ShellAudioData.
   DCHECK_EQ(audio_bus.channels(), 1);
 
   const size_t num_samples = audio_bus.frames();
@@ -109,22 +110,26 @@
     audio_data =
         reinterpret_cast<const int16_t*>(audio_bus.interleaved_data());
   }
-
+#else
+EpStatus Endpointer::ProcessAudio(const AudioChunk& raw_audio, float* rms_out) {
+  const int16_t* audio_data = raw_audio.SamplesData16();
+  const int num_samples = raw_audio.NumSamples();
+#endif
   EpStatus ep_status = EP_PRE_SPEECH;
 
-  // Process the input data in blocks of kFrameSize, dropping any incomplete
+  // Process the input data in blocks of frame_size_, dropping any incomplete
   // frames at the end (which is ok since typically the caller will be recording
   // audio in multiples of our frame size).
   int sample_index = 0;
-  while (static_cast<size_t>(sample_index + kFrameSize) <= num_samples) {
+  while (sample_index + frame_size_ <= num_samples) {
     // Have the endpointer process the frame.
     energy_endpointer_.ProcessAudioFrame(audio_frame_time_us_,
                                          audio_data + sample_index,
-                                         kFrameSize,
+                                         frame_size_,
                                          rms_out);
-    sample_index += kFrameSize;
+    sample_index += frame_size_;
     audio_frame_time_us_ +=
-        (kFrameSize * Time::kMicrosecondsPerSecond) / sample_rate_;
+        (frame_size_ * kMicrosecondsPerSecond) / sample_rate_;
 
     // Get the status of the endpointer.
     int64_t ep_time;
diff --git a/src/content/browser/speech/endpointer/endpointer.h b/src/content/browser/speech/endpointer/endpointer.h
index 62d85dd..16bfed6 100644
--- a/src/content/browser/speech/endpointer/endpointer.h
+++ b/src/content/browser/speech/endpointer/endpointer.h
@@ -7,17 +7,16 @@
 
 #include <stdint.h>
 
-#include "content/browser/speech/endpointer/energy_endpointer.h"
-#if defined(COBALT_MEDIA_SOURCE_2016)
 #include "cobalt/media/base/shell_audio_bus.h"
-#else  // defined(COBALT_MEDIA_SOURCE_2016)
-#include "media/base/shell_audio_bus.h"
-#endif  // defined(COBALT_MEDIA_SOURCE_2016)
+#include "content/browser/speech/endpointer/energy_endpointer.h"
+#include "content/common/content_export.h"
 
 class EpStatus;
 
 namespace content {
 
+class AudioChunk;
+
 // A simple interface to the underlying energy-endpointer implementation, this
 // class lets callers provide audio as being recorded and let them poll to find
 // when the user has stopped speaking.
@@ -46,13 +45,9 @@
 // The timeout length is speech_input_complete_silence_length until
 // long_speech_length, when it changes to
 // long_speech_input_complete_silence_length.
-class Endpointer {
+class CONTENT_EXPORT Endpointer {
  public:
-#if defined(COBALT_MEDIA_SOURCE_2016)
   typedef cobalt::media::ShellAudioBus ShellAudioBus;
-#else   // defined(COBALT_MEDIA_SOURCE_2016)
-  typedef ::media::ShellAudioBus ShellAudioBus;
-#endif  // defined(COBALT_MEDIA_SOURCE_2016)
 
   explicit Endpointer(int sample_rate);
 
@@ -72,7 +67,11 @@
 
   // Process a segment of audio, which may be more than one frame.
   // The status of the last frame will be returned.
+#if defined(STARBOARD)
   EpStatus ProcessAudio(const ShellAudioBus& audio_bus, float* rms_out);
+#else
+  EpStatus ProcessAudio(const AudioChunk& raw_audio, float* rms_out);
+#endif
 
   // Get the status of the endpointer.
   EpStatus Status(int64_t* time_us);
@@ -107,7 +106,9 @@
     return speech_input_complete_;
   }
 
+#if defined(STARBOARD)
   int sample_rate() const { return sample_rate_; }
+#endif
 
   // RMS background noise level in dB.
   float NoiseLevelDb() const { return energy_endpointer_.GetNoiseLevelDb(); }
@@ -156,8 +157,7 @@
   bool speech_input_complete_;
   EnergyEndpointer energy_endpointer_;
   int sample_rate_;
-  // 1 frame = (1 / frame_rate_) second of audio.
-  int frame_rate_;
+  int32_t frame_size_;
 };
 
 }  // namespace content
diff --git a/src/content/browser/speech/endpointer/endpointer_unittest.cc b/src/content/browser/speech/endpointer/endpointer_unittest.cc
index 1f404d3..200c42c 100644
--- a/src/content/browser/speech/endpointer/endpointer_unittest.cc
+++ b/src/content/browser/speech/endpointer/endpointer_unittest.cc
@@ -4,8 +4,8 @@
 
 #include <stdint.h>
 
+#include "content/browser/speech/audio_buffer.h"
 #include "content/browser/speech/endpointer/endpointer.h"
-#include "media/base/shell_audio_bus.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -15,13 +15,8 @@
 // At 8 sample per second a 20 ms frame is 160 samples, which corrsponds
 // to the AMR codec.
 const int kFrameSize = kSampleRate / kFrameRate;  // 160 samples.
-
-#if defined(OS_STARBOARD)
-SB_COMPILE_ASSERT(kFrameSize == 160, invalid_frame_size);
-#else
-COMPILE_ASSERT(kFrameSize == 160, invalid_frame_size);
-#endif  // defined(OS_STARBOARD)
-}  // namespace
+static_assert(kFrameSize == 160, "invalid frame size");
+}
 
 namespace content {
 
@@ -84,8 +79,8 @@
 
   EpStatus ProcessFrame(int64_t time,
                         int16_t* samples,
-                        int /*frame_size*/) override {
-    endpointer_->ProcessAudioFrame(time, samples, kFrameSize, NULL);
+                        int frame_size) override {
+    endpointer_->ProcessAudioFrame(time, samples, kFrameSize, nullptr);
     int64_t ep_time;
     return endpointer_->Status(&ep_time);
   }
@@ -124,15 +119,15 @@
 // Test endpointer wrapper class.
 class EndpointerFrameProcessor : public FrameProcessor {
  public:
-  typedef Endpointer::ShellAudioBus ShellAudioBus;
   explicit EndpointerFrameProcessor(Endpointer* endpointer)
       : endpointer_(endpointer) {}
 
-  EpStatus ProcessFrame(int64_t /*time*/,
+  EpStatus ProcessFrame(int64_t time,
                         int16_t* samples,
-                        int /*frame_size*/) override {
-    scoped_ptr<ShellAudioBus> frame(new ShellAudioBus(1, kFrameSize, samples));
-    endpointer_->ProcessAudio(*frame, NULL);
+                        int frame_size) override {
+    scoped_refptr<AudioChunk> frame(
+        new AudioChunk(reinterpret_cast<uint8_t*>(samples), kFrameSize * 2, 2));
+    endpointer_->ProcessAudio(*frame.get(), nullptr);
     int64_t ep_time;
     return endpointer_->Status(&ep_time);
   }
@@ -142,6 +137,8 @@
 };
 
 TEST(EndpointerTest, TestEmbeddedEndpointerEvents) {
+  const int kSampleRate = 8000;  // 8 k samples per second for AMR encoding.
+
   Endpointer endpointer(kSampleRate);
   const int64_t kMillisecondsPerMicrosecond = 1000;
   const int64_t short_timeout = 300 * kMillisecondsPerMicrosecond;
diff --git a/src/content/browser/speech/endpointer/energy_endpointer.cc b/src/content/browser/speech/endpointer/energy_endpointer.cc
index b8a01d5..fc1d871 100644
--- a/src/content/browser/speech/endpointer/energy_endpointer.cc
+++ b/src/content/browser/speech/endpointer/energy_endpointer.cc
@@ -12,6 +12,7 @@
 #include <stddef.h>
 
 #include "base/logging.h"
+#include "base/macros.h"
 
 namespace {
 
@@ -36,7 +37,7 @@
 
 float GetDecibel(float value) {
   if (value > 1.0e-100)
-    return static_cast<float>(20 * log10(value));
+    return 20 * log10(value);
   return -2000.0;
 }
 
@@ -80,21 +81,20 @@
   insertion_index_ = 0;
   decision_points_.clear();
   DecisionPoint init = { -1, initial_state };
-  decision_points_.resize(static_cast<size_t>(size), init);
+  decision_points_.resize(size, init);
 }
 
 void EnergyEndpointer::HistoryRing::Insert(int64_t time_us, bool decision) {
-  decision_points_[static_cast<size_t>(insertion_index_)].time_us = time_us;
-  decision_points_[static_cast<size_t>(insertion_index_)].decision = decision;
-  insertion_index_ =
-      static_cast<int>((insertion_index_ + 1) % decision_points_.size());
+  decision_points_[insertion_index_].time_us = time_us;
+  decision_points_[insertion_index_].decision = decision;
+  insertion_index_ = (insertion_index_ + 1) % decision_points_.size();
 }
 
 int64_t EnergyEndpointer::HistoryRing::EndTime() const {
   int ind = insertion_index_ - 1;
   if (ind < 0)
-    ind = static_cast<int>(decision_points_.size() - 1);
-  return decision_points_[static_cast<size_t>(ind)].time_us;
+    ind = decision_points_.size() - 1;
+  return decision_points_[ind].time_us;
 }
 
 float EnergyEndpointer::HistoryRing::RingSum(float duration_sec) {
@@ -104,23 +104,23 @@
   int64_t sum_us = 0;
   int ind = insertion_index_ - 1;
   if (ind < 0)
-    ind = static_cast<int>(decision_points_.size() - 1);
-  int64_t end_us = decision_points_[static_cast<size_t>(ind)].time_us;
-  bool is_on = decision_points_[static_cast<size_t>(ind)].decision;
+    ind = decision_points_.size() - 1;
+  int64_t end_us = decision_points_[ind].time_us;
+  bool is_on = decision_points_[ind].decision;
   int64_t start_us =
       end_us - static_cast<int64_t>(0.5 + (1.0e6 * duration_sec));
   if (start_us < 0)
     start_us = 0;
   size_t n_summed = 1;  // n points ==> (n-1) intervals
-  while ((decision_points_[static_cast<size_t>(ind)].time_us > start_us) &&
+  while ((decision_points_[ind].time_us > start_us) &&
          (n_summed < decision_points_.size())) {
     --ind;
     if (ind < 0)
-      ind = static_cast<int>(decision_points_.size() - 1);
+      ind = decision_points_.size() - 1;
     if (is_on)
-      sum_us += end_us - decision_points_[static_cast<size_t>(ind)].time_us;
-    is_on = decision_points_[static_cast<size_t>(ind)].decision;
-    end_us = decision_points_[static_cast<size_t>(ind)].time_us;
+      sum_us += end_us - decision_points_[ind].time_us;
+    is_on = decision_points_[ind].decision;
+    end_us = decision_points_[ind].time_us;
     n_summed++;
   }
 
@@ -298,8 +298,6 @@
         }
         break;
 
-      case EP_POST_SPEECH:
-        // fall-through
       default:
         LOG(WARNING) << "Invalid case in switch: " << status_;
         break;
@@ -366,7 +364,7 @@
       noise_level_ = (0.95f * noise_level_) + (0.05f * rms);
   }
   if (estimating_environment_ || (frame_counter_ < fast_update_frames_)) {
-    decision_threshold_ = noise_level_ * 2;  // 6dB above noise level.
+    decision_threshold_ = noise_level_ * 2; // 6dB above noise level.
     // Set a floor
     if (decision_threshold_ < params_.min_decision_threshold())
       decision_threshold_ = params_.min_decision_threshold();
diff --git a/src/content/browser/speech/endpointer/energy_endpointer.h b/src/content/browser/speech/endpointer/energy_endpointer.h
index 2d379b9..7b0b292 100644
--- a/src/content/browser/speech/endpointer/energy_endpointer.h
+++ b/src/content/browser/speech/endpointer/energy_endpointer.h
@@ -42,8 +42,9 @@
 #include <memory>
 #include <vector>
 
-#include "base/memory/scoped_ptr.h"
+#include "base/macros.h"
 #include "content/browser/speech/endpointer/energy_endpointer_params.h"
+#include "content/common/content_export.h"
 
 namespace content {
 
@@ -56,7 +57,7 @@
   EP_POST_SPEECH,
 };
 
-class EnergyEndpointer {
+class CONTENT_EXPORT EnergyEndpointer {
  public:
   // The default construction MUST be followed by Init(), before any
   // other use can be made of the instance.
@@ -124,7 +125,7 @@
   float sample_rate_;  // Sampling rate.
 
   // Ring buffers to hold the speech activity history.
-  scoped_ptr<HistoryRing> history_;
+  std::unique_ptr<HistoryRing> history_;
 
   // Configuration parameters.
   EnergyEndpointerParams params_;
diff --git a/src/content/browser/speech/endpointer/energy_endpointer_params.h b/src/content/browser/speech/endpointer/energy_endpointer_params.h
index 303b3b0..1510435 100644
--- a/src/content/browser/speech/endpointer/energy_endpointer_params.h
+++ b/src/content/browser/speech/endpointer/energy_endpointer_params.h
@@ -5,10 +5,12 @@
 #ifndef CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_PARAMS_H_
 #define CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_PARAMS_H_
 
+#include "content/common/content_export.h"
+
 namespace content {
 
 // Input parameters for the EnergyEndpointer class.
-class EnergyEndpointerParams {
+class CONTENT_EXPORT EnergyEndpointerParams {
  public:
   EnergyEndpointerParams();
 
diff --git a/src/content/browser/speech/speech.gyp b/src/content/browser/speech/speech.gyp
index e41cfad..4e1a669 100644
--- a/src/content/browser/speech/speech.gyp
+++ b/src/content/browser/speech/speech.gyp
@@ -18,6 +18,8 @@
       'target_name': 'speech',
       'type': 'static_library',
       'sources': [
+        'audio_buffer.cc',
+        'audio_buffer.h',
         'chunked_byte_buffer.cc',
         'chunked_byte_buffer.h',
         'endpointer/endpointer.cc',
@@ -38,7 +40,7 @@
       'dependencies': [
         'speech',
         '<(DEPTH)/base/base.gyp:run_all_unittests',
-        '<(DEPTH)/cobalt/media/media2.gyp:media2',
+        '<(DEPTH)/cobalt/media/media.gyp:media',
         '<(DEPTH)/testing/gtest.gyp:gtest',
       ],
     },