mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-20 17:40:12 +00:00
Added yuri UltraGrid decoder for audio
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
#ifndef _AUDIO_UTILS_H_
|
||||
#define _AUDIO_UTILS_H_
|
||||
|
||||
#include <audio/audio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -336,6 +336,18 @@ void audio_decoder_destroy(void *state)
|
||||
free(s);
|
||||
}
|
||||
|
||||
bool parse_audio_hdr(uint32_t *hdr, struct audio_desc *desc)
|
||||
{
|
||||
desc->ch_count = ((ntohl(hdr[0]) >> 22) & 0x3ff) + 1;
|
||||
desc->sample_rate = ntohl(hdr[3]) & 0x3fffff;
|
||||
desc->bps = (ntohl(hdr[3]) >> 26) / 8;
|
||||
|
||||
uint32_t audio_tag = ntohl(hdr[4]);
|
||||
desc->codec = get_audio_codec_to_tag(audio_tag);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int decode_audio_frame(struct coded_data *cdata, void *data)
|
||||
{
|
||||
struct pbuf_audio_data *s = (struct pbuf_audio_data *) data;
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct coded_data;
|
||||
|
||||
int decode_audio_frame(struct coded_data *cdata, void *data);
|
||||
@@ -59,3 +63,9 @@ void *audio_decoder_init(char *audio_channel_map, const char *audio_scale,
|
||||
const char *encryption);
|
||||
void audio_decoder_destroy(void *state);
|
||||
|
||||
bool parse_audio_hdr(uint32_t *hdr, struct audio_desc *desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -119,7 +119,6 @@ static void wait_for_framebuffer_swap(struct state_video_decoder *decoder);
|
||||
static void *fec_thread(void *args);
|
||||
static void *decompress_thread(void *args);
|
||||
static void cleanup(struct state_video_decoder *decoder);
|
||||
static bool parse_video_hdr(uint32_t *hdr, struct video_desc *desc);
|
||||
|
||||
static int sum_map(map<int, int> const & m) {
|
||||
int ret = 0;
|
||||
@@ -1367,7 +1366,7 @@ static bool reconfigure_decoder(struct state_video_decoder *decoder,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_video_hdr(uint32_t *hdr, struct video_desc *desc)
|
||||
bool parse_video_hdr(uint32_t *hdr, struct video_desc *desc)
|
||||
{
|
||||
uint32_t tmp;
|
||||
int fps_pt, fpsd, fd, fi;
|
||||
@@ -1815,71 +1814,3 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes a participant buffer representing one video frame.
|
||||
* @param cdata PBUF buffer
|
||||
* @param decoder_data @ref vcodec_state containing decoder state and some additional data
|
||||
* @retval TRUE if decoding was successful.
|
||||
* It stil doesn't mean that the frame will be correctly displayed,
|
||||
* decoding may fail in some subsequent (asynchronous) steps.
|
||||
* @retval FALSE if decoding failed
|
||||
*/
|
||||
int decode_yuri_frame(struct coded_data *cdata, void *decoder_data)
|
||||
{
|
||||
yuri_decoder_data *s = (yuri_decoder_data *) decoder_data;
|
||||
char *received_data = NULL;
|
||||
|
||||
int len;
|
||||
rtp_packet *pckt = NULL;
|
||||
char *data;
|
||||
uint32_t data_pos;
|
||||
uint32_t tmp;
|
||||
uint32_t substream;
|
||||
|
||||
int buffer_number, buffer_length;
|
||||
|
||||
int pt;
|
||||
|
||||
uint32_t *hdr;
|
||||
pckt = cdata->data;
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
struct video_desc network_desc;
|
||||
parse_video_hdr(hdr, &network_desc);
|
||||
|
||||
buffer_length = ntohl(hdr[2]);
|
||||
s->yuri_frame = s->create_yuri_frame(&network_desc, buffer_length, &received_data, s->log);
|
||||
|
||||
if (!s->yuri_frame) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (cdata != NULL) {
|
||||
uint32_t *hdr;
|
||||
pckt = cdata->data;
|
||||
|
||||
pt = pckt->pt;
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
data_pos = ntohl(hdr[1]);
|
||||
tmp = ntohl(hdr[0]);
|
||||
substream = tmp >> 22;
|
||||
buffer_number = tmp & 0x3ffff;
|
||||
buffer_length = ntohl(hdr[2]);
|
||||
|
||||
assert(pt == PT_VIDEO);
|
||||
assert(substream == 0);
|
||||
|
||||
len = pckt->data_len - sizeof(video_payload_hdr_t);
|
||||
data = (char *) hdr + sizeof(video_payload_hdr_t);
|
||||
|
||||
memcpy(received_data + data_pos, (unsigned char*) data, len);
|
||||
|
||||
cdata = cdata->nxt;
|
||||
}
|
||||
|
||||
if(!pckt) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,35 +62,18 @@ struct video_frame;
|
||||
struct state_decompress;
|
||||
struct tile;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <memory>
|
||||
namespace yuri {
|
||||
namespace core {
|
||||
class Frame;
|
||||
typedef std::shared_ptr<Frame> pFrame;
|
||||
}
|
||||
}
|
||||
|
||||
struct yuri_decoder_data {
|
||||
yuri::core::pFrame (*create_yuri_frame)(struct video_desc *desc, size_t data_len, char **data, void *log);
|
||||
void *log;
|
||||
yuri::core::pFrame yuri_frame;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
int decode_video_frame(struct coded_data *received_data, void *decoder_data);
|
||||
|
||||
int decode_yuri_frame(struct coded_data *received_data, void *decoder_data);
|
||||
|
||||
struct state_video_decoder *video_decoder_init(struct module *parent, enum video_mode,
|
||||
const char *postprocess, struct display *display, const char *encryption);
|
||||
void video_decoder_destroy(struct state_video_decoder *decoder);
|
||||
bool video_decoder_register_display(struct state_video_decoder *decoder, struct display *display);
|
||||
void video_decoder_remove_display(struct state_video_decoder *decoder);
|
||||
bool parse_video_hdr(uint32_t *hdr, struct video_desc *desc);
|
||||
|
||||
/** @} */ // end of video_rtp_decoder
|
||||
|
||||
|
||||
180
src/rtp/yuri_decoders.cpp
Normal file
180
src/rtp/yuri_decoders.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @file rtp/yuri_decoders.cpp
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2013 CESNET z.s.p.o.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, is permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of CESNET nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config_unix.h"
|
||||
#include "config_win32.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include "audio/utils.h"
|
||||
#include "rtp/rtp.h"
|
||||
#include "rtp/rtp_callback.h"
|
||||
#include "rtp/pbuf.h"
|
||||
#include "rtp/audio_decoders.h"
|
||||
#include "rtp/yuri_decoders.h"
|
||||
#include "rtp/video_decoders.h"
|
||||
|
||||
#include "yuri/core/frame/RawAudioFrame.h"
|
||||
#include "yuri/core/frame/CompressedVideoFrame.h"
|
||||
#include "yuri/core/frame/RawVideoFrame.h"
|
||||
#include "modules/ultragrid/YuriUltragrid.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static int decode_yuri_audio_frame(struct coded_data *cdata, yuri_decoder_data *s)
|
||||
{
|
||||
rtp_packet *pckt = NULL;
|
||||
uint32_t *hdr;
|
||||
int buffer_length;
|
||||
struct audio_desc network_desc;
|
||||
char *received_data = NULL;
|
||||
|
||||
pckt = cdata->data;
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
parse_audio_hdr(hdr, &network_desc);
|
||||
buffer_length = ntohl(hdr[2]);
|
||||
|
||||
if (network_desc.codec != AC_PCM) {
|
||||
s->log[yuri::log::warning] << "Compressed audio is not yet supported!";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
yuri::core::pRawAudioFrame frame = yuri::core::RawAudioFrame::create_empty(
|
||||
yuri::ultragrid::audio_uv_to_yuri(network_desc.bps * 8), network_desc.ch_count,
|
||||
network_desc.sample_rate, yuri::uvector<uint8_t>(buffer_length * network_desc.ch_count));
|
||||
received_data = reinterpret_cast<char *>(frame->data());
|
||||
s->yuri_frame = frame;
|
||||
if (!s->yuri_frame) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (cdata != NULL) {
|
||||
uint32_t *hdr;
|
||||
uint32_t substream;
|
||||
char *data;
|
||||
uint32_t data_pos;
|
||||
int len;
|
||||
|
||||
pckt = cdata->data;
|
||||
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
data_pos = ntohl(hdr[1]);
|
||||
substream = ntohl(hdr[0]) >> 22;
|
||||
|
||||
len = pckt->data_len - sizeof(audio_payload_hdr_t);
|
||||
data = (char *) hdr + sizeof(audio_payload_hdr_t);
|
||||
|
||||
mux_channel(received_data + data_pos * network_desc.ch_count, data, network_desc.bps,
|
||||
len, network_desc.ch_count, substream, 1.0);
|
||||
|
||||
cdata = cdata->nxt;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int decode_yuri_video_frame(struct coded_data *cdata, yuri_decoder_data *s)
|
||||
{
|
||||
char *received_data = NULL;
|
||||
|
||||
rtp_packet *pckt = NULL;
|
||||
int buffer_length;
|
||||
uint32_t *hdr;
|
||||
struct video_desc network_desc;
|
||||
|
||||
pckt = cdata->data;
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
parse_video_hdr(hdr, &network_desc);
|
||||
buffer_length = ntohl(hdr[2]);
|
||||
|
||||
s->yuri_frame = yuri::ultragrid::create_yuri_from_uv_desc(&network_desc, buffer_length, s->log);
|
||||
if (!s->yuri_frame) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
auto raw = dynamic_pointer_cast<yuri::core::RawVideoFrame>(s->yuri_frame);
|
||||
if (raw) {
|
||||
received_data = reinterpret_cast<char *>(PLANE_RAW_DATA(raw, 0));
|
||||
} else {
|
||||
auto compressed = dynamic_pointer_cast<yuri::core::CompressedVideoFrame>(s->yuri_frame);
|
||||
if (compressed) {
|
||||
received_data = reinterpret_cast<char *>(compressed->begin());
|
||||
}
|
||||
}
|
||||
|
||||
while (cdata != NULL) {
|
||||
char *data;
|
||||
uint32_t data_pos;
|
||||
int len;
|
||||
uint32_t *hdr;
|
||||
uint32_t substream;
|
||||
pckt = cdata->data;
|
||||
|
||||
hdr = (uint32_t *)(void *) pckt->data;
|
||||
data_pos = ntohl(hdr[1]);
|
||||
substream = ntohl(hdr[0]) >> 22;
|
||||
|
||||
if (substream > 0) {
|
||||
s->log[yuri::log::warning] << "Multiple substreams for video yet supported!";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
len = pckt->data_len - sizeof(video_payload_hdr_t);
|
||||
data = (char *) hdr + sizeof(video_payload_hdr_t);
|
||||
|
||||
memcpy(received_data + data_pos, (unsigned char*) data, len);
|
||||
|
||||
cdata = cdata->nxt;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int decode_yuri_frame(struct coded_data *cdata, void *decoder_data)
|
||||
{
|
||||
yuri_decoder_data *s = (yuri_decoder_data *) decoder_data;
|
||||
if (cdata->data->pt == PT_VIDEO) {
|
||||
return decode_yuri_video_frame(cdata, s);
|
||||
} else if (cdata->data ->pt == PT_AUDIO) {
|
||||
return decode_yuri_audio_frame(cdata, s);
|
||||
} else {
|
||||
s->log[yuri::log::warning] << "Unsupported UltraGrid pt " << cdata->data->pt << "!";
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
59
src/rtp/yuri_decoders.h
Normal file
59
src/rtp/yuri_decoders.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file yuri_decoders.h
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2014 CESNET, z. s. p. o.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, is permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of CESNET nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
struct coded_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "yuri/log/Log.h"
|
||||
#include "yuri/core/frame/Frame.h"
|
||||
|
||||
struct yuri_decoder_data {
|
||||
yuri_decoder_data(yuri::log::Log &log_) : log(log_) {}
|
||||
yuri::log::Log &log;
|
||||
yuri::core::pFrame yuri_frame;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
int decode_yuri_frame(struct coded_data *received_data, void *decoder_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user