Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fmtp #29

Merged
merged 10 commits into from
Mar 9, 2021
Merged

Fmtp #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ jobs:
libqt5x11extras5-dev libspeexdsp-dev libswresample-dev libswscale-dev libudev-dev libv4l-dev \
libvlc-dev libx11-dev libx264-dev libxcb-shm0-dev libxcb-xinerama0-dev libxcomposite-dev \
libxinerama-dev pkg-config python3-dev qtbase5-dev libqt5svg5-dev swig libxcb-randr0-dev \
libx11-xcb-dev libxcb-xfixes0-dev
# libxcb-xfixes0-dev libx11-xcb-dev libxcb1-dev \
# libx32gcc-4.8-dev libc6-dev-i386 lib32stdc++6 g++-multilib gcc-multilib \
# libmbedtls-dev:i386 libasound2-dev:i386 libavcodec-dev:i386 libavdevice-dev:i386 \
Expand Down
15 changes: 5 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ set(obs-rtspserver_HEADERS
)

if(WIN32)
set(OBS_VIRTUALOUTPUT_VERSION_MAJOR 2)
set(OBS_VIRTUALOUTPUT_VERSION_MINOR 0)
set(OBS_VIRTUALOUTPUT_VERSION_PATCH 5)
set(OBS_VIRTUALOUTPUT_VERSION_STRING "2.0.5")
set(OBS_RTSPSERVER_VERSION_MAJOR 1)
set(OBS_RTSPSERVER_VERSION_MINOR 4)
set(OBS_RTSPSERVER_VERSION_PATCH 0)
set(OBS_RTSPSERVER_VERSION_STRING "1.4.1")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rtspoutput.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/rtspoutput.rc)
endif()

Expand All @@ -51,11 +51,6 @@ include_directories(
"rtsp-server")

include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/UI/obs-frontend-api")

include_directories(../live/BasicUsageEnvironment/include)
include_directories(../live/groupsock/include)
include_directories(../live/liveMedia/include)
include_directories(../live/UsageEnvironment/include)

target_link_libraries(obs-rtspserver
${FFMPEG_LIBRARIES}
Expand All @@ -75,7 +70,7 @@ else()
set_target_properties(obs-rtspserver
PROPERTIES
FOLDER "plugins"
VERSION "1.4.0"
VERSION "1.4.1"
PRODUCTNAME "OBS RTSP Server Plugin")
endif()

Expand Down
31 changes: 31 additions & 0 deletions helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <obs-module.h>
#include <util/config-file.h>
#include <util/platform.h>
#include <obs-avc.h>

#ifndef RTSP_HELPER_H
#define RTSP_HELPER_H
Expand Down Expand Up @@ -53,4 +54,34 @@ static config_t *rtsp_properties_open_config()
return config;
}

static void rtsp_output_avc_get_sps_pps(const uint8_t *data, size_t size,
const uint8_t **sps, size_t *sps_size,
const uint8_t **pps, size_t *pps_size)
{
const uint8_t *nal_start, *nal_end;
const uint8_t *end = data + size;
int type;

nal_start = obs_avc_find_startcode(data, end);
while (true) {
while (nal_start < end && !*(nal_start++))
;

if (nal_start == end)
break;

nal_end = obs_avc_find_startcode(nal_start, end);

type = nal_start[0] & 0x1F;
if (type == OBS_NAL_SPS) {
*sps = nal_start;
*sps_size = nal_end - nal_start;
} else if (type == OBS_NAL_PPS) {
*pps = nal_start;
*pps_size = nal_end - nal_start;
}

nal_start = nal_end;
}
}
#endif // RTSP_HELPER_H
16 changes: 16 additions & 0 deletions rtsp-server/3rdpart/libb64/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.5)
project(libb64)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include_directories("include")

