Bug 945135 - Part 1: Refactor of TrackEncoder and AudioTrackEncoder. r=roc
authorShelly Lin <slin@mozilla.com>
Tue, 12 Nov 2013 10:29:09 +0800
changeset 173920 72f2f506fe013bfba7d51b31dfe63e63d20e315c
parent 173919 f6d8a9a56abbe302d67dbd49508be59717067fcd
child 173921 5dddd0b5ff519329703fd5c6d265c2f0589226de
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs945135
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 945135 - Part 1: Refactor of TrackEncoder and AudioTrackEncoder. r=roc
content/media/encoder/EncodedFrameContainer.h
content/media/encoder/OpusTrackEncoder.cpp
content/media/encoder/OpusTrackEncoder.h
content/media/encoder/TrackEncoder.cpp
content/media/encoder/TrackEncoder.h
--- a/content/media/encoder/EncodedFrameContainer.h
+++ b/content/media/encoder/EncodedFrameContainer.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef EncodedFrameContainer_H_
 #define EncodedFrameContainer_H_
 
+#include "nsAutoPtr.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
 class EncodedFrame;
 
 /*
  * This container is used to carry video or audio encoded data from encoder to muxer.
--- a/content/media/encoder/OpusTrackEncoder.cpp
+++ b/content/media/encoder/OpusTrackEncoder.cpp
@@ -111,43 +111,42 @@ SerializeOpusCommentHeader(const nsCStri
   }
 }
 
 }  // Anonymous namespace.
 
 OpusTrackEncoder::OpusTrackEncoder()
   : AudioTrackEncoder()
   , mEncoder(nullptr)
-  , mSourceSegment(new AudioSegment())
   , mLookahead(0)
   , mResampler(nullptr)
 {
 }
 
 OpusTrackEncoder::~OpusTrackEncoder()
 {
   if (mEncoder) {
     opus_encoder_destroy(mEncoder);
   }
   if (mResampler) {
     speex_resampler_destroy(mResampler);
+    mResampler = nullptr;
   }
-
 }
 
 nsresult
 OpusTrackEncoder::Init(int aChannels, int aSamplingRate)
 {
   // This monitor is used to wake up other methods that are waiting for encoder
   // to be completely initialized.
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
   // This version of encoder API only support 1 or 2 channels,
   // So set the mChannels less or equal 2 and
   // let InterleaveTrackData downmix pcm data.
-  mChannels = aChannels > 2 ? 2 : aChannels;
+  mChannels = aChannels > MAX_CHANNELS ? MAX_CHANNELS : aChannels;
 
   if (aChannels <= 0) {
     return NS_ERROR_FAILURE;
   }
   // The granule position is required to be incremented at a rate of 48KHz, and
   // it is simply calculated as |granulepos = samples * (48000/source_rate)|,
   // that is, the source sampling rate must divide 48000 evenly.
   // If this constraint is not satisfied, we resample the input to 48kHz.
@@ -190,22 +189,22 @@ OpusTrackEncoder::GetPacketDuration()
 }
 
 already_AddRefed<TrackMetadataBase>
 OpusTrackEncoder::GetMetadata()
 {
   {
     // Wait if mEncoder is not initialized.
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    while (!mCanceled && !mEncoder) {
+    while (!mCanceled && !mInitialized) {
       mReentrantMonitor.Wait();
     }
   }
 
-  if (mCanceled || mDoneEncoding) {
+  if (mCanceled || mEncodingComplete) {
     return nullptr;
   }
 
   nsRefPtr<OpusMetadata> meta = new OpusMetadata();
 
   mLookahead = 0;
   int error = opus_encoder_ctl(mEncoder, OPUS_GET_LOOKAHEAD(&mLookahead));
   if (error != OPUS_OK) {
@@ -233,39 +232,40 @@ OpusTrackEncoder::GetEncodedTrack(Encode
 {
   {
     // Move all the samples from mRawSegment to mSourceSegment. We only hold
     // the monitor in this block.
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
     // Wait if mEncoder is not initialized, or when not enough raw data, but is
     // not the end of stream nor is being canceled.
-    while (!mCanceled && (!mEncoder || (mRawSegment->GetDuration() +
-           mSourceSegment->GetDuration() < GetPacketDuration() &&
+    while (!mCanceled && (!mInitialized || (mRawSegment.GetDuration() +
+           mSourceSegment.GetDuration() < GetPacketDuration() &&
            !mEndOfStream))) {
       mReentrantMonitor.Wait();
     }
 
-    if (mCanceled || mDoneEncoding) {
+    if (mCanceled || mEncodingComplete) {
       return NS_ERROR_FAILURE;
     }
 
-    mSourceSegment->AppendFrom(mRawSegment);
+    mSourceSegment.AppendFrom(&mRawSegment);
 
     // Pad |mLookahead| samples to the end of source stream to prevent lost of
     // original data, the pcm duration will be calculated at rate 48K later.
-    if (mEndOfStream) {
-      mSourceSegment->AppendNullData(mLookahead);
+    if (mEndOfStream && !mEosSetInEncoder) {
+      mEosSetInEncoder = true;
+      mSourceSegment.AppendNullData(mLookahead);
     }
   }
 
   // Start encoding data.
   nsAutoTArray<AudioDataValue, 9600> pcm;
   pcm.SetLength(GetPacketDuration() * mChannels);
-  AudioSegment::ChunkIterator iter(*mSourceSegment);
+  AudioSegment::ChunkIterator iter(mSourceSegment);
   int frameCopied = 0;
   while (!iter.IsEnded() && frameCopied < GetPacketDuration()) {
     AudioChunk chunk = *iter;
 
     // Chunk to the required frame size.
     int frameToCopy = chunk.GetDuration();
     if (frameCopied + frameToCopy > GetPacketDuration()) {
       frameToCopy = GetPacketDuration() - frameCopied;
@@ -314,22 +314,22 @@ OpusTrackEncoder::GetEncodedTrack(Encode
   } else {
     // The ogg time stamping and pre-skip is always timed at 48000.
     audiodata->SetDuration(frameCopied * (kOpusSamplingRate / mSamplingRate));
   }
 
   // Remove the raw data which has been pulled to pcm buffer.
   // The value of frameCopied should equal to (or smaller than, if eos)
   // GetPacketDuration().
-  mSourceSegment->RemoveLeading(frameCopied);
+  mSourceSegment.RemoveLeading(frameCopied);
 
   // Has reached the end of input stream and all queued data has pulled for
   // encoding.
-  if (mSourceSegment->GetDuration() == 0 && mEndOfStream) {
-    mDoneEncoding = true;
+  if (mSourceSegment.GetDuration() == 0 && mEndOfStream) {
+    mEncodingComplete = true;
     LOG("[Opus] Done encoding.");
   }
 
   // Append null data to pcm buffer if the leftover data is not enough for
   // opus encoder.
   if (frameCopied < GetPacketDuration() && mEndOfStream) {
     memset(pcm.Elements() + frameCopied * mChannels, 0,
            (GetPacketDuration()-frameCopied)*mChannels*sizeof(AudioDataValue));
@@ -348,17 +348,17 @@ OpusTrackEncoder::GetEncodedTrack(Encode
   result = opus_encode_float(mEncoder, pcmBuf, GetPacketDuration(),
                              frameData.Elements(), MAX_DATA_BYTES);
 #endif
   frameData.SetLength(result >= 0 ? result : 0);
 
   if (result < 0) {
     LOG("[Opus] Fail to encode data! Result: %s.", opus_strerror(result));
   }
-  if (mDoneEncoding) {
+  if (mEncodingComplete) {
     if (mResampler) {
       speex_resampler_destroy(mResampler);
       mResampler = nullptr;
     }
   }
 
   audiodata->SetFrameData(&frameData);
   aData.AppendEncodedFrame(audiodata);
--- a/content/media/encoder/OpusTrackEncoder.h
+++ b/content/media/encoder/OpusTrackEncoder.h
@@ -32,38 +32,39 @@ public:
   OpusTrackEncoder();
   virtual ~OpusTrackEncoder();
 
   already_AddRefed<TrackMetadataBase> GetMetadata() MOZ_OVERRIDE;
 
   nsresult GetEncodedTrack(EncodedFrameContainer& aData) MOZ_OVERRIDE;
 
 protected:
-  int GetPacketDuration() MOZ_OVERRIDE;
+  int GetPacketDuration();
 
   nsresult Init(int aChannels, int aSamplingRate) MOZ_OVERRIDE;
 
 private:
   /**
    * Get the samplerate of the data to be fed to the Opus encoder. This might be
    * different from the intput samplerate if resampling occurs.
    */
   int GetOutputSampleRate();
 
   /**
    * The Opus encoder from libopus.
    */
   OpusEncoder* mEncoder;
 
   /**
-   * A local segment queue which stores the raw segments. Opus encoder only
-   * takes GetPacketDuration() samples from mSourceSegment in every encoding
-   * cycle, thus it needs to store the raw track data.
+   * A local segment queue which takes the raw data out from mRawSegment in the
+   * call of GetEncodedTrack(). Opus encoder only accepts GetPacketDuration()
+   * samples from mSourceSegment every encoding cycle, thus it needs to be
+   * global in order to store the leftover segments taken from mRawSegment.
    */
