rtp: convert to new channel layout API

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Vittorio Giovara 2017-03-31 18:25:12 +02:00 committed by James Almer
parent b76e878f5b
commit 620d151e5c
6 changed files with 21 additions and 19 deletions

View File

@ -77,8 +77,11 @@ int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type)
if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) {
par->codec_type = rtp_payload_types[i].codec_type;
par->codec_id = rtp_payload_types[i].codec_id;
if (rtp_payload_types[i].audio_channels > 0)
par->channels = rtp_payload_types[i].audio_channels;
if (rtp_payload_types[i].audio_channels > 0) {
av_channel_layout_uninit(&par->ch_layout);
par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
par->ch_layout.nb_channels = rtp_payload_types[i].audio_channels;
}
if (rtp_payload_types[i].clock_rate > 0)
par->sample_rate = rtp_payload_types[i].clock_rate;
return 0;
@ -111,13 +114,13 @@ int ff_rtp_get_payload_type(const AVFormatContext *fmt,
/* G722 has 8000 as nominal rate even if the sample rate is 16000,
* see section 4.5.2 in RFC 3551. */
if (par->codec_id == AV_CODEC_ID_ADPCM_G722 &&
par->sample_rate == 16000 && par->channels == 1)
par->sample_rate == 16000 && par->ch_layout.nb_channels == 1)
return rtp_payload_types[i].pt;
if (par->codec_type == AVMEDIA_TYPE_AUDIO &&
((rtp_payload_types[i].clock_rate > 0 &&
par->sample_rate != rtp_payload_types[i].clock_rate) ||
(rtp_payload_types[i].audio_channels > 0 &&
par->channels != rtp_payload_types[i].audio_channels)))
par->ch_layout.nb_channels != rtp_payload_types[i].audio_channels)))
continue;
return rtp_payload_types[i].pt;
}

View File

@ -538,7 +538,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar)
* This mapping family only supports mono and stereo layouts. And RFC7587
* specifies that the number of channels in the SDP must be 2.
*/
if (codecpar->channels > 2) {
if (codecpar->ch_layout.nb_channels > 2) {
return AVERROR_INVALIDDATA;
}
@ -553,7 +553,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar)
/* Version */
bytestream_put_byte (&bs, 0x1);
/* Channel count */
bytestream_put_byte (&bs, codecpar->channels);
bytestream_put_byte (&bs, codecpar->ch_layout.nb_channels);
/* Pre skip */
bytestream_put_le16 (&bs, 0);
/* Input sample rate */

View File

@ -64,11 +64,11 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
return AVERROR_INVALIDDATA;
}
if (st->codecpar->channels != 1) {
if (st->codecpar->ch_layout.nb_channels != 1) {
av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n");
return AVERROR_INVALIDDATA;
}
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
av_channel_layout_default(&st->codecpar->ch_layout, 1);
/* The AMR RTP packet consists of one header byte, followed
* by one TOC byte for each AMR frame in the packet, followed

View File

@ -236,7 +236,7 @@ static int rtp_write_header(AVFormatContext *s1)
avpriv_set_pts_info(st, 32, 1, 8000);
break;
case AV_CODEC_ID_OPUS:
if (st->codecpar->channels > 2) {
if (st->codecpar->ch_layout.nb_channels > 2) {
av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
goto fail;
}
@ -264,7 +264,7 @@ static int rtp_write_header(AVFormatContext *s1)
av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
goto fail;
}
if (st->codecpar->channels != 1) {
if (st->codecpar->ch_layout.nb_channels != 1) {
av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
goto fail;
}
@ -541,24 +541,24 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
case AV_CODEC_ID_PCM_ALAW:
case AV_CODEC_ID_PCM_U8:
case AV_CODEC_ID_PCM_S8:
return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels);
case AV_CODEC_ID_PCM_U16BE:
case AV_CODEC_ID_PCM_U16LE:
case AV_CODEC_ID_PCM_S16BE:
case AV_CODEC_ID_PCM_S16LE:
return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels);
return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->ch_layout.nb_channels);
case AV_CODEC_ID_PCM_S24BE:
return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->channels);
return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->ch_layout.nb_channels);
case AV_CODEC_ID_ADPCM_G722:
/* The actual sample size is half a byte per sample, but since the
* stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
* the correct parameter for send_samples_bits is 8 bits per stream
* clock. */
return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels);
case AV_CODEC_ID_ADPCM_G726:
case AV_CODEC_ID_ADPCM_G726LE:
return rtp_send_samples(s1, pkt->data, size,
st->codecpar->bits_per_coded_sample * st->codecpar->channels);
st->codecpar->bits_per_coded_sample * st->codecpar->ch_layout.nb_channels);
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
rtp_send_mpegaudio(s1, pkt->data, size);

View File

@ -323,19 +323,19 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
case AVMEDIA_TYPE_AUDIO:
av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name);
par->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE;
par->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS;
par->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
if (i > 0) {
par->sample_rate = i;
avpriv_set_pts_info(st, 32, 1, par->sample_rate);
get_word_sep(buf, sizeof(buf), "/", &p);
i = atoi(buf);
if (i > 0)
par->channels = i;
av_channel_layout_default(&par->ch_layout, i);
}
av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n",
par->sample_rate);
av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n",
par->channels);
par->ch_layout.nb_channels);
break;
case AVMEDIA_TYPE_VIDEO:
av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name);

View File

@ -75,7 +75,6 @@ enum RTSPControlTransport {
#define RTSPS_DEFAULT_PORT 322
#define RTSP_MAX_TRANSPORTS 8
#define RTSP_TCP_MAX_PACKET_SIZE 1472
#define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
#define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
#define RTSP_RTP_PORT_MIN 5000
#define RTSP_RTP_PORT_MAX 65000