webrtc_internal: Add APIs to set/get payload type 53/280053/2
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 23 Aug 2022 03:34:28 +0000 (12:34 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 23 Aug 2022 07:26:58 +0000 (16:26 +0900)
Functions below are added
 : webrtc_media_source_set_payload_type()
 : webrtc_media_source_get_payload_type()

[Version] 0.3.209
[Issue Type] Internal API

Change-Id: I69c20167d1a6d07a6f12ac784c3e921e929fc0f1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_source_private.c

index a09fda009b429fd2fa7d3e747740ff991088e138..41f1f6c09919f6dfcb7773ca96d04d68fd8026af 100644 (file)
@@ -152,6 +152,43 @@ int webrtc_media_source_set_video_loopback_to_ecore_wl(webrtc_h webrtc, unsigned
  */
 int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_internal_e type, unsigned int *source_id);
 
+/**
+ * @internal
+ * @brief Sets the payload type to the media source.
+ * @since_tizen 7.0
+ * @remarks This function would be useful when @a webrtc is operated as an answerer and a remote peer is using another implementation, not this API.
+ * @param[in] webrtc      WebRTC handle
+ * @param[in] source_id   The media source id
+ * @param[in] media_type  The media type
+ * @param[in] pt          The payload type
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state
+ * @pre Add media source to @a webrtc to get @a source_id by calling webrtc_add_media_source().
+ * @pre @a webrtc state must be set to #WEBRTC_STATE_IDLE.
+ * @see webrtc_media_source_get_payload_type()
+ */
+int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt);
+
+/**
+ * @internal
+ * @brief Gets the payload type of the media source.
+ * @since_tizen 7.0
+ * @param[in] webrtc      WebRTC handle
+ * @param[in] source_id   The media source id
+ * @param[in] media_type  The media type
+ * @param[out] pt         The payload type
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre Add media source to @a webrtc to get @a source_id by calling webrtc_add_media_source().
+ * @see webrtc_media_source_set_payload_type()
+ */
+int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt);
+
 /**
  * @internal
  * @brief Sets the crop coordinates of screen source.
index 4ea4bce42778180b4ffed2bbbb43e19bdfc4fc96..cca62f22f864b61530c5194e5de97ca1d3d0aa36 100644 (file)
@@ -545,6 +545,7 @@ typedef struct _webrtc_gst_slot_s {
                bool inbandfec;
                int packet_loss_percentage;
                unsigned int pt;
+               bool pt_set_by_api;
                struct {
                        unsigned int track_id;
                        bool need_decoding;
index 1a10a8010f08a5dc107f289cf908946faab6fb2c..08faf486fe8b933828b442f648d3a89c6541f42b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.208
+Version:    0.3.209
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 9845d6447478c03670a2718d5e930c8be9e84a64..95cfd99e24ba81ab86aee24bbaf213a7e3f9a0cd 100644 (file)
@@ -79,6 +79,50 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i
        return ret;
 }
 
+int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt)
+{
+       webrtc_s *_webrtc = (webrtc_s *)webrtc;
+       webrtc_gst_slot_s *source;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0");
+       RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL,
+               WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE");
+
+       source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt = pt;
+       source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt_set_by_api = true;
+
+       LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, pt);
+
+       return WEBRTC_ERROR_NONE;
+}
+
+int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt)
+{
+       webrtc_s *_webrtc = (webrtc_s *)webrtc;
+       webrtc_gst_slot_s *source;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0");
+       RET_VAL_IF(pt == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "pt is NULL");
+       RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL,
+               WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       *pt = source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt;
+
+       LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, *pt);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
 {
        g_autoptr(GMutexLocker) locker = NULL;
index a34ef513f590ff3114df0d7e90ee20c3238b79d5..737d8d7375649efd45091f4ebfaed8737e74397b 100644 (file)
@@ -417,6 +417,11 @@ int _set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, c
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
 
+       if (source->av[av_idx].pt_set_by_api) {
+               LOG_INFO("current pt[%u] might be set by api, skip it", source->av[av_idx].pt);
+               return WEBRTC_ERROR_NONE;
+       }
+
        if (media_type)
                if ((payload_type = __get_fixed_payload_type(media_type)) != -1)
                        goto out;