icecast_client.h
Go to the documentation of this file.
1 /**
2  * @file icecast_client.h
3  * @brief Icecast client
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.8
29  **/
30 
31 #ifndef _ICECAST_CLIENT_H
32 #define _ICECAST_CLIENT_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/socket.h"
37 
38 //Icecast client support
39 #ifndef ICECAST_CLIENT_SUPPORT
40  #define ICECAST_CLIENT_SUPPORT DISABLED
41 #elif (ICECAST_CLIENT_SUPPORT != ENABLED && ICECAST_CLIENT_SUPPORT != DISABLED)
42  #error ICECAST_CLIENT_SUPPORT parameter is not valid
43 #endif
44 
45 //Stack size required to run the Icecast client
46 #ifndef ICECAST_CLIENT_STACK_SIZE
47  #define ICECAST_CLIENT_STACK_SIZE 650
48 #elif (ICECAST_CLIENT_STACK_SIZE < 1)
49  #error ICECAST_CLIENT_STACK_SIZE parameter is not valid
50 #endif
51 
52 //Priority at which the Icecast client should run
53 #ifndef ICECAST_CLIENT_PRIORITY
54  #define ICECAST_CLIENT_PRIORITY OS_TASK_PRIORITY_NORMAL
55 #endif
56 
57 //Maximum time the Icecast client will wait before closing the connection
58 #ifndef ICECAST_CLIENT_TIMEOUT
59  #define ICECAST_CLIENT_TIMEOUT 10000
60 #elif (ICECAST_CLIENT_TIMEOUT < 1000)
61  #error ICECAST_CLIENT_TIMEOUT parameter is not valid
62 #endif
63 
64 //Recovery delay
65 #ifndef ICECAST_RECOVERY_DELAY
66  #define ICECAST_RECOVERY_DELAY 5000
67 #elif (ICECAST_RECOVERY_DELAY < 1000)
68  #error ICECAST_RECOVERY_DELAY parameter is not valid
69 #endif
70 
71 //Maximum length of the server name
72 #ifndef ICECAST_SERVER_NAME_MAX_LEN
73  #define ICECAST_SERVER_NAME_MAX_LEN 48
74 #elif (ICECAST_SERVER_NAME_MAX_LEN < 1)
75  #error ICECAST_SERVER_NAME_MAX_LEN parameter is not valid
76 #endif
77 
78 //Maxmimum length of the requested resource
79 #ifndef ICECAST_RESOURCE_MAX_LEN
80  #define ICECAST_RESOURCE_MAX_LEN 32
81 #elif (ICECAST_RESOURCE_MAX_LEN < 1)
82  #error ICECAST_RESOURCE_MAX_LEN parameter is not valid
83 #endif
84 
85 //Maximum size of metadata blocks
86 #ifndef ICECAST_CLIENT_METADATA_MAX_SIZE
87  #define ICECAST_CLIENT_METADATA_MAX_SIZE 512
88 #elif (ICECAST_CLIENT_METADATA_MAX_SIZE < 128)
89  #error ICECAST_CLIENT_METADATA_MAX_SIZE parameter is not valid
90 #endif
91 
92 //C++ guard
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 
98 /**
99  * @brief Icecast client settings
100  **/
101 
102 typedef struct
103 {
104  NetInterface *interface; ///<Underlying network interface
105  char_t serverName[ICECAST_SERVER_NAME_MAX_LEN]; ///<Icecast server name
106  uint16_t serverPort; ///<Icecast server port
107  char_t resource[ICECAST_RESOURCE_MAX_LEN]; ///<Requested resource
108  size_t bufferSize; ///<Streaming buffer size
110 
111 
112 /**
113  * @brief Icecast client context
114  **/
115 
116 typedef struct
117 {
118  IcecastClientSettings settings; ///<User settings
119  OsMutex mutex; ///<Mutex protecting critical sections
120  OsEvent writeEvent; ///<This event tells whether the buffer is writable
121  OsEvent readEvent; ///<This event tells whether the buffer is readable
122  Socket *socket; ///<Underlying socket
123  size_t blockSize; ///<Number of data bytes between subsequent metadata blocks
124  uint8_t *streamBuffer; ///<Streaming buffer
125  size_t bufferSize; ///<Streaming buffer size
126  size_t bufferLength; ///<Streaming buffer length
127  size_t writeIndex; ///<Current write index within the buffer
128  size_t readIndex; ///<Current read index within the buffer
129  size_t totalLength; ///<Total number of bytes that have been received
130  char_t buffer[ICECAST_CLIENT_METADATA_MAX_SIZE]; ///<Memory buffer for input/output operations
131  char_t metadata[ICECAST_CLIENT_METADATA_MAX_SIZE]; ///<Metadata information
132  size_t metadataLength; ///<Length of the metadata
134 
135 
136 //Icecast related functions
138 
140  const IcecastClientSettings *settings);
141 
143 
145  uint8_t *data, size_t size, size_t *length, systime_t timeout);
146 
148  char_t *metadata, size_t size, size_t *length);
149 
150 void icecastClientTask(void *param);
151 
154 
155 //C++ guard
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif
size_t metadataLength
Length of the metadata.
uint8_t length
Definition: coap_common.h:190
size_t bufferLength
Streaming buffer length.
Icecast client context.
error_t icecastClientReadStream(IcecastClientContext *context, uint8_t *data, size_t size, size_t *length, systime_t timeout)
Copy data from input stream.
size_t writeIndex
Current write index within the buffer.
uint8_t data[]
Definition: ethernet.h:209
Icecast client settings.
#define ICECAST_RESOURCE_MAX_LEN
Event object.
void icecastClientTask(void *param)
Icecast client task.
size_t totalLength
Total number of bytes that have been received.
error_t icecastClientReadMetadata(IcecastClientContext *context, char_t *metadata, size_t size, size_t *length)
Copy metadata from input stream.
IcecastClientSettings settings
User settings.
error_t
Error codes.
Definition: error.h:42
OsMutex mutex
Mutex protecting critical sections.
size_t bufferSize
Streaming buffer size.
#define NetInterface
Definition: net.h:36
NetInterface * interface
Underlying network interface.
OsEvent readEvent
This event tells whether the buffer is readable.
Mutex object.
error_t icecastClientProcessMetadata(IcecastClientContext *context)
Decode metadata block.
char char_t
Definition: compiler_port.h:43
void icecastClientGetDefaultSettings(IcecastClientSettings *settings)
Initialize settings with default values.
error_t icecastClientConnect(IcecastClientContext *context)
Connect to the specified Icecast server.
#define ICECAST_SERVER_NAME_MAX_LEN
error_t icecastClientStart(IcecastClientContext *context)
Start Icecast client.
#define Socket
Definition: socket.h:36
OsEvent writeEvent
This event tells whether the buffer is writable.
Socket * socket
Underlying socket.
Socket API.
size_t readIndex
Current read index within the buffer.
size_t blockSize
Number of data bytes between subsequent metadata blocks.
error_t icecastClientInit(IcecastClientContext *context, const IcecastClientSettings *settings)
Icecast client initialization.
size_t bufferSize
Streaming buffer size.
TCP/IP stack core.
#define ICECAST_CLIENT_METADATA_MAX_SIZE
uint32_t systime_t
Definition: compiler_port.h:46
uint16_t serverPort
Icecast server port.
uint8_t * streamBuffer
Streaming buffer.