summaryrefslogtreecommitdiff
path: root/src/audio/stream_event.cpp
blob: d7533ea2b27cdba1141957089bea057b418bd765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#include "stream_event.hpp"
#include <cstddef>
#include <memory>
#include "arena.hpp"
#include "stream_info.hpp"

namespace audio {

auto StreamEvent::CreateStreamInfo(QueueHandle_t source,
                                   const StreamInfo& payload) -> StreamEvent* {
  auto event = new StreamEvent;
  event->tag = StreamEvent::STREAM_INFO;
  event->source = source;
  event->stream_info = new StreamInfo(payload);
  return event;
}

auto StreamEvent::CreateArenaChunk(QueueHandle_t source, memory::ArenaPtr ptr)
    -> StreamEvent* {
  auto event = new StreamEvent;
  event->tag = StreamEvent::ARENA_CHUNK;
  event->source = source;
  event->arena_chunk = ptr;

  return event;
}

auto StreamEvent::CreateChunkNotification(QueueHandle_t source)
    -> StreamEvent* {
  auto event = new StreamEvent;
  event->tag = StreamEvent::CHUNK_NOTIFICATION;
  event->source = source;
  return event;
}

auto StreamEvent::CreateEndOfStream(QueueHandle_t source) -> StreamEvent* {
  auto event = new StreamEvent;
  event->tag = StreamEvent::END_OF_STREAM;
  event->source = source;
  return event;
}

auto StreamEvent::CreateLogStatus() -> StreamEvent* {
  auto event = new StreamEvent;
  event->tag = StreamEvent::LOG_STATUS;
  return event;
}

StreamEvent::StreamEvent() : tag(StreamEvent::UNINITIALISED) {}

StreamEvent::~StreamEvent() {
  switch (tag) {
    case UNINITIALISED:
      break;
    case STREAM_INFO:
      delete stream_info;
      break;
    case ARENA_CHUNK:
      arena_chunk.owner->Return(arena_chunk);
      break;
    case CHUNK_NOTIFICATION:
      break;
    case END_OF_STREAM:
      break;
    case LOG_STATUS:
      break;
  }
}

StreamEvent::StreamEvent(StreamEvent&& other) {
  tag = other.tag;
  source = other.source;
  switch (tag) {
    case UNINITIALISED:
      break;
    case STREAM_INFO:
      stream_info = other.stream_info;
      other.stream_info = nullptr;
      break;
    case ARENA_CHUNK:
      arena_chunk = other.arena_chunk;
      other.arena_chunk = {
          .owner = nullptr, .start = nullptr, .size = 0, .used_size = 0};
      break;
    case CHUNK_NOTIFICATION:
      break;
    case END_OF_STREAM:
      break;
    case LOG_STATUS:
      break;
  }
  other.tag = StreamEvent::UNINITIALISED;
}

}  // namespace audio