generated from AMWA-TV/info-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ST2110-30 receiver to the gstreamer and demo
- Loading branch information
1 parent
6a069a4
commit 45379c8
Showing
5 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
cpp/libs/ossrf_gstreamer_api/lib/src/receiver/st2110_30_receiver_plugin.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (C) 2024 Advanced Media Workflow Association | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "st2110_30_receiver_plugin.h" | ||
#include "bisect/expected/macros.h" | ||
#include "bisect/pipeline.h" | ||
#include <gst/gst.h> | ||
|
||
using namespace bisect; | ||
using namespace ossrf::gst::receiver; | ||
using namespace ossrf::gst::plugins; | ||
|
||
namespace | ||
{ | ||
constexpr auto queue_max_size_time = 200000; | ||
constexpr auto queue_max_size_buffers = 0; | ||
constexpr auto queue_max_size_bytes = 0; | ||
}; // namespace | ||
|
||
struct gst_st2110_30_receiver_impl : gst_receiver_plugin_t | ||
{ | ||
receiver_settings s_; | ||
audio_info_t f_; | ||
gst::pipeline pipeline_; | ||
|
||
gst_st2110_30_receiver_impl(receiver_settings settings, audio_info_t format) : s_(settings), f_(format) {} | ||
|
||
~gst_st2110_30_receiver_impl() { stop(); } | ||
|
||
maybe_ok create_gstreamer_pipeline() | ||
{ | ||
// Create pipeline and check if all elements are created successfully | ||
BST_CHECK_ASSIGN(pipeline_, bisect::gst::pipeline::create(NULL)); | ||
auto* pipeline = pipeline_.get(); | ||
|
||
// Add pipeline udp source | ||
auto* source = gst_element_factory_make("udpsrc", NULL); | ||
BST_ENFORCE(source != nullptr, "Failed creating GStreamer element udpsrc"); | ||
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), source), "Failed adding udpsrc to the pipeline"); | ||
|
||
// Set udp source params | ||
g_object_set(G_OBJECT(source), "address", s_.primary.source_ip_address.c_str(), NULL); | ||
g_object_set(G_OBJECT(source), "auto-multicast", TRUE, NULL); | ||
g_object_set(G_OBJECT(source), "port", s_.primary.source_port, NULL); | ||
g_object_set(G_OBJECT(source), "multicast-iface", s_.primary.interface_name.c_str(), NULL); | ||
|
||
// Create and set caps for udp source | ||
GstCaps* caps = gst_caps_from_string("application/x-rtp, clock-rate=48000, channels=2"); | ||
g_object_set(G_OBJECT(source), "caps", caps, NULL); | ||
|
||
// Add pipeline rtpjitterbuffer | ||
auto* jitter_buffer = gst_element_factory_make("rtpjitterbuffer", NULL); | ||
BST_ENFORCE(jitter_buffer != nullptr, "Failed creating GStreamer element jitter_buffer"); | ||
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), jitter_buffer), "Failed adding jitter_buffer to the pipeline"); | ||
|
||
// Add pipeline queue1 | ||
auto* queue1 = gst_element_factory_make("queue", NULL); | ||
BST_ENFORCE(queue1 != nullptr, "Failed creating GStreamer element queue"); | ||
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), queue1), "Failed adding queue to the pipeline"); | ||
g_object_set(G_OBJECT(queue1), "max-size-time", queue_max_size_time, "max-size-buffers", queue_max_size_buffers, | ||
"max-size-bytes", queue_max_size_bytes, NULL); | ||
|
||
// Add pipeline rtp depay | ||
auto* depay = gst_element_factory_make("rtpL24depay", NULL); | ||
BST_ENFORCE(depay != nullptr, "Failed creating GStreamer element depay"); | ||
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), depay), "Failed adding depay to the pipeline"); | ||
|
||
// Add pipeline video sink | ||
auto* sink = gst_element_factory_make("pulsesink", NULL); | ||
BST_ENFORCE(sink != nullptr, "Failed creating GStreamer element sink"); | ||
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), sink), "Failed adding sink to the pipeline"); | ||
|
||
// Link all elements together | ||
BST_ENFORCE(gst_element_link_many(source, jitter_buffer, queue1, depay, sink, NULL), | ||
"Failed linking GStreamer video pipeline"); | ||
|
||
// Setup runner | ||
pipeline_.run_loop(); | ||
|
||
return {}; | ||
} | ||
|
||
void stop() noexcept override | ||
{ | ||
pipeline_.stop(); | ||
pipeline_ = {}; | ||
} | ||
}; | ||
|
||
// TODO this function will need to receive an SDP and use the information in it to build the GST pipeline | ||
expected<gst_receiver_plugin_uptr> ossrf::gst::plugins::create_gst_st2110_30_plugin(receiver_settings settings, | ||
audio_info_t format) noexcept | ||
{ | ||
auto i = std::make_unique<gst_st2110_30_receiver_impl>(settings, format); | ||
|
||
BST_CHECK(i->create_gstreamer_pipeline()); | ||
|
||
return i; | ||
} |
24 changes: 24 additions & 0 deletions
24
cpp/libs/ossrf_gstreamer_api/lib/src/receiver/st2110_30_receiver_plugin.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (C) 2024 Advanced Media Workflow Association | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
#include "ossrf/gstreamer/api/receiver/receiver_plugin.h" | ||
#include "ossrf/gstreamer/api/receiver/receiver_configuration.h" | ||
|
||
namespace ossrf::gst::plugins | ||
{ | ||
bisect::expected<gst_receiver_plugin_uptr> | ||
create_gst_st2110_30_plugin(ossrf::gst::receiver::receiver_settings settings, | ||
ossrf::gst::receiver::audio_info_t format) noexcept; | ||
} |