diff options
author | Riza Sulistyo <riza@teluu.com> | 2015-07-01 02:20:12 +0000 |
---|---|---|
committer | Riza Sulistyo <riza@teluu.com> | 2015-07-01 02:20:12 +0000 |
commit | e485c1bee41247d998f62fae1cdf0edd7fb93925 (patch) | |
tree | dc40ca58f6e79533c9ba7a9cdceb30a8d5d45ea6 /pjsip | |
parent | 9a0f3e938494f0f48e073d39e68b0ed2fc76e112 (diff) |
Re #1863: Initial implementation of PJSUA2 Video Codec API and Video Device API.
- Codec management (enum codec, set prio, get param, set param)
- Device management (enum dev, dev count, dev info).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5123 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua2/endpoint.hpp | 60 | ||||
-rw-r--r-- | pjsip/include/pjsua2/media.hpp | 109 | ||||
-rw-r--r-- | pjsip/src/pjsua2/endpoint.cpp | 86 | ||||
-rw-r--r-- | pjsip/src/pjsua2/media.cpp | 143 |
4 files changed, 377 insertions, 21 deletions
diff --git a/pjsip/include/pjsua2/endpoint.hpp b/pjsip/include/pjsua2/endpoint.hpp index 0001da1b..7d71231a 100644 --- a/pjsip/include/pjsua2/endpoint.hpp +++ b/pjsip/include/pjsua2/endpoint.hpp @@ -1069,6 +1069,13 @@ public: */ AudDevManager &audDevManager(); + /** + * Get the instance of Video Device Manager. + * + * @return The Video Device Manager. + */ + VidDevManager &vidDevManager(); + /************************************************************************* * Codec management operations */ @@ -1095,10 +1102,10 @@ public: /** * Get codec parameters. * - * @param codec_id Codec ID. + * @param codec_id Codec ID. * - * @return Codec parameters. If codec is not found, Error - * will be thrown. + * @return Codec parameters. If codec is not found, Error + * will be thrown. * */ CodecParam codecGetParam(const string &codec_id) const throw(Error); @@ -1114,6 +1121,47 @@ public: void codecSetParam(const string &codec_id, const CodecParam param) throw(Error); + /** + * Enum all supported video codecs in the system. + * + * @return Array of video codec info. + */ + const CodecInfoVector &videoCodecEnum() throw(Error); + + /** + * Change video codec priority. + * + * @param codec_id Codec ID, which is a string that uniquely identify + * the codec (such as "H263/90000"). Please see pjsua + * manual or pjmedia codec reference for details. + * @param priority Codec priority, 0-255, where zero means to disable + * the codec. + * + */ + void videoCodecSetPriority(const string &codec_id, + pj_uint8_t priority) throw(Error); + + /** + * Get video codec parameters. + * + * @param codec_id Codec ID. + * + * @return Codec parameters. If codec is not found, Error + * will be thrown. + * + */ + CodecParam videoCodecGetParam(const string &codec_id) const throw(Error); + + /** + * Set video codec parameters. + * + * @param codec_id Codec ID. + * @param param Codec parameter to set. Set to NULL to reset + * codec parameter to library default settings. + * + */ + void videoCodecSetParam(const string &codec_id, + const CodecParam param) throw(Error); public: /* @@ -1182,7 +1230,9 @@ private: LogWriter *writer; // Custom writer, if any AudioMediaVector mediaList; AudDevManager audioDevMgr; + VidDevManager videoDevMgr; CodecInfoVector codecInfoList; + CodecInfoVector videoCodecInfoList; std::map<pj_thread_t*, pj_thread_desc*> threadDescMap; /* Pending logging */ @@ -1316,7 +1366,9 @@ private: unsigned flags); private: - void clearCodecInfoList(); + void clearCodecInfoList(CodecInfoVector &codec_list); + void updateCodecInfoList(pjsua_codec_info pj_codec[], unsigned count, + CodecInfoVector &codec_list); }; diff --git a/pjsip/include/pjsua2/media.hpp b/pjsip/include/pjsua2/media.hpp index 16df4ca5..c3bf6e2d 100644 --- a/pjsip/include/pjsua2/media.hpp +++ b/pjsip/include/pjsua2/media.hpp @@ -89,12 +89,22 @@ struct MediaFormatAudio : public MediaFormat */ struct MediaFormatVideo : public MediaFormat { - unsigned width; /**< Video width. */ - unsigned height; /**< Video height. */ + unsigned width; /**< Video width. */ + unsigned height; /**< Video height. */ int fpsNum; /**< Frames per second numerator. */ int fpsDenum; /**< Frames per second denumerator. */ pj_uint32_t avgBps; /**< Average bitrate. */ pj_uint32_t maxBps; /**< Maximum bitrate. */ + + /** + * Construct from pjmedia_format. + */ + void fromPj(const pjmedia_format &format); + + /** + * Export to pjmedia_format. + */ + pjmedia_format toPj() const; }; /** Array of MediaFormat */ @@ -1587,6 +1597,101 @@ private: pjmedia_vid_dev_index devId; }; +/** + * Video device information structure. + */ +struct VideoDevInfo +{ + /** + * The device name + */ + string name; + + /** + * The underlying driver name + */ + string driver; + + /** + * The supported direction of the video device, i.e. whether it supports + * capture only, render only, or both. + */ + pjmedia_dir dir; + + /** + * Device capabilities, as bitmask combination of #pjmedia_vid_dev_cap + */ + unsigned caps; + + /** + * Array of supported video formats. Some fields in each supported video + * format may be set to zero or of "unknown" value, to indicate that the + * value is unknown or should be ignored. When these value are not set + * to zero, it indicates that the exact format combination is being used. + */ + MediaFormatVector fmt; + + /** + * Construct from pjmedia_vid_dev_info. + */ + void fromPj(const pjmedia_vid_dev_info &dev_info); + + /** + * Destructor. + */ + ~VideoDevInfo(); +}; + +/** Array of video device info */ +typedef std::vector<VideoDevInfo*> VideoDevInfoVector; + +/** + * Video device manager. + */ +class VidDevManager { +public: + /** + * Get the number of video devices installed in the system. + * + * @return The number of devices. + */ + unsigned getDevCount(); + + /** + * Retrieve the video device info for the specified device index. + * + * @param dev_id The video device id + * + * @return The list of video device info + */ + VideoDevInfo getDevInfo(int dev_id) const throw(Error); + + /** + * Enum all video devices installed in the system. + * + * @return The list of video device info + */ + const VideoDevInfoVector &enumDev() throw(Error); + +private: + VideoDevInfoVector videoDevList; + + void clearVideoDevList(); + + /** + * Constructor. + */ + VidDevManager(); + + /** + * Destructor. + */ + ~VidDevManager(); + + friend class Endpoint; +}; + + /************************************************************************* * Codec management */ diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp index d06b2007..6b8ab942 100644 --- a/pjsip/src/pjsua2/endpoint.cpp +++ b/pjsip/src/pjsua2/endpoint.cpp @@ -387,7 +387,8 @@ Endpoint::~Endpoint() delete cur_media; /* this will remove itself from the list */ } - clearCodecInfoList(); + clearCodecInfoList(codecInfoList); + clearCodecInfoList(videoCodecInfoList); try { libDestroy(); @@ -1618,6 +1619,11 @@ AudDevManager &Endpoint::audDevManager() return audioDevMgr; } +VidDevManager &Endpoint::vidDevManager() +{ + return videoDevMgr; +} + /* * Codec operations. */ @@ -1628,15 +1634,7 @@ const CodecInfoVector &Endpoint::codecEnum() throw(Error) PJSUA2_CHECK_EXPR( pjsua_enum_codecs(pj_codec, &count) ); - pj_enter_critical_section(); - clearCodecInfoList(); - for (unsigned i=0; i<count; ++i) { - CodecInfo *codec_info = new CodecInfo; - - codec_info->fromPj(pj_codec[i]); - codecInfoList.push_back(codec_info); - } - pj_leave_critical_section(); + updateCodecInfoList(pj_codec, count, codecInfoList); return codecInfoList; } @@ -1666,10 +1664,70 @@ void Endpoint::codecSetParam(const string &codec_id, PJSUA2_CHECK_EXPR( pjsua_codec_set_param(&codec_str, pj_param) ); } -void Endpoint::clearCodecInfoList() +void Endpoint::clearCodecInfoList(CodecInfoVector &codec_list) +{ + for (unsigned i=0;i<codec_list.size();++i) { + delete codec_list[i]; + } + codec_list.clear(); +} + +void Endpoint::updateCodecInfoList(pjsua_codec_info pj_codec[], unsigned count, + CodecInfoVector &codec_list) { - for (unsigned i=0;i<codecInfoList.size();++i) { - delete codecInfoList[i]; + pj_enter_critical_section(); + clearCodecInfoList(codec_list); + for (unsigned i = 0; i<count; ++i) { + CodecInfo *codec_info = new CodecInfo; + + codec_info->fromPj(pj_codec[i]); + codecInfoList.push_back(codec_info); } - codecInfoList.clear(); + pj_leave_critical_section(); +} + +const CodecInfoVector &Endpoint::videoCodecEnum() throw(Error) +{ +#if PJSUA_HAS_VIDEO + pjsua_codec_info pj_codec[MAX_CODEC_NUM]; + unsigned count = MAX_CODEC_NUM; + + PJSUA2_CHECK_EXPR(pjsua_vid_enum_codecs(pj_codec, &count)); + + updateCodecInfoList(pj_codec, count, videoCodecInfoList); +#endif + return codecInfoList; +} + +void Endpoint::videoCodecSetPriority(const string &codec_id, + pj_uint8_t priority) throw(Error) +{ +#if PJSUA_HAS_VIDEO + pj_str_t codec_str = str2Pj(codec_id); + PJSUA2_CHECK_EXPR(pjsua_vid_codec_set_priority(&codec_str, priority)); +#endif +} + +CodecParam Endpoint::videoCodecGetParam(const string &codec_id) const + throw(Error) +{ + pjmedia_vid_codec_param *pj_param = NULL; +#if PJSUA_HAS_VIDEO + pj_str_t codec_str = str2Pj(codec_id); + + PJSUA2_CHECK_EXPR(pjsua_vid_codec_get_param(&codec_str, pj_param)); +#endif + return pj_param; +} + +void Endpoint::videoCodecSetParam(const string &codec_id, + const CodecParam param) throw(Error) +{ +#if PJSUA_HAS_VIDEO + pj_str_t codec_str = str2Pj(codec_id); + pjmedia_vid_codec_param *pj_param = (pjmedia_vid_codec_param*)param; + + PJSUA2_CHECK_EXPR(pjsua_vid_codec_set_param(&codec_str, pj_param)); +#endif } + diff --git a/pjsip/src/pjsua2/media.cpp b/pjsip/src/pjsua2/media.cpp index 12e67f52..46c60a46 100644 --- a/pjsip/src/pjsua2/media.cpp +++ b/pjsip/src/pjsua2/media.cpp @@ -1094,7 +1094,6 @@ void VideoWindow::setWindow(const VideoWindowHandle &win) throw(Error) #endif } /////////////////////////////////////////////////////////////////////////////// - VideoPreviewOpParam::VideoPreviewOpParam() { #if PJSUA_HAS_VIDEO @@ -1177,6 +1176,148 @@ VideoWindow VideoPreview::getVideoWindow() } /////////////////////////////////////////////////////////////////////////////// +void MediaFormatVideo::fromPj(const pjmedia_format &format) +{ +#if PJSUA_HAS_VIDEO + if ((format.type != PJMEDIA_TYPE_VIDEO) && + (format.detail_type != PJMEDIA_FORMAT_DETAIL_VIDEO)) + { + type = PJMEDIA_TYPE_UNKNOWN; + return; + } + + id = format.id; + type = format.type; + + /* Detail. */ + width = format.det.vid.size.w; + height = format.det.vid.size.h; + fpsNum = format.det.vid.fps.num; + fpsDenum = format.det.vid.fps.denum; + avgBps = format.det.vid.avg_bps; + maxBps = format.det.vid.max_bps; +#else + type = PJMEDIA_TYPE_UNKNOWN; +#endif +} + +pjmedia_format MediaFormatVideo::toPj() const +{ + pjmedia_format pj_format; + +#if PJSUA_HAS_VIDEO + pj_format.id = id; + pj_format.type = type; + + pj_format.detail_type = PJMEDIA_FORMAT_DETAIL_VIDEO; + pj_format.det.vid.size.w = width; + pj_format.det.vid.size.h = height; + pj_format.det.vid.fps.num = fpsNum; + pj_format.det.vid.fps.denum = fpsDenum; + pj_format.det.vid.avg_bps = avgBps; + pj_format.det.vid.max_bps = maxBps; +#else + pj_format.type = PJMEDIA_TYPE_UNKNOWN; +#endif + return pj_format; +} + +/////////////////////////////////////////////////////////////////////////////// +void VideoDevInfo::fromPj(const pjmedia_vid_dev_info &dev_info) +{ +#if PJSUA_HAS_VIDEO + name = dev_info.name; + driver = dev_info.driver; + dir = dev_info.dir; + caps = dev_info.caps; + + for (unsigned i = 0; i<dev_info.fmt_cnt;++i) { + MediaFormatVideo *format = new MediaFormatVideo; + + format->fromPj(dev_info.fmt[i]); + if (format->type == PJMEDIA_TYPE_VIDEO) + fmt.push_back(format); + } +#else + PJ_UNUSED_ARG(dev_info); +#endif +} + +VideoDevInfo::~VideoDevInfo() +{ +#if PJSUA_HAS_VIDEO + for (unsigned i = 0;i<fmt.size();++i) { + delete fmt[i]; + } + fmt.clear(); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +unsigned VidDevManager::getDevCount() +{ +#if PJSUA_HAS_VIDEO + return pjsua_vid_dev_count(); +#else + return 0; +#endif +} + +VideoDevInfo VidDevManager::getDevInfo(int dev_id) const throw(Error) +{ + VideoDevInfo dev_info; +#if PJSUA_HAS_VIDEO + pjmedia_vid_dev_info pj_info; + + PJSUA2_CHECK_EXPR(pjsua_vid_dev_get_info(dev_id, &pj_info)); + + dev_info.fromPj(pj_info); +#endif + return dev_info; +} + +const VideoDevInfoVector &VidDevManager::enumDev() throw(Error) +{ +#if PJSUA_HAS_VIDEO + pjmedia_vid_dev_info pj_info[MAX_DEV_COUNT]; + unsigned count = MAX_DEV_COUNT; + + PJSUA2_CHECK_EXPR(pjsua_vid_enum_devs(pj_info, &count)); + + pj_enter_critical_section(); + clearVideoDevList(); + for (unsigned i = 0; i<count;++i) { + VideoDevInfo *dev_info = new VideoDevInfo; + dev_info->fromPj(pj_info[i]); + videoDevList.push_back(dev_info); + } + pj_leave_critical_section(); +#endif + return videoDevList; +} + +void VidDevManager::clearVideoDevList() +{ +#if PJSUA_HAS_VIDEO + for (unsigned i = 0;i<videoDevList.size();++i) { + delete videoDevList[i]; + } + videoDevList.clear(); +#endif +} + +VidDevManager::VidDevManager() +{ +} + +VidDevManager::~VidDevManager() +{ +#if PJSUA_HAS_VIDEO + clearVideoDevList(); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// void CodecInfo::fromPj(const pjsua_codec_info &codec_info) { codecId = pj2Str(codec_info.codec_id); |