Ring Daemon
Loading...
Searching...
No Matches
audio_receive_thread.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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) { onSuccessfulSetup_ = cb; }
54
55 void setRecorderCallback(const std::function<void(const MediaStream& ms)>& cb);
56
57private:
59
60 static constexpr auto SDP_FILENAME = "dummyFilename";
61
62 static int interruptCb(void* ctx);
63 static int readFunction(void* opaque, uint8_t* buf, int buf_size);
64
65 /*-----------------------------------------------------------------*/
66 /* These variables should be used in thread (i.e. process()) only! */
67 /*-----------------------------------------------------------------*/
68 const std::string streamId_;
69 const AudioFormat& format_;
70
71 DeviceParams args_;
72
73 std::istringstream stream_;
74 mutable std::mutex mutex_;
75 std::unique_ptr<MediaDecoder> audioDecoder_;
76 std::unique_ptr<MediaIOHandle> sdpContext_;
77 std::unique_ptr<MediaIOHandle> demuxContext_;
78
79 std::shared_ptr<RingBuffer> ringbuffer_;
80
81 uint16_t mtu_;
82
83 ThreadLoop loop_;
84 bool setup();
85 void process();
86 void cleanup();
87
88 std::function<void(MediaType, bool)> onSuccessfulSetup_;
89 std::function<void(const MediaStream& ms)> recorderCallback_;
90};
91
92} // 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 jami_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.