Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
iframe_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roc 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_audio/iframe_encoder.h
10 //! @brief Audio frame encoder interface.
11 
12 #ifndef ROC_AUDIO_IFRAME_ENCODER_H_
13 #define ROC_AUDIO_IFRAME_ENCODER_H_
14 
15 #include "roc_audio/units.h"
16 #include "roc_core/stddefs.h"
17 #include "roc_packet/packet.h"
18 #include "roc_packet/units.h"
19 
20 namespace roc {
21 namespace audio {
22 
23 //! Audio frame encoder interface.
25 public:
26  virtual ~IFrameEncoder();
27 
28  //! Get encoded frame size for given number of samples per channel.
29  virtual size_t encoded_size(size_t num_samples) const = 0;
30 
31  //! Start encoding a new frame.
32  //!
33  //! @remarks
34  //! After this call, write() will store samples to the given @p frame_data
35  //! until @p frame_size bytes are written or end() is called.
36  virtual void begin(void* frame_data, size_t frame_size) = 0;
37 
38  //! Write samples into current frame.
39  //!
40  //! @b Parameters
41  //! - @p samples - samples to be encoded
42  //! - @p n_samples - number of samples to be encoded per channel
43  //! - @p channels - channel mask of the samples to be encoded
44  //!
45  //! @remarks
46  //! Encodes samples and writes to the current frame.
47  //!
48  //! @returns
49  //! number of samples encoded per channel. The returned value can be fewer than
50  //! @p n_samples if the frame is full and no more samples can be written to it.
51  //!
52  //! @pre
53  //! This method may be called only between begin() and end() calls.
54  //!
55  //! @note
56  //! Encoded and decoded channel masks may differ. If the provided samples have
57  //! extra channels, they are ignored. If they don't have some channels, these
58  //! channels are filled with zeros.
59  virtual size_t
60  write(const sample_t* samples, size_t n_samples, packet::channel_mask_t channels) = 0;
61 
62  //! Finish encoding current frame.
63  //!
64  //! @remarks
65  //! After this call, the frame is fully encoded and no more samples will be
66  //! written to the frame. A new frame should be started by calling begin().
67  virtual void end() = 0;
68 };
69 
70 } // namespace audio
71 } // namespace roc
72 
73 #endif // ROC_AUDIO_IFRAME_ENCODER_H_
virtual size_t write(const sample_t *samples, size_t n_samples, packet::channel_mask_t channels)=0
Write samples into current frame.
Various units used in audio processing.
Root namespace.
virtual size_t encoded_size(size_t num_samples) const =0
Get encoded frame size for given number of samples per channel.
float sample_t
Audio sample.
Definition: units.h:21
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition: units.h:77
Commonly used types and functions.
Audio frame encoder interface.
virtual void begin(void *frame_data, size_t frame_size)=0
Start encoding a new frame.
virtual void end()=0
Finish encoding current frame.
Various units used in packets.
Packet.