• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GST_AUDIO_CAPTURE_SRC_H
17 #define GST_AUDIO_CAPTURE_SRC_H
18 
19 #include <memory>
20 #include <gst/base/gstpushsrc.h>
21 #include "audio_capture.h"
22 #include "common_utils.h"
23 #include "watchdog.h"
24 
25 namespace OHOS {
26 namespace Media {
27 class AudioManager : public OHOS::Media::WatchDog, public NoCopyable {
28 public:
AudioManager(GstPushSrc & owner,uint32_t timeoutMs)29     explicit AudioManager(GstPushSrc &owner, uint32_t timeoutMs) : WatchDog(timeoutMs), owner_(owner) {}
30     ~AudioManager() = default;
31 
32     void Alarm() override;
33 private:
34     GstPushSrc &owner_;
35 };
36 } // namespace Media
37 } // namespace OHOS
38 
39 G_BEGIN_DECLS
40 
41 #define GST_TYPE_AUDIO_CAPTURE_SRC \
42     (gst_audio_capture_src_get_type())
43 #define GST_AUDIO_CAPTURE_SRC(obj) \
44     (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AUDIO_CAPTURE_SRC, GstAudioCaptureSrc))
45 #define GST_FD_SRC_CLASS(klass) \
46     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AUDIO_CAPTURE_SRC, GstAudioCaptureSrcClass))
47 #define GST_IS_AUDIO_CAPTURE_SRC(obj) \
48     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AUDIO_CAPTURE_SRC))
49 #define GST_IS_AUDIO_CAPTURE_SRC_CLASS(klass) \
50     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AUDIO_CAPTURE_SRC))
51 
52 /**
53  * GstAudioCaptureSrc:
54  *
55  * Opaque #GstAudioCaptureSrc data structure.
56  */
57 struct _GstAudioCaptureSrc {
58     GstPushSrc element;
59 
60     /* private */
61     AudioStreamType stream_type;
62     AudioSourceType source_type;
63     std::unique_ptr<OHOS::Media::AudioCapture> audio_capture;
64     std::shared_ptr<OHOS::Media::AudioManager> audio_mgr;
65     GstCaps *src_caps;
66     guint32 bitrate;
67     guint32 channels;
68     guint32 sample_rate;
69     gboolean is_start;
70     gboolean need_caps_info;
71     guint32 token_id;
72     gint32 appuid;
73     gint32 apppid;
74     gboolean bypass_audio;
75     gboolean input_detection;
76 };
77 
78 struct _GstAudioCaptureSrcClass {
79     GstPushSrcClass parent_class;
80 };
81 
82 using GstAudioCaptureSrc = struct _GstAudioCaptureSrc;
83 using GstAudioCaptureSrcClass = struct _GstAudioCaptureSrcClass;
84 
85 
86 #define CHECK_AND_BREAK_REP_ERR(cond, src, fmt, ...)   \
87     do {                                               \
88         if (!(cond)) {                                 \
89             GST_ELEMENT_ERROR (src, CORE, STATE_CHANGE,         \
90                 (fmt, ##__VA_ARGS__), (fmt, ##__VA_ARGS__));    \
91             break;                                     \
92         }                                              \
93     } while (0)
94 
95 G_GNUC_INTERNAL GType gst_audio_capture_src_get_type(void);
96 
97 G_END_DECLS
98 
99 #endif /* GST_AUDIO_CAPTURE_SRC_H */
100