-  nsAutoPtr<AudioSegment> mSourceSegment;
+  AudioSegment mSourceSegment;
 
   /**
    * Total samples of delay added by codec, can be queried by the encoder. From
    * the perspective of decoding, real data begins this many samples late, so
    * the encoder needs to append this many null samples to the end of stream,
    * in order to align the time of input and output.
    */
   int mLookahead;
--- a/content/media/encoder/TrackEncoder.cpp
+++ b/content/media/encoder/TrackEncoder.cpp
@@ -1,125 +1,104 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "TrackEncoder.h"
+#include "AudioChannelFormat.h"
 #include "MediaStreamGraph.h"
-#include "AudioChannelFormat.h"
+#include "VideoUtils.h"
 
 #undef LOG
 #ifdef MOZ_WIDGET_GONK
 #include <android/log.h>
-#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "MediakEncoder", ## args);
+#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "MediaEncoder", ## args);
 #else
 #define LOG(args, ...)
 #endif
 
 namespace mozilla {
 
-static const int  DEFAULT_CHANNELS = 1;
-static const int  DEFAULT_SAMPLING_RATE = 16000;
+static const int DEFAULT_CHANNELS = 1;
+static const int DEFAULT_SAMPLING_RATE = 16000;
 
 void
 AudioTrackEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph,
                                             TrackID aID,
                                             TrackRate aTrackRate,
                                             TrackTicks aTrackOffset,
                                             uint32_t aTrackEvents,
                                             const MediaSegment& aQueuedMedia)
 {
   if (mCanceled) {
     return;
   }
 
-  AudioSegment* audio = const_cast<AudioSegment*>
-                        (static_cast<const AudioSegment*>(&aQueuedMedia));
+  const AudioSegment& audio = static_cast<const AudioSegment&>(aQueuedMedia);
 
   // Check and initialize parameters for codec encoder.
   if (!mInitialized) {
-    AudioSegment::ChunkIterator iter(*audio);
+    AudioSegment::ChunkIterator iter(const_cast<AudioSegment&>(audio));
     while (!iter.IsEnded()) {
       AudioChunk chunk = *iter;
 
       // The number of channels is determined by the first non-null chunk, and
       // thus the audio encoder is initialized at this time.
       if (!chunk.IsNull()) {
         nsresult rv = Init(chunk.mChannelData.Length(), aTrackRate);
         if (NS_FAILED(rv)) {
           LOG("[AudioTrackEncoder]: Fail to initialize the encoder!");
           NotifyCancel();
         }
         break;
-      } else {
-        mSilentDuration += chunk.mDuration;
       }
+
       iter.Next();
     }
   }
 
   // Append and consume this raw segment.
-  if (mInitialized) {
-    AppendAudioSegment(audio);
-  }
+  AppendAudioSegment(audio);
+
 
   // The stream has stopped and reached the end of track.
   if (aTrackEvents == MediaStreamListener::TRACK_EVENT_ENDED) {
     LOG("[AudioTrackEncoder]: Receive TRACK_EVENT_ENDED .");
     NotifyEndOfStream();
   }
 }
 
 void
