Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
transcoder_sink.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_pipeline/transcoder_sink.h
10 //! @brief Transcoder sink pipeline.
11 
12 #ifndef ROC_PIPELINE_TRANSCODER_SINK_H_
13 #define ROC_PIPELINE_TRANSCODER_SINK_H_
14 
17 #include "roc_audio/iresampler.h"
18 #include "roc_audio/null_writer.h"
21 #include "roc_core/ipool.h"
22 #include "roc_core/optional.h"
23 #include "roc_core/scoped_ptr.h"
24 #include "roc_pipeline/config.h"
25 #include "roc_sndio/isink.h"
26 
27 namespace roc {
28 namespace pipeline {
29 
30 //! Transcoder sink pipeline.
31 //! @remarks
32 //! - input: frames
33 //! - output: frames
34 class TranscoderSink : public sndio::ISink, public core::NonCopyable<> {
35 public:
36  //! Initialize.
38  audio::IFrameWriter* output_writer,
39  core::IPool& buffer_pool,
40  core::IArena& arena);
41 
42  //! Check if the pipeline was successfully constructed.
43  bool is_valid();
44 
45  //! Cast IDevice to ISink.
46  virtual sndio::ISink* to_sink();
47 
48  //! Cast IDevice to ISink.
50 
51  //! Get device type.
52  virtual sndio::DeviceType type() const;
53 
54  //! Get device state.
55  virtual sndio::DeviceState state() const;
56 
57  //! Pause reading.
58  virtual void pause();
59 
60  //! Resume paused reading.
61  virtual bool resume();
62 
63  //! Restart reading from the beginning.
64  virtual bool restart();
65 
66  //! Get sample specification of the sink.
67  virtual audio::SampleSpec sample_spec() const;
68 
69  //! Get latency of the sink.
70  virtual core::nanoseconds_t latency() const;
71 
72  //! Check if the sink supports latency reports.
73  virtual bool has_latency() const;
74 
75  //! Check if the sink has own clock.
76  virtual bool has_clock() const;
77 
78  //! Write audio frame.
79  virtual void write(audio::Frame& frame);
80 
81 private:
82  audio::FrameFactory frame_factory_;
83 
84  audio::NullWriter null_writer_;
85 
86  core::Optional<audio::ChannelMapperWriter> channel_mapper_writer_;
87 
90 
92 
93  audio::IFrameWriter* frame_writer_;
94 
95  TranscoderConfig config_;
96 
97  bool valid_;
98 };
99 
100 } // namespace pipeline
101 } // namespace roc
102 
103 #endif // ROC_PIPELINE_TRANSCODER_SINK_H_
Channel mapper writer.
Audio frame.
Definition: frame.h:25
Frame writer interface.
Definition: iframe_writer.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 sink pipeline.
virtual sndio::DeviceType type() const
Get device type.
virtual sndio::ISink * to_sink()
Cast IDevice to ISink.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
bool is_valid()
Check if the pipeline was successfully constructed.
virtual core::nanoseconds_t latency() const
Get latency of the sink.
virtual void pause()
Pause reading.
virtual bool resume()
Resume paused reading.
virtual bool restart()
Restart reading from the beginning.
virtual void write(audio::Frame &frame)
Write audio frame.
virtual sndio::ISource * to_source()
Cast IDevice to ISink.
virtual bool has_clock() const
Check if the sink has own clock.
virtual sndio::DeviceState state() const
Get device state.
TranscoderSink(const TranscoderConfig &config, audio::IFrameWriter *output_writer, core::IPool &buffer_pool, core::IArena &arena)
Initialize.
virtual bool has_latency() const
Check if the sink supports latency reports.
Sink interface.
Definition: isink.h:22
Source interface.
Definition: isource.h:23
Frame factory.
Memory pool interface.
Audio resampler interface.
Sink interface.
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.
Null writer.
Optionally constructed object.
Profiling writer.
Pipeline config.
Unique ownrship pointer.
Converter parameters.
Definition: config.h:214