summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2015-08-21 06:00:46 +0000
committerRiza Sulistyo <riza@teluu.com>2015-08-21 06:00:46 +0000
commit8c6f78c4426aae98c9d72b14afd010a3458a662d (patch)
tree80fb8c2c54bccfda1464c3571e76fd961cf79c2f /pjsip
parent110c26a8ca47442eba6c625646b034be97002823 (diff)
Re #1879:
- Implement set video codec param in PJSUA2 API - Fix bug in videoCodecEnum and updateCodecInfoList git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5165 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/include/pjsua2/call.hpp6
-rw-r--r--pjsip/include/pjsua2/endpoint.hpp17
-rw-r--r--pjsip/include/pjsua2/media.hpp57
-rw-r--r--pjsip/src/pjsua2/endpoint.cpp41
-rw-r--r--pjsip/src/pjsua2/media.cpp55
5 files changed, 149 insertions, 27 deletions
diff --git a/pjsip/include/pjsua2/call.hpp b/pjsip/include/pjsua2/call.hpp
index 0614270e..917965e5 100644
--- a/pjsip/include/pjsua2/call.hpp
+++ b/pjsip/include/pjsua2/call.hpp
@@ -47,12 +47,6 @@ using std::vector;
//////////////////////////////////////////////////////////////////////////////
/**
- * Codec parameters, corresponds to pjmedia_codec_param or
- * pjmedia_vid_codec_param.
- */
-typedef void *CodecParam;
-
-/**
* Media stream, corresponds to pjmedia_stream
*/
typedef void *MediaStream;
diff --git a/pjsip/include/pjsua2/endpoint.hpp b/pjsip/include/pjsua2/endpoint.hpp
index ac97ea89..e4039874 100644
--- a/pjsip/include/pjsua2/endpoint.hpp
+++ b/pjsip/include/pjsua2/endpoint.hpp
@@ -1150,18 +1150,25 @@ public:
* will be thrown.
*
*/
- CodecParam videoCodecGetParam(const string &codec_id) const throw(Error);
+ VidCodecParam getVideoCodecParam(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.
+ * @param param Codec parameter to set.
+ *
+ */
+ void setVideoCodecParam(const string &codec_id,
+ const VidCodecParam &param) throw(Error);
+
+ /**
+ * Reset video codec parameters to library default settings.
+ *
+ * @param codec_id Codec ID.
*
*/
- void videoCodecSetParam(const string &codec_id,
- const CodecParam param) throw(Error);
+ void resetVideoCodecParam(const string &codec_id) throw(Error);
public:
/*
diff --git a/pjsip/include/pjsua2/media.hpp b/pjsip/include/pjsua2/media.hpp
index 82909165..e642d171 100644
--- a/pjsip/include/pjsua2/media.hpp
+++ b/pjsip/include/pjsua2/media.hpp
@@ -1941,11 +1941,64 @@ struct CodecInfo
typedef std::vector<CodecInfo*> CodecInfoVector;
/**
- * Codec parameters, corresponds to pjmedia_codec_param or
- * pjmedia_vid_codec_param.
+ * Codec parameters, corresponds to pjmedia_codec_param.
*/
typedef void *CodecParam;
+/**
+ * Structure of codec specific parameters which contains name=value pairs.
+ * The codec specific parameters are to be used with SDP according to
+ * the standards (e.g: RFC 3555) in SDP 'a=fmtp' attribute.
+ */
+typedef struct CodecFmtp
+{
+ string name;
+ string val;
+} CodecFmtp;
+
+/** Array of codec fmtp */
+typedef std::vector<CodecFmtp> CodecFmtpVector;
+
+/**
+ * Detailed codec attributes used in configuring a codec and in querying
+ * the capability of codec factories.
+ *
+ * Please note that codec parameter also contains SDP specific setting,
+ * #decFmtp and #encFmtp, which may need to be set appropriately based on
+ * the effective setting. See each codec documentation for more detail.
+ */
+struct VidCodecParam
+{
+ pjmedia_dir dir; /**< Direction */
+ pjmedia_vid_packing packing; /**< Packetization strategy. */
+
+ struct
+ MediaFormatVideo encFmt; /**< Encoded format */
+ CodecFmtpVector encFmtp; /**< Encoder fmtp params */
+ unsigned encMtu; /**< MTU or max payload size setting*/
+
+ struct
+ MediaFormatVideo decFmt; /**< Decoded format */
+ CodecFmtpVector decFmtp; /**< Decoder fmtp params */
+
+ bool ignoreFmtp; /**< Ignore fmtp params. If set to
+ true, the codec will apply
+ format settings specified in
+ encFmt and decFmt only. */
+
+ void fromPj(const pjmedia_vid_codec_param &param);
+
+ pjmedia_vid_codec_param toPj() const;
+
+private:
+ void setCodecFmtp(const pjmedia_codec_fmtp &in_fmtp,
+ CodecFmtpVector &out_fmtp);
+
+ void getCodecFmtp(const CodecFmtpVector &in_fmtp,
+ pjmedia_codec_fmtp &out_fmtp) const;
+
+};
+
/**
* @} // PJSUA2_MED
diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp
index 7eed8138..137dadf0 100644
--- a/pjsip/src/pjsua2/endpoint.cpp
+++ b/pjsip/src/pjsua2/endpoint.cpp
@@ -1683,7 +1683,7 @@ void Endpoint::updateCodecInfoList(pjsua_codec_info pj_codec[], unsigned count,
CodecInfo *codec_info = new CodecInfo;
codec_info->fromPj(pj_codec[i]);
- codecInfoList.push_back(codec_info);
+ codec_list.push_back(codec_info);
}
pj_leave_critical_section();
}
@@ -1698,7 +1698,7 @@ const CodecInfoVector &Endpoint::videoCodecEnum() throw(Error)
updateCodecInfoList(pj_codec, count, videoCodecInfoList);
#endif
- return codecInfoList;
+ return videoCodecInfoList;
}
void Endpoint::videoCodecSetPriority(const string &codec_id,
@@ -1713,31 +1713,44 @@ void Endpoint::videoCodecSetPriority(const string &codec_id,
#endif
}
-CodecParam Endpoint::videoCodecGetParam(const string &codec_id) const
- throw(Error)
-{
- pjmedia_vid_codec_param *pj_param = NULL;
+VidCodecParam Endpoint::getVideoCodecParam(const string &codec_id) const
+ throw(Error)
+{
+ VidCodecParam codec_param;
#if PJSUA_HAS_VIDEO
- pj_str_t codec_str = str2Pj(codec_id);
+ pjmedia_vid_codec_param pj_param;
+ pj_str_t codec_str = str2Pj(codec_id);
- PJSUA2_CHECK_EXPR(pjsua_vid_codec_get_param(&codec_str, pj_param));
+ PJSUA2_CHECK_EXPR(pjsua_vid_codec_get_param(&codec_str, &pj_param));
+ codec_param.fromPj(pj_param);
#else
PJ_UNUSED_ARG(codec_id);
#endif
- return pj_param;
+ return codec_param;
}
-void Endpoint::videoCodecSetParam(const string &codec_id,
- const CodecParam param) throw(Error)
+void Endpoint::setVideoCodecParam(const string &codec_id,
+ const VidCodecParam &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));
+ pjmedia_vid_codec_param pj_param = param.toPj();
+
+ PJSUA2_CHECK_EXPR(pjsua_vid_codec_set_param(&codec_str, &pj_param));
#else
PJ_UNUSED_ARG(codec_id);
PJ_UNUSED_ARG(param);
#endif
}
+void Endpoint::resetVideoCodecParam(const string &codec_id) throw(Error)
+{
+#if PJSUA_HAS_VIDEO
+ pj_str_t codec_str = str2Pj(codec_id);
+
+ PJSUA2_CHECK_EXPR(pjsua_vid_codec_set_param(&codec_str, NULL));
+#else
+ PJ_UNUSED_ARG(codec_id);
+ PJ_UNUSED_ARG(param);
+#endif
+}
diff --git a/pjsip/src/pjsua2/media.cpp b/pjsip/src/pjsua2/media.cpp
index ba443703..b6b73ea3 100644
--- a/pjsip/src/pjsua2/media.cpp
+++ b/pjsip/src/pjsua2/media.cpp
@@ -1506,3 +1506,58 @@ void CodecInfo::fromPj(const pjsua_codec_info &codec_info)
priority = codec_info.priority;
desc = pj2Str(codec_info.desc);
}
+
+void VidCodecParam::fromPj(const pjmedia_vid_codec_param &param)
+{
+ dir = param.dir;
+ packing = param.packing;
+ ignoreFmtp = param.ignore_fmtp;
+ encMtu = param.enc_mtu;
+ encFmt.fromPj(param.enc_fmt);
+ decFmt.fromPj(param.dec_fmt);
+ setCodecFmtp(param.enc_fmtp, encFmtp);
+ setCodecFmtp(param.dec_fmtp, decFmtp);
+}
+
+pjmedia_vid_codec_param VidCodecParam::toPj() const
+{
+ pjmedia_vid_codec_param param;
+ pj_bzero(&param, sizeof(param));
+ param.dir = dir;
+ param.packing = packing;
+ param.ignore_fmtp = ignoreFmtp;
+ param.enc_mtu = encMtu;
+ param.enc_fmt = encFmt.toPj();
+ param.dec_fmt = decFmt.toPj();
+ getCodecFmtp(encFmtp, param.enc_fmtp);
+ getCodecFmtp(decFmtp, param.dec_fmtp);
+ return param;
+}
+
+void VidCodecParam::setCodecFmtp(const pjmedia_codec_fmtp &in_fmtp,
+ CodecFmtpVector &out_fmtp)
+{
+ unsigned i = 0;
+ for ( ; i<in_fmtp.cnt; ++i) {
+ CodecFmtp fmtp;
+ fmtp.name = pj2Str(in_fmtp.param[i].name);
+ fmtp.val = pj2Str(in_fmtp.param[i].val);
+
+ out_fmtp.push_back(fmtp);
+ }
+}
+
+void VidCodecParam::getCodecFmtp(const CodecFmtpVector &in_fmtp,
+ pjmedia_codec_fmtp &out_fmtp) const
+{
+ CodecFmtpVector::const_iterator i;
+ out_fmtp.cnt = 0;
+ for (i=in_fmtp.begin(); i!=in_fmtp.end();++i) {
+ if (out_fmtp.cnt >= PJMEDIA_CODEC_MAX_FMTP_CNT) {
+ break;
+ }
+ out_fmtp.param[out_fmtp.cnt].name = str2Pj((*i).name);
+ out_fmtp.param[out_fmtp.cnt].val = str2Pj((*i).val);
+ ++out_fmtp.cnt;
+ }
+}