-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,804 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
project(obs-webrtc) | ||
|
||
include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
Corrosion | ||
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git | ||
GIT_TAG origin/master # Optionally specify a version tag or branch here | ||
) | ||
|
||
FetchContent_MakeAvailable(Corrosion) | ||
|
||
# find_package(Libcurl REQUIRED) | ||
|
||
include_directories(${LIBCURL_INCLUDE_DIRS}) | ||
|
||
include_directories(${OBS_JANSSON_INCLUDE_DIRS}) | ||
|
||
option(ENABLE_FFMPEG_LOGGING "Enables obs-ffmpeg logging" OFF) | ||
|
||
find_package( | ||
FFmpeg REQUIRED | ||
COMPONENTS avcodec | ||
avfilter | ||
avdevice | ||
avutil | ||
swscale | ||
avformat | ||
swresample) | ||
include_directories(${FFMPEG_INCLUDE_DIRS}) | ||
|
||
set(obs-webrtc_HEADERS webrtc-stream.h webrtc-source.h webrtc-call.h) | ||
set(obs-webrtc_SOURCES whip.c webrtc-stream.c webrtc-source.c webrtc.c | ||
webrtc-call.c) | ||
|
||
if(WIN32) | ||
set(MODULE_DESCRIPTION "OBS webrtc module") | ||
configure_file(${CMAKE_SOURCE_DIR}/cmake/bundle/windows/obs-module.rc.in | ||
obs-webrtc.rc) | ||
list(APPEND obs-webrtc_SOURCES obs-webrtc.rc) | ||
endif() | ||
|
||
add_library(obs-webrtc MODULE ${obs-webrtc_SOURCES} ${obs-webrtc_HEADERS}) | ||
|
||
corrosion_import_crate(MANIFEST_PATH webrtc/Cargo.toml) | ||
|
||
target_link_libraries(obs-webrtc libobs webrtc-rs-lib ${OBS_JANSSON_IMPORT} | ||
${LIBCURL_LIBRARIES} ${FFMPEG_LIBRARIES}) | ||
set_target_properties(obs-webrtc PROPERTIES FOLDER "plugins") | ||
|
||
setup_plugin_target(obs-webrtc data) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include <libavformat/avformat.h> | ||
#include <libavcodec/avcodec.h> | ||
|
||
#include <graphics/graphics.h> | ||
|
||
#include "./webrtc/bindings.h" | ||
|
||
#include <obs.h> | ||
|
||
OBSWebRTCCall *call; | ||
struct gs_texture *texture; | ||
|
||
static inline enum video_format convert_pixel_format(int f) | ||
{ | ||
switch (f) { | ||
case AV_PIX_FMT_NONE: | ||
return VIDEO_FORMAT_NONE; | ||
case AV_PIX_FMT_YUV420P: | ||
return VIDEO_FORMAT_I420; | ||
case AV_PIX_FMT_NV12: | ||
return VIDEO_FORMAT_NV12; | ||
case AV_PIX_FMT_YUYV422: | ||
return VIDEO_FORMAT_YUY2; | ||
case AV_PIX_FMT_YUV444P: | ||
return VIDEO_FORMAT_I444; | ||
case AV_PIX_FMT_UYVY422: | ||
return VIDEO_FORMAT_UYVY; | ||
case AV_PIX_FMT_RGBA: | ||
return VIDEO_FORMAT_RGBA; | ||
case AV_PIX_FMT_BGRA: | ||
return VIDEO_FORMAT_BGRA; | ||
case AV_PIX_FMT_BGR0: | ||
return VIDEO_FORMAT_BGRX; | ||
case AV_PIX_FMT_YUVA420P: | ||
return VIDEO_FORMAT_I40A; | ||
case AV_PIX_FMT_YUVA422P: | ||
return VIDEO_FORMAT_I42A; | ||
case AV_PIX_FMT_YUVA444P: | ||
return VIDEO_FORMAT_YUVA; | ||
default:; | ||
} | ||
|
||
return VIDEO_FORMAT_NONE; | ||
} | ||
|
||
void packet_callback(void *user_data, uint8_t *packet_data, int length) | ||
{ | ||
|
||
//blog(LOG_INFO, "%d", length); | ||
|
||
AVCodecContext *context = (AVCodecContext *)user_data; | ||
|
||
AVPacket *packet = av_packet_alloc(); | ||
|
||
av_new_packet(packet, 1024 * 10); | ||
|
||
memcpy(packet->data, packet_data, length); | ||
|
||
avcodec_send_packet(context, packet); | ||
|
||
AVFrame *frame = av_frame_alloc(); | ||
int res = avcodec_receive_frame(context, frame); | ||
if (res == 0) { | ||
blog(LOG_INFO, "Width: %d, Height: %d", frame->width, | ||
frame->height); | ||
int format = convert_pixel_format(frame->format); | ||
|
||
obs_enter_graphics(); | ||
|
||
struct gs_texture *texture = | ||
gs_texture_create(frame->width, frame->height, format, | ||
1, (const uint8_t **)&frame->data, 0); | ||
|
||
obs_leave_graphics(); | ||
} | ||
|
||
if (res == AVERROR(EAGAIN)) { | ||
// NO FRAME | ||
} | ||
|
||
av_free(frame); | ||
} | ||
|
||
void setup_call() | ||
{ | ||
AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264); | ||
|
||
AVDictionary *opts = NULL; | ||
//av_dict_set(&opts, "b", "2.5M", 0); | ||
if (!codec) | ||
exit(1); | ||
AVCodecContext *context = avcodec_alloc_context3(codec); | ||
if (avcodec_open2(context, codec, &opts) < 0) | ||
exit(1); | ||
|
||
AVCodecParameters *codecpar = avcodec_parameters_alloc(); | ||
codecpar->codec_id = AV_CODEC_ID_H264; | ||
codecpar->height = 720; | ||
codecpar->width = 1280; | ||
|
||
//codecpar-> | ||
|
||
//avcodec_parameters_to_context(context, codecpar); | ||
|
||
call = obs_webrtc_call_init(context, packet_callback); | ||
} | ||
|
||
void start_call() | ||
{ | ||
obs_webrtc_call_start(call); | ||
} | ||
|
||
void frame(AVCodecContext *context) | ||
{ | ||
AVFrame frame; | ||
avcodec_receive_frame(context, &frame); | ||
|
||
struct gs_texture *texture = | ||
gs_texture_create(frame.width, frame.height, frame.format, 1, | ||
(const uint8_t **)&frame.data, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
void setup_call(); | ||
void start_call(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "util/text-lookup.h" | ||
#include "util/threading.h" | ||
#include "util/platform.h" | ||
#include "util/dstr.h" | ||
#include "obs-module.h" | ||
#include "file-updater/file-updater.h" | ||
|
||
OBS_DECLARE_MODULE() | ||
OBS_MODULE_USE_DEFAULT_LOCALE("obs-webrtc-services", "en-US") | ||
MODULE_EXPORT const char *obs_module_description(void) | ||
{ | ||
return "OBS core WebRTC services"; | ||
} | ||
|
||
#define RTMP_SERVICES_LOG_STR "[obs-webrtc-services plugin] " | ||
#define RTMP_SERVICES_VER_STR \ | ||
"obs-webrtc-services plugin (libobs " OBS_VERSION ")" | ||
|
||
extern struct obs_service_info whip_service; | ||
|
||
static update_info_t *update_info = NULL; | ||
static struct dstr module_name = {0}; | ||
|
||
const char *get_module_name(void) | ||
{ | ||
return module_name.array; | ||
} | ||
|
||
bool obs_module_load(void) | ||
{ | ||
dstr_copy(&module_name, "obs-webrtc-services plugin (libobs "); | ||
dstr_cat(&module_name, obs_get_version_string()); | ||
dstr_cat(&module_name, ")"); | ||
|
||
obs_register_service(&whip_service); | ||
return true; | ||
} | ||
|
||
void obs_module_unload(void) | ||
{ | ||
dstr_free(&module_name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <obs-module.h> | ||
|
||
static const char *webrtc_source_getname(void *unused) | ||
{ | ||
UNUSED_PARAMETER(unused); | ||
return obs_module_text("WebRTCSource"); | ||
} | ||
|
||
static void *webrtc_source_create(obs_data_t *settings, obs_source_t *source) {} | ||
|
||
static void webrtc_source_destroy(void *data) {} | ||
|
||
static obs_properties_t *webrtc_source_get_properties(void *data) {} | ||
|
||
struct obs_source_info webrtc_source_info = { | ||
.id = "webrtc_source", | ||
.type = OBS_SOURCE_TYPE_INPUT, | ||
.output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO | | ||
OBS_SOURCE_DO_NOT_DUPLICATE, | ||
.get_name = webrtc_source_getname, | ||
.create = webrtc_source_create, | ||
.destroy = webrtc_source_destroy, | ||
.get_properties = webrtc_source_get_properties, | ||
.icon_type = OBS_ICON_TYPE_MEDIA, | ||
}; |
Empty file.
Oops, something went wrong.