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