2
// Copyright 2004--2005, Google Inc.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
7
// 1. Redistributions of source code must retain the above copyright notice,
8
// this list of conditions and the following disclaimer.
9
// 2. Redistributions in binary form must reproduce the above copyright notice,
10
// this list of conditions and the following disclaimer in the documentation
11
// and/or other materials provided with the distribution.
12
// 3. The name of the author may not be used to endorse or promote products
13
// derived from this software without specific prior written permission.
15
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
#ifndef TALK_SESSION_PHONE_FILEMEDIAENGINE_H_
27
#define TALK_SESSION_PHONE_FILEMEDIAENGINE_H_
32
#include "talk/base/scoped_ptr.h"
33
#include "talk/base/stream.h"
34
#include "talk/session/phone/codec.h"
35
#include "talk/session/phone/mediachannel.h"
36
#include "talk/session/phone/mediaengine.h"
39
class StreamInterface;
44
// A media engine contains a capturer, an encoder, and a sender in the sender
45
// side and a receiver, a decoder, and a renderer in the receiver side.
46
// FileMediaEngine simulates the capturer and the encoder via an input RTP dump
47
// stream and simulates the decoder and the renderer via an output RTP dump
48
// stream. Depending on the parameters of the constructor, FileMediaEngine can
49
// act as file voice engine, file video engine, or both. Currently, we use
50
// only the RTP dump packets. TODO: Enable RTCP packets.
51
class FileMediaEngine : public MediaEngineInterface {
54
virtual ~FileMediaEngine() {}
56
// Set the file name of the input or output RTP dump for voice or video.
57
// Should be called before the channel is created.
58
void set_voice_input_filename(const std::string& filename) {
59
voice_input_filename_ = filename;
61
void set_voice_output_filename(const std::string& filename) {
62
voice_output_filename_ = filename;
64
void set_video_input_filename(const std::string& filename) {
65
video_input_filename_ = filename;
67
void set_video_output_filename(const std::string& filename) {
68
video_output_filename_ = filename;
71
// Should be called before codecs() and video_codecs() are called. We need to
72
// set the voice and video codecs; otherwise, Jingle initiation will fail.
73
void set_voice_codecs(const std::vector<AudioCodec>& codecs) {
74
voice_codecs_ = codecs;
76
void set_video_codecs(const std::vector<VideoCodec>& codecs) {
77
video_codecs_ = codecs;
80
// Implement pure virtual methods of MediaEngine.
81
virtual bool Init() { return true; }
82
virtual void Terminate() {}
83
virtual int GetCapabilities();
84
virtual VoiceMediaChannel* CreateChannel();
85
virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch);
86
virtual SoundclipMedia* CreateSoundclip() { return NULL; }
87
virtual bool SetAudioOptions(int options) { return true; }
88
virtual bool SetVideoOptions(int options) { return true; }
89
virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
92
virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
95
virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
96
virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/, uint32 /*ssrc*/) {
99
virtual bool GetOutputVolume(int* level) {
103
virtual bool SetOutputVolume(int level) { return true; }
104
virtual int GetInputLevel() { return 0; }
105
virtual bool SetLocalMonitor(bool enable) { return true; }
106
virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
107
// TODO: control channel send?
108
virtual CaptureResult SetVideoCapture(bool capture) { return CR_SUCCESS; }
109
virtual const std::vector<AudioCodec>& audio_codecs() {
110
return voice_codecs_;
112
virtual const std::vector<VideoCodec>& video_codecs() {
113
return video_codecs_;
115
virtual bool FindAudioCodec(const AudioCodec& codec) { return true; }
116
virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
117
virtual void SetVoiceLogging(int min_sev, const char* filter) {}
118
virtual void SetVideoLogging(int min_sev, const char* filter) {}
120
virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
123
virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
126
virtual bool RegisterVoiceProcessor(uint32 ssrc,
127
VoiceProcessor* processor,
128
MediaProcessorDirection direction) {
131
virtual bool UnregisterVoiceProcessor(uint32 ssrc,
132
VoiceProcessor* processor,
133
MediaProcessorDirection direction) {
138
std::string voice_input_filename_;
139
std::string voice_output_filename_;
140
std::string video_input_filename_;
141
std::string video_output_filename_;
142
std::vector<AudioCodec> voice_codecs_;
143
std::vector<VideoCodec> video_codecs_;
145
DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
148
class RtpSenderReceiver; // Forward declaration. Defined in the .cc file.
150
class FileVoiceChannel : public VoiceMediaChannel {
152
FileVoiceChannel(talk_base::StreamInterface* input_file_stream,
153
talk_base::StreamInterface* output_file_stream);
154
virtual ~FileVoiceChannel();
156
// Implement pure virtual methods of VoiceMediaChannel.
157
virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
160
virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
161
virtual bool SetRecvRtpHeaderExtensions(
162
const std::vector<RtpHeaderExtension>& extensions) {
165
virtual bool SetSendRtpHeaderExtensions(
166
const std::vector<RtpHeaderExtension>& extensions) {
169
virtual bool SetPlayout(bool playout) { return true; }
170
virtual bool SetSend(SendFlags flag);
171
virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
172
virtual int GetOutputLevel() { return 0; }
173
virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
176
virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
179
virtual bool SetRingbackTone(const char* buf, int len) { return true; }
180
virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
183
virtual bool PressDTMF(int event, bool playout) { return true; }
184
virtual bool GetStats(VoiceMediaInfo* info) { return true; }
186
// Implement pure virtual methods of MediaChannel.
187
virtual void OnPacketReceived(talk_base::Buffer* packet);
188
virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
189
virtual bool AddSendStream(const StreamParams& sp);
190
virtual bool RemoveSendStream(uint32 ssrc);
191
virtual bool AddRecvStream(const StreamParams& sp) { return true; }
192
virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
193
virtual bool Mute(bool on) { return false; }
194
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
195
virtual bool SetOptions(int options) {
199
virtual int GetOptions() const { return options_; }
203
talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
206
DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
209
class FileVideoChannel : public VideoMediaChannel {
211
FileVideoChannel(talk_base::StreamInterface* input_file_stream,
212
talk_base::StreamInterface* output_file_stream);
213
virtual ~FileVideoChannel();
215
// Implement pure virtual methods of VideoMediaChannel.
216
virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
219
virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
220
virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
223
virtual bool SetRecvRtpHeaderExtensions(
224
const std::vector<RtpHeaderExtension>& extensions) {
227
virtual bool SetSendRtpHeaderExtensions(
228
const std::vector<RtpHeaderExtension>& extensions) {
231
virtual bool SetRender(bool render) { return true; }
232
virtual bool SetSend(bool send);
233
virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
236
virtual bool AddScreencast(uint32 ssrc, const ScreencastId& id, int fps) {
239
virtual bool RemoveScreencast(uint32 ssrc) { return true; }
240
virtual bool GetStats(VideoMediaInfo* info) { return true; }
241
virtual bool SendIntraFrame() { return false; }
242
virtual bool RequestIntraFrame() { return false; }
244
// Implement pure virtual methods of MediaChannel.
245
virtual void OnPacketReceived(talk_base::Buffer* packet);
246
virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
247
virtual bool AddSendStream(const StreamParams& sp);
248
virtual bool RemoveSendStream(uint32 ssrc);
249
virtual bool AddRecvStream(const StreamParams& sp) { return true; }
250
virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
251
virtual bool Mute(bool on) { return false; }
252
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
253
virtual bool SetOptions(int options) {
257
virtual int GetOptions() const { return options_; }
261
talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
264
DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
267
} // namespace cricket
269
#endif // TALK_SESSION_PHONE_FILEMEDIAENGINE_H_