blob: 1b4eddce80b9c686d775c2a220bca5cb49ffaa0c [file] [log] [blame]
Alexandre Lision0e143012014-01-22 11:02:46 -05001/* $Id: media.hpp 4704 2014-01-16 05:30:46Z ming $ */
2/*
3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifndef __PJSUA2_MEDIA_HPP__
21#define __PJSUA2_MEDIA_HPP__
22
23/**
24 * @file pjsua2/media.hpp
25 * @brief PJSUA2 media operations
26 */
27#include <pjsua-lib/pjsua.h>
28#include <pjsua2/types.hpp>
29
30/** PJSUA2 API is inside pj namespace */
31namespace pj
32{
33
34/**
35 * @defgroup PJSUA2_MED Media
36 * @ingroup PJSUA2_Ref
37 * @{
38 */
39
40using std::string;
41using std::vector;
42
43/**
44 * This structure contains all the information needed to completely describe
45 * a media.
46 */
47struct MediaFormat
48{
49 /**
50 * The format id that specifies the audio sample or video pixel format.
51 * Some well known formats ids are declared in pjmedia_format_id
52 * enumeration.
53 *
54 * @see pjmedia_format_id
55 */
56 pj_uint32_t id;
57
58 /**
59 * The top-most type of the media, as an information.
60 */
61 pjmedia_type type;
62};
63
64/**
65 * This structure describe detail information about an audio media.
66 */
67struct MediaFormatAudio : public MediaFormat
68{
69 unsigned clockRate; /**< Audio clock rate in samples or Hz. */
70 unsigned channelCount; /**< Number of channels. */
71 unsigned frameTimeUsec; /**< Frame interval, in microseconds. */
72 unsigned bitsPerSample; /**< Number of bits per sample. */
73 pj_uint32_t avgBps; /**< Average bitrate */
74 pj_uint32_t maxBps; /**< Maximum bitrate */
75
76 /**
77 * Construct from pjmedia_format.
78 */
79 void fromPj(const pjmedia_format &format);
80
81 /**
82 * Export to pjmedia_format.
83 */
84 pjmedia_format toPj() const;
85};
86
87/**
88 * This structure describe detail information about an video media.
89 */
90struct MediaFormatVideo : public MediaFormat
91{
92 unsigned width; /**< Video width. */
93 unsigned height; /**< Video height. */
94 int fpsNum; /**< Frames per second numerator. */
95 int fpsDenum; /**< Frames per second denumerator. */
96 pj_uint32_t avgBps; /**< Average bitrate. */
97 pj_uint32_t maxBps; /**< Maximum bitrate. */
98};
99
100/** Array of MediaFormat */
101typedef std::vector<MediaFormat*> MediaFormatVector;
102
103/**
104 * This structure descibes information about a particular media port that
105 * has been registered into the conference bridge.
106 */
107struct ConfPortInfo
108{
109 /**
110 * Conference port number.
111 */
112 int portId;
113
114 /**
115 * Port name.
116 */
117 string name;
118
119 /**
120 * Media audio format information
121 */
122 MediaFormatAudio format;
123
124 /**
125 * Tx level adjustment. Value 1.0 means no adjustment, value 0 means
126 * the port is muted, value 2.0 means the level is amplified two times.
127 */
128 float txLevelAdj;
129
130 /**
131 * Rx level adjustment. Value 1.0 means no adjustment, value 0 means
132 * the port is muted, value 2.0 means the level is amplified two times.
133 */
134 float rxLevelAdj;
135
136 /**
137 * Array of listeners (in other words, ports where this port is
138 * transmitting to.
139 */
140 IntVector listeners;
141
142public:
143 /**
144 * Construct from pjsua_conf_port_info.
145 */
146 void fromPj(const pjsua_conf_port_info &port_info);
147};
148
149/**
150 * Media port, corresponds to pjmedia_port
151 */
152typedef void *MediaPort;
153
154/**
155 * Media.
156 */
157class Media
158{
159public:
160 /**
161 * Virtual destructor.
162 */
163 virtual ~Media();
164
165 /**
166 * Get type of the media.
167 *
168 * @return The media type.
169 */
170 pjmedia_type getType() const;
171
172protected:
173 /**
174 * Constructor.
175 */
176 Media(pjmedia_type med_type);
177
178private:
179 /**
180 * Media type.
181 */
182 pjmedia_type type;
183};
184
185/**
186 * Audio Media.
187 */
188class AudioMedia : public Media
189{
190public:
191 /**
192 * Get information about the specified conference port.
193 */
194 ConfPortInfo getPortInfo() const throw(Error);
195
196 /**
197 * Get port Id.
198 */
199 int getPortId() const;
200
201 /**
202 * Get information from specific port id.
203 */
204 static ConfPortInfo getPortInfoFromId(int port_id) throw(Error);
205
206 /**
207 * Establish unidirectional media flow to sink. This media port
208 * will act as a source, and it may transmit to multiple destinations/sink.
209 * And if multiple sources are transmitting to the same sink, the media
210 * will be mixed together. Source and sink may refer to the same Media,
211 * effectively looping the media.
212 *
213 * If bidirectional media flow is desired, application needs to call
214 * this method twice, with the second one called from the opposite source
215 * media.
216 *
217 * @param sink The destination Media.
218 */
219 void startTransmit(const AudioMedia &sink) const throw(Error);
220
221 /**
222 * Stop media flow to destination/sink port.
223 *
224 * @param sink The destination media.
225 *
226 */
227 void stopTransmit(const AudioMedia &sink) const throw(Error);
228
229 /**
230 * Adjust the signal level to be transmitted from the bridge to this
231 * media port by making it louder or quieter.
232 *
233 * @param level Signal level adjustment. Value 1.0 means no
234 * level adjustment, while value 0 means to mute
235 * the port.
236 */
237 void adjustRxLevel(float level) throw(Error);
238
239 /**
240 * Adjust the signal level to be received from this media port (to
241 * the bridge) by making it louder or quieter.
242 *
243 * @param level Signal level adjustment. Value 1.0 means no
244 * level adjustment, while value 0 means to mute
245 * the port.
246 */
247 void adjustTxLevel(float level) throw(Error);
248
249 /**
250 * Get the last received signal level.
251 *
252 * @return Signal level in percent.
253 */
254 unsigned getRxLevel() const throw(Error);
255
256 /**
257 * Get the last transmitted signal level.
258 *
259 * @return Signal level in percent.
260 */
261 unsigned getTxLevel() const throw(Error);
262
263 /**
264 * Typecast from base class Media. This is useful for application written
265 * in language that does not support downcasting such as Python.
266 *
267 * @param media The object to be downcasted
268 *
269 * @return The object as AudioMedia instance
270 */
271 static AudioMedia* typecastFromMedia(Media *media);
272
273 /**
274 * Virtual Destructor
275 */
276 virtual ~AudioMedia();
277
278protected:
279 /**
280 * Conference port Id.
281 */
282 int id;
283
284protected:
285 /**
286 * Default Constructor.
287 */
288 AudioMedia();
289
290 /**
291 * This method needs to be called by descendants of this class to register
292 * the media port created to the conference bridge and Endpoint's
293 * media list.
294 *
295 * param port the media port to be registered to the conference bridge.
296 *
297 */
298 void registerMediaPort(MediaPort port) throw(Error);
299
300 /**
301 * This method needs to be called by descendants of this class to remove
302 * the media port from the conference bridge and Endpoint's media list.
303 * Descendant should only call this method if it has registered the media
304 * with the previous call to registerMediaPort().
305 */
306 void unregisterMediaPort();
307
308private:
309 pj_caching_pool mediaCachingPool;
310 pj_pool_t *mediaPool;
311
312private:
313 unsigned getSignalLevel(bool is_rx = true) const throw(Error);
314};
315
316/** Array of Audio Media */
317typedef std::vector<AudioMedia*> AudioMediaVector;
318
319/**
320 * Audio Media Player.
321 */
322class AudioMediaPlayer : public AudioMedia
323{
324public:
325 /**
326 * Constructor.
327 */
328 AudioMediaPlayer();
329
330 /**
331 * Create a file player, and automatically add this
332 * player to the conference bridge.
333 *
334 * @param file_name The filename to be played. Currently only
335 * WAV files are supported, and the WAV file MUST be
336 * formatted as 16bit PCM mono/single channel (any
337 * clock rate is supported).
338 * @param options Optional option flag. Application may specify
339 * PJMEDIA_FILE_NO_LOOP to prevent playback loop.
340 */
341 void createPlayer(const string &file_name,
342 unsigned options=PJMEDIA_FILE_NO_LOOP) throw(Error);
343
344 /**
345 * Create a file playlist media port, and automatically add the port
346 * to the conference bridge.
347 *
348 * @param file_names Array of file names to be added to the play list.
349 * Note that the files must have the same clock rate,
350 * number of channels, and number of bits per sample.
351 * @param label Optional label to be set for the media port.
352 * @param options Optional option flag. Application may specify
353 * PJMEDIA_FILE_NO_LOOP to prevent looping.
354 */
355 void createPlaylist(const StringVector &file_names,
356 const string &label="",
357 unsigned options=PJMEDIA_FILE_NO_LOOP) throw(Error);
358
359 /**
360 * Set playback position. This operation is not valid for playlist.
361 */
362 void setPos(pj_uint32_t samples) throw(Error);
363
364 /**
365 * Typecast from base class AudioMedia. This is useful for application
366 * written in language that does not support downcasting such as Python.
367 *
368 * @param media The object to be downcasted
369 *
370 * @return The object as AudioMediaPlayer instance
371 */
372 static AudioMediaPlayer* typecastFromAudioMedia(AudioMedia *media);
373
374 /**
375 * Virtual destructor.
376 */
377 virtual ~AudioMediaPlayer();
378
379private:
380 /**
381 * Player Id.
382 */
383 int playerId;
384
385};
386
387/**
388 * Audio Media Recorder.
389 */
390class AudioMediaRecorder : public AudioMedia
391{
392public:
393 /**
394 * Constructor.
395 */
396 AudioMediaRecorder();
397
398 /**
399 * Create a file recorder, and automatically connect this recorder to
400 * the conference bridge. The recorder currently supports recording WAV
401 * file. The type of the recorder to use is determined by the extension of
402 * the file (e.g. ".wav").
403 *
404 * @param file_name Output file name. The function will determine the
405 * default format to be used based on the file extension.
406 * Currently ".wav" is supported on all platforms.
407 * @param enc_type Optionally specify the type of encoder to be used to
408 * compress the media, if the file can support different
409 * encodings. This value must be zero for now.
410 * @param max_size Maximum file size. Specify zero or -1 to remove size
411 * limitation. This value must be zero or -1 for now.
412 * @param options Optional options.
413 */
414 void createRecorder(const string &file_name,
415 unsigned enc_type=0,
416 pj_ssize_t max_size=0,
417 unsigned options=PJMEDIA_FILE_WRITE_PCM) throw(Error);
418
419 /**
420 * Typecast from base class AudioMedia. This is useful for application
421 * written in language that does not support downcasting such as Python.
422 *
423 * @param media The object to be downcasted
424 *
425 * @return The object as AudioMediaRecorder instance
426 */
427 static AudioMediaRecorder* typecastFromAudioMedia(AudioMedia *media);
428
429 /**
430 * Virtual destructor.
431 */
432 virtual ~AudioMediaRecorder();
433
434private:
435 /**
436 * Recorder Id.
437 */
438 int recorderId;
439};
440
441/*************************************************************************
442* Sound device management
443*/
444
445/**
446 * Audio device information structure.
447 */
448struct AudioDevInfo
449{
450 /**
451 * The device name
452 */
453 string name;
454
455 /**
456 * Maximum number of input channels supported by this device. If the
457 * value is zero, the device does not support input operation (i.e.
458 * it is a playback only device).
459 */
460 unsigned inputCount;
461
462 /**
463 * Maximum number of output channels supported by this device. If the
464 * value is zero, the device does not support output operation (i.e.
465 * it is an input only device).
466 */
467 unsigned outputCount;
468
469 /**
470 * Default sampling rate.
471 */
472 unsigned defaultSamplesPerSec;
473
474 /**
475 * The underlying driver name
476 */
477 string driver;
478
479 /**
480 * Device capabilities, as bitmask combination of pjmedia_aud_dev_cap.
481 */
482 unsigned caps;
483
484 /**
485 * Supported audio device routes, as bitmask combination of
486 * pjmedia_aud_dev_route. The value may be zero if the device
487 * does not support audio routing.
488 */
489 unsigned routes;
490
491 /**
492 * Array of supported extended audio formats
493 */
494 MediaFormatVector extFmt;
495
496 /**
497 * Construct from pjmedia_aud_dev_info.
498 */
499 void fromPj(const pjmedia_aud_dev_info &dev_info);
500
501 /**
502 * Destructor.
503 */
504 ~AudioDevInfo();
505};
506
507/** Array of audio device info */
508typedef std::vector<AudioDevInfo*> AudioDevInfoVector;
509
510/**
511 * Audio device manager.
512 */
513class AudDevManager
514{
515public:
516 /**
517 * Get currently active capture sound devices. If sound devices has not been
518 * created, it is possible that the function returns -1 as device IDs.
519 *
520 * @return Device ID of the capture device.
521 */
522 int getCaptureDev() const throw(Error);
523
524 /**
525 * Get the AudioMedia of the capture audio device.
526 *
527 * @return Audio media for the capture device.
528 */
529 AudioMedia &getCaptureDevMedia() throw(Error);
530
531 /**
532 * Get currently active playback sound devices. If sound devices has not
533 * been created, it is possible that the function returns -1 as device IDs.
534 *
535 * @return Device ID of the playback device.
536 */
537 int getPlaybackDev() const throw(Error);
538
539 /**
540 * Get the AudioMedia of the speaker/playback audio device.
541 *
542 * @return Audio media for the speaker/playback device.
543 */
544 AudioMedia &getPlaybackDevMedia() throw(Error);
545
546 /**
547 * Select or change capture sound device. Application may call this
548 * function at any time to replace current sound device.
549 *
550 * @param capture_dev Device ID of the capture device.
551 */
552 void setCaptureDev(int capture_dev) const throw(Error);
553
554 /**
555 * Select or change playback sound device. Application may call this
556 * function at any time to replace current sound device.
557 *
558 * @param playback_dev Device ID of the playback device.
559 */
560 void setPlaybackDev(int playback_dev) const throw(Error);
561
562 /**
563 * Enum all audio devices installed in the system.
564 *
565 * @return The list of audio device info.
566 */
567 const AudioDevInfoVector &enumDev() throw(Error);
568
569 /**
570 * Set pjsua to use null sound device. The null sound device only provides
571 * the timing needed by the conference bridge, and will not interract with
572 * any hardware.
573 *
574 */
575 void setNullDev() throw(Error);
576
577 /**
578 * Disconnect the main conference bridge from any sound devices, and let
579 * application connect the bridge to it's own sound device/master port.
580 *
581 * @return The port interface of the conference bridge,
582 * so that application can connect this to it's
583 * own sound device or master port.
584 */
585 MediaPort *setNoDev();
586
587 /**
588 * Change the echo cancellation settings.
589 *
590 * The behavior of this function depends on whether the sound device is
591 * currently active, and if it is, whether device or software AEC is
592 * being used.
593 *
594 * If the sound device is currently active, and if the device supports AEC,
595 * this function will forward the change request to the device and it will
596 * be up to the device on whether support the request. If software AEC is
597 * being used (the software EC will be used if the device does not support
598 * AEC), this function will change the software EC settings. In all cases,
599 * the setting will be saved for future opening of the sound device.
600 *
601 * If the sound device is not currently active, this will only change the
602 * default AEC settings and the setting will be applied next time the
603 * sound device is opened.
604 *
605 * @param tail_msec The tail length, in miliseconds. Set to zero to
606 * disable AEC.
607 * @param options Options to be passed to pjmedia_echo_create().
608 * Normally the value should be zero.
609 *
610 */
611 void setEcOptions(unsigned tail_msec, unsigned options) throw(Error);
612
613 /**
614 * Get current echo canceller tail length.
615 *
616 * @return The EC tail length in milliseconds,
617 * If AEC is disabled, the value will be zero.
618 */
619 unsigned getEcTail() const throw(Error);
620
621 /**
622 * Check whether the sound device is currently active. The sound device
623 * may be inactive if the application has set the auto close feature to
624 * non-zero (the sndAutoCloseTime setting in MediaConfig), or
625 * if null sound device or no sound device has been configured via the
626 * setNoDev() function.
627 */
628 bool sndIsActive() const;
629
630 /**
631 * Refresh the list of sound devices installed in the system. This method
632 * will only refresh the list of audio device so all active audio streams
633 * will be unaffected. After refreshing the device list, application MUST
634 * make sure to update all index references to audio devices before calling
635 * any method that accepts audio device index as its parameter.
636 *
637 */
638 void refreshDevs() throw(Error);
639
640 /**
641 * Get the number of sound devices installed in the system.
642 *
643 * @return The number of sound devices installed in the
644 * system.
645 *
646 */
647 unsigned getDevCount() const;
648
649 /**
650 * Get device information.
651 *
652 * @param id The audio device ID.
653 *
654 * @return The device information which will be filled in
655 * by this method once it returns successfully.
656 */
657 AudioDevInfo getDevInfo(int id) const throw(Error);
658
659 /**
660 * Lookup device index based on the driver and device name.
661 *
662 * @param drv_name The driver name.
663 * @param dev_name The device name.
664 *
665 * @return The device ID. If the device is not found,
666 * Error will be thrown.
667 */
668 int lookupDev(const string &drv_name,
669 const string &dev_name) const throw(Error);
670
671 /**
672 * Get string info for the specified capability.
673 *
674 * @param cap The capability ID.
675 *
676 * @return Capability name.
677 */
678 string capName(pjmedia_aud_dev_cap cap) const;
679
680 /**
681 * This will configure audio format capability (other than PCM) to the
682 * sound device being used. If sound device is currently active, the method
683 * will forward the setting to the sound device instance to be applied
684 * immediately, if it supports it.
685 *
686 * This method is only valid if the device has
687 * PJMEDIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps flags,
688 * otherwise Error will be thrown.
689 *
690 * Note that in case the setting is kept for future use, it will be applied
691 * to any devices, even when application has changed the sound device to be
692 * used.
693 *
694 * @param format The audio format.
695 * @param keep Specify whether the setting is to be kept for
696 * future use.
697 *
698 */
699 void
700 setExtFormat(const MediaFormatAudio &format, bool keep=true) throw(Error);
701
702 /**
703 * Get the audio format capability (other than PCM) of the sound device
704 * being used. If sound device is currently active, the method will forward
705 * the request to the sound device. If sound device is currently inactive,
706 * and if application had previously set the setting and mark the setting
707 * as kept, then that setting will be returned. Otherwise, this method
708 * will raise error.
709 *
710 * This method is only valid if the device has
711 * PJMEDIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps flags,
712 * otherwise Error will be thrown.
713 *
714 * @return The audio format.
715 *
716 */
717 MediaFormatAudio getExtFormat() const throw(Error);
718
719 /**
720 * This will configure audio input latency control or query capability to
721 * the sound device being used. If sound device is currently active,
722 * the method will forward the setting to the sound device instance to be
723 * applied immediately, if it supports it.
724 *
725 * This method is only valid if the device has
726 * PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps flags,
727 * otherwise Error will be thrown.
728 *
729 * Note that in case the setting is kept for future use, it will be applied
730 * to any devices, even when application has changed the sound device to be
731 * used.
732 *
733 * @param latency_msec The input latency.
734 * @param keep Specify whether the setting is to be kept
735 * for future use.
736 */
737 void
738 setInputLatency(unsigned latency_msec, bool keep=true) throw(Error);
739
740 /**
741 * Get the audio input latency control or query capability of the sound
742 * device being used. If sound device is currently active, the method will
743 * forward the request to the sound device. If sound device is currently
744 * inactive, and if application had previously set the setting and mark the
745 * setting as kept, then that setting will be returned. Otherwise, this
746 * method will raise error.
747 *
748 * This method is only valid if the device has
749 * PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps flags,
750 * otherwise Error will be thrown.
751 *
752 * @return The audio input latency.
753 *
754 */
755 unsigned getInputLatency() const throw(Error);
756
757 /**
758 * This will configure audio output latency control or query capability to
759 * the sound device being used. If sound device is currently active,
760 * the method will forward the setting to the sound device instance to be
761 * applied immediately, if it supports it.
762 *
763 * This method is only valid if the device has
764 * PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps flags,
765 * otherwise Error will be thrown.
766 *
767 * Note that in case the setting is kept for future use, it will be applied
768 * to any devices, even when application has changed the sound device to be
769 * used.
770 *
771 * @param latency_msec The output latency.
772 * @param keep Specify whether the setting is to be kept
773 * for future use.
774 *
775 */
776 void
777 setOutputLatency(unsigned latency_msec, bool keep=true) throw(Error);
778
779 /**
780 * Get the audio output latency control or query capability of the sound
781 * device being used. If sound device is currently active, the method will
782 * forward the request to the sound device. If sound device is currently
783 * inactive, and if application had previously set the setting and mark the
784 * setting as kept, then that setting will be returned. Otherwise, this
785 * method will raise error.
786 *
787 * This method is only valid if the device has
788 * PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps flags,
789 * otherwise Error will be thrown.
790 *
791 * @return The audio output latency.
792 *
793 */
794 unsigned getOutputLatency() const throw(Error);
795
796 /**
797 * This will configure audio input volume level capability to the
798 * sound device being used.
799 * If sound device is currently active, the method will forward the
800 * setting to the sound device instance to be applied immediately,
801 * if it supports it.
802 *
803 * This method is only valid if the device has
804 * PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in AudioDevInfo.caps
805 * flags, otherwise Error will be thrown.
806 *
807 * Note that in case the setting is kept for future use, it will be applied
808 * to any devices, even when application has changed the sound device to be
809 * used.
810 *
811 * @param volume The input volume level, in percent.
812 * @param keep Specify whether the setting is to be kept for
813 * future use.
814 *
815 */
816 void setInputVolume(unsigned volume, bool keep=true) throw(Error);
817
818 /**
819 * Get the audio input volume level capability of the sound device being
820 * used. If sound device is currently active, the method will forward the
821 * request to the sound device. If sound device is currently inactive,
822 * and if application had previously set the setting and mark the setting
823 * as kept, then that setting will be returned. Otherwise, this method
824 * will raise error.
825 *
826 * This method is only valid if the device has
827 * PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in AudioDevInfo.caps
828 * flags, otherwise Error will be thrown. *
829
830 * @return The audio input volume level, in percent.
831 *
832 */
833 unsigned getInputVolume() const throw(Error);
834
835 /**
836 * This will configure audio output volume level capability to the sound
837 * device being used. If sound device is currently active, the method will
838 * forward the setting to the sound device instance to be applied
839 * immediately, if it supports it.
840 *
841 * This method is only valid if the device has
842 * PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps
843 * flags, otherwise Error will be thrown.
844 *
845 * Note that in case the setting is kept for future use, it will be applied
846 * to any devices, even when application has changed the sound device to be
847 * used.
848 *
849 * @param volume The output volume level, in percent.
850 * @param keep Specify whether the setting is to be kept
851 * for future use.
852 *
853 */
854 void setOutputVolume(unsigned volume, bool keep=true) throw(Error);
855
856 /**
857 * Get the audio output volume level capability of the sound device being
858 * used. If sound device is currently active, the method will forward the
859 * request to the sound device. If sound device is currently inactive,
860 * and if application had previously set the setting and mark the setting
861 * as kept, then that setting will be returned. Otherwise, this method
862 * will raise error.
863 *
864 * This method is only valid if the device has
865 * PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps
866 * flags, otherwise Error will be thrown.
867 *
868 * @return The audio output volume level, in percent.
869 *
870 */
871 unsigned getOutputVolume() const throw(Error);
872
873 /**
874 * Get the audio input signal level capability of the sound device being
875 * used. If sound device is currently active, the method will forward the
876 * request to the sound device. If sound device is currently inactive,
877 * and if application had previously set the setting and mark the setting
878 * as kept, then that setting will be returned. Otherwise, this method
879 * will raise error.
880 *
881 * This method is only valid if the device has
882 * PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER capability in AudioDevInfo.caps
883 * flags, otherwise Error will be thrown.
884 *
885 * @return The audio input signal level, in percent.
886 *
887 */
888 unsigned getInputSignal() const throw(Error);
889
890 /**
891 * Get the audio output signal level capability of the sound device being
892 * used. If sound device is currently active, the method will forward the
893 * request to the sound device. If sound device is currently inactive,
894 * and if application had previously set the setting and mark the setting
895 * as kept, then that setting will be returned. Otherwise, this method
896 * will raise error.
897 *
898 * This method is only valid if the device has
899 * PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER capability in AudioDevInfo.caps
900 * flags, otherwise Error will be thrown.
901 *
902 * @return The audio output signal level, in percent.
903 *
904 */
905 unsigned getOutputSignal() const throw(Error);
906
907 /**
908 * This will configure audio input route capability to the sound device
909 * being used. If sound device is currently active, the method will
910 * forward the setting to the sound device instance to be applied
911 * immediately, if it supports it.
912 *
913 * This method is only valid if the device has
914 * PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE capability in AudioDevInfo.caps
915 * flags, otherwise Error will be thrown.
916 *
917 * Note that in case the setting is kept for future use, it will be applied
918 * to any devices, even when application has changed the sound device to be
919 * used.
920 *
921 * @param route The audio input route.
922 * @param keep Specify whether the setting is to be kept
923 * for future use.
924 *
925 */
926 void
927 setInputRoute(pjmedia_aud_dev_route route, bool keep=true) throw(Error);
928
929 /**
930 * Get the audio input route capability of the sound device being used.
931 * If sound device is currently active, the method will forward the
932 * request to the sound device. If sound device is currently inactive,
933 * and if application had previously set the setting and mark the setting
934 * as kept, then that setting will be returned. Otherwise, this method
935 * will raise error.
936 *
937 * This method is only valid if the device has
938 * PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE capability in AudioDevInfo.caps
939 * flags, otherwise Error will be thrown.
940 *
941 * @return The audio input route.
942 *
943 */
944 pjmedia_aud_dev_route getInputRoute() const throw(Error);
945
946 /**
947 * This will configure audio output route capability to the sound device
948 * being used. If sound device is currently active, the method will
949 * forward the setting to the sound device instance to be applied
950 * immediately, if it supports it.
951 *
952 * This method is only valid if the device has
953 * PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
954 * flags, otherwise Error will be thrown.
955 *
956 * Note that in case the setting is kept for future use, it will be applied
957 * to any devices, even when application has changed the sound device to be
958 * used.
959 *
960 * @param route The audio output route.
961 * @param keep Specify whether the setting is to be kept
962 * for future use.
963 *
964 */
965 void
966 setOutputRoute(pjmedia_aud_dev_route route, bool keep=true) throw(Error);
967
968 /**
969 * Get the audio output route capability of the sound device being used.
970 * If sound device is currently active, the method will forward the
971 * request to the sound device. If sound device is currently inactive,
972 * and if application had previously set the setting and mark the setting
973 * as kept, then that setting will be returned. Otherwise, this method
974 * will raise error.
975 *
976 * This method is only valid if the device has
977 * PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
978 * flags, otherwise Error will be thrown.
979 *
980 * @return The audio output route.
981 *
982 */
983 pjmedia_aud_dev_route getOutputRoute() const throw(Error);
984
985 /**
986 * This will configure audio voice activity detection capability to
987 * the sound device being used. If sound device is currently active,
988 * the method will forward the setting to the sound device instance
989 * to be applied immediately, if it supports it.
990 *
991 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD
992 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
993 *
994 * Note that in case the setting is kept for future use, it will be applied
995 * to any devices, even when application has changed the sound device to be
996 * used.
997 *
998 * @param enable Enable/disable voice activity detection
999 * feature. Set true to enable.
1000 * @param keep Specify whether the setting is to be kept for
1001 * future use.
1002 *
1003 */
1004 void setVad(bool enable, bool keep=true) throw(Error);
1005
1006 /**
1007 * Get the audio voice activity detection capability of the sound device
1008 * being used. If sound device is currently active, the method will
1009 * forward the request to the sound device. If sound device is currently
1010 * inactive, and if application had previously set the setting and mark
1011 * the setting as kept, then that setting will be returned. Otherwise,
1012 * this method will raise error.
1013 *
1014 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD
1015 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1016 *
1017 * @return The audio voice activity detection feature.
1018 *
1019 */
1020 bool getVad() const throw(Error);
1021
1022 /**
1023 * This will configure audio comfort noise generation capability to
1024 * the sound device being used. If sound device is currently active,
1025 * the method will forward the setting to the sound device instance
1026 * to be applied immediately, if it supports it.
1027 *
1028 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG
1029 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1030 *
1031 * Note that in case the setting is kept for future use, it will be applied
1032 * to any devices, even when application has changed the sound device to be
1033 * used.
1034 *
1035 * @param enable Enable/disable comfort noise generation
1036 * feature. Set true to enable.
1037 * @param keep Specify whether the setting is to be kept for
1038 * future use.
1039 *
1040 */
1041 void setCng(bool enable, bool keep=true) throw(Error);
1042
1043 /**
1044 * Get the audio comfort noise generation capability of the sound device
1045 * being used. If sound device is currently active, the method will
1046 * forward the request to the sound device. If sound device is currently
1047 * inactive, and if application had previously set the setting and mark
1048 * the setting as kept, then that setting will be returned. Otherwise,
1049 * this method will raise error.
1050 *
1051 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG
1052 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1053 *
1054 * @return The audio comfort noise generation feature.
1055 *
1056 */
1057 bool getCng() const throw(Error);
1058
1059 /**
1060 * This will configure audio packet loss concealment capability to
1061 * the sound device being used. If sound device is currently active,
1062 * the method will forward the setting to the sound device instance
1063 * to be applied immediately, if it supports it.
1064 *
1065 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC
1066 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1067 *
1068 * Note that in case the setting is kept for future use, it will be applied
1069 * to any devices, even when application has changed the sound device to be
1070 * used.
1071 *
1072 * @param enable Enable/disable packet loss concealment
1073 * feature. Set true to enable.
1074 * @param keep Specify whether the setting is to be kept for
1075 * future use.
1076 *
1077 */
1078 void setPlc(bool enable, bool keep=true) throw(Error);
1079
1080 /**
1081 * Get the audio packet loss concealment capability of the sound device
1082 * being used. If sound device is currently active, the method will
1083 * forward the request to the sound device. If sound device is currently
1084 * inactive, and if application had previously set the setting and mark
1085 * the setting as kept, then that setting will be returned. Otherwise,
1086 * this method will raise error.
1087 *
1088 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC
1089 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1090 *
1091 * @return The audio packet loss concealment feature.
1092 *
1093 */
1094 bool getPlc() const throw(Error);
1095
1096private:
1097 AudioDevInfoVector audioDevList;
1098 AudioMedia *devMedia;
1099
1100 /**
1101 * Constructor.
1102 */
1103 AudDevManager();
1104
1105 /**
1106 * Destructor.
1107 */
1108 ~AudDevManager();
1109
1110 void clearAudioDevList();
1111 int getActiveDev(bool is_capture) const throw(Error);
1112
1113 friend class Endpoint;
1114};
1115
1116/*************************************************************************
1117* Codec management
1118*/
1119
1120/**
1121 * This structure describes codec information.
1122 */
1123struct CodecInfo
1124{
1125 /**
1126 * Codec unique identification.
1127 */
1128 string codecId;
1129
1130 /**
1131 * Codec priority (integer 0-255).
1132 */
1133 pj_uint8_t priority;
1134
1135 /**
1136 * Codec description.
1137 */
1138 string desc;
1139
1140 /**
1141 * Construct from pjsua_codec_info.
1142 */
1143 void fromPj(const pjsua_codec_info &codec_info);
1144};
1145
1146/** Array of codec info */
1147typedef std::vector<CodecInfo*> CodecInfoVector;
1148
1149/**
1150 * Codec parameters, corresponds to pjmedia_codec_param or
1151 * pjmedia_vid_codec_param.
1152 */
1153typedef void *CodecParam;
1154
1155
1156/**
1157 * @} // PJSUA2_MED
1158 */
1159
1160} // namespace pj
1161
1162#endif /* __PJSUA2_MEDIA_HPP__ */