-AudioTrackEncoder::NotifyRemoved(MediaStreamGraph* aGraph)
-{
-  // In case that MediaEncoder does not receive a TRACK_EVENT_ENDED event.
-  LOG("[AudioTrackEncoder]: NotifyRemoved.");
-  NotifyEndOfStream();
-}
-
-void
 AudioTrackEncoder::NotifyEndOfStream()
 {
-  // If source audio chunks are completely silent till the end of encoding,
-  // initialize the encoder with default channel counts and sampling rate, and
-  // append this many null data to the segment of track encoder.
+  // If source audio track is completely silent till the end of encoding,
+  // initialize the encoder with default channel counts and sampling rate.
   if (!mCanceled && !mInitialized) {
     Init(DEFAULT_CHANNELS, DEFAULT_SAMPLING_RATE);
-    mRawSegment->AppendNullData(mSilentDuration);
-    mSilentDuration = 0;
   }
 
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
   mEndOfStream = true;
   mReentrantMonitor.NotifyAll();
 }
 
 nsresult
-AudioTrackEncoder::AppendAudioSegment(MediaSegment* aSegment)
+AudioTrackEncoder::AppendAudioSegment(const AudioSegment& aSegment)
 {
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
-  AudioSegment* audio = static_cast<AudioSegment*>(aSegment);
-  AudioSegment::ChunkIterator iter(*audio);
-
-  // Append this many null data to our queued segment if there is a complete
-  // silence before the audio track encoder has initialized.
-  if (mSilentDuration > 0) {
-    mRawSegment->AppendNullData(mSilentDuration);
-    mSilentDuration = 0;
-  }
-
+  AudioSegment::ChunkIterator iter(const_cast<AudioSegment&>(aSegment));
   while (!iter.IsEnded()) {
     AudioChunk chunk = *iter;
     // Append and consume both non-null and null chunks.
-    mRawSegment->AppendAndConsumeChunk(&chunk);
+    mRawSegment.AppendAndConsumeChunk(&chunk);
     iter.Next();
   }
-  if (mRawSegment->GetDuration() >= GetPacketDuration()) {
+
+  if (mRawSegment.GetDuration() >= GetPacketDuration()) {
     mReentrantMonitor.NotifyAll();
   }
 
   return NS_OK;
 }
 
 static const int AUDIO_PROCESSING_FRAMES = 640; /* > 10ms of 48KHz audio */
 static const uint8_t gZeroChannel[MAX_AUDIO_SAMPLE_SIZE*AUDIO_PROCESSING_FRAMES] = {0};
--- a/content/media/encoder/TrackEncoder.h
+++ b/content/media/encoder/TrackEncoder.h
@@ -4,19 +4,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef TrackEncoder_h_
 #define TrackEncoder_h_
 
 #include "mozilla/ReentrantMonitor.h"
 
 #include "AudioSegment.h"
+#include "EncodedFrameContainer.h"
 #include "StreamBuffer.h"
 #include "TrackMetadataBase.h"
-#include "EncodedFrameContainer.h"
 
 namespace mozilla {
 
 class MediaStreamGraph;
 
 /**
  * Base class of AudioTrackEncoder and VideoTrackEncoder. Lifetimes managed by
  * MediaEncoder. Most methods can only be called on the MediaEncoder's thread,
@@ -25,116 +25,163 @@ class MediaStreamGraph;
  * NotifyQueuedTrackChanges is called on subclasses of this class from the
  * MediaStreamGraph thread, and AppendAudioSegment/AppendVideoSegment is then
  * called to store media data in the TrackEncoder. Later on, GetEncodedTrack is
  * called on MediaEncoder's thread to encode and retrieve the encoded data.
  */
 class TrackEncoder
 {
 public:
-  TrackEncoder() {}
+  TrackEncoder()
+    : mReentrantMonitor("media.TrackEncoder")
+    , mEncodingComplete(false)
+    , mEosSetInEncoder(false)
+    , mInitialized(false)
+    , mEndOfStream(false)
+    , mCanceled(false)
+  {}
+
   virtual ~TrackEncoder() {}
 
   /**
    * Notified by the same callbcak of MediaEncoder when it has received a track
    * change from MediaStreamGraph. Called on the MediaStreamGraph thread.
    */
   virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
                                         TrackRate aTrackRate,
                                         TrackTicks aTrackOffset,
                                         uint32_t aTrackEvents,
                                         const MediaSegment& aQueuedMedia) = 0;
 
   /**
    * Notified by the same callback of MediaEncoder when it has been removed from
    * MediaStreamGraph. Called on the MediaStreamGraph thread.
    */
-  virtual void NotifyRemoved(MediaStreamGraph* aGraph) = 0;
+  void NotifyRemoved(MediaStreamGraph* aGraph) { NotifyEndOfStream(); }
 
   /**
-   * Creates and sets up meta data for a specific codec
+   * Creates and sets up meta data for a specific codec, called on the worker
+   * thread.
    */
   virtual already_AddRefed<TrackMetadataBase> GetMetadata() = 0;
 
   /**
-   * Encodes raw segments. Result data is returned in aData.
+   * Encodes raw segments. Result data is returned in aData, and called on the
+   * worker thread.
    */
   virtual nsresult GetEncodedTrack(EncodedFrameContainer& aData) = 0;
-};
 
-class AudioTrackEncoder : public TrackEncoder
-{
-public:
-  AudioTrackEncoder()
-    : TrackEncoder()
-    , mChannels(0)
-    , mSamplingRate(0)
-    , mInitialized(false)
-    , mDoneEncoding(false)
-    , mReentrantMonitor("media.AudioEncoder")
-    , mRawSegment(new AudioSegment())
-    , mEndOfStream(false)
-    , mCanceled(false)
-    , mSilentDuration(0)
-  {}
-
-  void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
-                                TrackRate aTrackRate,
-                                TrackTicks aTrackOffset,
-                                uint32_t aTrackEvents,
-                                const MediaSegment& aQueuedMedia) MOZ_OVERRIDE;
-
-  void NotifyRemoved(MediaStreamGraph* aGraph) MOZ_OVERRIDE;
-
-  bool IsEncodingComplete()
-  {
-    return mDoneEncoding;
-  }
+  /**
+   * True if the track encoder has encoded all source segments coming from
+   * MediaStreamGraph. Call on the worker thread.
+   */
+  bool IsEncodingComplete() { return mEncodingComplete; }
 
   /**
    * Notifies from MediaEncoder to cancel the encoding, and wakes up
    * mReentrantMonitor if encoder is waiting on it.
    */
   void NotifyCancel()
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     mCanceled = true;
     mReentrantMonitor.NotifyAll();
   }
 
 protected:
   /**
+   * Notifies track encoder that we have reached the end of source stream, and
+   * wakes up mReentrantMonitor if encoder is waiting for any source data.
+   */
+  virtual void NotifyEndOfStream() = 0;
+
+  /**
+   * A ReentrantMonitor to protect the pushing and pulling of mRawSegment which
+   * is declared in its subclasses, and the following flags: mInitialized,
+   * EndOfStream and mCanceled. The control of protection is managed by its
+   * subclasses.
+   */
+  ReentrantMonitor mReentrantMonitor;
+
+  /**
+   * True if the track encoder has encoded all source data.
+   */
+  bool mEncodingComplete;
+
+  /**
+   * True if flag of EOS or any form of indicating EOS has set in the codec-
+   * encoder.
+   */
+  bool mEosSetInEncoder;
+
+  /**
+   * True if the track encoder has initialized successfully, protected by
+   * mReentrantMonitor.
+   */
+  bool mInitialized;
+
+  /**
+   * True if the TrackEncoder has received an event of TRACK_EVENT_ENDED from
+   * MediaStreamGraph, or the MediaEncoder is removed from its source stream,
+   * protected by mReentrantMonitor.
+   */
+  bool mEndOfStream;
+
+  /**
+   * True if a cancellation of encoding is sent from MediaEncoder, protected by
+   * mReentrantMonitor.
+   */
+  bool mCanceled;
+};
+
+class AudioTrackEncoder : public TrackEncoder
+{
+public:
+  AudioTrackEncoder()
+    : TrackEncoder()
+    , mChannels(0)
+    , mSamplingRate(0)
+  {}
+
+  void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
+                                TrackRate aTrackRate,
+                                TrackTicks aTrackOffset,
+                                uint32_t aTrackEvents,
+                                const MediaSegment& aQueuedMedia) MOZ_OVERRIDE;
+
+protected:
+  /**
    * Number of samples per channel in a pcm buffer. This is also the value of
    * frame size required by audio encoder, and mReentrantMonitor will be
    * notified when at least this much data has been added to mRawSegment.
    */
