Skylicht Engine
Loading...
Searching...
No Matches
IStream.h
1/*
2!@
3MIT License
4
5Copyright (c) 2012 - 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#ifndef _SKYLICHTAUDIO_ISTREAM_H_
26#define _SKYLICHTAUDIO_ISTREAM_H_
27
28#include "SkylichtAudioAPI.h"
29
30namespace Skylicht
31{
32 namespace Audio
33 {
39 {
40 public:
50 public:
51 virtual ~IStreamCursor()
52 {
53 }
54
61 virtual int seek(int pos, EOrigin origin) = 0;
62
67 virtual int tell() = 0;
68
75 virtual int read(unsigned char* buff, int len) = 0;
76
81 virtual bool endOfStream() = 0;
82
87 virtual int size() = 0;
88
94 virtual bool readyReadData(int len) = 0;
95
99 virtual void trim() {}
100 };
101
106 class IStream
107 {
108 protected:
109 int m_referenceCount;
110
111 // the sampleRate & channel for stream recoder
112 int m_sampleRate;
113 int m_channels;
114
115 public:
116 IStream()
117 {
118 m_referenceCount = 1;
119 m_channels = 2;
120 m_sampleRate = 0;
121 }
122
123 virtual ~IStream()
124 {
125 }
126
132
136 virtual void grab()
137 {
138 m_referenceCount++;
139 }
140
145 virtual bool drop()
146 {
147 m_referenceCount--;
148 if (m_referenceCount <= 0)
149 {
150 delete this;
151 return true;
152 }
153 return false;
154 }
155
161 {
162 return m_sampleRate;
163 }
164
170 {
171 return m_channels;
172 }
173
179 void setStreamAudio(int sampleRate, int channels)
180 {
181 m_sampleRate = sampleRate;
182 m_channels = channels;
183 }
184
190 virtual void uploadData(unsigned char* buffer, int size)
191 {
192
193 }
194
198 virtual void stopStream()
199 {
200
201 }
202 };
203 }
204}
205
206#endif
Interface for a stream cursor, providing seek and read operations on an audio stream.
Definition IStream.h:39
virtual bool readyReadData(int len)=0
Check if a certain amount of data is ready to be read.
virtual bool endOfStream()=0
Check if the cursor is at the end of the stream.
EOrigin
Origin for seek operations.
Definition IStream.h:45
@ OriginCurrent
Seek from the current position.
Definition IStream.h:47
@ OriginEnd
Seek from the end of the stream.
Definition IStream.h:48
@ OriginStart
Seek from the beginning of the stream.
Definition IStream.h:46
virtual int seek(int pos, EOrigin origin)=0
Move the cursor position.
virtual int size()=0
Get total size of the stream.
virtual int tell()=0
Get current cursor position.
virtual void trim()
Trim read data from the stream (used in dynamic streams).
Definition IStream.h:99
virtual int read(unsigned char *buff, int len)=0
Read data from the stream.
virtual IStreamCursor * createCursor()=0
Create a new cursor for this stream.
int getChannels()
Get number of channels (for recorder/procedural streams).
Definition IStream.h:169
virtual void grab()
Increment reference count.
Definition IStream.h:136
virtual bool drop()
Decrement reference count and delete if zero.
Definition IStream.h:145
int getSampleRate()
Get expected sample rate (for recorder/procedural streams).
Definition IStream.h:160
virtual void uploadData(unsigned char *buffer, int size)
Upload new data to the stream (used in online/dynamic streams).
Definition IStream.h:190
void setStreamAudio(int sampleRate, int channels)
Set stream audio properties.
Definition IStream.h:179
virtual void stopStream()
Stop the stream and clear buffers.
Definition IStream.h:198
Handles all core audio functionality.
Definition AudioDebugLog.h:31
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29