GStreamer Video Analytics (GVA) Plugin
|
Go to the documentation of this file.
20 #include <gst/audio/audio.h>
21 #include <gst/audio/gstaudiometa.h>
22 #include <gst/gstbuffer.h>
53 std::unique_ptr<GstAudioInfo, std::function<void(GstAudioInfo *)>>
info;
65 throw std::invalid_argument(
"GVA::AudioFrame: buffer or info nullptr");
75 if (not
buffer or not caps) {
76 throw std::invalid_argument(
"GVA::AudioFrame: buffer or caps nullptr");
78 info = std::unique_ptr<GstAudioInfo, std::function<void(GstAudioInfo *)>>(gst_audio_info_new(),
80 if (!gst_audio_info_from_caps(
info.get(), caps)) {
81 throw std::runtime_error(
"GVA::AudioFrame: gst_audio_info_from_caps failed");
93 throw std::invalid_argument(
"GVA::AudioFrame: buffer is nullptr");
97 throw std::logic_error(
"GVA::AudioFrame: audio_meta() is nullptr");
99 info = std::unique_ptr<GstAudioInfo, std::function<void(GstAudioInfo *)>>(gst_audio_info_new(),
100 gst_audio_info_free);
102 throw std::logic_error(
"GVA::AudioFrame: gst_audio_info_new() failed");
104 memcpy(
info.get(), &meta->info,
sizeof(meta->info));
112 return gst_buffer_get_audio_meta(
buffer);
135 const std::vector<AudioEvent>
events()
const {
144 return get_tensors();
152 return get_tensors();
160 std::vector<std::string> json_messages;
161 GstGVAJSONMeta *meta = NULL;
162 gpointer state = NULL;
163 GType meta_api_type = g_type_from_name(GVA_JSON_META_API_NAME);
164 while ((meta = (GstGVAJSONMeta *)gst_buffer_iterate_meta_filtered(
buffer, &state, meta_api_type))) {
165 json_messages.emplace_back(meta->message);
167 return json_messages;
178 AudioEvent add_event(
long start_time,
long end_time, std::string label = std::string(),
double confidence = 0.0) {
183 GstStructure *detection = gst_structure_new(
"detection",
"start_timestamp", G_TYPE_LONG, start_time,
184 "end_timestamp", G_TYPE_LONG, end_time, NULL);
186 gst_structure_set(detection,
"confidence", G_TYPE_DOUBLE, confidence, NULL);
188 gst_gva_audio_event_meta_add_param(meta, detection);
198 const GstMetaInfo *meta_info = gst_meta_get_info(GVA_TENSOR_META_IMPL_NAME);
200 if (!gst_buffer_is_writable(
buffer))
201 throw std::runtime_error(
"Buffer is not writable.");
213 const GstMetaInfo *meta_info = gst_meta_get_info(GVA_JSON_META_IMPL_NAME);
215 if (!gst_buffer_is_writable(
buffer))
216 throw std::runtime_error(
"Buffer is not writable.");
218 GstGVAJSONMeta *json_meta = (GstGVAJSONMeta *)gst_buffer_add_meta(
buffer, meta_info, NULL);
219 json_meta->message = g_strdup(message.c_str());
227 if (!gst_buffer_is_writable(
buffer))
228 throw std::runtime_error(
"Buffer is not writable.");
230 if (!gst_buffer_remove_meta(
buffer, (GstMeta *)event.
_meta())) {
231 throw std::out_of_range(
"GVA::AudioFrame: AudioEvent doesn't belong to this frame");
241 gpointer state = NULL;
242 while ((meta = GST_GVA_TENSOR_META_ITERATE(
buffer, &state))) {
244 if (!gst_buffer_is_writable(
buffer))
245 throw std::runtime_error(
"Buffer is not writable.");
247 if (gst_buffer_remove_meta(
buffer, (GstMeta *)meta))
251 throw std::out_of_range(
"GVA::AudioFrame: Tensor doesn't belong to this frame");
255 std::vector<AudioEvent> get_events()
const {
256 std::vector<AudioEvent>
events;
257 GstMeta *meta = NULL;
258 gpointer state = NULL;
260 while ((meta = gst_buffer_iterate_meta_filtered(
buffer, &state, GST_GVA_AUDIO_EVENT_META_API_TYPE)))
265 std::vector<Tensor> get_tensors()
const {
268 gpointer state = NULL;
269 GType meta_api_type = g_type_from_name(
"GstGVATensorMetaAPI");
std::unique_ptr< GstAudioInfo, std::function< void(GstAudioInfo *)> > info
GstAudioInfo containing actual audio information for this AudioFrame.
Definition: audio_frame.h:53
const std::vector< AudioEvent > events() const
Get AudioEvent objects attached to AudioFrame.
Definition: audio_frame.h:135
GstGVAAudioEventMeta * _meta() const
Internal function, don't use or use with caution.
Definition: audio_event.h:156
std::vector< std::string > messages()
Get messages attached to this AudioFrame.
Definition: audio_frame.h:159
void remove_event(const AudioEvent &event)
Remove AudioEvent.
Definition: audio_frame.h:226
void remove_tensor(const Tensor &tensor)
Remove Tensor.
Definition: audio_frame.h:239
This file contains GVA::AudioEvent class to control audio event for particular GVA::AudioFrame with G...
AudioEvent add_event(long start_time, long end_time, std::string label=std::string(), double confidence=0.0)
Attach AudioEvent to this AudioFrame. This function takes ownership of event_tensor,...
Definition: audio_frame.h:178
GstBuffer * buffer
GstBuffer with inference results metadata attached (Gstreamer pipeline's GstBuffer,...
Definition: audio_frame.h:48
This class represents audio frame - object for working with AudioEvent and Tensor objects which belon...
Definition: audio_frame.h:42
std::vector< Tensor > tensors()
Get Tensor objects attached to AudioFrame.
Definition: audio_frame.h:143
GstAudioInfo * audio_info()
Get GstAudioInfo of this AudioFrame. This is preferrable way of getting audio information.
Definition: audio_frame.h:119
const std::vector< Tensor > tensors() const
Get Tensor objects attached to AudioFrame.
Definition: audio_frame.h:151
GstAudioMeta * audio_meta()
Get audio metadata of buffer.
Definition: audio_frame.h:111
GstStructure * _structure
ptr to GstStructure that contains all tensor (inference results) data & info.
Definition: tensor.h:358
void add_message(const std::string &message)
Attach message to this AudioFrame.
Definition: audio_frame.h:212
This class represents tensor - map-like storage for inference result information, such as output blob...
Definition: tensor.h:38
AudioFrame(GstBuffer *buffer, const GstCaps *caps)
Construct AudioFrame instance from GstBuffer and GstCaps.
Definition: audio_frame.h:74
AudioFrame(GstBuffer *buffer, GstAudioInfo *info)
Construct AudioFrame instance from GstBuffer and GstAudioInfo. This is preferred way of creating Audi...
Definition: audio_frame.h:62
Tensor add_tensor()
Attach empty Tensor to this AudioFrame.
Definition: audio_frame.h:197
This class represents audio event - object describing audio event detection result (segment) and cont...
Definition: audio_event.h:45
AudioFrame(GstBuffer *buffer)
Construct AudioFrame instance from GstBuffer. Audio information will be obtained from buffer....
Definition: audio_frame.h:91
std::vector< AudioEvent > events()
Get AudioEvent objects attached to AudioFrame.
Definition: audio_frame.h:127