]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_amr.c
libavformat: Add a muxer wrapping mpegts encoding into RTP
[ffmpeg] / libavformat / rtpdec_amr.c
index 802e7c1ce8cc27f00be2501769b344a72a9ba0c7..86348bb0e8519140e7a643af1d1c74299e5ae5d9 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/channel_layout.h"
 #include "avformat.h"
 #include "rtpdec_formats.h"
 #include "libavutil/avstring.h"
@@ -50,13 +51,10 @@ static void amr_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static int amr_handle_packet(AVFormatContext *ctx,
-                             PayloadContext *data,
-                             AVStream *st,
-                             AVPacket * pkt,
-                             uint32_t * timestamp,
-                             const uint8_t * buf,
-                             int len, int flags)
+static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
+                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     const uint8_t *frame_sizes = NULL;
     int frames;
@@ -64,9 +62,9 @@ static int amr_handle_packet(AVFormatContext *ctx,
     const uint8_t *speech_data;
     uint8_t *ptr;
 
-    if (st->codec->codec_id == CODEC_ID_AMR_NB) {
+    if (st->codec->codec_id == AV_CODEC_ID_AMR_NB) {
         frame_sizes = frame_sizes_nb;
-    } else if (st->codec->codec_id == CODEC_ID_AMR_WB) {
+    } else if (st->codec->codec_id == AV_CODEC_ID_AMR_WB) {
         frame_sizes = frame_sizes_wb;
     } else {
         av_log(ctx, AV_LOG_ERROR, "Bad codec ID\n");
@@ -77,6 +75,7 @@ static int amr_handle_packet(AVFormatContext *ctx,
         av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n");
         return AVERROR_INVALIDDATA;
     }
+    st->codec->channel_layout = AV_CH_LAYOUT_MONO;
 
     /* The AMR RTP packet consists of one header byte, followed
      * by one TOC byte for each AMR frame in the packet, followed
@@ -140,7 +139,8 @@ static int amr_handle_packet(AVFormatContext *ctx,
     return 0;
 }
 
-static int amr_parse_fmtp(AVStream *stream, PayloadContext *data,
+static int amr_parse_fmtp(AVFormatContext *s,
+                          AVStream *stream, PayloadContext *data,
                           char *attr, char *value)
 {
     /* Some AMR SDP configurations contain "octet-align", without
@@ -148,8 +148,8 @@ static int amr_parse_fmtp(AVStream *stream, PayloadContext *data,
      * interpret it as "1".
      */
     if (!strcmp(value, "")) {
-        av_log(NULL, AV_LOG_WARNING, "AMR fmtp attribute %s had "
-                                     "nonstandard empty value\n", attr);
+        av_log(s, AV_LOG_WARNING, "AMR fmtp attribute %s had "
+                                  "nonstandard empty value\n", attr);
         strcpy(value, "1");
     }
     if (!strcmp(attr, "octet-align"))
@@ -169,13 +169,16 @@ static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
     const char *p;
     int ret;
 
+    if (st_index < 0)
+        return 0;
+
     /* Parse an fmtp line this one:
      * a=fmtp:97 octet-align=1; interleaving=0
      * That is, a normal fmtp: line followed by semicolon & space
      * separated key/value pairs.
      */
     if (av_strstart(line, "fmtp:", &p)) {
-        ret = ff_parse_fmtp(s->streams[st_index], data, p, amr_parse_fmtp);
+        ret = ff_parse_fmtp(s, s->streams[st_index], data, p, amr_parse_fmtp);
         if (!data->octet_align || data->crc ||
             data->interleaving || data->channels != 1) {
             av_log(s, AV_LOG_ERROR, "Unsupported RTP/AMR configuration!\n");
@@ -189,20 +192,19 @@ static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
 RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = {
     .enc_name         = "AMR",
     .codec_type       = AVMEDIA_TYPE_AUDIO,
-    .codec_id         = CODEC_ID_AMR_NB,
+    .codec_id         = AV_CODEC_ID_AMR_NB,
     .parse_sdp_a_line = amr_parse_sdp_line,
-    .open             = amr_new_context,
-    .close            = amr_free_context,
+    .alloc            = amr_new_context,
+    .free             = amr_free_context,
     .parse_packet     = amr_handle_packet,
 };
 
 RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = {
     .enc_name         = "AMR-WB",
     .codec_type       = AVMEDIA_TYPE_AUDIO,
-    .codec_id         = CODEC_ID_AMR_WB,
+    .codec_id         = AV_CODEC_ID_AMR_WB,
     .parse_sdp_a_line = amr_parse_sdp_line,
-    .open             = amr_new_context,
-    .close            = amr_free_context,
+    .alloc            = amr_new_context,
+    .free             = amr_free_context,
     .parse_packet     = amr_handle_packet,
 };
-