[SCM] libav/experimental: Handle G.722 in RTP, and all the exceptions mandated in RFC 3551

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 17:15:50 UTC 2013


The following commit has been merged in the experimental branch:
commit 0048a2a8d347c9a81a781f4126023018f1b29527
Author: Martin Storsjö <martin at martin.st>
Date:   Wed Sep 15 17:35:39 2010 +0000

    Handle G.722 in RTP, and all the exceptions mandated in RFC 3551
    
    Originally committed as revision 25125 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index a8dcfd7..70c5e99 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -48,7 +48,7 @@ static const struct
   {6, "DVI4",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_NONE, 16000, 1},
   {7, "LPC",         AVMEDIA_TYPE_AUDIO,   CODEC_ID_NONE, 8000, 1},
   {8, "PCMA",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_PCM_ALAW, 8000, 1},
-  {9, "G722",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_NONE, 8000, 1},
+  {9, "G722",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_ADPCM_G722, 8000, 1},
   {10, "L16",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_PCM_S16BE, 44100, 2},
   {11, "L16",        AVMEDIA_TYPE_AUDIO,   CODEC_ID_PCM_S16BE, 44100, 1},
   {12, "QCELP",      AVMEDIA_TYPE_AUDIO,   CODEC_ID_QCELP, 8000, 1},
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index debc14c..942b8d7 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -365,6 +365,13 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r
         case CODEC_ID_H264:
             st->need_parsing = AVSTREAM_PARSE_FULL;
             break;
+        case CODEC_ID_ADPCM_G722:
+            av_set_pts_info(st, 32, 1, st->codec->sample_rate);
+            /* According to RFC 3551, the stream clock rate is 8000
+             * even if the sample rate is 16000. */
+            if (st->codec->sample_rate == 8000)
+                st->codec->sample_rate = 16000;
+            break;
         default:
             if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index f5e1e3b..0a2959d 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -56,6 +56,7 @@ static int is_supported(enum CodecID id)
     case CODEC_ID_VORBIS:
     case CODEC_ID_THEORA:
     case CODEC_ID_VP8:
+    case CODEC_ID_ADPCM_G722:
         return 1;
     default:
         return 0;
@@ -148,6 +149,11 @@ static int rtp_write_header(AVFormatContext *s1)
     case CODEC_ID_VP8:
         av_log(s1, AV_LOG_WARNING, "RTP VP8 payload is still experimental\n");
         break;
+    case CODEC_ID_ADPCM_G722:
+        /* Due to a historical error, the clock rate for G722 in RTP is
+         * 8000, even if the sample rate is 16000. See RFC 3551. */
+        av_set_pts_info(st, 32, 1, 8000);
+        break;
     case CODEC_ID_AMR_NB:
     case CODEC_ID_AMR_WB:
         if (!s->max_frames_per_packet)
@@ -382,6 +388,12 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
     case CODEC_ID_PCM_S16LE:
         rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels);
         break;
+    case 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 is 1 byte per stream clock. */
+        rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels);
+        break;
     case CODEC_ID_MP2:
     case CODEC_ID_MP3:
         rtp_send_mpegaudio(s1, pkt->data, size);
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index f7c1193..a4bf7fb 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -419,6 +419,12 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
             av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n",
                                      payload_type);
             break;
+        case CODEC_ID_ADPCM_G722:
+            if (payload_type >= RTP_PT_PRIVATE)
+                av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n",
+                                         payload_type,
+                                         8000, c->channels);
+            break;
         default:
             /* Nothing special to do here... */
             break;

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list