]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutdec.c
10l trocadero: now return value of ff_rtmp_packet_read() has different meaning
[ffmpeg] / libavformat / nutdec.c
index 5dac94c4b900b32b09885b73e1085735a8078b91..564faf2030ac0a4e64b442e3abc802da2d112a24 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;
         }
@@ -314,15 +316,15 @@ static int decode_stream_header(NUTContext *nut){
     {
         case 0:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
-            st->codec->codec_id = codec_get_id(codec_bmp_tags, tmp);
+            st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp);
             break;
         case 1:
             st->codec->codec_type = CODEC_TYPE_AUDIO;
-            st->codec->codec_id = codec_get_id(codec_wav_tags, tmp);
+            st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, tmp);
             break;
         case 2:
             st->codec->codec_type = CODEC_TYPE_SUBTITLE;
-            st->codec->codec_id = codec_get_id(ff_nut_subtitle_tags, tmp);
+            st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp);
             break;
         case 3:
             st->codec->codec_type = CODEC_TYPE_DATA;
@@ -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 */
@@ -394,6 +396,7 @@ static int decode_info_header(NUTContext *nut){
     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);
@@ -409,7 +412,8 @@ static int decode_info_header(NUTContext *nut){
         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));
@@ -439,21 +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);
-        }
-        if(chapter && !strcmp(type, "UTF-8")){
-            if(!strcmp(name, "Title"))
-                chapter->title= av_strdup(str_value);
+            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);
         }
     }
 
@@ -846,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;
 
@@ -905,7 +904,7 @@ static int nut_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_NUT_DEMUXER
+#if CONFIG_NUT_DEMUXER
 AVInputFormat nut_demuxer = {
     "nut",
     NULL_IF_CONFIG_SMALL("NUT format"),