#ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
#include <deque>
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "content/public/renderer/media_stream_audio_sink.h"
#include "content/renderer/pepper/pepper_media_stream_track_host_base.h"
#include "media/audio/audio_parameters.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
namespace base {
class MessageLoopProxy;
}
namespace content {
class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase {
public:
PepperMediaStreamAudioTrackHost(RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource,
const blink::WebMediaStreamTrack& track);
private:
class AudioSink : public MediaStreamAudioSink {
public:
explicit AudioSink(PepperMediaStreamAudioTrackHost* host);
virtual ~AudioSink();
void EnqueueBuffer(int32_t index);
private:
void InitBuffersOnMainThread(int32_t number_of_buffers,
int32_t buffer_size);
void SendEnqueueBufferMessageOnMainThread(int32_t index);
virtual void OnData(const int16* audio_data,
int sample_rate,
int number_of_channels,
int number_of_frames) OVERRIDE;
virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
PepperMediaStreamAudioTrackHost* host_;
base::TimeDelta timestamp_;
base::TimeDelta buffer_duration_;
media::AudioParameters audio_params_;
media::AudioParameters original_audio_params_;
uint32_t buffer_data_size_;
base::Lock lock_;
std::deque<int32_t> buffers_;
scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
base::ThreadChecker audio_thread_checker_;
base::WeakPtrFactory<AudioSink> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AudioSink);
};
virtual ~PepperMediaStreamAudioTrackHost();
virtual void OnClose() OVERRIDE;
virtual void OnNewBufferEnqueued() OVERRIDE;
virtual void DidConnectPendingHostToResource() OVERRIDE;
blink::WebMediaStreamTrack track_;
bool connected_;
AudioSink audio_sink_;
DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
};
}
#endif