summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/AudioOutputObserver.h
blob: 517eaa8919eef212254db4a8c5a6a40bd4fb699a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* 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 AUDIOOUTPUTOBSERVER_H_
#define AUDIOOUTPUTOBSERVER_H_

#include "mozilla/StaticPtr.h"
#include "nsAutoPtr.h"
#include "AudioMixer.h"

namespace webrtc {
class SingleRwFifo;
}

namespace mozilla {

typedef struct FarEndAudioChunk_ {
  uint16_t mSamples;
  bool mOverrun;
  int16_t mData[1]; // variable-length
} FarEndAudioChunk;

// XXX Really a singleton currently
class AudioOutputObserver : public MixerCallbackReceiver
{
public:
  AudioOutputObserver();

  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioOutputObserver);

  void MixerCallback(AudioDataValue* aMixedBuffer,
                     AudioSampleFormat aFormat,
                     uint32_t aChannels,
                     uint32_t aFrames,
                     uint32_t aSampleRate) override;

  void Clear();
  void InsertFarEnd(const AudioDataValue *aBuffer, uint32_t aFrames, bool aOverran,
                    int aFreq, int aChannels, AudioSampleFormat aFormat);
  uint32_t PlayoutFrequency() { return mPlayoutFreq; }
  uint32_t PlayoutChannels() { return mPlayoutChannels; }

  FarEndAudioChunk *Pop();
  uint32_t Size();

private:
  virtual ~AudioOutputObserver();
  uint32_t mPlayoutFreq;
  uint32_t mPlayoutChannels;

  nsAutoPtr<webrtc::SingleRwFifo> mPlayoutFifo;
  uint32_t mChunkSize;

  // chunking to 10ms support
  FarEndAudioChunk *mSaved; // can't be nsAutoPtr since we need to use free(), not delete
  uint32_t mSamplesSaved;
};

extern StaticRefPtr<AudioOutputObserver> gFarendObserver;

}

#endif