]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutdec.c
In dv decoder, set sample aspect aspect ratio, fix issue #1612
[ffmpeg] / libavformat / nutdec.c
index 8ca59231a8452a236b7129615a8454bd1f3bc78e..fa1cb188d7dc698866d4a31a08c9f4b3cd4b1077 100644 (file)
 #undef NDEBUG
 #include <assert.h>
 
+#if FF_API_MAX_STREAMS
+#define NUT_MAX_STREAMS MAX_STREAMS
+#else
+#define NUT_MAX_STREAMS 256    /* arbitrary sanity check value */
+#endif
+
 static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
     unsigned int len= ff_get_v(bc);
 
@@ -94,8 +100,8 @@ static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_ch
     int64_t size;
 //    start= url_ftell(bc) - 8;
 
-    startcode= be2me_64(startcode);
-    startcode= ff_crc04C11DB7_update(0, &startcode, 8);
+    startcode= av_be2ne64(startcode);
+    startcode= ff_crc04C11DB7_update(0, (uint8_t*)&startcode, 8);
 
     init_checksum(bc, ff_crc04C11DB7_update, startcode);
     size= ff_get_v(bc);
@@ -136,7 +142,7 @@ static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){
  * Find the given startcode.
  * @param code the startcode
  * @param pos the start position of the search, or -1 if the current position
- * @returns the position of the startcode or -1 if not found
+ * @return the position of the startcode or -1 if not found
  */
 static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){
     for(;;){
@@ -193,7 +199,7 @@ static int decode_main_header(NUTContext *nut){
     end += url_ftell(bc);
 
     GET_V(tmp              , tmp >=2 && tmp <= 3)
-    GET_V(stream_count     , tmp > 0 && tmp <=MAX_STREAMS)
+    GET_V(stream_count     , tmp > 0 && tmp <= NUT_MAX_STREAMS)
 
     nut->max_distance = ff_get_v(bc);
     if(nut->max_distance > 65536){
@@ -315,26 +321,29 @@ static int decode_stream_header(NUTContext *nut){
     switch(class)
     {
         case 0:
-            st->codec->codec_type = CODEC_TYPE_VIDEO;
-            st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp);
+            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+            st->codec->codec_id = av_codec_get_id(
+                (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, 0 },
+                tmp);
             break;
         case 1:
-            st->codec->codec_type = CODEC_TYPE_AUDIO;
+            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
             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_type = AVMEDIA_TYPE_SUBTITLE;
             st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp);
             break;
         case 3:
-            st->codec->codec_type = CODEC_TYPE_DATA;
+            st->codec->codec_type = AVMEDIA_TYPE_DATA;
             break;
         default:
             av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
             return -1;
     }
     if(class<3 && st->codec->codec_id == CODEC_ID_NONE)
-        av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
+        av_log(s, AV_LOG_ERROR, "Unknown codec tag '0x%04x' for stream number %d\n",
+               (unsigned int)tmp, stream_id);
 
     GET_V(stc->time_base_id    , tmp < nut->time_base_count);
     GET_V(stc->msb_pts_shift   , tmp < 16);
@@ -349,7 +358,7 @@ static int decode_stream_header(NUTContext *nut){
         get_buffer(bc, st->codec->extradata, st->codec->extradata_size);
     }
 
-    if (st->codec->codec_type == CODEC_TYPE_VIDEO){
+    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
         GET_V(st->codec->width , tmp > 0)
         GET_V(st->codec->height, tmp > 0)
         st->sample_aspect_ratio.num= ff_get_v(bc);
@@ -359,7 +368,7 @@ static int decode_stream_header(NUTContext *nut){
             return -1;
         }
         ff_get_v(bc); /* csp type */
-    }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){
+    }else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO){
         GET_V(st->codec->sample_rate , tmp > 0)
         ff_get_v(bc); // samplerate_den
         GET_V(st->codec->channels, tmp > 0)
@@ -389,8 +398,8 @@ static void set_disposition_bits(AVFormatContext* avf, char* value, int stream_i
 static int decode_info_header(NUTContext *nut){
     AVFormatContext *s= nut->avf;
     ByteIOContext *bc = s->pb;
-    uint64_t tmp;
-    unsigned int stream_id_plus1, chapter_start, chapter_len, count;
+    uint64_t tmp, chapter_start, chapter_len;
+    unsigned int stream_id_plus1, count;
     int chapter_id, i;
     int64_t value, end;
     char name[256], str_value[1024], type_str[256];
@@ -452,7 +461,7 @@ static int decode_info_header(NUTContext *nut){
             else                      metadata= &s->metadata;
             if(metadata && strcasecmp(name,"Uses")
                && strcasecmp(name,"Depends") && strcasecmp(name,"Replaces"))
-                av_metadata_set(metadata, name, str_value);
+                av_metadata_set2(metadata, name, str_value, 0);
         }
     }
 
@@ -754,7 +763,7 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){
 
     pkt->stream_index = stream_id;
     if (stc->last_flags & FLAG_KEY)
-        pkt->flags |= PKT_FLAG_KEY;
+        pkt->flags |= AV_PKT_FLAG_KEY;
     pkt->pts = pts;
 
     return 0;
@@ -859,7 +868,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag
         pos2= st->index_entries[index].pos;
         ts  = st->index_entries[index].timestamp;
     }else{
-        av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, next_node);
+        av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp,
+                     (void **) next_node);
         av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos,
                                                     next_node[0]->ts , next_node[1]->ts);
         pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos,
@@ -868,7 +878,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag
         if(!(flags & AVSEEK_FLAG_BACKWARD)){
             dummy.pos= pos+16;
             next_node[1]= &nopts_sp;
-            av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, next_node);
+            av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
+                         (void **) next_node);
             pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos     , next_node[1]->pos, next_node[1]->pos,
                                                 next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp);
             if(pos2>=0)
@@ -876,7 +887,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag
             //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);
+        sp= av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
+                         NULL);
 
         assert(sp);
         pos2= sp->back_ptr  - 15;
@@ -901,7 +913,7 @@ static int nut_read_close(AVFormatContext *s)
 
     av_freep(&nut->time_base);
     av_freep(&nut->stream);
-    av_tree_destroy_free_elem(nut->syncpoints);
+    ff_nut_free_sp(nut);
     for(i = 1; i < nut->header_count; i++)
         av_freep(&nut->header[i]);
 
@@ -920,5 +932,6 @@ AVInputFormat nut_demuxer = {
     read_seek,
     .extensions = "nut",
     .metadata_conv = ff_nut_metadata_conv,
+    .codec_tag = (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
 };
 #endif