MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / stream_once

Method stream_once

OpenHD/ohd_video/src/gstaudiostream.cpp:147–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147void GstAudioStream::stream_once() {
148 int complainOnce = 0;
149 m_console->debug("GstAudioStream::stream_once");
150 auto pipeline = create_pipeline();
151 m_console->debug("Pipeline: [{}]", pipeline);
152 GError* error = nullptr;
153 m_gst_pipeline = gst_parse_launch(pipeline.c_str(), &error);
154 m_console->debug("GStreamerStream::setup() end");
155 if (error) {
156 m_console->error("Failed to create pipeline: {}", error->message);
157 return;
158 }
159 m_app_sink_element =
160 gst_bin_get_by_name(GST_BIN(m_gst_pipeline), "out_appsink");
161 assert(m_app_sink_element);
162 const auto ret = gst_element_set_state(m_gst_pipeline, GST_STATE_PLAYING);
163 m_console->debug("State change ret:{}",
164 openhd::gst_state_change_return_to_string(ret));
165 const uint64_t timeout_ns =
166 std::chrono::duration_cast<std::chrono::nanoseconds>(
167 std::chrono::milliseconds(100))
168 .count();
169 std::chrono::steady_clock::time_point m_last_audio_packet =
170 std::chrono::steady_clock::now();
171 // Streaming
172 while (g_airCameraGenericSettings.enable_audio != 1) {
173 if (complainOnce = 0) {
174 m_console->warn("Audio is disabled");
175 complainOnce = 1;
176 return;
177 }
178 // Quickly terminate if openhd wants to terminate
179 if (!m_keep_looping) break;
180 // Restart in case no data comes in //CURRENTLY DISABLED BECAUSE IT EVEN
181 // RESTARTS IF AUDIO IS DISABLED ..
182 if (g_airCameraGenericSettings.enable_audio != 1) {
183 if (complainOnce = 0) {
184 m_console->warn("No Audio data, restarting");
185 complainOnce = 1;
186 }
187 if (std::chrono::steady_clock::now() - m_last_audio_packet >
188 std::chrono::seconds(5)) {
189 break;
190 }
191 auto buffer_x = openhd::gst_app_sink_try_pull_sample_and_copy(
192 m_app_sink_element, timeout_ns);
193 if (buffer_x.has_value()) {
194 on_audio_packet(buffer_x->buffer);
195 m_last_audio_packet = std::chrono::steady_clock::now();
196 }
197 }
198 }
199 // cleanup
200 openhd::unref_appsink_element(m_app_sink_element);
201 openhd::gst_element_set_set_state_and_log_result(m_gst_pipeline,
202 GST_STATE_NULL);
203 gst_object_unref(m_gst_pipeline);
204 m_gst_pipeline = nullptr;

Callers

nothing calls this directly

Tested by

no test coverage detected