NVIDIA DeepStream SDK API Reference

6.4 Release
gstnvstreammux_audio.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __GST_NVSTREAMMUX_AUDIO_H__
25 #define __GST_NVSTREAMMUX_AUDIO_H__
26 
27 #include "gstnvstreammux_impl.h"
28 #include "nvbufaudio.h"
29 
30 #define NVSTREAMMUX_BYTES_TO_AUDIOSAMPLESIZE(bytes, channels, bpf) \
31  ((bytes) / ( (channels) * (bpf)))
32 
33 #define NVSTREAMMUX_AUDIOSAMPLESIZE_TO_BYTES(samples, channels, bpf) \
34  ((samples) * (channels) * (bpf))
35 
36 
37 extern "C"
38 {
39 static void
40 audio_mem_buf_unref_callback (gpointer data);
41 }
42 
43 
50 {
51 
52  public :
53  GstAudioBatchBufferWrapper(GstNvStreamMux * mux, unsigned int size, bool is_raw) : NvDsBatchBufferWrapper(size) , is_raw(is_raw), mux(mux), api((GstElement*)mux)
54  {
55 
56  batch = malloc(sizeof(NvBufAudio));
57  memset (batch, 0 , sizeof(NvBufAudio));
58  ((NvBufAudio *)batch)->audioBuffers = (NvBufAudioParams *)malloc(sizeof(NvBufAudioParams) * size);
59  ((NvBufAudio *)batch)->numFilled = 0;
60  ((NvBufAudio *)batch)->batchSize = size;
61  if(!is_raw)
62  {
63  gst_buffer =
64  gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (NvBufAudio *)batch, sizeof (NvBufAudio),
65  0, sizeof (NvBufAudio), (void *)this, audio_mem_buf_unref_callback);
66  //gst_buffer_ref(gst_buffer);
67  }
68  else
69  {
70  raw_batch = gst_buffer_list_new_sized (size);
71  }
72  }
73 
74  void unref() override;
75  void reset_batch();
76  void dummy(){}
77  void copy_meta(unsigned int id, std::shared_ptr<BufferWrapper> src_buffer, unsigned int batch_id, unsigned int frame_number, unsigned int num_surfaces_per_frame, NvDsBatchMeta * dest_batch_meta, unsigned int source_id) override;
78  unsigned int copy_buf(std::shared_ptr<BufferWrapper> src, unsigned int pos) override;
79  bool push(SourcePad * src_pad, TimePoint current_play_start, NanoSecondsType accum_dur) override;
80  bool push(SourcePad * src_pad, unsigned long pts) override;
81  void unref_gst_bufs();
82 
83  GstBufferList *raw_batch;
85  bool is_raw;
87  std::vector<std::shared_ptr<GstBufferWrapper> > gst_in_bufs;
88 
89  private:
90 
91  unsigned int copy_buf_impl(std::shared_ptr<BufferWrapper> buf, unsigned int pos);
92 
93  private:
95 
96 };
97 
98 extern "C"
99 {
100 static void
102 {
103 
104  if(data != NULL)
105  {
107  batch->unref_gst_bufs();
108  delete batch;
109  }
110 
111 }
112 }
113 
114 
115 #endif
GstAudioBatchBufferWrapper::unref_gst_bufs
void unref_gst_bufs()
_GstNvStreamMux
Definition: gstnvstreammux.h:53
GstAudioBatchBufferWrapper::copy_buf
unsigned int copy_buf(std::shared_ptr< BufferWrapper > src, unsigned int pos) override
NvBufAudioParams
Definition: nvbufaudio.h:80
GstAudioBatchBufferWrapper::dummy
void dummy()
Definition: gstnvstreammux_audio.h:76
NvDsBatchBufferWrapper
Definition: nvstreammux_batch.h:119
GstCommonBufferAPI
Definition: gstnvstreammux_impl.h:43
audio_mem_buf_unref_callback
static void audio_mem_buf_unref_callback(gpointer data)
Definition: gstnvstreammux_audio.h:101
GstAudioBatchBufferWrapper::mux
GstNvStreamMux * mux
Definition: gstnvstreammux_audio.h:86
GstAudioBatchBufferWrapper::gst_buffer
GstBuffer * gst_buffer
Definition: gstnvstreammux_audio.h:84
SourcePad
Definition: nvstreammux_pads.h:151
NvBufAudio
Definition: nvbufaudio.h:107
GstAudioBatchBufferWrapper::reset_batch
void reset_batch()
BatchBufferWrapper::batch
void * batch
Definition: nvstreammux_batch.h:113
gstnvstreammux_impl.h
_NvDsBatchMeta
Holds information about a formed batch containing frames from different sources.
Definition: nvdsmeta.h:240
GstAudioBatchBufferWrapper::gst_in_bufs
std::vector< std::shared_ptr< GstBufferWrapper > > gst_in_bufs
Definition: gstnvstreammux_audio.h:87
nvbufaudio.h
GstAudioBatchBufferWrapper::raw_batch
GstBufferList * raw_batch
Definition: gstnvstreammux_audio.h:83
GstAudioBatchBufferWrapper::copy_meta
void copy_meta(unsigned int id, std::shared_ptr< BufferWrapper > src_buffer, unsigned int batch_id, unsigned int frame_number, unsigned int num_surfaces_per_frame, NvDsBatchMeta *dest_batch_meta, unsigned int source_id) override
NanoSecondsType
std::chrono::duration< double, std::nano > NanoSecondsType
Definition: nvstreammux_pads.h:33
GstBuffer
struct _GstBuffer GstBuffer
Definition: idatatype.h:19
GstAudioBatchBufferWrapper
The GStreamer wrapper code for NvDsBatchBufferWrapper which represent one batched buffer.
Definition: gstnvstreammux_audio.h:49
GstAudioBatchBufferWrapper::is_raw
bool is_raw
Definition: gstnvstreammux_audio.h:85
GstAudioBatchBufferWrapper::GstAudioBatchBufferWrapper
GstAudioBatchBufferWrapper(GstNvStreamMux *mux, unsigned int size, bool is_raw)
Definition: gstnvstreammux_audio.h:53
GstAudioBatchBufferWrapper::push
bool push(SourcePad *src_pad, TimePoint current_play_start, NanoSecondsType accum_dur) override
TimePoint
std::chrono::time_point< std::chrono::steady_clock, NanoSecondsType > TimePoint
Definition: nvstreammux_batch.h:48
GstAudioBatchBufferWrapper::unref
void unref() override