-  virtual int GetPacketDuration() = 0;
+  virtual int GetPacketDuration() { return 0; }
 
   /**
    * Initializes the audio encoder. The call of this method is delayed until we
    * have received the first valid track from MediaStreamGraph, and the
    * mReentrantMonitor will be notified if other methods is waiting for encoder
    * to be completely initialized. This method is called on the MediaStreamGraph
    * thread.
    */
   virtual nsresult Init(int aChannels, int aSamplingRate) = 0;
 
   /**
    * Appends and consumes track data from aSegment, this method is called on
    * the MediaStreamGraph thread. mReentrantMonitor will be notified when at
    * least GetPacketDuration() data has been added to mRawSegment, wake up other
    * method which is waiting for more data from mRawSegment.
    */
-  nsresult AppendAudioSegment(MediaSegment* aSegment);
+  nsresult AppendAudioSegment(const AudioSegment& aSegment);
 
   /**
    * Notifies the audio encoder that we have reached the end of source stream,
    * and wakes up mReentrantMonitor if encoder is waiting for more track data.
    */
-  void NotifyEndOfStream();
+  virtual void NotifyEndOfStream() MOZ_OVERRIDE;
 
   /**
    * Interleaves the track data and stores the result into aOutput. Might need
    * to up-mix or down-mix the channel data if the channels number of this chunk
    * is different from mChannels. The channel data from aChunk might be modified
    * by up-mixing.
    */
   void InterleaveTrackData(AudioChunk& aChunk, int32_t aDuration,
@@ -142,48 +189,26 @@ protected:
 
   /**
    * The number of channels are used for processing PCM data in the audio encoder.
    * This value comes from the first valid audio chunk. If encoder can't support
    * the channels in the chunk, downmix PCM stream can be performed.
    * This value also be used to initialize the audio encoder.
    */
   int mChannels;
-  int mSamplingRate;
-  bool mInitialized;
-  bool mDoneEncoding;
 
   /**
-   * A ReentrantMonitor to protect the pushing and pulling of mRawSegment.
+   * The sampling rate of source audio data.
    */
-  ReentrantMonitor mReentrantMonitor;
+  int mSamplingRate;
 
   /**
    * A segment queue of audio track data, protected by mReentrantMonitor.
    */
-  nsAutoPtr<AudioSegment> mRawSegment;
-
-  /**
-   * True if we have received an event of TRACK_EVENT_ENDED from MediaStreamGraph,
-   * or the MediaEncoder is removed from its source stream, protected by
-   * mReentrantMonitor.
-   */
-  bool mEndOfStream;
-
-  /**
-   * True if a cancellation of encoding is sent from MediaEncoder, protected by
-   * mReentrantMonitor.
-   */
-  bool mCanceled;
-
-  /**
-   * The total duration of null chunks we have received from MediaStreamGraph
-   * before initializing the audio track encoder.
-   */
-  TrackTicks mSilentDuration;
+  AudioSegment mRawSegment;
 };
 
 class VideoTrackEncoder : public TrackEncoder
 {
 
 };
 
 }