Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
transcoder_source.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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_pipeline/transcoder_source.h
10 //! @brief Transcoder source pipeline.
11 
12 #ifndef ROC_PIPELINE_TRANSCODER_SOURCE_H_
13 #define ROC_PIPELINE_TRANSCODER_SOURCE_H_
14 
17 #include "roc_audio/iresampler.h"
20 #include "roc_core/ipool.h"
21 #include "roc_core/optional.h"
22 #include "roc_core/scoped_ptr.h"
23 #include "roc_pipeline/config.h"
24 #include "roc_sndio/isource.h"
25 
26 namespace roc {
27 namespace pipeline {
28 
29 //! Transcoder source pipeline.
30 //! @remarks
31 //! - input: frames
32 //! - output: frames
34 public:
35  //! Initialize.
37  sndio::ISource& input_source,
38  core::IPool& buffer_pool,
39  core::IArena& arena);
40 
41  //! Check if the pipeline was successfully constructed.
42  bool is_valid();
43 
44  //! Cast IDevice to ISink.
45  virtual sndio::ISink* to_sink();
46 
47  //! Cast IDevice to ISink.
49 
50  //! Get device type.
51  virtual sndio::DeviceType type() const;
52 
53  //! Get device state.
54  virtual sndio::DeviceState state() const;
55 
56  //! Pause reading.
57  virtual void pause();
58 
59  //! Resume paused reading.
60  virtual bool resume();
61 
62  //! Restart reading from the beginning.
63  virtual bool restart();
64 
65  //! Get sample specification of the source.
66  virtual audio::SampleSpec sample_spec() const;
67 
68  //! Get latency of the source.
69  virtual core::nanoseconds_t latency() const;
70 
71  //! Check if the source supports latency reports.
72  virtual bool has_latency() const;
73 
74  //! Check if the sink has own clock.
75  virtual bool has_clock() const;
76 
77  //! Adjust source clock to match consumer clock.
79 
80  //! Read frame.
81  virtual bool read(audio::Frame&);
82 
83 private:
84  audio::FrameFactory frame_factory_;
85 
86  core::Optional<audio::ChannelMapperReader> channel_mapper_reader_;
87 
90 
92 
93  sndio::ISource& input_source_;
94  audio::IFrameReader* frame_reader_;
95 
96  TranscoderConfig config_;
97 
98  bool valid_;
99 };
100 
101 } // namespace pipeline
102 } // namespace roc
103 
104 #endif // ROC_PIPELINE_TRANSCODER_SOURCE_H_
Channel mapper reader.
Audio frame.
Definition: frame.h:25
Frame reader interface.
Definition: iframe_reader.h:22
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:30
Memory arena interface.
Definition: iarena.h:23
Memory pool interface.
Definition: ipool.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Optionally constructed object.
Definition: optional.h:25
Shared ownership intrusive pointer.
Definition: shared_ptr.h:32
Transcoder source pipeline.
virtual sndio::DeviceState state() const
Get device state.
virtual void pause()
Pause reading.
virtual sndio::DeviceType type() const
Get device type.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the source.
virtual bool resume()
Resume paused reading.
virtual sndio::ISink * to_sink()
Cast IDevice to ISink.
bool is_valid()
Check if the pipeline was successfully constructed.
virtual core::nanoseconds_t latency() const
Get latency of the source.
virtual void reclock(core::nanoseconds_t timestamp)
Adjust source clock to match consumer clock.
virtual bool read(audio::Frame &)
Read frame.
virtual bool has_clock() const
Check if the sink has own clock.
virtual bool restart()
Restart reading from the beginning.
virtual bool has_latency() const
Check if the source supports latency reports.
virtual sndio::ISource * to_source()
Cast IDevice to ISink.
TranscoderSource(const TranscoderConfig &config, sndio::ISource &input_source, core::IPool &buffer_pool, core::IArena &arena)
Initialize.
Sink interface.
Definition: isink.h:22
Source interface.
Definition: isource.h:23
Frame factory.
Memory pool interface.
Audio resampler interface.
Source interface.
nanoseconds_t timestamp(clock_t clock)
Get current timestamp in nanoseconds.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
DeviceType
Device type.
Definition: device_type.h:19
DeviceState
Device state.
Definition: device_state.h:19
Root namespace.
Optionally constructed object.
Profiling reader.
Pipeline config.
Unique ownrship pointer.
Converter parameters.
Definition: config.h:214