file(GLOB libb64_SOURCES
src/*.c)

file(GLOB libb64_HEADERS
include/b64/*.h)

add_library(libb64 STATIC
${libb64_SOURCES}
${libb64_HEADERS})
29 changes: 29 additions & 0 deletions rtsp-server/3rdpart/libb64/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright-Only Dedication (based on United States law)
or Public Domain Certification

The person or persons who have associated work with this document (the
"Dedicator" or "Certifier") hereby either (a) certifies that, to the best of
his knowledge, the work of authorship identified is in the public domain of the
country from which the work is published, or (b) hereby dedicates whatever
copyright the dedicators holds in the work of authorship identified below (the
"Work") to the public domain. A certifier, moreover, dedicates any copyright
interest he may have in the associated work, and for these purposes, is
described as a "dedicator" below.

A certifier has taken reasonable steps to verify the copyright status of this
work. Certifier recognizes that his good faith efforts may not shield him from
liability if in fact the work certified is not in the public domain.

Dedicator makes this dedication for the benefit of the public at large and to
the detriment of the Dedicator's heirs and successors. Dedicator intends this
dedication to be an overt act of relinquishment in perpetuity of all present
and future rights under copyright law, whether vested or contingent, in the
Work. Dedicator understands that such relinquishment of all rights includes
the relinquishment of all rights to enforce (by lawsuit or otherwise) those
copyrights in the Work.

Dedicator recognizes that, once placed in the public domain, the Work may be
freely reproduced, distributed, transmitted, used, modified, built upon, or
otherwise exploited by anyone for any purpose, commercial or non-commercial,
and in any way, including by methods that have not yet been invented or
conceived.
138 changes: 138 additions & 0 deletions rtsp-server/3rdpart/libb64/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
b64: Base64 Encoding/Decoding Routines
======================================

Overview:
--------
libb64 is a library of ANSI C routines for fast encoding/decoding data into and
from a base64-encoded format. C++ wrappers are included, as well as the source
code for standalone encoding and decoding executables.

base64 consists of ASCII text, and is therefore a useful encoding for storing
binary data in a text file, such as xml, or sending binary data over text-only
email.

References:
----------
* Wikipedia article:
http://en.wikipedia.org/wiki/Base64
* base64, another implementation of a commandline en/decoder:
http://www.fourmilab.ch/webtools/base64/

Why?
---
I did this because I need an implementation of base64 encoding and decoding,
without any licensing problems. Most OS implementations are released under
either the GNU/GPL, or a BSD-variant, which is not what I require.

Also, the chance to actually use the co-routine implementation in code is rare,
and its use here is fitting. I couldn't pass up the chance.
For more information on this technique, see "Coroutines in C", by Simon Tatham,
which can be found online here:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

So then, under which license do I release this code? On to the next section...

License:
-------
This work is released under into the Public Domain.
It basically boils down to this: I put this work in the public domain, and you
can take it and do whatever you want with it.

An example of this "license" is the Creative Commons Public Domain License, a
copy of which can be found in the LICENSE file, and also online at
http://creativecommons.org/licenses/publicdomain/

Commandline Use:
---------------
There is a new executable available, it is simply called base64.
It can encode and decode files, as instructed by the user.

To encode a file:
$ ./base64 -e filea fileb
fileb will now be the base64-encoded version of filea.

To decode a file:
$ ./base64 -d fileb filec
filec will now be identical to filea.

Programming:
-----------
Some C++ wrappers are provided as well, so you don't have to get your hands
dirty. Encoding from standard input to standard output is as simple as

#include <b64/encode.h>
#include <iostream>
int main()
{
base64::encoder E;
E.encode(std::cin, std::cout);
return 0;
}

Both standalone executables and a static library is provided in the package,

Implementation:
--------------
It is DAMN fast, if I may say so myself. The C code uses a little trick which
has been used to implement coroutines, of which one can say that this
implementation is an example.

(To see how the libb64 codebase compares with some other BASE64 implementations
available, see the BENCHMARKS file)

The trick involves the fact that a switch-statement may legally cross into
sub-blocks. A very thorough and enlightening essay on co-routines in C, using
this method, can be found in the above mentioned "Coroutines in C", by Simon
Tatham: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

For example, an RLE decompressing routine, adapted from the article:
1 static int STATE = 0;
2 static int len, c;
3 switch (STATE)
4 {
5 while (1)
6 {
7 c = getchar();
8 if (c == EOF) return EOF;
9 if (c == 0xFF) {
10 len = getchar();
11 c = getchar();
12 while (len--)
13 {
14 STATE = 0;
15 return c;
16 case 0:
17 }
18 } else
19 STATE = 1;
20 return c;
21 case 1:
22 }
23 }
24 }

As can be seen from this example, a coroutine depends on a state variable,
which it sets directly before exiting (lines 14 and 119). The next time the
routine is entered, the switch moves control to the specific point directly
after the previous exit (lines 16 and 21).hands

(As an aside, in the mentioned article the combination of the top-level switch,
the various setting of the state, the return of a value, and the labelling of
the exit point is wrapped in #define macros, making the structure of the
routine even clearer.)

The obvious problem with any such routine is the static keyword.
Any static variables in a function spell doom for multithreaded applications.
Also, in situations where this coroutine is used by more than one other
coroutines, the consistency is disturbed.

What is needed is a structure for storing these variabled, which is passed to
the routine seperately. This obviously breaks the modularity of the function,
since now the caller has to worry about and care for the internal state of the
routine (the callee). This allows for a fast, multithreading-enabled
implementation, which may (obviously) be wrapped in a C++ object for ease of
use.

The base64 encoding and decoding functionality in this package is implemented
in exactly this way, providing both a high-speed high-maintanence C interface,
and a wrapped C++ which is low-maintanence and only slightly less performant.
28 changes: 28 additions & 0 deletions rtsp-server/3rdpart/libb64/include/b64/cdecode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
cdecode.h - c header for a base64 decoding algorithm

This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/

#ifndef BASE64_CDECODE_H
#define BASE64_CDECODE_H

typedef enum
{
step_a, step_b, step_c, step_d
} base64_decodestep;

typedef struct
{
base64_decodestep step;
char plainchar;
} base64_decodestate;

void base64_init_decodestate(base64_decodestate* state_in);

int base64_decode_value(char value_in);

int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in);

#endif /* BASE64_CDECODE_H */
31 changes: 31 additions & 0 deletions rtsp-server/3rdpart/libb64/include/b64/cencode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
cencode.h - c header for a base64 encoding algorithm

This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/

#ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H

typedef enum
{
step_A, step_B, step_C
} base64_encodestep;

typedef struct
{
base64_encodestep step;
char result;
int stepcount;
} base64_encodestate;

void base64_init_encodestate(base64_encodestate* state_in);

char base64_encode_value(char value_in);

int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);

int base64_encode_blockend(char* code_out, base64_encodestate* state_in);

#endif /* BASE64_CENCODE_H */