From f152c380a747824df5868b3e46b5dd104786fc0d Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 27 Jan 2021 14:45:37 +0900 Subject: [PATCH] webrtc_source: Revise caps information of appsrc in case of H264 format To make negotiation with incoming media packet source of H264 byte stream data caps information set to appsrc is revised. [Version] 0.1.100 [Issue Type] Improvement Change-Id: I0a95e4f5bdb1a02e195095ce1b862409fd65c64d Signed-off-by: Sangchul Lee --- packaging/capi-media-webrtc.spec | 2 +- src/webrtc_source.c | 39 ++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 741833ca..525930fd 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.1.99 +Version: 0.1.100 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 17607587..3aaf42fe 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -156,6 +156,8 @@ static const char *__get_format_name(media_format_mimetype_e mime_type) case MEDIA_FORMAT_VP9: return "VP9"; case MEDIA_FORMAT_H264_SP: /* baseline profile */ + case MEDIA_FORMAT_H264_MP: /* main profile */ + case MEDIA_FORMAT_H264_HP: /* high profile */ return "H264"; default: LOG_ERROR("not supported mime_type(0x%x)", mime_type); @@ -198,6 +200,8 @@ static bool __is_supported_mime_type(media_format_mimetype_e mime_type) case MEDIA_FORMAT_VP8: case MEDIA_FORMAT_VP9: case MEDIA_FORMAT_H264_SP: + case MEDIA_FORMAT_H264_MP: + case MEDIA_FORMAT_H264_HP: LOG_INFO("[%s][ENCODED/%s] mime_type[0x%x]", mime_type & MEDIA_FORMAT_AUDIO ? "AUDIO" : "VIDEO", __get_format_name(mime_type), mime_type); return true; @@ -958,6 +962,30 @@ static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gs return _set_ghost_pad_target(source->src_pad, capsfilter, true); } +static GstCaps *__make_encoded_caps_for_appsrc(webrtc_gst_slot_s *source) +{ + GstCaps *caps; + media_format_mimetype_e mime_type; + const char *_media_type; + + RET_VAL_IF(source == NULL, NULL, "source is NULL"); + RET_VAL_IF(source->media_format == NULL, NULL, "media_format is NULL"); + RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, NULL, "invalid media source type(%d)", source->type); + RET_VAL_IF(media_format_get_video_info(source->media_format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE, + NULL, "failed to media_format_get_video_info()"); + + _media_type = __get_video_media_type(__get_format_name(mime_type)); + RET_VAL_IF(g_strcmp0(_media_type, MEDIA_TYPE_VIDEO_H264), NULL, "not supported type(%s)", _media_type); + /* FIXME: prepare other types */ + + caps = gst_caps_new_simple(_media_type, + "stream-format", G_TYPE_STRING, "byte-stream", + "alignment", G_TYPE_STRING, "au", + NULL); + + return caps; +} + static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source) { int ret = WEBRTC_ERROR_NONE; @@ -976,8 +1004,8 @@ static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrt appsrc = __find_element_in_bin(source->bin, "appsrc"); RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL"); - if (!(sink_caps = __make_encoded_caps_from_media_format(source, NULL))) { - LOG_ERROR("failed to __make_encoded_caps_from_media_format()"); + if (!(sink_caps = __make_encoded_caps_for_appsrc(source))) { + LOG_ERROR("failed to __make_encoded_caps_for_appsrc()"); return WEBRTC_ERROR_INVALID_OPERATION; } caps_str = gst_caps_to_string(sink_caps); @@ -1228,7 +1256,7 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(format == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "format 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"); - RET_VAL_IF(!__find_element_in_bin(source->bin, "appsrc"), WEBRTC_ERROR_INVALID_PARAMETER, "source_id[%u] is not for media packet source", source_id); + RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media source type(%d)", source->type); RET_VAL_IF(source->media_format != NULL, WEBRTC_ERROR_INVALID_OPERATION, "format is already set to this media packet source"); RET_VAL_IF(media_format_get_type(format, &format_type) != MEDIA_FORMAT_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION, @@ -1363,6 +1391,7 @@ int _push_media_packet(webrtc_s *webrtc, unsigned int source_id, media_packet_h GstElement *appsrc; GstBuffer *new_buffer; guint64 pts = 0; + guint64 dts = 0; guint64 duration = 0; guint64 size = 0; GstFlowReturn gst_ret = GST_FLOW_OK; @@ -1410,11 +1439,13 @@ int _push_media_packet(webrtc_s *webrtc, unsigned int source_id, media_packet_h media_packet_get_pts(packet, &pts); GST_BUFFER_PTS(new_buffer) = pts; + media_packet_get_dts(packet, &dts); + GST_BUFFER_DTS(new_buffer) = dts; media_packet_get_duration(packet, &duration); GST_BUFFER_DURATION(new_buffer) = duration; - LOG_DEBUG("new gst buffer[%p, pts:%llu, duration:%llu]", new_buffer, pts, duration); + LOG_DEBUG("new gst buffer[%p, pts:%llu, dts:%llu, duration:%llu]", new_buffer, pts, dts, duration); g_signal_emit_by_name(G_OBJECT(appsrc), "push-buffer", new_buffer, &gst_ret, NULL); gst_buffer_unref(new_buffer); -- 2.34.1