SDP: complain about unsupported codecs

This commit is contained in:
Martin Pulec
2018-11-16 17:16:21 +01:00
parent 7d3d1f8346
commit f8656a08d6
5 changed files with 39 additions and 10 deletions

View File

@@ -109,6 +109,7 @@ static bool is422_8(enum AVPixelFormat pix_fmt) __attribute__((unused));
static bool is420_8(enum AVPixelFormat pix_fmt) __attribute__((unused));
static void print_decoder_error(const char *mod_name, int rc) __attribute__((unused));
static void print_libav_error(int verbosity, const char *msg, int rc) __attribute__((unused));
static bool libav_codec_has_extradata(codec_t codec) __attribute__((unused));
static bool is444_8(enum AVPixelFormat pix_fmt) {
for(unsigned int i = 0; i < sizeof(fmts444_8) / sizeof(enum AVPixelFormat); ++i) {

View File

@@ -148,7 +148,7 @@ static int new_stream(struct sdp *sdp){
return -1;
}
void sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, audio_codec_t codec)
bool sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, audio_codec_t codec)
{
int index = new_stream(sdp);
assert(index >= 0);
@@ -173,11 +173,14 @@ void sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, aud
ts_rate = 48000; // RFC 7587 specifies always 48 kHz for OPUS
break;
default:
abort();
log_msg(LOG_LEVEL_ERROR, "[SDP] Currently only PCMA, PCMU and OPUS audio codecs are supported!\n");
return false;
}
snprintf(sdp->stream[index].rtpmap, STR_LENGTH, "a=rtpmap:%d %s/%i/%i", PT_DynRTP_Type97, audio_codec, ts_rate, channels);
}
return true;
}
void sdp_add_video(struct sdp *sdp, int port, codec_t codec)

View File

@@ -50,7 +50,7 @@ extern "C" {
#define DEFAULT_SDP_HTTP_PORT 8554
struct sdp *new_sdp(int ip_version, const char *receiver);
void sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, audio_codec_t codec);
bool sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, audio_codec_t codec);
void sdp_add_video(struct sdp *sdp, int port, codec_t codec);
bool gen_sdp(struct sdp *sdp);
bool sdp_run_http_server(struct sdp *sdp, int port);

View File

@@ -77,20 +77,31 @@ h264_sdp_video_rxtx::h264_sdp_video_rxtx(std::map<std::string, param_u> const &p
if (m_sdp == nullptr) {
throw string("[SDP] SDP creation failed\n");
}
sdp_add_video(m_sdp, params.at("tx_port").i, H264);
/// @todo this should be done in audio module
if (params.at("a_tx_port").i != 0) {
sdp_add_audio(m_sdp, params.at("a_tx_port").i, params.at("audio_sample_rate").i, params.at("audio_channels").i, static_cast<audio_codec_t>(params.at("audio_codec").l));
if (!sdp_add_audio(m_sdp, params.at("a_tx_port").i, params.at("audio_sample_rate").i, params.at("audio_channels").i, static_cast<audio_codec_t>(params.at("audio_codec").l))) {
throw string("[SDP] Cannot add audio\n");
}
}
m_saved_tx_port = params.at("tx_port").i;
if (strstr(opts, "port=") == opts) {
m_requested_http_port = atoi(strchr(opts, '=') + 1);
}
}
void h264_sdp_video_rxtx::sdp_add_video(codec_t codec)
{
if (codec != H264) {
LOG(LOG_LEVEL_ERROR) << "[SDP] Currently only supported video codec is H.264!\n";
exit_uv(1);
return;
}
::sdp_add_video(m_sdp, m_saved_tx_port, codec);
if (!gen_sdp(m_sdp)){
throw string("[SDP] File creation failed\n");
}
#ifdef SDP_HTTP
int port = DEFAULT_SDP_HTTP_PORT;
if (strstr(opts, "port=") == opts) {
port = atoi(strchr(opts, '=') + 1);
}
if (!sdp_run_http_server(m_sdp, port)){
if (!sdp_run_http_server(m_sdp, m_requested_http_port)){
throw string("[SDP] Server run failed!\n");
}
#endif
@@ -98,6 +109,15 @@ h264_sdp_video_rxtx::h264_sdp_video_rxtx(std::map<std::string, param_u> const &p
void h264_sdp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame)
{
if (m_sdp_configured_codec == VIDEO_CODEC_NONE) {
sdp_add_video(tx_frame->color_spec);
m_sdp_configured_codec = tx_frame->color_spec;
}
if (m_sdp_configured_codec != tx_frame->color_spec) {
LOG(LOG_LEVEL_ERROR) << "[SDP] Video codec reconfiguration is not supported!\n";
}
if (m_connections_count == 1) { /* normal/default case - only one connection */
tx_send_h264(m_tx, tx_frame.get(), m_network_devices[0]);
} else {

View File

@@ -42,6 +42,7 @@
#ifndef VIDEO_RXTX_H264_SDP_H_
#define VIDEO_RXTX_H264_SDP_H_
#include "utils/sdp.h"
#include "video_rxtx.h"
#include "video_rxtx/rtp.h"
@@ -54,7 +55,11 @@ private:
virtual void *(*get_receiver_thread())(void *arg) {
return NULL;
}
void sdp_add_video(codec_t codec);
struct sdp *m_sdp;
codec_t m_sdp_configured_codec = VIDEO_CODEC_NONE;
int m_saved_tx_port;
int m_requested_http_port = DEFAULT_SDP_HTTP_PORT;
};
#endif // VIDEO_RXTX_H264_SDP_H_