Debian Codegraph @

Xpjproject/pjsip/include/pjsua2/media.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef __PJSUA2_MEDIA_HPP__
20 #define __PJSUA2_MEDIA_HPP__
21
22 /**
23 * @file pjsua2/media.hpp
24 * @brief PJSUA2 media operations
25 */
26 #include <pjsua-lib/pjsua.h>
27 #include <pjsua2/types.hpp>
28
29 /** PJSUA2 API is inside pj namespace */
30 namespace pj
31 {
32
33 /**
34 * @defgroup PJSUA2_MED Media
35 * @ingroup PJSUA2_Ref
36 * @{
37 */
38
39 using std::string;
40 using std::vector;
41
42 /**
43 * This structure contains all the information needed to completely describe
44 * a media.
45 */
46 struct MediaFormat
47 {
48 /**
49 * The format id that specifies the audio sample or video pixel format.
50 * Some well known formats ids are declared in pjmedia_format_id
51 * enumeration.
52 *
53 * @see pjmedia_format_id
54 */
55 pj_uint32_t id;
56
57 /**
58 * The top-most type of the media, as an information.
59 */
60 pjmedia_type type;
61
62 public:
63 /**
64 * Default constructor
65 */
66 MediaFormat() : id(0), type(PJMEDIA_TYPE_NONE)
67 {}
68 };
69
70 /**
71 * This structure describe detail information about an audio media.
72 */
73 struct MediaFormatAudio : public MediaFormat
74 {
75 unsigned clockRate; /**< Audio clock rate in samples or Hz. */
76 unsigned channelCount; /**< Number of channels. */
77 unsigned frameTimeUsec; /**< Frame interval, in microseconds. */
78 unsigned bitsPerSample; /**< Number of bits per sample. */
79 pj_uint32_t avgBps; /**< Average bitrate */
80 pj_uint32_t maxBps; /**< Maximum bitrate */
81
82 /**
83 * Construct from pjmedia_format.
84 */
85 void fromPj(const pjmedia_format &format);
86
87 /**
88 * Export to pjmedia_format.
89 */
90 pjmedia_format toPj() const;
91
92 public:
93 /**
94 * Default constructor
95 */
96 MediaFormatAudio() : clockRate(0), channelCount(0), frameTimeUsec(0),
97 bitsPerSample(0), avgBps(0), maxBps(0)
98 {}
99
100 /**
101 * Initialization
102 */
103 void init(pj_uint32_t formatId, unsigned clockRate, unsigned channelCount,
104 int frameTimeUsec, int bitsPerSample,
105 pj_uint32_t avgBps=0, pj_uint32_t maxBps=0);
106 };
107
108 /**
109 * This structure describe detail information about an video media.
110 */
111 struct MediaFormatVideo : public MediaFormat
112 {
113 unsigned width; /**< Video width. */
114 unsigned height; /**< Video height. */
115 int fpsNum; /**< Frames per second numerator. */
116 int fpsDenum; /**< Frames per second denumerator. */
117 pj_uint32_t avgBps; /**< Average bitrate. */
118 pj_uint32_t maxBps; /**< Maximum bitrate. */
119
120 /**
121 * Construct from pjmedia_format.
122 */
123 void fromPj(const pjmedia_format &format);
124
125 /**
126 * Export to pjmedia_format.
127 */
128 pjmedia_format toPj() const;
129
130 public:
131 /**
132 * Default constructor
133 */
134 MediaFormatVideo() : width(0), height(0), fpsNum(0),
135 fpsDenum(1), avgBps(0), maxBps(0)
136 {}
137
138 /**
139 * Initialization
140 */
141 void init(pj_uint32_t formatId, unsigned width, unsigned height,
142 int fpsNum, int fpsDenum=1,
143 pj_uint32_t avgBps=0, pj_uint32_t maxBps=0);
144 };
145
146 /** Array of MediaFormatAudio */
147 typedef std::vector<MediaFormatAudio> MediaFormatAudioVector;
148
149 /** Array of MediaFormatVideo */
150 typedef std::vector<MediaFormatVideo> MediaFormatVideoVector;
151
152 /**
153 * This structure descibes information about a particular media port that
154 * has been registered into the conference bridge.
155 */
156 struct ConfPortInfo
157 {
158 /**
159 * Conference port number.
160 */
161 int portId;
162
163 /**
164 * Port name.
165 */
166 string name;
167
168 /**
169 * Media audio format information
170 */
171 MediaFormatAudio format;
172
173 /**
174 * Tx level adjustment. Value 1.0 means no adjustment, value 0 means
175 * the port is muted, value 2.0 means the level is amplified two times.
176 */
177 float txLevelAdj;
178
179 /**
180 * Rx level adjustment. Value 1.0 means no adjustment, value 0 means
181 * the port is muted, value 2.0 means the level is amplified two times.
182 */
183 float rxLevelAdj;
184
185 /**
186 * Array of listeners (in other words, ports where this port is
187 * transmitting to).
188 */
189 IntVector listeners;
190
191 public:
192 /**
193 * Construct from pjsua_conf_port_info.
194 */
195 void fromPj(const pjsua_conf_port_info &port_info);
196 };
197
198 /**
199 * Media port, corresponds to pjmedia_port
200 */
201 typedef void *MediaPort;
202
203 /**
204 * Media.
205 */
206 class Media
207 {
208 public:
209 /**
210 * Virtual destructor.
211 */
212 virtual ~Media();
213
214 /**
215 * Get type of the media.
216 *
217 * @return The media type.
218 */
219 pjmedia_type getType() const;
220
221 protected:
222 /**
223 * Constructor.
224 */
225 Media(pjmedia_type med_type);
226
227 private:
228 /**
229 * Media type.
230 */
231 pjmedia_type type;
232 };
233
234 /**
235 * Parameters for AudioMedia::startTransmit2() method.
236 */
237 struct AudioMediaTransmitParam
238 {
239 /**
240 * Signal level adjustment. Value 1.0 means no level adjustment,
241 * while value 0 means to mute the port.
242 *
243 * Default: 1.0
244 */
245 float level;
246
247 public:
248 /**
249 * Default constructor
250 */
251 AudioMediaTransmitParam();
252 };
253
254 /**
255 * Audio Media. This is a lite wrapper class for audio conference bridge port,
256 * i.e: this class only maintains one data member, conference slot ID, and
257 * the methods are simply proxies for conference bridge operations.
258 *
259 * Application can create a derived class and use registerMediaPort2()/
260 * unregisterMediaPort() to register/unregister a media port to/from the
261 * conference bridge.
262 *
263 * The library will not keep a list of AudioMedia instances, so any
264 * AudioMedia (descendant) instances instantiated by application must be
265 * maintained and destroyed by the application itself.
266 *
267 * Note that any PJSUA2 APIs that return AudioMedia instance(s) such as
268 * Endpoint::mediaEnumPorts2() or Call::getAudioMedia() will just return
269 * generated copy. All AudioMedia methods should work normally on this
270 * generated copy instance.
271 */
272 class AudioMedia : public Media
273 {
274 public:
275 /**
276 * Get information about the specified conference port.
277 */
278 ConfPortInfo getPortInfo() const PJSUA2_THROW(Error);
279
280 /**
281 * Get port Id.
282 */
283 int getPortId() const;
284
285 /**
286 * Get information from specific port id.
287 */
288 static ConfPortInfo getPortInfoFromId(int port_id) PJSUA2_THROW(Error);
289
290 /**
291 * Establish unidirectional media flow to sink. This media port
292 * will act as a source, and it may transmit to multiple destinations/sink.
293 * And if multiple sources are transmitting to the same sink, the media
294 * will be mixed together. Source and sink may refer to the same Media,
295 * effectively looping the media.
296 *
297 * If bidirectional media flow is desired, application needs to call
298 * this method twice, with the second one called from the opposite source
299 * media.
300 *
301 * This operation executes asynchronously, use the callback set from
302 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
303 * completion.
304
305 *
306 * @param sink The destination Media.
307 */
308 void startTransmit(const AudioMedia &sink) const PJSUA2_THROW(Error);
309
310 /**
311 * Establish unidirectional media flow to sink. This media port
312 * will act as a source, and it may transmit to multiple destinations/sink.
313 * And if multiple sources are transmitting to the same sink, the media
314 * will be mixed together. Source and sink may refer to the same Media,
315 * effectively looping the media.
316 *
317 * Signal level from this source to the sink can be adjusted by making
318 * it louder or quieter via the parameter param. The level adjustment
319 * will apply to a specific connection only (i.e. only for signal
320 * from this source to the sink), as compared to
321 * adjustTxLevel()/adjustRxLevel() which applies to all signals from/to
322 * this media port. The signal adjustment
323 * will be cumulative, in this following order:
324 * signal from this source will be adjusted with the level specified
325 * in adjustTxLevel(), then with the level specified via this API,
326 * and finally with the level specified to the sink's adjustRxLevel().
327 *
328 * If bidirectional media flow is desired, application needs to call
329 * this method twice, with the second one called from the opposite source
330 * media.
331 *
332 * This operation executes asynchronously, use the callback set from
333 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
334 * completion.
335 *
336 * @param sink The destination Media.
337 * @param param The parameter.
338 */
339 void startTransmit2(const AudioMedia &sink,
340 const AudioMediaTransmitParam &param) const
341 PJSUA2_THROW(Error);
342
343 /**
344 * Stop media flow to destination/sink port.
345 *
346 * This operation executes asynchronously, use the callback set from
347 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
348 * completion.
349 *
350 * @param sink The destination media.
351 *
352 */
353 void stopTransmit(const AudioMedia &sink) const PJSUA2_THROW(Error);
354
355 /**
356 * Adjust the signal level to be transmitted from the bridge to this
357 * media port by making it louder or quieter.
358 *
359 * @param level Signal level adjustment. Value 1.0 means no
360 * level adjustment, while value 0 means to mute
361 * the port.
362 */
363 void adjustRxLevel(float level) PJSUA2_THROW(Error);
364
365 /**
366 * Adjust the signal level to be received from this media port (to
367 * the bridge) by making it louder or quieter.
368 *
369 * @param level Signal level adjustment. Value 1.0 means no
370 * level adjustment, while value 0 means to mute
371 * the port.
372 */
373 void adjustTxLevel(float level) PJSUA2_THROW(Error);
374
375 /**
376 * Get the last received signal level.
377 *
378 * @return Signal level in percent.
379 */
380 unsigned getRxLevel() const PJSUA2_THROW(Error);
381
382 /**
383 * Get the last transmitted signal level.
384 *
385 * @return Signal level in percent.
386 */
387 unsigned getTxLevel() const PJSUA2_THROW(Error);
388
389 /**
390 * Warning: deprecated and will be removed in future release.
391 *
392 * Typecast from base class Media. This is useful for application written
393 * in language that does not support downcasting such as Python.
394 *
395 * @param media The object to be downcasted
396 *
397 * @return The object as AudioMedia instance
398 */
399 static AudioMedia* typecastFromMedia(Media *media);
400
401 /**
402 * Default Constructor.
403 *
404 * Normally application will not create AudioMedia object directly,
405 * but it instantiates an AudioMedia derived class. This is set as public
406 * because some STL vector implementations require it.
407 */
408 AudioMedia();
409
410 /**
411 * Virtual Destructor.
412 */
413 virtual ~AudioMedia();
414
415 protected:
416 /**
417 * Conference port Id.
418 */
419 int id;
420
421 protected:
422 /**
423 * Warning: deprecated and will be removed in future release, use
424 * registerMediaPort2() instead.
425 *
426 * This method needs to be called by descendants of this class to register
427 * the media port created to the conference bridge and Endpoint's
428 * media list.
429 *
430 * This operation executes asynchronously, use the callback set from
431 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
432 * completion.
433 *
434 * param port The media port to be registered to the conference bridge.
435 *
436 */
437 void registerMediaPort(MediaPort port) PJSUA2_THROW(Error);
438
439 /**
440 * This method needs to be called by descendants of this class to register
441 * the media port created to the conference bridge and Endpoint's
442 * media list.
443 *
444 * This operation executes asynchronously, use the callback set from
445 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
446 * completion.
447 *
448 * param port The media port to be registered to the conference bridge.
449 * param pool The memory pool.
450 *
451 */
452 void registerMediaPort2(MediaPort port, pj_pool_t *pool)
453 PJSUA2_THROW(Error);
454
455 /**
456 * This method needs to be called by descendants of this class to remove
457 * the media port from the conference bridge and Endpoint's media list.
458 * Descendant should only call this method if it has registered the media
459 * with the previous call to registerMediaPort().
460 *
461 * This operation executes asynchronously, use the callback set from
462 * Endpoint::onAudioMediaOpCompleted() to receive notification upon
463 * completion.
464 */
465 void unregisterMediaPort() PJSUA2_THROW(Error);
466
467 private:
468 /* Memory pool for deprecated registerMediaPort() */
469 pj_caching_pool mediaCachingPool;
470 pj_pool_t *mediaPool;
471 };
472
473 /**
474 * Warning: deprecated, use AudioMediaVector2 instead.
475 *
476 * Array of Audio Media.
477 */
478 typedef std::vector<AudioMedia*> AudioMediaVector;
479
480
481 /** Array of Audio Media */
482 typedef std::vector<AudioMedia> AudioMediaVector2;
483
484 /**
485 * This structure describes a media frame.
486 */
487 struct MediaFrame
488 {
489 pjmedia_frame_type type; /**< Frame type. */
490 ByteVector buf; /**< Frame buffer content. */
491 unsigned size; /**< Frame size in bytes. */
492
493 public:
494 /**
495 * Default constructor
496 */
497 MediaFrame()
498 : type(PJMEDIA_FRAME_TYPE_NONE),
499 size(0)
500 {}
501 };
502
503 /**
504 * Audio Media Port.
505 */
506 class AudioMediaPort : public AudioMedia
507 {
508 public:
509 /**
510 * Constructor.
511 */
512 AudioMediaPort();
513
514 /**
515 * Destructor. This will unregister the audio media port from the
516 * conference bridge.
517 */
518 virtual ~AudioMediaPort();
519
520 /**
521 * Create an audio media port and register it to the conference bridge.
522 *
523 * @param name The port name.
524 * @param fmt The audio format.
525 */
526 void createPort(const string &name, MediaFormatAudio &fmt)
527 PJSUA2_THROW(Error);
528
529 /*
530 * Callbacks
531 */
532 /**
533 * This callback is called to request a frame from this port. On input,
534 * frame.size indicates the capacity of the frame buffer and frame.buf
535 * will initially be an empty vector. Application can then set the frame
536 * type and fill the vector.
537 *
538 * @param frame The frame.
539 */
540 virtual void onFrameRequested(MediaFrame &frame)
541 { PJ_UNUSED_ARG(frame); }
542
543 /**
544 * This callback is called when this port receives a frame. The frame
545 * content will be provided in frame.buf vector, and the frame size
546 * can be found in either frame.size or the vector's size (both
547 * have the same value).
548 *
549 * @param frame The frame.
550 */
551 virtual void onFrameReceived(MediaFrame &frame)
552 { PJ_UNUSED_ARG(frame); }
553
554 private:
555 pj_pool_t *pool;
556 pjmedia_port *port;
557 };
558
559
560 /**
561 * AI Media Port event data.
562 */
563 struct AiMediaEvent
564 {
565 /** Event type. */
566 pjmedia_ai_event_type type;
567
568 /** Status code. PJ_SUCCESS for informational events. */
569 pj_status_t status;
570
571 /** Text payload (transcript). Only valid for TRANSCRIPT events. */
572 string text;
573 };
574
575
576 /**
577 * AI Media Port creation parameters.
578 */
579 struct AiMediaPortParam
580 {
581 /**
582 * Enable voice activity detection (VAD) on the TX path.
583 * When enabled, silence frames are not sent to the AI service.
584 *
585 * Default: false
586 */
587 bool vadEnabled;
588
589 /**
590 * Ptime in milliseconds.
591 *
592 * Default: 20
593 */
594 unsigned ptimeMsec;
595
596 public:
597 /** Default constructor */
598 AiMediaPortParam() : vadEnabled(false), ptimeMsec(20) {}
599 };
600
601
602 /**
603 * AI Media Port.
604 *
605 * This wraps pjmedia_ai_port as an AudioMedia object that can be
606 * connected to the conference bridge. It bridges audio to/from
607 * real-time AI services (e.g. OpenAI Realtime API) over WebSocket.
608 *
609 * Basic usage:
610 * 1. Create with createPort() (uses the OpenAI Realtime API backend).
611 * 2. Connect to the AI service with connect().
612 * 3. Use startTransmit()/stopTransmit() to route audio from/to
613 * other conference bridge ports (e.g. AudioMedia from a call).
614 * 4. Disconnect with disconnect() when done.
615 *
616 * Events (connected, transcript, etc.) are delivered via the
617 * virtual onEvent() callback.
618 */
619 class AudioMediaAiPort : public AudioMedia
620 {
621 public:
622 /**
623 * Constructor.
624 */
625 AudioMediaAiPort();
626
627 /**
628 * Destructor. Disconnects from the AI service (if connected) and
629 * unregisters the port from the conference bridge.
630 */
631 virtual ~AudioMediaAiPort();
632
633 /**
634 * Create an AI media port with the OpenAI Realtime API backend and
635 * register it to the conference bridge. The port operates at the
636 * backend's native clock rate (e.g. 24kHz for OpenAI); the
637 * conference bridge handles resampling.
638 *
639 * @param prm Creation parameters.
640 */
641 void createPort(const AiMediaPortParam &prm = AiMediaPortParam())
642 PJSUA2_THROW(Error);
643
644 /**
645 * Connect to the AI service asynchronously. The onEvent() callback
646 * will be called with PJMEDIA_AI_EVENT_CONNECTED or
647 * PJMEDIA_AI_EVENT_DISCONNECTED when complete.
648 *
649 * @param url WebSocket URL (e.g.
650 * "wss://api.openai.com/v1/realtime?model=...")
651 * @param authToken Authentication token (e.g. OpenAI API key).
652 */
653 void connect(const string &url, const string &authToken)
654 PJSUA2_THROW(Error);
655
656 /**
657 * Disconnect from the AI service gracefully.
658 */
659 void disconnect() PJSUA2_THROW(Error);
660
661 /*
662 * Callbacks
663 */
664
665 /**
666 * Called when an AI event occurs (connected, transcript, etc.).
667 * This may be called from the ioqueue worker thread.
668 *
669 * @param event The event data.
670 */
671 virtual void onEvent(const AiMediaEvent &event)
672 { PJ_UNUSED_ARG(event); }
673
674 private:
675 pj_pool_t *pool;
676 pjmedia_ai_port *aiPort;
677 pjmedia_ai_backend *backend;
678 };
679
680
681 /**
682 * This structure contains additional info about AudioMediaPlayer.
683 */
684 struct AudioMediaPlayerInfo
685 {
686 /**
687 * Format ID of the payload.
688 */
689 pjmedia_format_id formatId;
690
691 /**
692 * The number of bits per sample of the file payload. For example,
693 * the value is 16 for PCM WAV and 8 for Alaw/Ulas WAV files.
694 */
695 unsigned payloadBitsPerSample;
696
697 /**
698 * The WAV payload size in bytes.
699 */
700 pj_uint32_t sizeBytes;
701
702 /**
703 * The WAV payload size in samples.
704 */
705 pj_uint32_t sizeSamples;
706
707 public:
708 /**
709 * Default constructor
710 */
711 AudioMediaPlayerInfo()
712 : formatId(PJMEDIA_FORMAT_L16),
713 payloadBitsPerSample(0),
714 sizeBytes(0),
715 sizeSamples(0)
716 {}
717 };
718
719 /**
720 * Audio Media Player.
721 */
722 class AudioMediaPlayer : public AudioMedia
723 {
724 public:
725 /**
726 * Constructor.
727 */
728 AudioMediaPlayer();
729
730 /**
731 * Create a file player, and automatically add this
732 * player to the conference bridge.
733 *
734 * @param file_name The filename to be played. Currently only
735 * WAV files are supported, and the WAV file MUST be
736 * formatted as 16bit PCM mono/single channel (any
737 * clock rate is supported).
738 * @param options Optional option flag. Application may specify
739 * PJMEDIA_FILE_NO_LOOP to prevent playback loop.
740 */
741 void createPlayer(const string &file_name,
742 unsigned options=0) PJSUA2_THROW(Error);
743
744 /**
745 * Create a file playlist media port, and automatically add the port
746 * to the conference bridge.
747 *
748 * @param file_names Array of file names to be added to the play list.
749 * Note that the files must have the same clock rate,
750 * number of channels, and number of bits per sample.
751 * @param label Optional label to be set for the media port.
752 * @param options Optional option flag. Application may specify
753 * PJMEDIA_FILE_NO_LOOP to prevent looping.
754 */
755 void createPlaylist(const StringVector &file_names,
756 const string &label="",
757 unsigned options=0) PJSUA2_THROW(Error);
758
759 /**
760 * Get additional info about the player. This operation is only valid
761 * for player. For playlist, Error will be thrown.
762 *
763 * @return the info.
764 */
765 AudioMediaPlayerInfo getInfo() const PJSUA2_THROW(Error);
766
767 /**
768 * Get current playback position in samples. This operation is not valid
769 * for playlist.
770 *
771 * @return Current playback position, in samples.
772 */
773 pj_uint32_t getPos() const PJSUA2_THROW(Error);
774
775 /**
776 * Set playback position in samples. This operation is not valid for
777 * playlist.
778 *
779 * @param samples The desired playback position, in samples.
780 */
781 void setPos(pj_uint32_t samples) PJSUA2_THROW(Error);
782
783 /**
784 * Warning: deprecated and will be removed in future release.
785 *
786 * Typecast from base class AudioMedia. This is useful for application
787 * written in language that does not support downcasting such as Python.
788 *
789 * @param media The object to be downcasted
790 *
791 * @return The object as AudioMediaPlayer instance
792 */
793 static AudioMediaPlayer* typecastFromAudioMedia(AudioMedia *media);
794
795 /**
796 * Destructor. This will unregister the player port from the conference
797 * bridge.
798 */
799 virtual ~AudioMediaPlayer();
800
801 public:
802 /*
803 * Callbacks
804 */
805
806
807 /* Unfortunately for pjsua2, a hard deprecation is inevitable. */
808 #if 0 // !DEPRECATED_FOR_TICKET_2251
809 /**
810 * Register a callback to be called when the file player reading has
811 * reached the end of file, or when the file reading has reached the
812 * end of file of the last file for a playlist. If the file or playlist
813 * is set to play repeatedly, then the callback will be called multiple
814 * times.
815 *
816 * @return If the callback returns false, the playback
817 * will stop. Note that if application destroys
818 * the player in the callback, it must return
819 * false here.
820 */
821 virtual bool onEof()
822 { return true; }
823 #endif
824
825 /**
826 * Register a callback to be called when the file player reading has
827 * reached the end of file, or when the file reading has reached the
828 * end of file of the last file for a playlist. If the file or playlist
829 * is set to play repeatedly, then the callback will be called multiple
830 * times.
831 *
832 * If application wishes to stop the playback, it can stop the media
833 * transmission in the callback, and only after all transmissions have
834 * been stopped, could the application safely destroy the player.
835 */
836 virtual void onEof2()
837 { }
838
839 private:
840 /**
841 * Player Id.
842 */
843 int playerId;
844
845 /**
846 * Low level PJMEDIA callback
847 */
848 static void eof_cb(pjmedia_port *port,
849 void *usr_data);
850 };
851
852 /**
853 * Audio Media Recorder.
854 */
855 class AudioMediaRecorder : public AudioMedia
856 {
857 public:
858 /**
859 * Constructor.
860 */
861 AudioMediaRecorder();
862
863 /**
864 * Create a file recorder, and automatically connect this recorder to
865 * the conference bridge. The recorder currently supports recording WAV
866 * file. The type of the recorder to use is determined by the extension of
867 * the file (e.g. ".wav").
868 *
869 * @param file_name Output file name. The function will determine the
870 * default format to be used based on the file extension.
871 * Currently ".wav" is supported on all platforms.
872 * @param enc_type Optionally specify the type of encoder to be used to
873 * compress the media, if the file can support different
874 * encodings. This value must be zero for now.
875 * @param max_size Maximum file size. Specify zero or -1 to remove size
876 * limitation. This value must be zero or -1 for now.
877 * @param options Optional options, which can be used to specify the
878 * recording file format. Supported options are
879 * PJMEDIA_FILE_WRITE_PCM, PJMEDIA_FILE_WRITE_ALAW,
880 * and PJMEDIA_FILE_WRITE_ULAW. Default is zero or
881 * PJMEDIA_FILE_WRITE_PCM.
882 */
883 void createRecorder(const string &file_name,
884 unsigned enc_type=0,
885 long max_size=0,
886 unsigned options=0) PJSUA2_THROW(Error);
887
888 /**
889 * Warning: deprecated and will be removed in future release.
890 *
891 * Typecast from base class AudioMedia. This is useful for application
892 * written in language that does not support downcasting such as Python.
893 *
894 * @param media The object to be downcasted
895 *
896 * @return The object as AudioMediaRecorder instance
897 */
898 static AudioMediaRecorder* typecastFromAudioMedia(AudioMedia *media);
899
900 /**
901 * Destructor. This will unregister the recorder port from the conference
902 * bridge.
903 */
904 virtual ~AudioMediaRecorder();
905
906 private:
907 /**
908 * Recorder Id.
909 */
910 int recorderId;
911 };
912
913 /**
914 * Tone descriptor (abstraction for pjmedia_tone_desc)
915 */
916 class ToneDesc : public pjmedia_tone_desc
917 {
918 public:
919 ToneDesc()
920 {
921 pj_bzero(this, sizeof(*this));
922 }
923 ~ToneDesc() {}
924 };
925
926 /**
927 * Array of tone descriptor.
928 */
929 typedef std::vector<ToneDesc> ToneDescVector;
930
931 /**
932 * Tone digit (abstraction for pjmedia_tone_digit)
933 */
934 class ToneDigit : public pjmedia_tone_digit
935 {
936 public:
937 ToneDigit()
938 {
939 pj_bzero(this, sizeof(*this));
940 }
941 ~ToneDigit() {}
942 };
943
944 /**
945 * Array of tone digits.
946 */
947 typedef std::vector<ToneDigit> ToneDigitVector;
948
949 /**
950 * A digit in tone digit map
951 */
952 struct ToneDigitMapDigit
953 {
954 public:
955 string digit; /**< the digit */
956 int freq1; /**< first frequency */
957 int freq2; /**< second frequency */
958 };
959
960 /**
961 * Tone digit map
962 */
963 typedef std::vector<ToneDigitMapDigit> ToneDigitMapVector;
964
965 /**
966 * Tone generator.
967 */
968 class ToneGenerator : public AudioMedia
969 {
970 public:
971 /**
972 * Constructor.
973 */
974 ToneGenerator();
975
976 /**
977 * Destructor. This will unregister the tone generator port from the
978 * conference bridge.
979 */
980 ~ToneGenerator();
981
982 /**
983 * Create tone generator and register the port to the conference bridge.
984 */
985 void createToneGenerator(unsigned clock_rate = 16000,
986 unsigned channel_count = 1) PJSUA2_THROW(Error);
987
988 /**
989 * Check if the tone generator is still busy producing some tones.
990 * @return Non-zero if busy.
991 */
992 bool isBusy() const;
993
994 /**
995 * Instruct the tone generator to stop current processing.
996 */
997 void stop() PJSUA2_THROW(Error);
998
999 /**
1000 * Rewind the playback. This will start the playback to the first
1001 * tone in the playback list.
1002 */
1003 void rewind() PJSUA2_THROW(Error);
1004
1005 /**
1006 * Instruct the tone generator to play single or dual frequency tones
1007 * with the specified duration. The new tones will be appended to
1008 * currently playing tones, unless stop() is called before calling this
1009 * function. The playback will begin as soon as the tone generator is
1010 * connected to other media.
1011 *
1012 * @param tones Array of tones to be played.
1013 * @param loop Play the tone in a loop.
1014 */
1015 void play(const ToneDescVector &tones,
1016 bool loop=false) PJSUA2_THROW(Error);
1017
1018 /**
1019 * Instruct the tone generator to play multiple MF digits with each of
1020 * the digits having individual ON/OFF duration. Each of the digit in the
1021 * digit array must have the corresponding descriptor in the digit map.
1022 * The new tones will be appended to currently playing tones, unless
1023 * stop() is called before calling this function. The playback will begin
1024 * as soon as the tone generator is connected to a sink media.
1025 *
1026 * @param digits Array of MF digits.
1027 * @param loop Play the tone in a loop.
1028 */
1029 void playDigits(const ToneDigitVector &digits,
1030 bool loop=false) PJSUA2_THROW(Error);
1031
1032 /**
1033 * Get the digit-map currently used by this tone generator.
1034 *
1035 * @return The digitmap currently used by the tone generator
1036 */
1037 ToneDigitMapVector getDigitMap() const PJSUA2_THROW(Error);
1038
1039 /**
1040 * Set digit map to be used by the tone generator.
1041 *
1042 * @param digit_map Digitmap to be used by the tone generator.
1043 */
1044 void setDigitMap(const ToneDigitMapVector &digit_map) PJSUA2_THROW(Error);
1045
1046 private:
1047 pj_pool_t *pool;
1048 pjmedia_port *tonegen;
1049 pjmedia_tone_digit_map digitMap;
1050 };
1051
1052
1053 /*************************************************************************
1054 * Sound device management
1055 */
1056
1057 /**
1058 * Audio device information structure.
1059 */
1060 struct AudioDevInfo
1061 {
1062 /**
1063 * The device ID
1064 */
1065 pjmedia_aud_dev_index id;
1066
1067 /**
1068 * The device name
1069 */
1070 string name;
1071
1072 /**
1073 * Maximum number of input channels supported by this device. If the
1074 * value is zero, the device does not support input operation (i.e.
1075 * it is a playback only device).
1076 */
1077 unsigned inputCount;
1078
1079 /**
1080 * Maximum number of output channels supported by this device. If the
1081 * value is zero, the device does not support output operation (i.e.
1082 * it is an input only device).
1083 */
1084 unsigned outputCount;
1085
1086 /**
1087 * Default sampling rate.
1088 */
1089 unsigned defaultSamplesPerSec;
1090
1091 /**
1092 * The underlying driver name
1093 */
1094 string driver;
1095
1096 /**
1097 * Device capabilities, as bitmask combination of pjmedia_aud_dev_cap.
1098 */
1099 unsigned caps;
1100
1101 /**
1102 * Supported audio device routes, as bitmask combination of
1103 * pjmedia_aud_dev_route. The value may be zero if the device
1104 * does not support audio routing.
1105 */
1106 unsigned routes;
1107
1108 /**
1109 * Array of supported extended audio formats
1110 */
1111 MediaFormatAudioVector extFmt;
1112
1113 /**
1114 * Construct from pjmedia_aud_dev_info.
1115 */
1116 void fromPj(const pjmedia_aud_dev_info &dev_info);
1117
1118 /**
1119 * Destructor.
1120 */
1121 ~AudioDevInfo();
1122 };
1123
1124 /**
1125 * Warning: deprecated, use AudioDevInfoVector2 instead.
1126 *
1127 * Array of audio device info.
1128 */
1129 typedef std::vector<AudioDevInfo*> AudioDevInfoVector;
1130
1131 /** Array of audio device info */
1132 typedef std::vector<AudioDevInfo> AudioDevInfoVector2;
1133
1134 /**
1135 * Audio device manager.
1136 */
1137 class AudDevManager
1138 {
1139 public:
1140 /**
1141 * Get currently active capture sound devices. If sound devices has not been
1142 * created, it is possible that the function returns -1 as device IDs.
1143 *
1144 * @return Device ID of the capture device.
1145 */
1146 int getCaptureDev() const PJSUA2_THROW(Error);
1147
1148 /**
1149 * Get the AudioMedia of the capture audio device.
1150 *
1151 * @return Audio media for the capture device.
1152 */
1153 AudioMedia &getCaptureDevMedia() PJSUA2_THROW(Error);
1154
1155 /**
1156 * Get currently active playback sound devices. If sound devices has not
1157 * been created, it is possible that the function returns -1 as device IDs.
1158 *
1159 * @return Device ID of the playback device.
1160 */
1161 int getPlaybackDev() const PJSUA2_THROW(Error);
1162
1163 /**
1164 * Get the AudioMedia of the speaker/playback audio device.
1165 *
1166 * @return Audio media for the speaker/playback device.
1167 */
1168 AudioMedia &getPlaybackDevMedia() PJSUA2_THROW(Error);
1169
1170 /**
1171 * Select or change capture sound device. Application may call this
1172 * function at any time to replace current sound device. Calling this
1173 * method will not change the state of the sound device (opened/closed).
1174 *
1175 * @param capture_dev Device ID of the capture device.
1176 */
1177 void setCaptureDev(int capture_dev) const PJSUA2_THROW(Error);
1178
1179 /**
1180 * Select or change playback sound device. Application may call this
1181 * function at any time to replace current sound device. Calling this
1182 * method will not change the state of the sound device (opened/closed).
1183 *
1184 * @param playback_dev Device ID of the playback device.
1185 */
1186 void setPlaybackDev(int playback_dev) const PJSUA2_THROW(Error);
1187
1188 #if !DEPRECATED_FOR_TICKET_2232
1189 /**
1190 * Warning: deprecated, use enumDev2 instead. This function is not
1191 * safe in multithreaded environment.
1192 *
1193 * Enum all audio devices installed in the system. This function is not
1194 * safe in multithreaded environment.
1195 *
1196 * @return The list of audio device info.
1197 */
1198 const AudioDevInfoVector &enumDev() PJSUA2_THROW(Error);
1199 #endif
1200
1201 /**
1202 * Enum all audio devices installed in the system.
1203 *
1204 * @return The list of audio device info.
1205 */
1206 AudioDevInfoVector2 enumDev2() const PJSUA2_THROW(Error);
1207
1208 /**
1209 * Set pjsua to use null sound device. The null sound device only provides
1210 * the timing needed by the conference bridge, and will not interract with
1211 * any hardware.
1212 *
1213 */
1214 void setNullDev() PJSUA2_THROW(Error);
1215
1216 /**
1217 * Disconnect the main conference bridge from any sound devices, and let
1218 * application connect the bridge to it's own sound device/master port.
1219 *
1220 * @return The port interface of the conference bridge,
1221 * so that application can connect this to it's
1222 * own sound device or master port.
1223 */
1224 MediaPort *setNoDev();
1225
1226 /**
1227 * Set sound device mode.
1228 *
1229 * Note that this method will open the sound device, using current
1230 * active IDs set via setCaptureDev() or setPlaybackDev(), if the flag
1231 * PJSUA_SND_DEV_NO_IMMEDIATE_OPEN is not specified.
1232 *
1233 * @param mode The sound device mode, as bitmask combination
1234 * of #pjsua_snd_dev_mode
1235 *
1236 */
1237 void setSndDevMode(unsigned mode) const PJSUA2_THROW(Error);
1238
1239 /**
1240 * Change the echo cancellation settings.
1241 *
1242 * The behavior of this function depends on whether the sound device is
1243 * currently active, and if it is, whether device or software AEC is
1244 * being used.
1245 *
1246 * If the sound device is currently active, and if the device supports AEC,
1247 * this function will forward the change request to the device and it will
1248 * be up to the device on whether support the request. If software AEC is
1249 * being used (the software EC will be used if the device does not support
1250 * AEC), this function will change the software EC settings. In all cases,
1251 * the setting will be saved for future opening of the sound device.
1252 *
1253 * If the sound device is not currently active, this will only change the
1254 * default AEC settings and the setting will be applied next time the
1255 * sound device is opened.
1256 *
1257 * @param tail_msec The tail length, in miliseconds. Set to zero to
1258 * disable AEC.
1259 * @param options Options to be passed to pjmedia_echo_create().
1260 * Normally the value should be zero.
1261 *
1262 */
1263 void setEcOptions(unsigned tail_msec, unsigned options) PJSUA2_THROW(Error);
1264
1265 /**
1266 * Get current echo canceller tail length.
1267 *
1268 * @return The EC tail length in milliseconds,
1269 * If AEC is disabled, the value will be zero.
1270 */
1271 unsigned getEcTail() const PJSUA2_THROW(Error);
1272
1273 /**
1274 * Check whether the sound device is currently active. The sound device
1275 * may be inactive if the application has set the auto close feature to
1276 * non-zero (the sndAutoCloseTime setting in MediaConfig), or
1277 * if null sound device or no sound device has been configured via the
1278 * setNoDev() function.
1279 */
1280 bool sndIsActive() const;
1281
1282 /**
1283 * Refresh the list of sound devices installed in the system. This method
1284 * will only refresh the list of audio device so all active audio streams
1285 * will be unaffected. After refreshing the device list, application MUST
1286 * make sure to update all index references to audio devices before calling
1287 * any method that accepts audio device index as its parameter.
1288 *
1289 */
1290 void refreshDevs() PJSUA2_THROW(Error);
1291
1292 /**
1293 * Get the number of sound devices installed in the system.
1294 *
1295 * @return The number of sound devices installed in the
1296 * system.
1297 *
1298 */
1299 unsigned getDevCount() const;
1300
1301 /**
1302 * Get device information.
1303 *
1304 * @param id The audio device ID.
1305 *
1306 * @return The device information which will be filled in
1307 * by this method once it returns successfully.
1308 */
1309 AudioDevInfo getDevInfo(int id) const PJSUA2_THROW(Error);
1310
1311 /**
1312 * Lookup device index based on the driver and device name.
1313 *
1314 * @param drv_name The driver name.
1315 * @param dev_name The device name.
1316 *
1317 * @return The device ID. If the device is not found,
1318 * Error will be thrown.
1319 */
1320 int lookupDev(const string &drv_name,
1321 const string &dev_name) const PJSUA2_THROW(Error);
1322
1323 /**
1324 * Get string info for the specified capability.
1325 *
1326 * @param cap The capability ID.
1327 *
1328 * @return Capability name.
1329 */
1330 string capName(pjmedia_aud_dev_cap cap) const;
1331
1332 /**
1333 * This will configure audio format capability (other than PCM) to the
1334 * sound device being used. If sound device is currently active, the method
1335 * will forward the setting to the sound device instance to be applied
1336 * immediately, if it supports it.
1337 *
1338 * This method is only valid if the device has
1339 * PJMEDIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps flags,
1340 * otherwise Error will be thrown.
1341 *
1342 * Note that in case the setting is kept for future use, it will be applied
1343 * to any devices, even when application has changed the sound device to be
1344 * used.
1345 *
1346 * @param format The audio format.
1347 * @param keep Specify whether the setting is to be kept for
1348 * future use.
1349 *
1350 */
1351 void setExtFormat(const MediaFormatAudio &format, bool keep=true)
1352 PJSUA2_THROW(Error);
1353
1354 /**
1355 * Get the audio format capability (other than PCM) of the sound device
1356 * being used. If sound device is currently active, the method will forward
1357 * the request to the sound device. If sound device is currently inactive,
1358 * and if application had previously set the setting and mark the setting
1359 * as kept, then that setting will be returned. Otherwise, this method
1360 * will raise error.
1361 *
1362 * This method is only valid if the device has
1363 * PJMEDIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps flags,
1364 * otherwise Error will be thrown.
1365 *
1366 * @return The audio format.
1367 *
1368 */
1369 MediaFormatAudio getExtFormat() const PJSUA2_THROW(Error);
1370
1371 /**
1372 * This will configure audio input latency control or query capability to
1373 * the sound device being used. If sound device is currently active,
1374 * the method will forward the setting to the sound device instance to be
1375 * applied immediately, if it supports it.
1376 *
1377 * This method is only valid if the device has
1378 * PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps flags,
1379 * otherwise Error will be thrown.
1380 *
1381 * Note that in case the setting is kept for future use, it will be applied
1382 * to any devices, even when application has changed the sound device to be
1383 * used.
1384 *
1385 * @param latency_msec The input latency.
1386 * @param keep Specify whether the setting is to be kept
1387 * for future use.
1388 */
1389 void
1390 setInputLatency(unsigned latency_msec, bool keep=true) PJSUA2_THROW(Error);
1391
1392 /**
1393 * Get the audio input latency control or query capability of the sound
1394 * device being used. If sound device is currently active, the method will
1395 * forward the request to the sound device. If sound device is currently
1396 * inactive, and if application had previously set the setting and mark the
1397 * setting as kept, then that setting will be returned. Otherwise, this
1398 * method will raise error.
1399 *
1400 * This method is only valid if the device has
1401 * PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps flags,
1402 * otherwise Error will be thrown.
1403 *
1404 * @return The audio input latency.
1405 *
1406 */
1407 unsigned getInputLatency() const PJSUA2_THROW(Error);
1408
1409 /**
1410 * This will configure audio output latency control or query capability to
1411 * the sound device being used. If sound device is currently active,
1412 * the method will forward the setting to the sound device instance to be
1413 * applied immediately, if it supports it.
1414 *
1415 * This method is only valid if the device has
1416 * PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps flags,
1417 * otherwise Error will be thrown.
1418 *
1419 * Note that in case the setting is kept for future use, it will be applied
1420 * to any devices, even when application has changed the sound device to be
1421 * used.
1422 *
1423 * @param latency_msec The output latency.
1424 * @param keep Specify whether the setting is to be kept
1425 * for future use.
1426 *
1427 */
1428 void
1429 setOutputLatency(unsigned latency_msec, bool keep=true) PJSUA2_THROW(Error);
1430
1431 /**
1432 * Get the audio output latency control or query capability of the sound
1433 * device being used. If sound device is currently active, the method will
1434 * forward the request to the sound device. If sound device is currently
1435 * inactive, and if application had previously set the setting and mark the
1436 * setting as kept, then that setting will be returned. Otherwise, this
1437 * method will raise error.
1438 *
1439 * This method is only valid if the device has
1440 * PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps flags,
1441 * otherwise Error will be thrown.
1442 *
1443 * @return The audio output latency.
1444 *
1445 */
1446 unsigned getOutputLatency() const PJSUA2_THROW(Error);
1447
1448 /**
1449 * This will configure audio input volume level capability to the
1450 * sound device being used.
1451 * If sound device is currently active, the method will forward the
1452 * setting to the sound device instance to be applied immediately,
1453 * if it supports it.
1454 *
1455 * This method is only valid if the device has
1456 * PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in AudioDevInfo.caps
1457 * flags, otherwise Error will be thrown.
1458 *
1459 * Note that in case the setting is kept for future use, it will be applied
1460 * to any devices, even when application has changed the sound device to be
1461 * used.
1462 *
1463 * @param volume The input volume level, in percent.
1464 * @param keep Specify whether the setting is to be kept for
1465 * future use.
1466 *
1467 */
1468 void setInputVolume(unsigned volume, bool keep=true) PJSUA2_THROW(Error);
1469
1470 /**
1471 * Get the audio input volume level capability of the sound device being
1472 * used. If sound device is currently active, the method will forward the
1473 * request to the sound device. If sound device is currently inactive,
1474 * and if application had previously set the setting and mark the setting
1475 * as kept, then that setting will be returned. Otherwise, this method
1476 * will raise error.
1477 *
1478 * This method is only valid if the device has
1479 * PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in AudioDevInfo.caps
1480 * flags, otherwise Error will be thrown. *
1481
1482 * @return The audio input volume level, in percent.
1483 *
1484 */
1485 unsigned getInputVolume() const PJSUA2_THROW(Error);
1486
1487 /**
1488 * This will configure audio output volume level capability to the sound
1489 * device being used. If sound device is currently active, the method will
1490 * forward the setting to the sound device instance to be applied
1491 * immediately, if it supports it.
1492 *
1493 * This method is only valid if the device has
1494 * PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps
1495 * flags, otherwise Error will be thrown.
1496 *
1497 * Note that in case the setting is kept for future use, it will be applied
1498 * to any devices, even when application has changed the sound device to be
1499 * used.
1500 *
1501 * @param volume The output volume level, in percent.
1502 * @param keep Specify whether the setting is to be kept
1503 * for future use.
1504 *
1505 */
1506 void setOutputVolume(unsigned volume, bool keep=true) PJSUA2_THROW(Error);
1507
1508 /**
1509 * Get the audio output volume level capability of the sound device being
1510 * used. If sound device is currently active, the method will forward the
1511 * request to the sound device. If sound device is currently inactive,
1512 * and if application had previously set the setting and mark the setting
1513 * as kept, then that setting will be returned. Otherwise, this method
1514 * will raise error.
1515 *
1516 * This method is only valid if the device has
1517 * PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps
1518 * flags, otherwise Error will be thrown.
1519 *
1520 * @return The audio output volume level, in percent.
1521 *
1522 */
1523 unsigned getOutputVolume() const PJSUA2_THROW(Error);
1524
1525 /**
1526 * Get the audio input signal level capability of the sound device being
1527 * used. If sound device is currently active, the method will forward the
1528 * request to the sound device. If sound device is currently inactive,
1529 * and if application had previously set the setting and mark the setting
1530 * as kept, then that setting will be returned. Otherwise, this method
1531 * will raise error.
1532 *
1533 * This method is only valid if the device has
1534 * PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER capability in AudioDevInfo.caps
1535 * flags, otherwise Error will be thrown.
1536 *
1537 * @return The audio input signal level, in percent.
1538 *
1539 */
1540 unsigned getInputSignal() const PJSUA2_THROW(Error);
1541
1542 /**
1543 * Get the audio output signal level capability of the sound device being
1544 * used. If sound device is currently active, the method will forward the
1545 * request to the sound device. If sound device is currently inactive,
1546 * and if application had previously set the setting and mark the setting
1547 * as kept, then that setting will be returned. Otherwise, this method
1548 * will raise error.
1549 *
1550 * This method is only valid if the device has
1551 * PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER capability in AudioDevInfo.caps
1552 * flags, otherwise Error will be thrown.
1553 *
1554 * @return The audio output signal level, in percent.
1555 *
1556 */
1557 unsigned getOutputSignal() const PJSUA2_THROW(Error);
1558
1559 /**
1560 * This will configure audio input route capability to the sound device
1561 * being used. If sound device is currently active, the method will
1562 * forward the setting to the sound device instance to be applied
1563 * immediately, if it supports it.
1564 *
1565 * This method is only valid if the device has
1566 * PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE capability in AudioDevInfo.caps
1567 * flags, otherwise Error will be thrown.
1568 *
1569 * Note that in case the setting is kept for future use, it will be applied
1570 * to any devices, even when application has changed the sound device to be
1571 * used.
1572 *
1573 * @param route The audio input route.
1574 * @param keep Specify whether the setting is to be kept
1575 * for future use.
1576 *
1577 */
1578 void setInputRoute(pjmedia_aud_dev_route route, bool keep=true)
1579 PJSUA2_THROW(Error);
1580
1581 /**
1582 * Get the audio input route capability of the sound device being used.
1583 * If sound device is currently active, the method will forward the
1584 * request to the sound device. If sound device is currently inactive,
1585 * and if application had previously set the setting and mark the setting
1586 * as kept, then that setting will be returned. Otherwise, this method
1587 * will raise error.
1588 *
1589 * This method is only valid if the device has
1590 * PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE capability in AudioDevInfo.caps
1591 * flags, otherwise Error will be thrown.
1592 *
1593 * @return The audio input route.
1594 *
1595 */
1596 pjmedia_aud_dev_route getInputRoute() const PJSUA2_THROW(Error);
1597
1598 /**
1599 * This will configure audio output route capability to the sound device
1600 * being used. If sound device is currently active, the method will
1601 * forward the setting to the sound device instance to be applied
1602 * immediately, if it supports it.
1603 *
1604 * This method is only valid if the device has
1605 * PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
1606 * flags, otherwise Error will be thrown.
1607 *
1608 * Note that in case the setting is kept for future use, it will be applied
1609 * to any devices, even when application has changed the sound device to be
1610 * used.
1611 *
1612 * @param route The audio output route.
1613 * @param keep Specify whether the setting is to be kept
1614 * for future use.
1615 *
1616 */
1617 void setOutputRoute(pjmedia_aud_dev_route route, bool keep=true)
1618 PJSUA2_THROW(Error);
1619
1620 /**
1621 * Get the audio output route capability of the sound device being used.
1622 * If sound device is currently active, the method will forward the
1623 * request to the sound device. If sound device is currently inactive,
1624 * and if application had previously set the setting and mark the setting
1625 * as kept, then that setting will be returned. Otherwise, this method
1626 * will raise error.
1627 *
1628 * This method is only valid if the device has
1629 * PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
1630 * flags, otherwise Error will be thrown.
1631 *
1632 * @return The audio output route.
1633 *
1634 */
1635 pjmedia_aud_dev_route getOutputRoute() const PJSUA2_THROW(Error);
1636
1637 /**
1638 * This will configure audio voice activity detection capability to
1639 * the sound device being used. If sound device is currently active,
1640 * the method will forward the setting to the sound device instance
1641 * to be applied immediately, if it supports it.
1642 *
1643 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD
1644 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1645 *
1646 * Note that in case the setting is kept for future use, it will be applied
1647 * to any devices, even when application has changed the sound device to be
1648 * used.
1649 *
1650 * @param enable Enable/disable voice activity detection
1651 * feature. Set true to enable.
1652 * @param keep Specify whether the setting is to be kept for
1653 * future use.
1654 *
1655 */
1656 void setVad(bool enable, bool keep=true) PJSUA2_THROW(Error);
1657
1658 /**
1659 * Get the audio voice activity detection capability of the sound device
1660 * being used. If sound device is currently active, the method will
1661 * forward the request to the sound device. If sound device is currently
1662 * inactive, and if application had previously set the setting and mark
1663 * the setting as kept, then that setting will be returned. Otherwise,
1664 * this method will raise error.
1665 *
1666 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD
1667 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1668 *
1669 * @return The audio voice activity detection feature.
1670 *
1671 */
1672 bool getVad() const PJSUA2_THROW(Error);
1673
1674 /**
1675 * This will configure audio comfort noise generation capability to
1676 * the sound device being used. If sound device is currently active,
1677 * the method will forward the setting to the sound device instance
1678 * to be applied immediately, if it supports it.
1679 *
1680 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG
1681 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1682 *
1683 * Note that in case the setting is kept for future use, it will be applied
1684 * to any devices, even when application has changed the sound device to be
1685 * used.
1686 *
1687 * @param enable Enable/disable comfort noise generation
1688 * feature. Set true to enable.
1689 * @param keep Specify whether the setting is to be kept for
1690 * future use.
1691 *
1692 */
1693 void setCng(bool enable, bool keep=true) PJSUA2_THROW(Error);
1694
1695 /**
1696 * Get the audio comfort noise generation capability of the sound device
1697 * being used. If sound device is currently active, the method will
1698 * forward the request to the sound device. If sound device is currently
1699 * inactive, and if application had previously set the setting and mark
1700 * the setting as kept, then that setting will be returned. Otherwise,
1701 * this method will raise error.
1702 *
1703 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG
1704 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1705 *
1706 * @return The audio comfort noise generation feature.
1707 *
1708 */
1709 bool getCng() const PJSUA2_THROW(Error);
1710
1711 /**
1712 * This will configure audio packet loss concealment capability to
1713 * the sound device being used. If sound device is currently active,
1714 * the method will forward the setting to the sound device instance
1715 * to be applied immediately, if it supports it.
1716 *
1717 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC
1718 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1719 *
1720 * Note that in case the setting is kept for future use, it will be applied
1721 * to any devices, even when application has changed the sound device to be
1722 * used.
1723 *
1724 * @param enable Enable/disable packet loss concealment
1725 * feature. Set true to enable.
1726 * @param keep Specify whether the setting is to be kept for
1727 * future use.
1728 *
1729 */
1730 void setPlc(bool enable, bool keep=true) PJSUA2_THROW(Error);
1731
1732 /**
1733 * Get the audio packet loss concealment capability of the sound device
1734 * being used. If sound device is currently active, the method will
1735 * forward the request to the sound device. If sound device is currently
1736 * inactive, and if application had previously set the setting and mark
1737 * the setting as kept, then that setting will be returned. Otherwise,
1738 * this method will raise error.
1739 *
1740 * This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC
1741 * capability in AudioDevInfo.caps flags, otherwise Error will be thrown.
1742 *
1743 * @return The audio packet loss concealment feature.
1744 *
1745 */
1746 bool getPlc() const PJSUA2_THROW(Error);
1747
1748 private:
1749 #if !DEPRECATED_FOR_TICKET_2232
1750 AudioDevInfoVector audioDevList;
1751 #endif
1752 AudioMedia *devMedia;
1753
1754 /**
1755 * Constructor.
1756 */
1757 AudDevManager();
1758
1759 /**
1760 * Destructor.
1761 */
1762 ~AudDevManager();
1763
1764 void clearAudioDevList();
1765 int getActiveDev(bool is_capture) const PJSUA2_THROW(Error);
1766
1767 friend class Endpoint;
1768 };
1769
1770
1771 /**
1772 * Extra audio device. This class allows application to have multiple
1773 * sound device instances active concurrently.
1774
1775 * Application may also use this class to improve media clock. Normally
1776 * media clock is driven by sound device in master port, but unfortunately
1777 * some sound devices may produce jittery clock. To improve media clock,
1778 * application can install Null Sound Device (i.e: using
1779 * AudDevManager::setNullDev()), which will act as a master port, and
1780 * install the sound device as extra sound device.
1781 *
1782 * Note that extra sound device will not have auto-close upon idle feature.
1783 * Also note that the extra sound device only supports mono channel.
1784 */
1785 class ExtraAudioDevice : public AudioMedia
1786 {
1787 public:
1788 /**
1789 * Constructor.
1790 *
1791 * @param playdev Playback device ID.
1792 * @param recdev Record device ID.
1793 */
1794 ExtraAudioDevice(int playdev, int recdev);
1795
1796 /**
1797 * Destructor.
1798 */
1799 virtual ~ExtraAudioDevice();
1800
1801 /**
1802 * Open the audio device using format (e.g.: clock rate, bit per sample,
1803 * samples per frame) matched to the conference bridge's format, except
1804 * the channel count, which will be set to one (mono channel). This will
1805 * also register the audio device port to conference bridge.
1806 */
1807 void open();
1808
1809 /**
1810 * Close the audio device and unregister the audio device port from the
1811 * conference bridge.
1812 */
1813 void close() PJSUA2_THROW(Error);
1814
1815 /**
1816 * Is the extra audio device opened?
1817 *
1818 * @return 'true' if it is opened.
1819 */
1820 bool isOpened();
1821
1822 protected:
1823 int playDev;
1824 int recDev;
1825 void *ext_snd_dev;
1826 };
1827
1828
1829 /*************************************************************************
1830 * Video media
1831 */
1832
1833 /**
1834 * Representation of media coordinate.
1835 */
1836 struct MediaCoordinate
1837 {
1838 int x; /**< X position of the coordinate */
1839 int y; /**< Y position of the coordinate */
1840 };
1841
1842 /**
1843 * Representation of media size.
1844 */
1845 struct MediaSize
1846 {
1847 unsigned w; /**< The width. */
1848 unsigned h; /**< The height. */
1849 };
1850
1851
1852 /**
1853 * This structure descibes information about a particular media port that
1854 * has been registered into the conference bridge.
1855 */
1856 struct VidConfPortInfo
1857 {
1858 /**
1859 * Conference port number.
1860 */
1861 int portId;
1862
1863 /**
1864 * Port name.
1865 */
1866 string name;
1867
1868 /**
1869 * Media audio format information
1870 */
1871 MediaFormatVideo format;
1872
1873 /**
1874 * Array of listeners (in other words, ports where this port is
1875 * transmitting to).
1876 */
1877 IntVector listeners;
1878
1879 /**
1880 * Array of listeners (in other words, ports where this port is
1881 * listening to).
1882 */
1883 IntVector transmitters;
1884
1885 public:
1886 /**
1887 * Construct from pjsua_conf_port_info.
1888 */
1889 void fromPj(const pjsua_vid_conf_port_info &port_info);
1890 };
1891
1892 /**
1893 * Parameters for VideoMedia::startTransmit() method.
1894 */
1895 struct VideoMediaTransmitParam
1896 {
1897 };
1898
1899 /**
1900 * Video Media.
1901 */
1902 class VideoMedia : public Media
1903 {
1904 public:
1905 /**
1906 * Get information about the specified conference port.
1907 */
1908 VidConfPortInfo getPortInfo() const PJSUA2_THROW(Error);
1909
1910 /**
1911 * Get port Id.
1912 */
1913 int getPortId() const;
1914
1915 /**
1916 * Get information from specific port id.
1917 */
1918 static VidConfPortInfo getPortInfoFromId(int port_id) PJSUA2_THROW(Error);
1919
1920 /**
1921 * Establish unidirectional media flow to sink. This media port
1922 * will act as a source, and it may transmit to multiple destinations/sink.
1923 * And if multiple sources are transmitting to the same sink, the media
1924 * will be mixed together. Source and sink may refer to the same Media,
1925 * effectively looping the media.
1926 *
1927 * If bidirectional media flow is desired, application needs to call
1928 * this method twice, with the second one called from the opposite source
1929 * media.
1930 *
1931 * This operation executes asynchronously, use the callback set from
1932 * Endpoint::onVideoMediaOpCompleted() to receive notification upon
1933 * completion.
1934 *
1935 * @param sink The destination Media.
1936 * @param param The parameter.
1937 */
1938 void startTransmit(const VideoMedia &sink,
1939 const VideoMediaTransmitParam &param) const
1940 PJSUA2_THROW(Error);
1941
1942 /**
1943 * Stop media flow to destination/sink port.
1944 *
1945 * This operation executes asynchronously, use the callback set from
1946 * Endpoint::onVideoMediaOpCompleted() to receive notification upon
1947 * completion.
1948 *
1949 * @param sink The destination media.
1950 *
1951 */
1952 void stopTransmit(const VideoMedia &sink) const PJSUA2_THROW(Error);
1953
1954 /**
1955 * Update or refresh port states from video port info. Some port may
1956 * change its port info in the middle of a session, for example when
1957 * a video stream decoder learns that incoming video size or frame rate
1958 * has changed, video conference needs to be informed to update its
1959 * internal states.
1960 *
1961 * This operation executes asynchronously, use the callback set from
1962 * Endpoint::onVideoMediaOpCompleted() to receive notification upon
1963 * completion.
1964 *
1965 */
1966 void update() const PJSUA2_THROW(Error);
1967
1968 /**
1969 * Default Constructor.
1970 *
1971 * Normally application will not create VideoMedia object directly,
1972 * but it instantiates a VideoMedia derived class. This is set as public
1973 * because some STL vector implementations require it.
1974 */
1975 VideoMedia();
1976
1977 /**
1978 * Virtual Destructor
1979 */
1980 virtual ~VideoMedia();
1981
1982 protected:
1983 /**
1984 * Conference port Id.
1985 */
1986 int id;
1987
1988 protected:
1989 /**
1990 * This method needs to be called by descendants of this class to register
1991 * the media port created to the conference bridge and Endpoint's
1992 * media list.
1993 *
1994 * This operation executes asynchronously, use the callback set from
1995 * Endpoint::onVideoMediaOpCompleted() to receive notification upon
1996 * completion.
1997 *
1998 * param port The media port to be registered to the conference bridge.
1999 * param pool The memory pool.
2000 */
2001 void registerMediaPort(MediaPort port, pj_pool_t *pool) PJSUA2_THROW(Error);
2002
2003 /**
2004 * This method needs to be called by descendants of this class to remove
2005 * the media port from the conference bridge and Endpoint's media list.
2006 * Descendant should only call this method if it has registered the media
2007 * with the previous call to registerMediaPort().
2008 *
2009 * This operation executes asynchronously, use the callback set from
2010 * Endpoint::onVideoMediaOpCompleted() to receive notification upon
2011 * completion.
2012 *
2013 */
2014 void unregisterMediaPort();
2015 };
2016
2017 /** Array of Video Media */
2018 typedef std::vector<VideoMedia> VideoMediaVector;
2019
2020
2021 /**
2022 * Window handle.
2023 */
2024 typedef struct WindowHandle {
2025 void *window; /**< Window */
2026 void *display; /**< Display */
2027 } WindowHandle;
2028
2029 /**
2030 * Video window handle.
2031 */
2032 struct VideoWindowHandle
2033 {
2034 /**
2035 * The window handle type.
2036 */
2037 pjmedia_vid_dev_hwnd_type type;
2038
2039 /**
2040 * The window handle.
2041 */
2042 WindowHandle handle;
2043 };
2044
2045 /**
2046 * This structure describes video window info.
2047 */
2048 typedef struct VideoWindowInfo
2049 {
2050 /**
2051 * Flag to indicate whether this window is a native window,
2052 * such as created by built-in preview device. If this field is
2053 * true, only the video window handle field of this
2054 * structure is valid.
2055 */
2056 bool isNative;
2057
2058 /**
2059 * Video window handle.
2060 */
2061 VideoWindowHandle winHandle;
2062
2063 /**
2064 * Renderer device ID.
2065 */
2066 int renderDeviceId;
2067
2068 /**
2069 * Window show status. The window is hidden if false.
2070 */
2071 bool show;
2072
2073 /**
2074 * Window position.
2075 */
2076 MediaCoordinate pos;
2077
2078 /**
2079 * Window size.
2080 */
2081 MediaSize size;
2082
2083 } VideoWindowInfo;
2084
2085 /**
2086 * Video window.
2087 */
2088 class VideoWindow
2089 {
2090 public:
2091 /**
2092 * Constructor
2093 */
2094 VideoWindow(int win_id);
2095
2096 /**
2097 * Get window info.
2098 *
2099 * @return video window info.
2100 */
2101 VideoWindowInfo getInfo() const PJSUA2_THROW(Error);
2102
2103 /**
2104 * Get video media or conference bridge port of the renderer of
2105 * this video window.
2106 *
2107 * @return Video media of this renderer window.
2108 */
2109 VideoMedia getVideoMedia() PJSUA2_THROW(Error);
2110
2111 /**
2112 * Show or hide window. This operation is not valid for native windows
2113 * (VideoWindowInfo.isNative=true), on which native windowing API
2114 * must be used instead.
2115 *
2116 * @param show Set to true to show the window, false to
2117 * hide the window.
2118 *
2119 */
2120 void Show(bool show) PJSUA2_THROW(Error);
2121
2122 /**
2123 * Set video window position. This operation is not valid for native windows
2124 * (VideoWindowInfo.isNative=true), on which native windowing API
2125 * must be used instead.
2126 *
2127 * @param pos The window position.
2128 *
2129 */
2130 void setPos(const MediaCoordinate &pos) PJSUA2_THROW(Error);
2131
2132 /**
2133 * Resize window. This operation is not valid for native windows
2134 * (VideoWindowInfo.isNative=true), on which native windowing API
2135 * must be used instead.
2136 *
2137 * @param size The new window size.
2138 *
2139 */
2140 void setSize(const MediaSize &size) PJSUA2_THROW(Error);
2141
2142 /**
2143 * Rotate the video window. This function will change the video orientation
2144 * and also possibly the video window size (width and height get swapped).
2145 * This operation is not valid for native windows (VideoWindowInfo.isNative
2146 * =true), on which native windowing API must be used instead.
2147 *
2148 * @param angle The rotation angle in degrees, must be
2149 * multiple of 90.
2150 * Specify positive value for clockwise rotation or
2151 * negative value for counter-clockwise rotation.
2152 */
2153 void rotate(int angle) PJSUA2_THROW(Error);
2154
2155 /**
2156 * Set output window. This operation is valid only when the underlying
2157 * video device supports PJMEDIA_VIDEO_DEV_CAP_OUTPUT_WINDOW capability AND
2158 * allows the output window to be changed on-the-fly, otherwise Error will
2159 * be thrown. Currently it is only supported on Android.
2160 *
2161 * @param win The new output window.
2162 */
2163 void setWindow(const VideoWindowHandle &win) PJSUA2_THROW(Error);
2164
2165 /**
2166 * Set video window full-screen. This operation is valid only when the
2167 * underlying video device supports PJMEDIA_VID_DEV_CAP_OUTPUT_FULLSCREEN
2168 * capability. Currently it is only supported on SDL backend.
2169 *
2170 * @param enabled Set to true if full screen is desired, false
2171 * otherwise.
2172 */
2173 void setFullScreen(bool enabled) PJSUA2_THROW(Error);
2174
2175 /**
2176 * Set video window full-screen. This operation is valid only when the
2177 * underlying video device supports PJMEDIA_VID_DEV_CAP_OUTPUT_FULLSCREEN
2178 * capability. Currently it is only supported on SDL backend.
2179 *
2180 * @param mode Fullscreen mode, see
2181 * pjmedia_vid_dev_fullscreen_flag.
2182 */
2183 void setFullScreen2(pjmedia_vid_dev_fullscreen_flag mode)
2184 PJSUA2_THROW(Error);
2185
2186 private:
2187 pjsua_vid_win_id winId;
2188 };
2189
2190 /**
2191 * This structure contains parameters for VideoPreview::start()
2192 */
2193 struct VideoPreviewOpParam {
2194 /**
2195 * Device ID for the video renderer to be used for rendering the
2196 * capture stream for preview. This parameter is ignored if native
2197 * preview is being used.
2198 *
2199 * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
2200 */
2201 pjmedia_vid_dev_index rendId;
2202
2203 /**
2204 * Show window initially.
2205 *
2206 * Default: PJ_TRUE.
2207 */
2208 bool show;
2209
2210 /**
2211 * Window flags. The value is a bitmask combination of
2212 * \a pjmedia_vid_dev_wnd_flag.
2213 *
2214 * Default: 0.
2215 */
2216 unsigned windowFlags;
2217
2218 /**
2219 * Media format video. By default, this parameter is uninitialized
2220 * and will not be used.
2221 *
2222 * To initialize it, use MediaFormatVideo::init().
2223 * If left uninitialized, the capture device will be opened using
2224 * PJMEDIA wrapper default format, e.g:
2225 * - Android : PJMEDIA_FORMAT_I420 using the first supported size and 15fps
2226 * - iOS : PJMEDIA_FORMAT_BGRA using size 352x288 and 15fps
2227 * Note that when the preview is already opened, this setting will be
2228 * ignored.
2229 */
2230 MediaFormatVideo format;
2231
2232 /**
2233 * Optional output window to be used to display the video preview.
2234 * This parameter will only be used if the video device supports
2235 * PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW capability and the capability
2236 * is not read-only.
2237 */
2238 VideoWindowHandle window;
2239
2240 public:
2241 /**
2242 * Default constructor initializes with default values.
2243 */
2244 VideoPreviewOpParam();
2245
2246 /**
2247 * Convert from pjsip
2248 */
2249 void fromPj(const pjsua_vid_preview_param &prm);
2250
2251 /**
2252 * Convert to pjsip
2253 */
2254 pjsua_vid_preview_param toPj() const;
2255 };
2256
2257 /**
2258 * Video Preview
2259 */
2260 class VideoPreview {
2261 public:
2262 /**
2263 * Constructor
2264 */
2265 VideoPreview(int dev_id);
2266
2267 /**
2268 * Determine if the specified video input device has built-in native
2269 * preview capability. This is a convenience function that is equal to
2270 * querying device's capability for PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW
2271 * capability.
2272 *
2273 * @return true if it has.
2274 */
2275 bool hasNative();
2276
2277 /**
2278 * Start video preview window for the specified capture device.
2279 *
2280 * @param param Video preview parameters.
2281 */
2282 void start(const VideoPreviewOpParam &param) PJSUA2_THROW(Error);
2283
2284 /**
2285 * Stop video preview.
2286 */
2287 void stop() PJSUA2_THROW(Error);
2288
2289 /**
2290 * Get the preview window handle associated with the capture device,if any.
2291 */
2292 VideoWindow getVideoWindow();
2293
2294 /**
2295 * Get video media or conference bridge port of the video capture device.
2296 *
2297 * @return Video media of the video capture device.
2298 */
2299 VideoMedia getVideoMedia() PJSUA2_THROW(Error);
2300
2301 private:
2302 pjmedia_vid_dev_index devId;
2303 pjsua_vid_win_id winId;
2304 void updateDevId();
2305 };
2306
2307 /**
2308 * Video device information structure.
2309 */
2310 struct VideoDevInfo
2311 {
2312 /**
2313 * The device ID
2314 */
2315 pjmedia_vid_dev_index id;
2316
2317 /**
2318 * The device name
2319 */
2320 string name;
2321
2322 /**
2323 * The underlying driver name
2324 */
2325 string driver;
2326
2327 /**
2328 * The supported direction of the video device, i.e. whether it supports
2329 * capture only, render only, or both.
2330 */
2331 pjmedia_dir dir;
2332
2333 /**
2334 * Device capabilities, as bitmask combination of #pjmedia_vid_dev_cap
2335 */
2336 unsigned caps;
2337
2338 /**
2339 * Array of supported video formats. Some fields in each supported video
2340 * format may be set to zero or of "unknown" value, to indicate that the
2341 * value is unknown or should be ignored. When these value are not set
2342 * to zero, it indicates that the exact format combination is being used.
2343 */
2344 MediaFormatVideoVector fmt;
2345
2346 public:
2347 /**
2348 * Default constructor
2349 */
2350 VideoDevInfo() : id(-1), dir(PJMEDIA_DIR_NONE), caps(0)
2351 {}
2352
2353 /**
2354 * Construct from pjmedia_vid_dev_info.
2355 */
2356 void fromPj(const pjmedia_vid_dev_info &dev_info);
2357
2358 /**
2359 * Destructor.
2360 */
2361 ~VideoDevInfo();
2362 };
2363
2364 /**
2365 * Warning: deprecated, use VideoDevInfoVector2 instead.
2366 *
2367 * Array of video device info.
2368 */
2369 typedef std::vector<VideoDevInfo*> VideoDevInfoVector;
2370
2371 /** Array of video device info */
2372 typedef std::vector<VideoDevInfo> VideoDevInfoVector2;
2373
2374 /**
2375 * Parameter for switching device with PJMEDIA_VID_DEV_CAP_SWITCH capability.
2376 */
2377 struct VideoSwitchParam
2378 {
2379 /**
2380 * Target device ID to switch to. Once the switching is successful, the
2381 * video stream will use this device and the old device will be closed.
2382 */
2383 pjmedia_vid_dev_index target_id;
2384 };
2385
2386 /**
2387 * Video device manager.
2388 */
2389 class VidDevManager {
2390 public:
2391
2392 /**
2393 * Initialize the video device subsystem. This will register all supported
2394 * video device factories to the video device subsystem.
2395 *
2396 * By default, library will initialize video device subsystem automatically
2397 * on library initialization, so application will never need to invoke this
2398 * function. However, when PJSUA_DONT_INIT_VID_DEV_SUBSYS is set to
2399 * non-zero, application should invoke this function before accessing
2400 * video device.
2401 */
2402 void initSubsys() PJSUA2_THROW(Error);
2403
2404 /**
2405 * Refresh the list of video devices installed in the system. This function
2406 * will only refresh the list of video device so all active video streams
2407 * will be unaffected. After refreshing the device list, application MUST
2408 * make sure to update all index references to video devices (i.e. all
2409 * variables of type pjmedia_vid_dev_index) before calling any function
2410 * that accepts video device index as its parameter.
2411 */
2412 void refreshDevs() PJSUA2_THROW(Error);
2413
2414 /**
2415 * Get the number of video devices installed in the system.
2416 *
2417 * @return The number of devices.
2418 */
2419 unsigned getDevCount();
2420
2421 /**
2422 * Retrieve the video device info for the specified device index.
2423 *
2424 * @param dev_id The video device id
2425 *
2426 * @return The list of video device info
2427 */
2428 VideoDevInfo getDevInfo(int dev_id) const PJSUA2_THROW(Error);
2429
2430 #if !DEPRECATED_FOR_TICKET_2232
2431 /**
2432 * Warning: deprecated, use enumDev2() instead. This function is not
2433 * safe in multithreaded environment.
2434 *
2435 * Enum all video devices installed in the system.
2436 *
2437 * @return The list of video device info
2438 */
2439 const VideoDevInfoVector &enumDev() PJSUA2_THROW(Error);
2440 #endif
2441
2442 /**
2443 * Enum all video devices installed in the system.
2444 *
2445 * @return The list of video device info
2446 */
2447 VideoDevInfoVector2 enumDev2() const PJSUA2_THROW(Error);
2448
2449 /**
2450 * Lookup device index based on the driver and device name.
2451 *
2452 * @param drv_name The driver name.
2453 * @param dev_name The device name.
2454 *
2455 * @return The device ID. If the device is not found,
2456 * Error will be thrown.
2457 */
2458 int lookupDev(const string &drv_name,
2459 const string &dev_name) const PJSUA2_THROW(Error);
2460
2461 /**
2462 * Get string info for the specified capability.
2463 *
2464 * @param cap The capability ID.
2465 *
2466 * @return Capability name.
2467 */
2468 string capName(pjmedia_vid_dev_cap cap) const;
2469
2470 /**
2471 * This will configure video format capability to the video device.
2472 * If video device is currently active, the method will forward the setting
2473 * to the video device instance to be applied immediately, if it
2474 * supports it.
2475 *
2476 * This method is only valid if the device has
2477 * PJMEDIA_VID_DEV_CAP_FORMAT capability in VideoDevInfo.caps flags,
2478 * otherwise Error will be thrown.
2479 *
2480 * Note that in case the setting is kept for future use, it will be applied
2481 * to any devices, even when application has changed the video device to be
2482 * used.
2483 *
2484 * @param dev_id The video device id.
2485 * @param format The video format.
2486 * @param keep Specify whether the setting is to be kept for
2487 * future use.
2488 */
2489 void setFormat(int dev_id,
2490 const MediaFormatVideo &format,
2491 bool keep) PJSUA2_THROW(Error);
2492
2493 /**
2494 * Get the video format capability to the video device.
2495 * If video device is currently active, the method will forward the request
2496 * to the video device. If video device is currently inactive, and if
2497 * application had previously set the setting and mark the setting as kept,
2498 * then that setting will be returned. Otherwise, this method will
2499 * raise error.
2500 *
2501 * This method is only valid if the device has
2502 * PJMEDIA_VID_DEV_CAP_FORMAT capability in VideoDevInfo.caps flags,
2503 * otherwise Error will be thrown.
2504 *
2505 * @param dev_id The video device id.
2506 * @return keep The video format.
2507 */
2508 MediaFormatVideo getFormat(int dev_id) const PJSUA2_THROW(Error);
2509
2510 /**
2511 * This will configure video format capability to the video device.
2512 * If video device is currently active, the method will forward the setting
2513 * to the video device instance to be applied immediately, if it
2514 * supports it.
2515 *
2516 * This method is only valid if the device has
2517 * PJMEDIA_VID_DEV_CAP_INPUT_SCALE capability in VideoDevInfo.caps flags,
2518 * otherwise Error will be thrown.
2519 *
2520 * Note that in case the setting is kept for future use, it will be applied
2521 * to any devices, even when application has changed the video device to be
2522 * used.
2523 *
2524 * @param dev_id The video device id.
2525 * @param scale The video scale.
2526 * @param keep Specify whether the setting is to be kept for
2527 * future use.
2528 */
2529 void setInputScale(int dev_id,
2530 const MediaSize &scale,
2531 bool keep) PJSUA2_THROW(Error);
2532
2533 /**
2534 * Get the video input scale capability to the video device.
2535 * If video device is currently active, the method will forward the request
2536 * to the video device. If video device is currently inactive, and if
2537 * application had previously set the setting and mark the setting as kept,
2538 * then that setting will be returned. Otherwise, this method will
2539 * raise error.
2540 *
2541 * This method is only valid if the device has
2542 * PJMEDIA_VID_DEV_CAP_FORMAT capability in VideoDevInfo.caps flags,
2543 * otherwise Error will be thrown.
2544 *
2545 * @param dev_id The video device id.
2546 * @return keep The video format.
2547 */
2548 MediaSize getInputScale(int dev_id) const PJSUA2_THROW(Error);
2549
2550 /**
2551 * This will configure fast switching to another video device.
2552 * If video device is currently active, the method will forward the setting
2553 * to the video device instance to be applied immediately, if it
2554 * supports it.
2555 *
2556 * This method is only valid if the device has
2557 * PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW_FLAGS capability in VideoDevInfo.caps
2558 * flags, otherwise Error will be thrown.
2559 *
2560 * Note that in case the setting is kept for future use, it will be applied
2561 * to any devices, even when application has changed the video device to be
2562 * used.
2563 *
2564 * @param dev_id The video device id.
2565 * @param flags The video window flag.
2566 * @param keep Specify whether the setting is to be kept for
2567 * future use.
2568 */
2569 void setOutputWindowFlags(int dev_id, int flags, bool keep)
2570 PJSUA2_THROW(Error);
2571
2572 /**
2573 * Get the window output flags capability to the video device.
2574 * If video device is currently active, the method will forward the request
2575 * to the video device. If video device is currently inactive, and if
2576 * application had previously set the setting and mark the setting as kept,
2577 * then that setting will be returned. Otherwise, this method will
2578 * raise error.
2579 *
2580 * This method is only valid if the device has
2581 * PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW_FLAGS capability in VideoDevInfo.caps
2582 * flags, otherwise Error will be thrown.
2583 *
2584 * @param dev_id The video device id.
2585 * @return keep The video format.
2586 */
2587 int getOutputWindowFlags(int dev_id) PJSUA2_THROW(Error);
2588
2589 /**
2590 * This will configure fast switching to another video device.
2591 * If video device is currently active, the method will forward the setting
2592 * to the video device instance to be applied immediately, if it
2593 * supports it.
2594 *
2595 * This method is only valid if the device has
2596 * PJMEDIA_VID_DEV_CAP_SWITCH capability in VideoDevInfo.caps flags,
2597 * otherwise Error will be thrown.
2598 *
2599 * @param dev_id The video device id.
2600 * @param param The video switch param.
2601 */
2602 void switchDev(int dev_id,
2603 const VideoSwitchParam &param) PJSUA2_THROW(Error);
2604
2605 /**
2606 * Check whether the video capture device is currently active, i.e. if
2607 * a video preview has been started or there is a video call using
2608 * the device.
2609 *
2610 * @param dev_id The video device id
2611 *
2612 * @return True if it's active.
2613 */
2614 bool isCaptureActive(int dev_id) const;
2615
2616 /**
2617 * This will configure video orientation of the video capture device.
2618 * If the device is currently active (i.e. if there is a video call
2619 * using the device or a video preview has been started), the method
2620 * will forward the setting to the video device instance to be applied
2621 * immediately, if it supports it.
2622 *
2623 * The setting will be saved for future opening of the video device,
2624 * if the "keep" argument is set to true. If the video device is
2625 * currently inactive, and the "keep" argument is false, this method
2626 * will throw Error.
2627 *
2628 * @param dev_id The video device id
2629 * @param orient The video orientation.
2630 * @param keep Specify whether the setting is to be kept for
2631 * future use.
2632 *
2633 */
2634 void setCaptureOrient(pjmedia_vid_dev_index dev_id,
2635 pjmedia_orient orient,
2636 bool keep=true) PJSUA2_THROW(Error);
2637
2638 private:
2639 #if !DEPRECATED_FOR_TICKET_2232
2640 VideoDevInfoVector videoDevList;
2641 #endif
2642
2643 void clearVideoDevList();
2644
2645 /**
2646 * Constructor.
2647 */
2648 VidDevManager();
2649
2650 /**
2651 * Destructor.
2652 */
2653 ~VidDevManager();
2654
2655 friend class Endpoint;
2656 };
2657
2658 /**
2659 * Video AVI Player.
2660 */
2661 class VideoPlayer
2662 {
2663 public:
2664 /**
2665 * Constructor.
2666 */
2667 VideoPlayer();
2668
2669 /**
2670 * Create an avi file player, and automatically add this player to
2671 * the audio/video conference bridge. The player will create a virtual
2672 * video device and audio/video media port based on the streams contained
2673 * in the file.
2674 * The maximum number of stream is limited to PJSUA_MAX_AVI_NUM_STREAMS
2675 * and the video stream is limited to one stream.
2676 *
2677 * @param filename The filename to be played. Currently only
2678 * AVI files are supported. The video stream is using
2679 * YUY2/I420/RGB24 format and the audio stream is using
2680 * 16bit PCM format.
2681 * Filename's length must be smaller than PJ_MAXPATH.
2682 *
2683 */
2684 void createVideoPlayer(const string &file_name) PJSUA2_THROW(Error);
2685
2686 /**
2687 * Enumerate all audio media port.
2688 *
2689 * @return The list of audio media port.
2690 */
2691 AudioMediaVector2 mediaEnumPorts() PJSUA2_THROW(Error);
2692
2693 /**
2694 * Enumerate all video media port.
2695 *
2696 * @return The list of video media port.
2697 */
2698 VideoMediaVector mediaEnumVidPorts() PJSUA2_THROW(Error);
2699
2700 /**
2701 * Get the video device index of the avi player. Application can use this
2702 * index as the video source/capture device.
2703 *
2704 * @return The video device index.
2705 */
2706 int getVideoDevId() PJSUA2_THROW(Error);
2707
2708 /**
2709 * Destructor. This will unregister the audio/video port from the
2710 * audio/video conference bridge.
2711 */
2712 virtual ~VideoPlayer();
2713
2714 private:
2715 /**
2716 * Player Id.
2717 */
2718 int playerId;
2719
2720 };
2721
2722 /**
2723 * Video AVI Recorder.
2724 */
2725 class VideoRecorder
2726 {
2727 public:
2728 /**
2729 * Constructor.
2730 */
2731 VideoRecorder();
2732
2733 /**
2734 * Create an avi recorder and automatically add a audio/video port
2735 * the audio/video conference bridge. User can connect the audio/video port
2736 * from a source port to store the uncompressed video and 16 bit PCM audio.
2737 * The recorder currently supports YUY2/I420/RGB24 video format and
2738 * PCM audio format.
2739 *
2740 * Note: Uncompressed video can lead to significant file size growth.
2741 *
2742 * @param filename The filename to be played. Currently only
2743 * AVI files are supported. Filename's length must be
2744 * smaller than PJ_MAXPATH.
2745 * Filename's length must be smaller than PJ_MAXPATH.
2746 * @param max_size Maximum file size.
2747 * @param vid_fmt The video format. If this is not set (NULL), the
2748 format will be set to:
2749 - format:PJMEDIA_FORMAT_I420
2750 - size:320x240
2751 - fps:15
2752 * @param aud_fmt The audio format. If this is not set (NULL), the
2753 format will be set to:
2754 - format:PJMEDIA_FORMAT_PCM
2755 - bits_per_sample:16
2756 - clock rate/chan count/ptime:the conf bridge settings
2757 * @param options Optional options.
2758 */
2759 void createVideoRecorder(const string& file_name,
2760 long max_size = 0,
2761 MediaFormatVideo *vid_fmt = NULL,
2762 MediaFormatAudio *aud_fmt = NULL,
2763 unsigned options = 0) PJSUA2_THROW(Error);
2764
2765 /**
2766 * Enumerate video media port.
2767 *
2768 * @return The list of audio media port.
2769 */
2770 VideoMedia getVideoMedia() PJSUA2_THROW(Error);
2771
2772 /**
2773 * Enumerate audio media port.
2774 *
2775 * @return The list of video media port.
2776 */
2777 AudioMedia getAudioMedia() PJSUA2_THROW(Error);
2778
2779 /**
2780 * Register a callback to be called when the file size has reached the
2781 * max size.
2782 */
2783 virtual void onMaxSize()
2784 {
2785 }
2786
2787 virtual ~VideoRecorder();
2788
2789 private:
2790 /**
2791 * Recorder Id.
2792 */
2793 int recorderId;
2794
2795 /**
2796 * Low level callback
2797 */
2798 static void max_size_cb(pjsua_recorder_id id, void *usr_data);
2799 };
2800
2801 /*************************************************************************
2802 * Codec management
2803 */
2804
2805 /**
2806 * This structure describes codec information.
2807 */
2808 struct CodecInfo
2809 {
2810 /**
2811 * Codec unique identification.
2812 */
2813 string codecId;
2814
2815 /**
2816 * Codec priority (integer 0-255).
2817 */
2818 pj_uint8_t priority;
2819
2820 /**
2821 * Codec description.
2822 */
2823 string desc;
2824
2825 /**
2826 * Construct from pjsua_codec_info.
2827 */
2828 void fromPj(const pjsua_codec_info &codec_info);
2829 };
2830
2831 /**
2832 * Warning: deprecated, use CodecInfoVector2 instead.
2833 *
2834 * Array of codec info.
2835 */
2836 typedef std::vector<CodecInfo*> CodecInfoVector;
2837
2838 /** Array of codec info */
2839 typedef std::vector<CodecInfo> CodecInfoVector2;
2840
2841 /**
2842 * Structure of codec specific parameters which contains name=value pairs.
2843 * The codec specific parameters are to be used with SDP according to
2844 * the standards (e.g: RFC 3555) in SDP 'a=fmtp' attribute.
2845 */
2846 typedef struct CodecFmtp
2847 {
2848 string name; /**< name */
2849 string val; /**< value */
2850 } CodecFmtp;
2851
2852 /** Array of codec fmtp */
2853 typedef std::vector<CodecFmtp> CodecFmtpVector;
2854
2855 /**
2856 * Audio codec parameters info.
2857 */
2858 struct CodecParamInfo
2859 {
2860 unsigned clockRate; /**< Sampling rate in Hz */
2861 unsigned channelCnt; /**< Channel count. */
2862 unsigned avgBps; /**< Average bandwidth in bits/sec */
2863 unsigned maxBps; /**< Maximum bandwidth in bits/sec */
2864 unsigned maxRxFrameSize; /**< Maximum frame size */
2865 unsigned frameLen; /**< Decoder frame ptime in msec. */
2866 unsigned frameLenDenum; /**< Decoder frame ptime denum, or
2867 zero if ptime is integer. */
2868 unsigned encFrameLen; /**< Encoder ptime, or zero if it's
2869 equal to decoder ptime. */
2870 unsigned encFrameLenDenum; /**< Encoder ptime denum, or zero
2871 if ptime is integer. */
2872 unsigned pcmBitsPerSample; /**< Bits/sample in the PCM side */
2873 unsigned pt; /**< Payload type. */
2874 pjmedia_format_id fmtId; /**< Source format, it's format of
2875 encoder input and decoder
2876 output. */
2877 public:
2878 /**
2879 * Default constructor
2880 */
2881 CodecParamInfo()
2882 : clockRate(0),
2883 channelCnt(0),
2884 avgBps(0),
2885 maxBps(0),
2886 maxRxFrameSize(0),
2887 frameLen(0),
2888 frameLenDenum(0),
2889 encFrameLen(0),
2890 encFrameLenDenum(0),
2891 pcmBitsPerSample(0),
2892 pt(0),
2893 fmtId(PJMEDIA_FORMAT_L16)
2894 {}
2895 };
2896
2897 /**
2898 * Audio codec parameters setting.
2899 */
2900 struct CodecParamSetting
2901 {
2902 unsigned frmPerPkt; /**< Number of frames per packet. */
2903 bool vad; /**< Voice Activity Detector. */
2904 bool cng; /**< Comfort Noise Generator. */
2905 bool penh; /**< Perceptual Enhancement */
2906 bool plc; /**< Packet loss concealment */
2907 bool reserved; /**< Reserved, must be zero. */
2908 CodecFmtpVector encFmtp; /**< Encoder's fmtp params. */
2909 CodecFmtpVector decFmtp; /**< Decoder's fmtp params. */
2910 unsigned packetLoss; /**< Encoder's expected pkt loss %. */
2911 unsigned complexity; /**< Encoder complexity, 0-10(max). */
2912 bool cbr; /**< Constant bit rate? */
2913 };
2914
2915 /**
2916 * Detailed codec attributes used in configuring an audio codec and in querying
2917 * the capability of audio codec factories.
2918 *
2919 * Please note that codec parameter also contains SDP specific setting,
2920 * setting::decFmtp and setting::encFmtp, which may need to be set
2921 * appropriately based on the effective setting.
2922 * See each codec documentation for more detail.
2923 */
2924 struct CodecParam
2925 {
2926 /** info */
2927 struct CodecParamInfo info;
2928 /** setting */
2929 struct CodecParamSetting setting;
2930
2931 void fromPj(const pjmedia_codec_param &param);
2932
2933 pjmedia_codec_param toPj() const;
2934 };
2935
2936 /**
2937 * Opus codec parameters setting;
2938 */
2939 struct CodecOpusConfig
2940 {
2941 unsigned sample_rate; /**< Sample rate in Hz. */
2942 unsigned channel_cnt; /**< Number of channels. */
2943 unsigned frm_ptime; /**< Frame time in msec. */
2944 unsigned frm_ptime_denum;/**< Frame time denumerator. */
2945 unsigned bit_rate; /**< Encoder bit rate in bps. */
2946 unsigned packet_loss; /**< Encoder's expected packet loss pct. */
2947 unsigned complexity; /**< Encoder complexity, 0-10(10 is highest)*/
2948 bool cbr; /**< Constant bit rate? */
2949
2950 pjmedia_codec_opus_config toPj() const;
2951 void fromPj(const pjmedia_codec_opus_config &config);
2952 };
2953
2954 /**
2955 * Lyra codec setting;
2956 */
2957 struct CodecLyraConfig
2958 {
2959 /**
2960 * The value represents the decoder bitrate requested by the receiver.
2961 * Endpoints can be configured with different bitrates. For example,
2962 * the local endpoint might be set to a bitrate of 3200, while
2963 * the remote endpoint is set to 6000. In this scenario, the remote
2964 * endpoint will send data at 3200 bitrate, while the local endpoint
2965 * will send data at 6000 bitrate. Valid bitrate: 3200, 6000, 9200.
2966 * By default it is set to PJMEDIA_CODEC_LYRA_DEFAULT_BIT_RATE.
2967 */
2968 unsigned bitRate;
2969
2970 /**
2971 * Lyra required some additional (model) files, including
2972 * \b lyra_config.binarypb , \b lyragan.tflite , \b quantizer.tflite and
2973 * \b soundstream_encoder.tflite .
2974 * This setting represents the folder containing the above files.
2975 * The specified folder should contain these files. If an invalid folder
2976 * is provided, the codec creation will fail.
2977 */
2978 string modelPath;
2979
2980 pjmedia_codec_lyra_config toPj() const;
2981 void fromPj(const pjmedia_codec_lyra_config &config);
2982 };
2983
2984 /**
2985 * Detailed codec attributes used in configuring a video codec and in querying
2986 * the capability of video codec factories.
2987 *
2988 * Please note that codec parameter also contains SDP specific setting,
2989 * #decFmtp and #encFmtp, which may need to be set appropriately based on
2990 * the effective setting. See each codec documentation for more detail.
2991 */
2992 struct VidCodecParam
2993 {
2994 pjmedia_dir dir; /**< Direction */
2995 pjmedia_vid_packing packing; /**< Packetization strategy. */
2996
2997 struct
2998 MediaFormatVideo encFmt; /**< Encoded format */
2999 CodecFmtpVector encFmtp; /**< Encoder fmtp params */
3000 unsigned encMtu; /**< MTU or max payload size setting*/
3001
3002 struct
3003 MediaFormatVideo decFmt; /**< Decoded format */
3004 CodecFmtpVector decFmtp; /**< Decoder fmtp params */
3005
3006 bool ignoreFmtp; /**< Ignore fmtp params. If set to
3007 true, the codec will apply
3008 format settings specified in
3009 encFmt and decFmt only. */
3010
3011 public:
3012 /**
3013 * Default constructor
3014 */
3015 VidCodecParam() : dir(PJMEDIA_DIR_NONE),
3016 packing(PJMEDIA_VID_PACKING_UNKNOWN),
3017 encMtu(0),
3018 ignoreFmtp(false)
3019 {}
3020
3021 void fromPj(const pjmedia_vid_codec_param &param);
3022
3023 pjmedia_vid_codec_param toPj() const;
3024 };
3025
3026
3027 /*************************************************************************
3028 * Media event
3029 */
3030
3031 /**
3032 * This structure describes a media format changed event.
3033 */
3034 struct MediaFmtChangedEvent
3035 {
3036 unsigned newWidth; /**< The new width. */
3037 unsigned newHeight; /**< The new height. */
3038 };
3039
3040 /**
3041 * This structure describes an audio device error event.
3042 */
3043 struct AudDevErrorEvent
3044 {
3045 pjmedia_dir dir; /**< The direction. */
3046 int id; /**< The audio device ID. */
3047 pj_status_t status; /**< The status code. */
3048 };
3049
3050 /**
3051 * Media event data.
3052 */
3053 typedef union MediaEventData {
3054 /**
3055 * Media format changed event data.
3056 */
3057 MediaFmtChangedEvent fmtChanged;
3058
3059 /**
3060 * Audio device error event data.
3061 */
3062 AudDevErrorEvent audDevError;
3063
3064 /**
3065 * Pointer to storage to user event data, if it's outside
3066 * this struct
3067 */
3068 GenericData ptr;
3069
3070 } MediaEventData;
3071
3072 /**
3073 * This structure describes a media event. It corresponds to the
3074 * pjmedia_event structure.
3075 */
3076 struct MediaEvent
3077 {
3078 /**
3079 * The event type.
3080 */
3081 pjmedia_event_type type;
3082
3083 /**
3084 * Additional data/parameters about the event. The type of data
3085 * will be specific to the event type being reported.
3086 */
3087 MediaEventData data;
3088
3089 /**
3090 * Pointer to original pjmedia_event. Only valid when the struct
3091 * is converted from PJSIP's pjmedia_event.
3092 */
3093 void *pjMediaEvent;
3094
3095 public:
3096 /**
3097 * Default constructor
3098 */
3099 MediaEvent() : type(PJMEDIA_EVENT_NONE), pjMediaEvent(NULL)
3100 {}
3101
3102 /**
3103 * Convert from pjsip
3104 */
3105 void fromPj(const pjmedia_event &ev);
3106 };
3107
3108 /**
3109 * @} // PJSUA2_MED
3110 */
3111
3112 } // namespace pj
3113
3114 #endif /* __PJSUA2_MEDIA_HPP__ */