#ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
#define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/base/audio_bus.h"
#include "media/cast/cast_config.h"
#include "media/cast/transport/cast_transport_config.h"
namespace base {
class TimeTicks;
class WaitableEvent;
}
namespace net {
class IPEndPoint;
}
namespace media {
class VideoFrame;
namespace cast {
class CastEnvironment;
class CastReceiver;
namespace transport {
class UdpTransport;
}
class InProcessReceiver {
public:
InProcessReceiver(const scoped_refptr<CastEnvironment>& cast_environment,
const net::IPEndPoint& local_end_point,
const net::IPEndPoint& remote_end_point,
const AudioReceiverConfig& audio_config,
const VideoReceiverConfig& video_config);
virtual ~InProcessReceiver();
scoped_refptr<CastEnvironment> cast_env() const { return cast_environment_; }
void Start();
void DestroySoon();
void Stop();
protected:
virtual void OnAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
const base::TimeTicks& playout_time) = 0;
virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
const base::TimeTicks& render_time) = 0;
virtual void StartOnMainThread();
virtual void StopOnMainThread(base::WaitableEvent* event);
virtual void UpdateCastTransportStatus(transport::CastTransportStatus status);
private:
friend class base::RefCountedThreadSafe<InProcessReceiver>;
void GotAudioFrame(scoped_ptr<AudioBus> audio_frame,
const base::TimeTicks& playout_time,
bool is_continuous);
void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
const base::TimeTicks& render_time);
void PullNextAudioFrame();
void PullNextVideoFrame();
static void WillDestroyReceiver(InProcessReceiver* receiver);
const scoped_refptr<CastEnvironment> cast_environment_;
const net::IPEndPoint local_end_point_;
const net::IPEndPoint remote_end_point_;
const AudioReceiverConfig audio_config_;
const VideoReceiverConfig video_config_;
scoped_ptr<transport::UdpTransport> transport_;
scoped_ptr<CastReceiver> cast_receiver_;
base::WeakPtrFactory<InProcessReceiver> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(InProcessReceiver);
};
}
}
#endif