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/src | |
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/src')
-rw-r--r-- | pjsip/src/pjsua2/endpoint.cpp | 86 | ||||
-rw-r--r-- | pjsip/src/pjsua2/media.cpp | 143 |
2 files changed, 214 insertions, 15 deletions
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); |