TDME2  1.9.200
PacketAudioStream.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
9 
11 
12 using std::string;
13 using std::to_string;
14 using std::vector;
15 
18 
19 void PacketAudioStream::rewind()
20 {
21  Console::println("PacketAudioStream::rewind(): Not supported!");
22 }
23 
25 {
26  if (initiated == true) return true;
27 
28  // check if underlying audio stream did initialize
29  if (AudioStream::initialize() == false) {
30  dispose();
31  return false;
32  }
33 
34  // success
35  initiated = true;
36  return true;
37 }
38 
40  if (byteBuffer->getPosition() == 0LL) return;
41  packets.emplace_back(byteBuffer->getPosition());
42  auto& packet = packets[packets.size() - 1];
43  // TODO: use memcpy or similar
44  for (auto i = 0LL; i < byteBuffer->getPosition(); i++) {
45  packet[i] = byteBuffer->get(i);
46  }
47 }
48 
50  // TODO: optimize me
51  while (data->getPosition() < data->getCapacity() && packets.empty() == false) {
52  data->put(packets[0][position++]);
53  if (position == packets[0].size()) {
54  position = 0LL;
55  packets.erase(packets.begin());
56  }
57  }
58 }
59 
61 {
62  if (initiated == false) return;
63 
64  // dispose audio stream
66 
67  //
68  initiated = false;
69 }
virtual void dispose() override
Dispose this entity from OpenAL.
virtual bool initialize() override
Initiates this OpenAL entity to OpenAl.
unique_ptr< ByteBuffer > data
Definition: AudioStream.h:34
void dispose() override
Dispose this entity from OpenAL.
vector< vector< uint8_t > > packets
bool initialize() override
Initiates this OpenAL entity to OpenAl.
void addPacket(ByteBuffer *byteBuffer)
Add audio packet.
void fillBuffer(ByteBuffer *data) override
Fill buffer.
uint8_t get(int64_t position) const
Definition: Buffer.h:107
virtual int64_t getPosition() const
Definition: Buffer.h:89
Byte buffer class.
Definition: ByteBuffer.h:27
Console class.
Definition: Console.h:29