2019-01-04 20:25:08 -08:00
|
|
|
#include "decklink-device-instance.hpp"
|
2017-03-30 21:03:38 -07:00
|
|
|
#include "audio-repack.hpp"
|
2015-02-18 15:15:38 -08:00
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
#include "DecklinkInput.hpp"
|
|
|
|
#include "DecklinkOutput.hpp"
|
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
#include <util/platform.h>
|
|
|
|
#include <util/threading.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
2018-09-25 15:51:32 -07:00
|
|
|
#include <algorithm>
|
2015-02-18 15:15:38 -08:00
|
|
|
|
2015-10-08 10:42:33 -07:00
|
|
|
static inline enum video_format ConvertPixelFormat(BMDPixelFormat format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case bmdFormat8BitBGRA: return VIDEO_FORMAT_BGRX;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case bmdFormat8BitYUV:;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VIDEO_FORMAT_UYVY;
|
|
|
|
}
|
|
|
|
|
2017-03-30 21:03:38 -07:00
|
|
|
static inline int ConvertChannelFormat(speaker_layout format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
case SPEAKERS_2POINT1:
|
2017-12-01 08:10:05 -08:00
|
|
|
case SPEAKERS_4POINT0:
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
case SPEAKERS_4POINT1:
|
2017-03-30 21:03:38 -07:00
|
|
|
case SPEAKERS_5POINT1:
|
|
|
|
case SPEAKERS_7POINT1:
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case SPEAKERS_STEREO:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 00:59:58 -08:00
|
|
|
static inline audio_repack_mode_t ConvertRepackFormat(speaker_layout format, bool swap)
|
2017-03-30 21:03:38 -07:00
|
|
|
{
|
|
|
|
switch (format) {
|
2017-12-04 15:26:47 -08:00
|
|
|
case SPEAKERS_2POINT1:
|
2018-06-27 17:11:15 -07:00
|
|
|
return repack_mode_8to3ch;
|
2017-12-01 08:10:05 -08:00
|
|
|
case SPEAKERS_4POINT0:
|
2018-06-27 17:11:15 -07:00
|
|
|
return repack_mode_8to4ch;
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
case SPEAKERS_4POINT1:
|
2019-03-01 00:59:58 -08:00
|
|
|
return swap? repack_mode_8to5ch_swap:repack_mode_8to5ch;
|
2017-03-30 21:03:38 -07:00
|
|
|
case SPEAKERS_5POINT1:
|
2019-03-01 00:59:58 -08:00
|
|
|
return swap ? repack_mode_8to6ch_swap : repack_mode_8to6ch;
|
2017-03-30 21:03:38 -07:00
|
|
|
case SPEAKERS_7POINT1:
|
2019-03-01 00:59:58 -08:00
|
|
|
return swap ? repack_mode_8ch_swap: repack_mode_8ch;
|
2017-03-30 21:03:38 -07:00
|
|
|
default:
|
|
|
|
assert(false && "No repack requested");
|
|
|
|
return (audio_repack_mode_t)-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
DeckLinkDeviceInstance::DeckLinkDeviceInstance(DecklinkBase *decklink_,
|
2015-02-18 15:15:38 -08:00
|
|
|
DeckLinkDevice *device_) :
|
|
|
|
currentFrame(), currentPacket(), decklink(decklink_), device(device_)
|
|
|
|
{
|
|
|
|
currentPacket.samples_per_sec = 48000;
|
|
|
|
currentPacket.speakers = SPEAKERS_STEREO;
|
|
|
|
currentPacket.format = AUDIO_FORMAT_16BIT;
|
|
|
|
}
|
|
|
|
|
2015-07-11 14:22:14 -07:00
|
|
|
DeckLinkDeviceInstance::~DeckLinkDeviceInstance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
void DeckLinkDeviceInstance::HandleAudioPacket(
|
|
|
|
IDeckLinkAudioInputPacket *audioPacket,
|
|
|
|
const uint64_t timestamp)
|
|
|
|
{
|
|
|
|
if (audioPacket == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *bytes;
|
|
|
|
if (audioPacket->GetBytes(&bytes) != S_OK) {
|
|
|
|
LOG(LOG_WARNING, "Failed to get audio packet data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-30 21:03:38 -07:00
|
|
|
const uint32_t frameCount = (uint32_t)audioPacket->GetSampleFrameCount();
|
|
|
|
currentPacket.frames = frameCount;
|
|
|
|
currentPacket.timestamp = timestamp;
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
if (decklink && !static_cast<DeckLinkInput*>(decklink)->buffering) {
|
2017-09-29 00:40:03 -07:00
|
|
|
currentPacket.timestamp = os_gettime_ns();
|
|
|
|
currentPacket.timestamp -=
|
|
|
|
(uint64_t)frameCount * 1000000000ULL /
|
|
|
|
(uint64_t)currentPacket.samples_per_sec;
|
|
|
|
}
|
|
|
|
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
int maxdevicechannel = device->GetMaxChannel();
|
|
|
|
|
|
|
|
if (channelFormat != SPEAKERS_UNKNOWN &&
|
|
|
|
channelFormat != SPEAKERS_MONO &&
|
|
|
|
channelFormat != SPEAKERS_STEREO &&
|
2019-03-01 00:59:58 -08:00
|
|
|
(channelFormat != SPEAKERS_7POINT1 || static_cast<DeckLinkInput*>(decklink)->swap)
|
|
|
|
&& maxdevicechannel >= 8) {
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
|
2017-03-30 21:03:38 -07:00
|
|
|
if (audioRepacker->repack((uint8_t *)bytes, frameCount) < 0) {
|
|
|
|
LOG(LOG_ERROR, "Failed to convert audio packet data");
|
|
|
|
return;
|
|
|
|
}
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
currentPacket.data[0] = (*audioRepacker)->packet_buffer;
|
2017-03-30 21:03:38 -07:00
|
|
|
} else {
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
currentPacket.data[0] = (uint8_t *)bytes;
|
2017-03-30 21:03:38 -07:00
|
|
|
}
|
2015-02-18 15:15:38 -08:00
|
|
|
|
2017-04-07 00:31:16 -07:00
|
|
|
nextAudioTS = timestamp +
|
|
|
|
((uint64_t)frameCount * 1000000000ULL / 48000ULL) + 1;
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
obs_source_output_audio(static_cast<DeckLinkInput*>(decklink)->GetSource(), ¤tPacket);
|
2015-02-18 15:15:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeckLinkDeviceInstance::HandleVideoFrame(
|
|
|
|
IDeckLinkVideoInputFrame *videoFrame, const uint64_t timestamp)
|
|
|
|
{
|
|
|
|
if (videoFrame == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *bytes;
|
|
|
|
if (videoFrame->GetBytes(&bytes) != S_OK) {
|
|
|
|
LOG(LOG_WARNING, "Failed to get video frame data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentFrame.data[0] = (uint8_t *)bytes;
|
|
|
|
currentFrame.linesize[0] = (uint32_t)videoFrame->GetRowBytes();
|
|
|
|
currentFrame.width = (uint32_t)videoFrame->GetWidth();
|
|
|
|
currentFrame.height = (uint32_t)videoFrame->GetHeight();
|
|
|
|
currentFrame.timestamp = timestamp;
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
obs_source_output_video(static_cast<DeckLinkInput*>(decklink)->GetSource(), ¤tFrame);
|
2015-02-18 15:15:38 -08:00
|
|
|
}
|
|
|
|
|
2017-03-30 21:03:38 -07:00
|
|
|
void DeckLinkDeviceInstance::FinalizeStream()
|
|
|
|
{
|
|
|
|
input->SetCallback(nullptr);
|
2017-05-05 05:55:06 -07:00
|
|
|
input->DisableVideoInput();
|
|
|
|
if (channelFormat != SPEAKERS_UNKNOWN)
|
|
|
|
input->DisableAudioInput();
|
2017-03-30 21:03:38 -07:00
|
|
|
|
|
|
|
if (audioRepacker != nullptr)
|
|
|
|
{
|
|
|
|
delete audioRepacker;
|
|
|
|
audioRepacker = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-05 05:55:06 -07:00
|
|
|
//#define LOG_SETUP_VIDEO_FORMAT 1
|
|
|
|
|
|
|
|
void DeckLinkDeviceInstance::SetupVideoFormat(DeckLinkDeviceMode *mode_)
|
|
|
|
{
|
|
|
|
if (mode_ == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentFrame.format = ConvertPixelFormat(pixelFormat);
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
colorSpace = static_cast<DeckLinkInput*>(decklink)->GetColorSpace();
|
2017-05-05 05:55:06 -07:00
|
|
|
if (colorSpace == VIDEO_CS_DEFAULT) {
|
|
|
|
const BMDDisplayModeFlags flags = mode_->GetDisplayModeFlags();
|
|
|
|
if (flags & bmdDisplayModeColorspaceRec709)
|
|
|
|
activeColorSpace = VIDEO_CS_709;
|
|
|
|
else if (flags & bmdDisplayModeColorspaceRec601)
|
|
|
|
activeColorSpace = VIDEO_CS_601;
|
|
|
|
else
|
|
|
|
activeColorSpace = VIDEO_CS_DEFAULT;
|
|
|
|
} else {
|
|
|
|
activeColorSpace = colorSpace;
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
colorRange = static_cast<DeckLinkInput*>(decklink)->GetColorRange();
|
2017-05-05 05:55:06 -07:00
|
|
|
currentFrame.full_range = colorRange == VIDEO_RANGE_FULL;
|
|
|
|
|
|
|
|
video_format_get_parameters(activeColorSpace, colorRange,
|
|
|
|
currentFrame.color_matrix, currentFrame.color_range_min,
|
|
|
|
currentFrame.color_range_max);
|
|
|
|
|
|
|
|
#ifdef LOG_SETUP_VIDEO_FORMAT
|
|
|
|
LOG(LOG_INFO, "Setup video format: %s, %s, %s",
|
|
|
|
pixelFormat == bmdFormat8BitYUV ? "YUV" : "RGB",
|
|
|
|
activeColorSpace == VIDEO_CS_709 ? "BT.709" : "BT.601",
|
|
|
|
colorRange == VIDEO_RANGE_FULL ? "full" : "limited");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
bool DeckLinkDeviceInstance::StartCapture(DeckLinkDeviceMode *mode_)
|
|
|
|
{
|
|
|
|
if (mode != nullptr)
|
|
|
|
return false;
|
|
|
|
if (mode_ == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LOG(LOG_INFO, "Starting capture...");
|
|
|
|
|
|
|
|
if (!device->GetInput(&input))
|
|
|
|
return false;
|
|
|
|
|
2017-05-05 05:55:06 -07:00
|
|
|
BMDVideoInputFlags flags;
|
2015-10-08 10:42:33 -07:00
|
|
|
|
2017-05-05 05:55:06 -07:00
|
|
|
bool isauto = mode_->GetName() == "Auto";
|
|
|
|
if (isauto) {
|
|
|
|
displayMode = bmdModeNTSC;
|
|
|
|
pixelFormat = bmdFormat8BitYUV;
|
|
|
|
flags = bmdVideoInputEnableFormatDetection;
|
|
|
|
} else {
|
|
|
|
displayMode = mode_->GetDisplayMode();
|
2018-09-25 15:51:32 -07:00
|
|
|
pixelFormat = static_cast<DeckLinkInput*>(decklink)->GetPixelFormat();
|
2017-05-05 05:55:06 -07:00
|
|
|
flags = bmdVideoInputFlagDefault;
|
|
|
|
}
|
2015-09-14 21:38:38 -07:00
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
const HRESULT videoResult = input->EnableVideoInput(displayMode,
|
2017-05-05 05:55:06 -07:00
|
|
|
pixelFormat, flags);
|
2015-02-18 15:15:38 -08:00
|
|
|
if (videoResult != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to enable video input");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-05 05:55:06 -07:00
|
|
|
SetupVideoFormat(mode_);
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
channelFormat = static_cast<DeckLinkInput*>(decklink)->GetChannelFormat();
|
2017-03-30 21:03:38 -07:00
|
|
|
currentPacket.speakers = channelFormat;
|
2019-03-01 00:59:58 -08:00
|
|
|
swap = static_cast<DeckLinkInput*>(decklink)->swap;
|
2015-02-18 15:15:38 -08:00
|
|
|
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
int maxdevicechannel = device->GetMaxChannel();
|
|
|
|
|
2017-03-30 21:03:38 -07:00
|
|
|
if (channelFormat != SPEAKERS_UNKNOWN) {
|
|
|
|
const int channel = ConvertChannelFormat(channelFormat);
|
|
|
|
const HRESULT audioResult = input->EnableAudioInput(
|
|
|
|
bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger,
|
|
|
|
channel);
|
|
|
|
if (audioResult != S_OK)
|
|
|
|
LOG(LOG_WARNING, "Failed to enable audio input; continuing...");
|
|
|
|
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
if (channelFormat != SPEAKERS_UNKNOWN &&
|
|
|
|
channelFormat != SPEAKERS_MONO &&
|
|
|
|
channelFormat != SPEAKERS_STEREO &&
|
2019-03-01 00:59:58 -08:00
|
|
|
(channelFormat != SPEAKERS_7POINT1 || swap)
|
|
|
|
&& maxdevicechannel >= 8) {
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
|
|
|
|
const audio_repack_mode_t repack_mode = ConvertRepackFormat
|
2019-03-01 00:59:58 -08:00
|
|
|
(channelFormat, swap);
|
2017-03-30 21:03:38 -07:00
|
|
|
audioRepacker = new AudioRepacker(repack_mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->SetCallback(this) != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to set callback");
|
|
|
|
FinalizeStream();
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
if (input->StartStreams() != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to start streams");
|
2017-03-30 21:03:38 -07:00
|
|
|
FinalizeStream();
|
2015-02-18 15:15:38 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = mode_;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeckLinkDeviceInstance::StopCapture(void)
|
|
|
|
{
|
|
|
|
if (mode == nullptr || input == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LOG(LOG_INFO, "Stopping capture of '%s'...",
|
|
|
|
GetDevice()->GetDisplayName().c_str());
|
|
|
|
|
|
|
|
input->StopStreams();
|
2017-03-30 21:03:38 -07:00
|
|
|
FinalizeStream();
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
bool DeckLinkDeviceInstance::StartOutput(DeckLinkDeviceMode *mode_)
|
|
|
|
{
|
|
|
|
if (mode != nullptr)
|
|
|
|
return false;
|
|
|
|
if (mode_ == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LOG(LOG_INFO, "Starting output...");
|
|
|
|
|
|
|
|
if (!device->GetOutput(&output))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const HRESULT videoResult = output->EnableVideoOutput(
|
|
|
|
mode_->GetDisplayMode(),
|
|
|
|
bmdVideoOutputFlagDefault);
|
|
|
|
if (videoResult != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to enable video output");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HRESULT audioResult = output->EnableAudioOutput(
|
|
|
|
bmdAudioSampleRate48kHz,
|
|
|
|
bmdAudioSampleType16bitInteger,
|
|
|
|
2,
|
|
|
|
bmdAudioOutputStreamTimestamped);
|
|
|
|
if (audioResult != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to enable audio output");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = mode_;
|
|
|
|
|
2019-01-04 20:25:08 -08:00
|
|
|
int keyerMode = device->GetKeyerMode();
|
2018-06-23 15:21:07 -07:00
|
|
|
|
|
|
|
IDeckLinkKeyer *deckLinkKeyer = nullptr;
|
|
|
|
if (device->GetKeyer(&deckLinkKeyer)) {
|
|
|
|
if (keyerMode) {
|
|
|
|
deckLinkKeyer->Enable(keyerMode == 1);
|
|
|
|
deckLinkKeyer->SetLevel(255);
|
|
|
|
} else {
|
|
|
|
deckLinkKeyer->Disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
auto decklinkOutput = dynamic_cast<DeckLinkOutput*>(decklink);
|
|
|
|
if (decklinkOutput == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2019-01-04 20:25:08 -08:00
|
|
|
int rowBytes = decklinkOutput->GetWidth() * 2;
|
|
|
|
if (decklinkOutput->keyerMode != 0) {
|
|
|
|
rowBytes = decklinkOutput->GetWidth() * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
|
|
|
|
if (keyerMode != 0) {
|
|
|
|
pixelFormat = bmdFormat8BitBGRA;
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
HRESULT result;
|
|
|
|
result = output->CreateVideoFrame(decklinkOutput->GetWidth(),
|
|
|
|
decklinkOutput->GetHeight(),
|
2019-01-04 20:25:08 -08:00
|
|
|
rowBytes,
|
|
|
|
pixelFormat,
|
2018-09-25 15:51:32 -07:00
|
|
|
bmdFrameFlagDefault,
|
|
|
|
&decklinkOutputFrame);
|
|
|
|
if (result != S_OK) {
|
|
|
|
blog(LOG_ERROR ,"failed to make frame 0x%X", result);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeckLinkDeviceInstance::StopOutput()
|
|
|
|
{
|
|
|
|
if (mode == nullptr || output == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LOG(LOG_INFO, "Stopping output of '%s'...",
|
|
|
|
GetDevice()->GetDisplayName().c_str());
|
|
|
|
|
|
|
|
output->DisableVideoOutput();
|
|
|
|
output->DisableAudioOutput();
|
|
|
|
|
|
|
|
if (decklinkOutputFrame != nullptr) {
|
|
|
|
decklinkOutputFrame->Release();
|
|
|
|
decklinkOutputFrame = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeckLinkDeviceInstance::DisplayVideoFrame(video_data *frame)
|
|
|
|
{
|
|
|
|
auto decklinkOutput = dynamic_cast<DeckLinkOutput*>(decklink);
|
|
|
|
if (decklinkOutput == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint8_t *destData;
|
|
|
|
decklinkOutputFrame->GetBytes((void**)&destData);
|
|
|
|
|
|
|
|
uint8_t *outData = frame->data[0];
|
|
|
|
|
2019-01-04 20:25:08 -08:00
|
|
|
int rowBytes = decklinkOutput->GetWidth() * 2;
|
|
|
|
if (device->GetKeyerMode()) {
|
|
|
|
rowBytes = decklinkOutput->GetWidth() * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::copy(outData, outData + (decklinkOutput->GetHeight() *
|
|
|
|
rowBytes), destData);
|
2018-09-25 15:51:32 -07:00
|
|
|
|
|
|
|
output->DisplayVideoFrameSync(decklinkOutputFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeckLinkDeviceInstance::WriteAudio(audio_data *frames)
|
|
|
|
{
|
|
|
|
uint32_t sampleFramesWritten;
|
|
|
|
output->WriteAudioSamplesSync(frames->data[0],
|
|
|
|
frames->frames,
|
|
|
|
&sampleFramesWritten);
|
|
|
|
}
|
|
|
|
|
2015-07-01 19:57:12 -07:00
|
|
|
#define TIME_BASE 1000000000
|
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::VideoInputFrameArrived(
|
|
|
|
IDeckLinkVideoInputFrame *videoFrame,
|
|
|
|
IDeckLinkAudioInputPacket *audioPacket)
|
|
|
|
{
|
2015-07-01 19:57:12 -07:00
|
|
|
BMDTimeValue videoTS = 0;
|
|
|
|
BMDTimeValue videoDur = 0;
|
|
|
|
BMDTimeValue audioTS = 0;
|
|
|
|
|
2017-04-07 00:31:16 -07:00
|
|
|
if (videoFrame) {
|
2015-07-25 09:51:30 -07:00
|
|
|
videoFrame->GetStreamTime(&videoTS, &videoDur, TIME_BASE);
|
2017-04-07 00:31:16 -07:00
|
|
|
lastVideoTS = (uint64_t)videoTS;
|
|
|
|
}
|
|
|
|
if (audioPacket) {
|
|
|
|
BMDTimeValue newAudioTS = 0;
|
|
|
|
int64_t diff;
|
|
|
|
|
|
|
|
audioPacket->GetPacketTime(&newAudioTS, TIME_BASE);
|
|
|
|
audioTS = newAudioTS + audioOffset;
|
|
|
|
|
|
|
|
diff = (int64_t)audioTS - (int64_t)nextAudioTS;
|
|
|
|
if (diff > 10000000LL) {
|
|
|
|
audioOffset -= diff;
|
|
|
|
audioTS = newAudioTS + audioOffset;
|
|
|
|
|
|
|
|
} else if (diff < -1000000) {
|
|
|
|
audioOffset = 0;
|
|
|
|
audioTS = newAudioTS;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 15:15:38 -08:00
|
|
|
|
2015-07-25 09:51:30 -07:00
|
|
|
if (videoFrame && videoTS >= 0)
|
2015-07-01 19:57:12 -07:00
|
|
|
HandleVideoFrame(videoFrame, (uint64_t)videoTS);
|
2015-07-25 09:51:30 -07:00
|
|
|
if (audioPacket && audioTS >= 0)
|
2015-07-01 19:57:12 -07:00
|
|
|
HandleAudioPacket(audioPacket, (uint64_t)audioTS);
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::VideoInputFormatChanged(
|
|
|
|
BMDVideoInputFormatChangedEvents events,
|
|
|
|
IDeckLinkDisplayMode *newMode,
|
|
|
|
BMDDetectedVideoInputFormatFlags detectedSignalFlags)
|
|
|
|
{
|
2017-05-05 05:55:06 -07:00
|
|
|
input->PauseStreams();
|
|
|
|
|
|
|
|
mode->SetMode(newMode);
|
|
|
|
|
|
|
|
if (events & bmdVideoInputDisplayModeChanged) {
|
|
|
|
displayMode = mode->GetDisplayMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & bmdVideoInputColorspaceChanged) {
|
|
|
|
switch (detectedSignalFlags) {
|
|
|
|
case bmdDetectedVideoInputRGB444:
|
|
|
|
pixelFormat = bmdFormat8BitBGRA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case bmdDetectedVideoInputYCbCr422:
|
|
|
|
pixelFormat = bmdFormat8BitYUV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const HRESULT videoResult = input->EnableVideoInput(displayMode,
|
|
|
|
pixelFormat, bmdVideoInputEnableFormatDetection);
|
|
|
|
if (videoResult != S_OK) {
|
|
|
|
LOG(LOG_ERROR, "Failed to enable video input");
|
|
|
|
input->StopStreams();
|
|
|
|
FinalizeStream();
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupVideoFormat(mode);
|
2015-02-18 15:15:38 -08:00
|
|
|
|
2017-05-05 05:55:06 -07:00
|
|
|
input->FlushStreams();
|
|
|
|
input->StartStreams();
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE DeckLinkDeviceInstance::AddRef(void)
|
|
|
|
{
|
|
|
|
return os_atomic_inc_long(&refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DeckLinkDeviceInstance::QueryInterface(REFIID iid,
|
|
|
|
LPVOID *ppv)
|
|
|
|
{
|
|
|
|
HRESULT result = E_NOINTERFACE;
|
|
|
|
|
|
|
|
*ppv = nullptr;
|
|
|
|
|
|
|
|
CFUUIDBytes unknown = CFUUIDGetUUIDBytes(IUnknownUUID);
|
|
|
|
if (memcmp(&iid, &unknown, sizeof(REFIID)) == 0) {
|
|
|
|
*ppv = this;
|
|
|
|
AddRef();
|
|
|
|
result = S_OK;
|
|
|
|
} else if (memcmp(&iid, &IID_IDeckLinkNotificationCallback,
|
|
|
|
sizeof(REFIID)) == 0) {
|
|
|
|
*ppv = (IDeckLinkNotificationCallback *)this;
|
|
|
|
AddRef();
|
|
|
|
result = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE DeckLinkDeviceInstance::Release(void)
|
|
|
|
{
|
|
|
|
const long newRefCount = os_atomic_dec_long(&refCount);
|
|
|
|
if (newRefCount == 0) {
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRefCount;
|
|
|
|
}
|