]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutdec.c
Make rtp_write_header() fail in case of unsupported payload type
[ffmpeg] / libavformat / nutdec.c
index 772a527f8e455363c66ad62100b4cb215e97d96b..2243d001d9c7f4cb345b596b2808f67252a614d7 100644 (file)
@@ -20,7 +20,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <strings.h>
 #include "libavutil/avstring.h"
+#include "libavutil/bswap.h"
 #include "libavutil/tree.h"
 #include "nut.h"
 
@@ -205,7 +207,7 @@ static int decode_main_header(NUTContext *nut){
     for(i=0; i<nut->time_base_count; i++){
         GET_V(nut->time_base[i].num, tmp>0 && tmp<(1ULL<<31))
         GET_V(nut->time_base[i].den, tmp>0 && tmp<(1ULL<<31))
-        if(ff_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
+        if(av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1){
             av_log(s, AV_LOG_ERROR, "time base invalid\n");
             return -1;
         }
@@ -350,10 +352,10 @@ static int decode_stream_header(NUTContext *nut){
     if (st->codec->codec_type == CODEC_TYPE_VIDEO){
         GET_V(st->codec->width , tmp > 0)
         GET_V(st->codec->height, tmp > 0)
-        st->codec->sample_aspect_ratio.num= ff_get_v(bc);
-        st->codec->sample_aspect_ratio.den= ff_get_v(bc);
-        if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){
-            av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->codec->sample_aspect_ratio.num, st->codec->sample_aspect_ratio.den);
+        st->sample_aspect_ratio.num= ff_get_v(bc);
+        st->sample_aspect_ratio.den= ff_get_v(bc);
+        if((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)){
+            av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
             return -1;
         }
         ff_get_v(bc); /* csp type */
@@ -393,6 +395,8 @@ static int decode_info_header(NUTContext *nut){
     int64_t value, end;
     char name[256], str_value[1024], type_str[256];
     const char *type;
+    AVChapter *chapter= NULL;
+    AVStream *st= NULL;
 
     end= get_packetheader(nut, bc, 1, INFO_STARTCODE);
     end += url_ftell(bc);
@@ -402,6 +406,15 @@ static int decode_info_header(NUTContext *nut){
     chapter_start= ff_get_v(bc);
     chapter_len  = ff_get_v(bc);
     count        = ff_get_v(bc);
+
+    if(chapter_id && !stream_id_plus1){
+        int64_t start= chapter_start / nut->time_base_count;
+        chapter= ff_new_chapter(s, chapter_id,
+                                nut->time_base[chapter_start % nut->time_base_count],
+                                start, start + chapter_len, NULL);
+    } else if(stream_id_plus1)
+        st= s->streams[stream_id_plus1 - 1];
+
     for(i=0; i<count; i++){
         get_str(bc, name, sizeof(name));
         value= get_s(bc);
@@ -430,17 +443,16 @@ static int decode_info_header(NUTContext *nut){
             continue;
         }
 
-        if(chapter_id==0 && !strcmp(type, "UTF-8")){
-            if     (!strcmp(name, "Author"))
-                av_strlcpy(s->author   , str_value, sizeof(s->author));
-            else if(!strcmp(name, "Title"))
-                av_strlcpy(s->title    , str_value, sizeof(s->title));
-            else if(!strcmp(name, "Copyright"))
-                av_strlcpy(s->copyright, str_value, sizeof(s->copyright));
-            else if(!strcmp(name, "Description"))
-                av_strlcpy(s->comment  , str_value, sizeof(s->comment));
-            else if(!strcmp(name, "Disposition"))
+        if(!strcmp(type, "UTF-8")){
+            AVMetadata **metadata = NULL;
+            if(chapter_id==0 && !strcmp(name, "Disposition"))
                 set_disposition_bits(s, str_value, stream_id_plus1 - 1);
+            else if(chapter)          metadata= &chapter->metadata;
+            else if(stream_id_plus1)  metadata= &st->metadata;
+            else                      metadata= &s->metadata;
+            if(metadata && strcasecmp(name,"Uses")
+               && strcasecmp(name,"Depends") && strcasecmp(name,"Replaces"))
+                av_metadata_set(metadata, name, str_value);
         }
     }
 
@@ -487,6 +499,7 @@ static int find_and_decode_index(NUTContext *nut){
     int64_t filesize= url_fsize(bc);
     int64_t *syncpoints;
     int8_t *has_keyframe;
+    int ret= -1;
 
     url_fseek(bc, filesize-12, SEEK_SET);
     url_fseek(bc, filesize-get_be64(bc), SEEK_SET);
@@ -503,7 +516,9 @@ static int find_and_decode_index(NUTContext *nut){
     syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count);
     has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1));
     for(i=0; i<syncpoint_count; i++){
-        GET_V(syncpoints[i], tmp>0)
+        syncpoints[i] = ff_get_v(bc);
+        if(syncpoints[i] <= 0)
+            goto fail;
         if(i)
             syncpoints[i] += syncpoints[i-1];
     }
@@ -520,7 +535,7 @@ static int find_and_decode_index(NUTContext *nut){
                 x>>=1;
                 if(n+x >= syncpoint_count + 1){
                     av_log(s, AV_LOG_ERROR, "index overflow A\n");
-                    return -1;
+                    goto fail;
                 }
                 while(x--)
                     has_keyframe[n++]= flag;
@@ -529,7 +544,7 @@ static int find_and_decode_index(NUTContext *nut){
                 while(x != 1){
                     if(n>=syncpoint_count + 1){
                         av_log(s, AV_LOG_ERROR, "index overflow B\n");
-                        return -1;
+                        goto fail;
                     }
                     has_keyframe[n++]= x&1;
                     x>>=1;
@@ -537,7 +552,7 @@ static int find_and_decode_index(NUTContext *nut){
             }
             if(has_keyframe[0]){
                 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
-                return -1;
+                goto fail;
             }
             assert(n<=syncpoint_count+1);
             for(; j<n && j<syncpoint_count; j++){
@@ -564,9 +579,13 @@ static int find_and_decode_index(NUTContext *nut){
 
     if(skip_reserved(bc, end) || get_checksum(bc)){
         av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
-        return -1;
+        goto fail;
     }
-    return 0;
+    ret= 0;
+fail:
+    av_free(syncpoints);
+    av_free(has_keyframe);
+    return ret;
 }
 
 static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
@@ -826,9 +845,9 @@ assert(0);
 static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags){
     NUTContext *nut = s->priv_data;
     AVStream *st= s->streams[stream_index];
-    syncpoint_t dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE};
-    syncpoint_t nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE};
-    syncpoint_t *sp, *next_node[2]= {&nopts_sp, &nopts_sp};
+    Syncpoint dummy={.ts= pts*av_q2d(st->time_base)*AV_TIME_BASE};
+    Syncpoint nopts_sp= {.ts= AV_NOPTS_VALUE, .back_ptr= AV_NOPTS_VALUE};
+    Syncpoint *sp, *next_node[2]= {&nopts_sp, &nopts_sp};
     int64_t pos, pos2, ts;
     int i;
 
@@ -885,10 +904,10 @@ static int nut_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_NUT_DEMUXER
+#if CONFIG_NUT_DEMUXER
 AVInputFormat nut_demuxer = {
     "nut",
-    "nut format",
+    NULL_IF_CONFIG_SMALL("NUT format"),
     sizeof(NUTContext),
     nut_probe,
     nut_read_header,