~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/session/phone/filemediaengine.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// libjingle
 
2
// Copyright 2004--2005, Google Inc.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are met:
 
6
//
 
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.
 
14
//
 
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.
 
25
 
 
26
#ifndef TALK_SESSION_PHONE_FILEMEDIAENGINE_H_
 
27
#define TALK_SESSION_PHONE_FILEMEDIAENGINE_H_
 
28
 
 
29
#include <string>
 
30
#include <vector>
 
31
 
 
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"
 
37
 
 
38
namespace talk_base {
 
39
class StreamInterface;
 
40
}
 
41
 
 
42
namespace cricket {
 
43
 
 
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 {
 
52
 public:
 
53
  FileMediaEngine() {}
 
54
  virtual ~FileMediaEngine() {}
 
55
 
 
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;
 
60
  }
 
61
  void set_voice_output_filename(const std::string& filename) {
 
62
    voice_output_filename_ = filename;
 
63
  }
 
64
  void set_video_input_filename(const std::string& filename) {
 
65
    video_input_filename_ = filename;
 
66
  }
 
67
  void set_video_output_filename(const std::string& filename) {
 
68
    video_output_filename_ = filename;
 
69
  }
 
70
 
 
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;
 
75
  }
 
76
  void set_video_codecs(const std::vector<VideoCodec>& codecs) {
 
77
    video_codecs_ = codecs;
 
78
  }
 
79
 
 
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) {
 
90
    return true;
 
91
  }
 
92
  virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
 
93
    return true;
 
94
  }
 
95
  virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
 
96
  virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/, uint32 /*ssrc*/) {
 
97
    return true;
 
98
  }
 
99
  virtual bool GetOutputVolume(int* level) {
 
100
    *level = 0;
 
101
    return true;
 
102
  }
 
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_;
 
111
  }
 
112
  virtual const std::vector<VideoCodec>& video_codecs() {
 
113
    return video_codecs_;
 
114
  }
 
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) {}
 
119
 
 
120
  virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
 
121
    return true;
 
122
  }
 
123
  virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
 
124
    return true;
 
125
  }
 
126
  virtual bool RegisterVoiceProcessor(uint32 ssrc,
 
127
                                      VoiceProcessor* processor,
 
128
                                      MediaProcessorDirection direction) {
 
129
    return true;
 
130
  }
 
131
  virtual bool UnregisterVoiceProcessor(uint32 ssrc,
 
132
                                        VoiceProcessor* processor,
 
133
                                        MediaProcessorDirection direction) {
 
134
    return true;
 
135
  }
 
136
 
 
137
 private:
 
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_;
 
144
 
 
145
  DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
 
146
};
 
147
 
 
148
class RtpSenderReceiver;  // Forward declaration. Defined in the .cc file.
 
149
 
 
150
class FileVoiceChannel : public VoiceMediaChannel {
 
151
 public:
 
152
  FileVoiceChannel(talk_base::StreamInterface* input_file_stream,
 
153
      talk_base::StreamInterface* output_file_stream);
 
154
  virtual ~FileVoiceChannel();
 
155
 
 
156
  // Implement pure virtual methods of VoiceMediaChannel.
 
157
  virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
 
158
    return true;
 
159
  }
 
160
  virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
 
161
  virtual bool SetRecvRtpHeaderExtensions(
 
162
      const std::vector<RtpHeaderExtension>& extensions) {
 
163
    return true;
 
164
  }
 
165
  virtual bool SetSendRtpHeaderExtensions(
 
166
      const std::vector<RtpHeaderExtension>& extensions) {
 
167
    return true;
 
168
  }
 
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) {
 
174
    return false;
 
175
  }
 
176
  virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
 
177
    return false;
 
178
  }
 
179
  virtual bool SetRingbackTone(const char* buf, int len) { return true; }
 
180
  virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
 
181
    return true;
 
182
  }
 
183
  virtual bool PressDTMF(int event, bool playout) { return true; }
 
184
  virtual bool GetStats(VoiceMediaInfo* info) { return true; }
 
185
 
 
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) {
 
196
    options_ = options;
 
197
    return true;
 
198
  }
 
199
  virtual int GetOptions() const { return options_; }
 
200
 
 
201
 private:
 
202
  uint32 send_ssrc_;
 
203
  talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
 
204
  int options_;
 
205
 
 
206
  DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
 
207
};
 
208
 
 
209
class FileVideoChannel : public VideoMediaChannel {
 
210
 public:
 
211
  FileVideoChannel(talk_base::StreamInterface* input_file_stream,
 
212
      talk_base::StreamInterface* output_file_stream);
 
213
  virtual ~FileVideoChannel();
 
214
 
 
215
  // Implement pure virtual methods of VideoMediaChannel.
 
216
  virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
 
217
    return true;
 
218
  }
 
219
  virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
 
220
  virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
 
221
    return true;
 
222
  }
 
223
  virtual bool SetRecvRtpHeaderExtensions(
 
224
      const std::vector<RtpHeaderExtension>& extensions) {
 
225
    return true;
 
226
  }
 
227
  virtual bool SetSendRtpHeaderExtensions(
 
228
      const std::vector<RtpHeaderExtension>& extensions) {
 
229
    return true;
 
230
  }
 
231
  virtual bool SetRender(bool render) { return true; }
 
232
  virtual bool SetSend(bool send);
 
233
  virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
 
234
    return true;
 
235
  }
 
236
  virtual bool AddScreencast(uint32 ssrc, const ScreencastId& id, int fps) {
 
237
    return true;
 
238
  }
 
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; }
 
243
 
 
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) {
 
254
    options_ = options;
 
255
    return true;
 
256
  }
 
257
  virtual int GetOptions() const { return options_; }
 
258
 
 
259
 private:
 
260
  uint32 send_ssrc_;
 
261
  talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
 
262
  int options_;
 
263
 
 
264
  DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
 
265
};
 
266
 
 
267
}  // namespace cricket
 
268
 
 
269
#endif  // TALK_SESSION_PHONE_FILEMEDIAENGINE_H_