Ring Daemon 16.0.0
Loading...
Searching...
No Matches
audio_receive_thread.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "audio_format.h"
20#include "media/media_buffer.h"
21#include "media/media_device.h"
22#include "media/media_codec.h"
23#include "noncopyable.h"
24#include "observer.h"
25#include "media/socket_pair.h"
26#include "threadloop.h"
27
28#include <functional>
29#include <sstream>
30
31namespace jami {
32
33class MediaDecoder;
34class MediaIOHandle;
35struct MediaStream;
36class RingBuffer;
37
38class AudioReceiveThread : public Observable<std::shared_ptr<MediaFrame>>
39{
40public:
41 AudioReceiveThread(const std::string& streamId,
42 const AudioFormat& format,
43 const std::string& sdp,
44 const uint16_t mtu);
46
47 MediaStream getInfo() const;
48
50 void startReceiver();
51 void stopReceiver();
52
53 void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb)
54 {
55 onSuccessfulSetup_ = cb;
56 }
57
58 void setRecorderCallback(const std::function<void(const MediaStream& ms)>& cb);
59
60private:
62
63 static constexpr auto SDP_FILENAME = "dummyFilename";
64
65 static int interruptCb(void* ctx);
66 static int readFunction(void* opaque, uint8_t* buf, int buf_size);
67
68 /*-----------------------------------------------------------------*/
69 /* These variables should be used in thread (i.e. process()) only! */
70 /*-----------------------------------------------------------------*/
71 const std::string streamId_;
72 const AudioFormat& format_;
73
74 DeviceParams args_;
75
76 std::istringstream stream_;
77 mutable std::mutex mutex_;
78 std::unique_ptr<MediaDecoder> audioDecoder_;
79 std::unique_ptr<MediaIOHandle> sdpContext_;
80 std::unique_ptr<MediaIOHandle> demuxContext_;
81
82 std::shared_ptr<RingBuffer> ringbuffer_;
83
84 uint16_t mtu_;
85
86 ThreadLoop loop_;
87 bool setup();
88 void process();
89 void cleanup();
90
91 std::function<void(MediaType, bool)> onSuccessfulSetup_;
92 std::function<void(const MediaStream& ms)> recorderCallback_;
93};
94
95} // namespace jami
void setSuccessfulSetupCb(const std::function< void(MediaType, bool)> &cb)
void addIOContext(SocketPair &socketPair)
void setRecorderCallback(const std::function< void(const MediaStream &ms)> &cb)
void emitSignal(Args... args)
Definition ring_signal.h:64
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30
Structure to hold sample rate and channel number associated with audio data.
DeviceParams Parameters used by MediaDecoder and MediaEncoder to open a LibAV device/stream.