]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/sdp.c
Remove unused variables, fixes the following warnings:
[ffmpeg] / libavformat / sdp.c
index 2809163342809c2e96be7a05bf9c14171f457fd1..f0c65b499ff8987ff029637849e98339ab5e08a4 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "avstring.h"
 #include "avformat.h"
+#include "rtp.h"
 
 #ifdef CONFIG_RTP_MUXER
 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2)
@@ -110,32 +111,61 @@ static char *data_to_hex(char *buff, const uint8_t *src, int s)
     return buff;
 }
 
+static char *extradata2config(const uint8_t *extradata, int extradata_size)
+{
+    char *config;
+
+    if (extradata_size > MAX_EXTRADATA_SIZE) {
+        av_log(NULL, AV_LOG_ERROR, "Too many extra data!\n");
+
+        return NULL;
+    }
+    config = av_malloc(10 + extradata_size * 2);
+    if (config == NULL) {
+        av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory for the config info\n");
+        return NULL;
+    }
+    memcpy(config, "; config=", 9);
+    data_to_hex(config + 9, extradata, extradata_size);
+    config[9 + extradata_size * 2] = 0;
+
+    return config;
+}
+
 static char *sdp_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type)
 {
     char *config = NULL;
 
     switch (c->codec_id) {
         case CODEC_ID_MPEG4:
-            if (c->flags & CODEC_FLAG_GLOBAL_HEADER) {
-                if (c->extradata_size > MAX_EXTRADATA_SIZE) {
-                    av_log(NULL, AV_LOG_ERROR, "Too many extra data!\n");
-
-                    return NULL;
-                }
-                config = av_malloc(10 + c->extradata_size * 2);
-                if (config == NULL) {
-                    av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory for the config info\n");
-                    return NULL;
-                }
-                memcpy(config, "; config=", 9);
-                data_to_hex(config + 9, c->extradata, c->extradata_size);
-                config[9 + c->extradata_size * 2] = 0;
+            if (c->extradata_size) {
+                config = extradata2config(c->extradata, c->extradata_size);
             }
             av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n"
                                     "a=fmtp:%d profile-level-id=1%s\r\n",
                                      payload_type,
                                      payload_type, config ? config : "");
             break;
+        case CODEC_ID_AAC:
+            if (c->extradata_size) {
+                config = extradata2config(c->extradata, c->extradata_size);
+            } else {
+                /* FIXME: maybe we can forge config information based on the
+                 *        codec parameters...
+                 */
+                av_log(NULL, AV_LOG_ERROR, "AAC with no global headers is currently not supported\n");
+                return NULL;
+            }
+            if (config == NULL) {
+                return NULL;
+            }
+            av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n"
+                                    "a=fmtp:%d profile-level-id=1;"
+                                    "mode=AAC-hbr;sizelength=13;indexlength=3;"
+                                    "indexdeltalength=3%s\r\n",
+                                     payload_type, c->sample_rate, c->channels,
+                                     payload_type, config);
+            break;
         default:
             /* Nothing special to do, here... */
             break;
@@ -169,19 +199,13 @@ static void sdp_write_media(char *buff, int size, AVCodecContext *c, const char
     sdp_media_attributes(buff, size, c, payload_type);
 }
 
-#define SDP_BUFFER_SIZE 2048
-char *avf_sdp_create(AVFormatContext *ac[], int n_files)
+int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size)
 {
-    char *buff;
     struct sdp_session_level s;
     int i, j, port, ttl;
     char dst[32];
 
-    buff = av_mallocz(SDP_BUFFER_SIZE);
-    if (buff == NULL) {
-        return NULL;
-    }
-
+    memset(buff, 0, size);
     memset(&s, 0, sizeof(struct sdp_session_level));
     s.user = "-";
     s.src_addr = "127.0.0.1";    /* FIXME: Properly set this */
@@ -196,7 +220,7 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files)
             s.ttl = ttl;
         }
     }
-    sdp_write_header(buff, SDP_BUFFER_SIZE, &s);
+    sdp_write_header(buff, size, &s);
 
     dst[0] = 0;
     for (i = 0; i < n_files; i++) {
@@ -204,21 +228,21 @@ char *avf_sdp_create(AVFormatContext *ac[], int n_files)
             port = get_address(dst, sizeof(dst), &ttl, ac[i]->filename);
         }
         for (j = 0; j < ac[i]->nb_streams; j++) {
-            sdp_write_media(buff, SDP_BUFFER_SIZE,
+            sdp_write_media(buff, size,
                                   ac[i]->streams[j]->codec, dst[0] ? dst : NULL,
                                   (port > 0) ? port + j * 2 : 0, ttl);
             if (port <= 0) {
-                av_strlcatf(buff, SDP_BUFFER_SIZE,
+                av_strlcatf(buff, size,
                                    "a=control:streamid=%d\r\n", i + j);
             }
         }
     }
 
-    return buff;
+    return 0;
 }
 #else
-char *avf_sdp_create(AVFormatContext *ac[], int n_files)
+int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size)
 {
-    return NULL;
+    return AVERROR(ENOSYS);
 }
 #endif