Skip to content

Commit 104c8a7

Browse files
authored
Merge pull request #137 from aous72/adding_rtp_decoder
Adding a simple RTP client that is compliant with draft-ietf-avtcore-rtp-j2k-scl-00.
2 parents cd15fb3 + c16c502 commit 104c8a7

21 files changed

+2484
-147
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ option(BUILD_SHARED_LIBS "Shared Libraries" ON)
1818
option(OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files" ON)
1919
option(OJPH_BUILD_TESTS "Enables building test code" OFF)
2020
option(OJPH_BUILD_EXECUTABLES "Enables building command line executables" ON)
21+
option(OJPH_BUILD_STREAM_EXPAND "Enables building ojph_stream_expand executable" OFF)
2122

2223
## Setting some of the options if EMSCRIPTEN is the compiler
2324
if(EMSCRIPTEN)
2425
set(OJPH_DISABLE_INTEL_SIMD ON)
2526
set(BUILD_SHARED_LIBS OFF)
2627
set(OJPH_ENABLE_TIFF_SUPPORT OFF)
28+
set(OJPH_BUILD_STREAM_EXPAND OFF)
2729
endif()
2830

2931
# This is related to how the timestamp is set for URL downloaded files.
@@ -50,7 +52,7 @@ message(STATUS "Building ${CMAKE_BUILD_TYPE}")
5052
# C++14 is needed for gtest, otherwise, C++11 is sufficient for the library
5153
set(CMAKE_CXX_STANDARD 14)
5254
if (MSVC)
53-
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
55+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
5456
endif()
5557
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
5658
add_compile_options(
@@ -64,9 +66,9 @@ endif()
6466

6567
## The option OJPH_DISABLE_INTEL_SIMD and OJPH_ENABLE_INTEL_AVX512
6668
if (OJPH_DISABLE_INTEL_SIMD)
67-
add_compile_options(-DOJPH_DISABLE_INTEL_SIMD)
69+
add_compile_definitions(OJPH_DISABLE_INTEL_SIMD)
6870
elseif (OJPH_ENABLE_INTEL_AVX512)
69-
add_compile_options(-DOJPH_ENABLE_INTEL_AVX512)
71+
add_compile_definitions(OJPH_ENABLE_INTEL_AVX512)
7072
endif()
7173

7274
## Build library and applications

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The interested reader is referred to the [short HTJ2K white paper](http://ds.jpe
1010

1111
The standard is available free of charge from [ITU website](https://www.itu.int/rec/T-REC-T.814/en). It can also be purchased from the [ISO website](https://www.iso.org/standard/76621.html).
1212

13-
# Tabke of Contents #
13+
# Table of Contents #
1414

1515
* [Status](/docs/status.md)
1616
* [Compiling](./docs/compiling.md)

src/apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ endif()
2121
## Build executables
2222
add_subdirectory(ojph_expand)
2323
add_subdirectory(ojph_compress)
24+
add_subdirectory(ojph_stream_expand)

src/apps/common/ojph_sockets.h

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
//***************************************************************************/
2+
// This software is released under the 2-Clause BSD license, included
3+
// below.
4+
//
5+
// Copyright (c) 2024, Aous Naman
6+
// Copyright (c) 2024, Kakadu Software Pty Ltd, Australia
7+
// Copyright (c) 2024, The University of New South Wales, Australia
8+
//
9+
// Redistribution and use in source and binary forms, with or without
10+
// modification, are permitted provided that the following conditions are
11+
// met:
12+
//
13+
// 1. Redistributions of source code must retain the above copyright
14+
// notice, this list of conditions and the following disclaimer.
15+
//
16+
// 2. Redistributions in binary form must reproduce the above copyright
17+
// notice, this list of conditions and the following disclaimer in the
18+
// documentation and/or other materials provided with the distribution.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23+
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26+
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
//***************************************************************************/
32+
// This file is part of the OpenJPH software implementation.
33+
// File: ojph_socket.h
34+
// Author: Aous Naman
35+
// Date: 17 April 2024
36+
//***************************************************************************/
37+
38+
#ifndef OJPH_SOCKET_H
39+
#define OJPH_SOCKET_H
40+
41+
#include <string>
42+
#include "ojph_arch.h"
43+
44+
#ifdef OJPH_OS_WINDOWS
45+
#include <winsock2.h>
46+
#include <WS2tcpip.h>
47+
48+
typedef SOCKET ojph_socket;
49+
#define OJPH_INVALID_SOCKET (INVALID_SOCKET)
50+
#define OJPH_EWOULDBLOCK (WSAEWOULDBLOCK)
51+
#else
52+
#include <sys/types.h>
53+
#include <sys/socket.h>
54+
#include <netinet/in.h>
55+
#include <arpa/inet.h>
56+
#include <netdb.h>
57+
#include <unistd.h>
58+
#include <errno.h>
59+
#include <fcntl.h>
60+
61+
typedef int ojph_socket;
62+
#define OJPH_INVALID_SOCKET (-1)
63+
#define OJPH_EWOULDBLOCK (EWOULDBLOCK)
64+
#endif
65+
66+
namespace ojph
67+
{
68+
namespace net
69+
{
70+
71+
///////////////////////////////////////////////////////////////////////////
72+
//
73+
//
74+
//
75+
//
76+
//
77+
///////////////////////////////////////////////////////////////////////////
78+
79+
//************************************************************************/
80+
/** @brief A small wrapper for socket that only abstract Winsock2
81+
*
82+
* This is a small wrapper that only abstracts the difference between
83+
* Windows and Linux/MacOS socket implementations.
84+
* It does not not do much other than define a local member variable
85+
* of type int for Linux/OS and type SOCKET for Windows, which is
86+
* unsigned int/int64.
87+
*/
88+
class socket {
89+
public:
90+
/**
91+
* @brief default constructor
92+
*/
93+
socket() { s = OJPH_INVALID_SOCKET; }
94+
95+
/**
96+
* @brief a copy constructor
97+
*/
98+
socket(const ojph_socket& s);
99+
100+
/**
101+
* @brief Abstracts socket closing function
102+
*/
103+
void close();
104+
105+
/**
106+
* @brief Sets the blocking mode
107+
*
108+
* @param block sets to true to operate in blocking mode
109+
* @return returns true when the operation succeeds
110+
*/
111+
bool set_blocking_mode(bool block);
112+
113+
/**
114+
* @brief provides access to the internal socket handle
115+
*
116+
* @return returns the internal socket handle
117+
*/
118+
ojph_socket intern() { return s; }
119+
120+
private:
121+
ojph_socket s; //!<int for Linux/MacOS and SOCKET for Windows
122+
};
123+
124+
///////////////////////////////////////////////////////////////////////////
125+
//
126+
//
127+
//
128+
//
129+
//
130+
///////////////////////////////////////////////////////////////////////////
131+
132+
//************************************************************************/
133+
/** @brief A small wrapper for some Winsock2 functionality
134+
*
135+
* This is useful for windows, as it initializes and destroys
136+
* WinSock2 library.
137+
* It keeps a count of how many times the constructor is called,
138+
* reducing the count whenever the destructor is called. When the
139+
* count reaches zero, the library is destroyed -- Windows only.
140+
*
141+
* It also allows the creation of a socket, access to the last error
142+
* in a portable way, and the translation of an error into a text
143+
* message.
144+
*/
145+
class socket_manager {
146+
public:
147+
/**
148+
* @brief default constructor
149+
*
150+
* This function initializes the Winsock2 stack in windows; it
151+
* also increments the static member that keeps count of how many
152+
* times this object is used.
153+
*/
154+
socket_manager();
155+
156+
/**
157+
* @brief default constructor
158+
*
159+
* This function cleans up the Winsock2 stack in windows when
160+
* the static member that keeps count of how many times this object
161+
* is used reaches zero.
162+
*
163+
*/
164+
~socket_manager();
165+
166+
/**
167+
* @brief Abstructs socket creation
168+
*
169+
* This function takes the same parameters as the conventional
170+
* socket() function
171+
*
172+
* @param domain the same as in conventional socket() function
173+
* @param type the same as in conventional socket() function
174+
* @param protocol the same as in conventional socket() function
175+
* @return returns an abstraction of socket
176+
*
177+
*/
178+
socket create_socket(int domain, int type, int protocol);
179+
180+
/**
181+
* @brief Abstructs get last error or errno
182+
*
183+
* This function abstracts Windows GetLastError or Linux errno
184+
*
185+
* @return returns a number representing the error
186+
*
187+
*/
188+
int get_last_error();
189+
190+
/**
191+
* @brief Abstructs obtaining a textual message for an errnum
192+
*
193+
* This function abstracts obtaining a textual message for an errnum
194+
*
195+
* @param errnum the error number
196+
* @return a string holding a textual message for the error number
197+
*
198+
*/
199+
std::string get_error_message(int errnum);
200+
201+
/**
202+
* @brief Abstructs obtaining a textual message for GetLastError/errno
203+
*
204+
* This function combines get_error_message() and get_last_error().
205+
* This function effectively calls get_last_error() and uses the
206+
* returned error number to obtain a string by calling
207+
* get_error_message(errnum).
208+
*
209+
* @return a string holding a textual message for the error number
210+
*
211+
*/
212+
std::string get_last_error_message();
213+
214+
/**
215+
* @brief Abstractly obtains the 32-bit IPv4 address integer
216+
*
217+
* This function obtains a 32-bit integer that represents the IPv4
218+
* address in abstrct way (working both in Windows and Linux).
219+
* This is really an independent function, but it is convenient to
220+
* put it here.
221+
*
222+
* @return returns an integer holding IPv4 address
223+
*
224+
*/
225+
static ui32 get_addr(const sockaddr_in& addr);
226+
227+
private:
228+
static int ojph_socket_manager_counter;
229+
};
230+
231+
} // !net namespace
232+
} // !ojph namespace
233+
234+
235+
236+
#endif // !OJPH_SOCKET_H

0 commit comments

Comments
 (0)