Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
sox_source.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_sndio/target_sox/roc_sndio/sox_source.h
10//! @brief SoX source.
11
12#ifndef ROC_SNDIO_SOX_SOURCE_H_
13#define ROC_SNDIO_SOX_SOURCE_H_
14
15#include <sox.h>
16
18#include "roc_core/array.h"
19#include "roc_core/iallocator.h"
21#include "roc_core/stddefs.h"
23#include "roc_packet/units.h"
24#include "roc_sndio/config.h"
25#include "roc_sndio/isource.h"
26
27namespace roc {
28namespace sndio {
29
30//! SoX source.
31//! @remarks
32//! Reads samples from input file or device.
33//! Supports multiple drivers for different file types and audio systems.
34class SoxSource : public ISource, private core::NonCopyable<> {
35public:
36 //! Initialize.
37 SoxSource(core::IAllocator& allocator, const Config& config);
38
39 virtual ~SoxSource();
40
41 //! Check if the object was successfully constructed.
42 bool valid() const;
43
44 //! Open input file or device.
45 //!
46 //! @b Parameters
47 //! - @p driver is input driver name;
48 //! - @p path is input file or device name, "-" for stdin.
49 //!
50 //! @remarks
51 //! If @p driver or @p path are NULL, defaults are used.
52 bool open(const char* driver, const char* path);
53
54 //! Get sample specification of the source.
56
57 //! Get latency of the source.
59
60 //! Check if the source has own clock.
61 virtual bool has_clock() const;
62
63 //! Get current source state.
64 virtual State state() const;
65
66 //! Pause reading.
67 virtual void pause();
68
69 //! Resume paused reading.
70 virtual bool resume();
71
72 //! Restart reading from the beginning.
73 virtual bool restart();
74
75 //! Adjust source clock to match consumer clock.
76 virtual void reclock(packet::ntp_timestamp_t timestamp);
77
78 //! Read frame.
79 virtual bool read(audio::Frame&);
80
81private:
82 bool setup_names_(const char* driver, const char* path);
83 bool setup_buffer_();
84
85 bool open_();
86 void close_();
87
88 bool seek_(uint64_t offset);
89
90 core::StringBuffer<16> driver_name_;
91 core::StringBuffer<> input_name_;
92
94 size_t buffer_size_;
95 core::nanoseconds_t frame_length_;
96 audio::SampleSpec sample_spec_;
97
98 sox_format_t* input_;
99 sox_signalinfo_t in_signal_;
100
101 bool is_file_;
102 bool eof_;
103 bool paused_;
104 bool valid_;
105};
106
107} // namespace sndio
108} // namespace roc
109
110#endif // ROC_SNDIO_SOX_SOURCE_H_
Dynamic array.
Audio frame.
Definition frame.h:22
Sample stream specification. Defines sample rate and channel layout.
Definition sample_spec.h:24
Dynamic array.
Definition array.h:38
Memory allocator interface.
Definition iallocator.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Source interface.
Definition isource.h:23
State
Source state.
Definition isource.h:28
bool open(const char *driver, const char *path)
Open input file or device.
virtual void pause()
Pause reading.
virtual bool has_clock() const
Check if the source has own clock.
virtual bool restart()
Restart reading from the beginning.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the source.
virtual core::nanoseconds_t latency() const
Get latency of the source.
virtual bool read(audio::Frame &)
Read frame.
virtual State state() const
Get current source state.
SoxSource(core::IAllocator &allocator, const Config &config)
Initialize.
virtual void reclock(packet::ntp_timestamp_t timestamp)
Adjust source clock to match consumer clock.
virtual bool resume()
Resume paused reading.
bool valid() const
Check if the object was successfully constructed.
Memory allocator interface.
Source interface.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
uint64_t ntp_timestamp_t
NTP timestamp.
Definition units.h:91
Root namespace.
Non-copyable object.
Sink and source config.
Sample specifications.
Commonly used types and functions.
String buffer.
Sink and source config.
Definition config.h:23
Various units used in packets.