Browse Source

rtp: convert to new channel layout API

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Vittorio Giovara 8 years ago
parent
commit
620d151e5c
6 changed files with 21 additions and 19 deletions
  1. 7 4
      libavformat/rtp.c
  2. 2 2
      libavformat/rtpdec.c
  3. 2 2
      libavformat/rtpdec_amr.c
  4. 7 7
      libavformat/rtpenc.c
  5. 3 3
      libavformat/rtsp.c
  6. 0 1
      libavformat/rtsp.h

+ 7 - 4
libavformat/rtp.c

@@ -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) {
             if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) {
                 par->codec_type = rtp_payload_types[i].codec_type;
                 par->codec_type = rtp_payload_types[i].codec_type;
                 par->codec_id = rtp_payload_types[i].codec_id;
                 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)
                 if (rtp_payload_types[i].clock_rate > 0)
                     par->sample_rate = rtp_payload_types[i].clock_rate;
                     par->sample_rate = rtp_payload_types[i].clock_rate;
                 return 0;
                 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,
             /* G722 has 8000 as nominal rate even if the sample rate is 16000,
              * see section 4.5.2 in RFC 3551. */
              * see section 4.5.2 in RFC 3551. */
             if (par->codec_id == AV_CODEC_ID_ADPCM_G722 &&
             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;
                 return rtp_payload_types[i].pt;
             if (par->codec_type == AVMEDIA_TYPE_AUDIO &&
             if (par->codec_type == AVMEDIA_TYPE_AUDIO &&
                 ((rtp_payload_types[i].clock_rate > 0 &&
                 ((rtp_payload_types[i].clock_rate > 0 &&
                   par->sample_rate != rtp_payload_types[i].clock_rate) ||
                   par->sample_rate != rtp_payload_types[i].clock_rate) ||
                  (rtp_payload_types[i].audio_channels > 0 &&
                  (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;
                 continue;
             return rtp_payload_types[i].pt;
             return rtp_payload_types[i].pt;
         }
         }

+ 2 - 2
libavformat/rtpdec.c

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

+ 2 - 2
libavformat/rtpdec_amr.c

@@ -64,11 +64,11 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
         return AVERROR_INVALIDDATA;
         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");
         av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n");
         return AVERROR_INVALIDDATA;
         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
     /* The AMR RTP packet consists of one header byte, followed
      * by one TOC byte for each AMR frame in the packet, followed
      * by one TOC byte for each AMR frame in the packet, followed

+ 7 - 7
libavformat/rtpenc.c

@@ -236,7 +236,7 @@ static int rtp_write_header(AVFormatContext *s1)
         avpriv_set_pts_info(st, 32, 1, 8000);
         avpriv_set_pts_info(st, 32, 1, 8000);
         break;
         break;
     case AV_CODEC_ID_OPUS:
     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");
             av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
             goto fail;
             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");
             av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
             goto fail;
             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");
             av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
             goto fail;
             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_ALAW:
     case AV_CODEC_ID_PCM_U8:
     case AV_CODEC_ID_PCM_U8:
     case AV_CODEC_ID_PCM_S8:
     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_U16BE:
     case AV_CODEC_ID_PCM_U16LE:
     case AV_CODEC_ID_PCM_U16LE:
     case AV_CODEC_ID_PCM_S16BE:
     case AV_CODEC_ID_PCM_S16BE:
     case AV_CODEC_ID_PCM_S16LE:
     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:
     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:
     case AV_CODEC_ID_ADPCM_G722:
         /* The actual sample size is half a byte per sample, but since the
         /* 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,
          * 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
          * the correct parameter for send_samples_bits is 8 bits per stream
          * clock. */
          * 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_G726:
     case AV_CODEC_ID_ADPCM_G726LE:
     case AV_CODEC_ID_ADPCM_G726LE:
         return rtp_send_samples(s1, pkt->data, size,
         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_MP2:
     case AV_CODEC_ID_MP3:
     case AV_CODEC_ID_MP3:
         rtp_send_mpegaudio(s1, pkt->data, size);
         rtp_send_mpegaudio(s1, pkt->data, size);

+ 3 - 3
libavformat/rtsp.c

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

+ 0 - 1
libavformat/rtsp.h

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