]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutdec.c
Motion Pixels MVI Demuxer.
[ffmpeg] / libavformat / nutdec.c
index 402f1f5d4a003db87e2fba4739830af48250a251..5dac94c4b900b32b09885b73e1085735a8078b91 100644 (file)
@@ -20,9 +20,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "tree.h"
+#include "libavutil/avstring.h"
+#include "libavutil/tree.h"
 #include "nut.h"
-#include "avstring.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -111,7 +111,7 @@ static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){
     uint64_t state=0;
 
     if(pos >= 0)
-        url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we are currently
+        url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we currently are
 
     while(!url_feof(bc)){
         state= (state<<8) | get_byte(bc);
@@ -322,7 +322,7 @@ static int decode_stream_header(NUTContext *nut){
             break;
         case 2:
             st->codec->codec_type = CODEC_TYPE_SUBTITLE;
-//            st->codec->codec_id = codec_get_id(codec_wav_tags, tmp); FIXME
+            st->codec->codec_id = codec_get_id(ff_nut_subtitle_tags, tmp);
             break;
         case 3:
             st->codec->codec_type = CODEC_TYPE_DATA;
@@ -371,6 +371,19 @@ static int decode_stream_header(NUTContext *nut){
     return 0;
 }
 
+static void set_disposition_bits(AVFormatContext* avf, char* value, int stream_id){
+    int flag = 0, i;
+    for (i=0; ff_nut_dispositions[i].flag; ++i) {
+        if (!strcmp(ff_nut_dispositions[i].str, value))
+            flag = ff_nut_dispositions[i].flag;
+    }
+    if (!flag)
+        av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
+    for (i = 0; i < avf->nb_streams; ++i)
+        if (stream_id == i || stream_id == -1)
+            avf->streams[i]->disposition |= flag;
+}
+
 static int decode_info_header(NUTContext *nut){
     AVFormatContext *s= nut->avf;
     ByteIOContext *bc = s->pb;
@@ -380,6 +393,7 @@ 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;
 
     end= get_packetheader(nut, bc, 1, INFO_STARTCODE);
     end += url_ftell(bc);
@@ -389,6 +403,14 @@ 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);
+    }
+
     for(i=0; i<count; i++){
         get_str(bc, name, sizeof(name));
         value= get_s(bc);
@@ -412,6 +434,11 @@ static int decode_info_header(NUTContext *nut){
             type= "v";
         }
 
+        if (stream_id_plus1 > s->nb_streams) {
+            av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");
+            continue;
+        }
+
         if(chapter_id==0 && !strcmp(type, "UTF-8")){
             if     (!strcmp(name, "Author"))
                 av_strlcpy(s->author   , str_value, sizeof(s->author));
@@ -421,6 +448,12 @@ static int decode_info_header(NUTContext *nut){
                 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"))
+                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);
         }
     }
 
@@ -467,6 +500,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);
@@ -483,7 +517,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];
     }
@@ -500,7 +536,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;
@@ -509,7 +545,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;
@@ -517,7 +553,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++){
@@ -544,9 +580,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)
@@ -834,7 +874,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag
                                                 next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp);
             if(pos2>=0)
                 pos= pos2;
-            //FIXME dir but i think it does not matter
+            //FIXME dir but I think it does not matter
         }
         dummy.pos= pos;
         sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL);
@@ -868,7 +908,7 @@ static int nut_read_close(AVFormatContext *s)
 #ifdef CONFIG_NUT_DEMUXER
 AVInputFormat nut_demuxer = {
     "nut",
-    "nut format",
+    NULL_IF_CONFIG_SMALL("NUT format"),
     sizeof(NUTContext),
     nut_probe,
     nut_read_header,