]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/jvdec.c
lavf: use conditional notation for default codec in muxer declarations.
[ffmpeg] / libavformat / jvdec.c
index 314a341ac6561c1a24489c388aaf7a04fbc82350..567f4625e0877b04ebe1759f507683b642d7008a 100644 (file)
@@ -2,20 +2,20 @@
  * Bitmap Brothers JV demuxer
  * Copyright (c) 2005, 2011 Peter Ross <pross@xvid.org>
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -27,6 +27,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "internal.h"
 
 #define JV_PREAMBLE_SIZE 5
 
@@ -57,8 +58,7 @@ static int read_probe(AVProbeData *pd)
     return 0;
 }
 
-static int read_header(AVFormatContext *s,
-                       AVFormatParameters *ap)
+static int read_header(AVFormatContext *s)
 {
     JVDemuxContext *jv = s->priv_data;
     AVIOContext *pb = s->pb;
@@ -69,28 +69,29 @@ static int read_header(AVFormatContext *s,
 
     avio_skip(pb, 80);
 
-    ast = av_new_stream(s, 0);
-    vst = av_new_stream(s, 1);
+    ast = avformat_new_stream(s, NULL);
+    vst = avformat_new_stream(s, NULL);
     if (!ast || !vst)
         return AVERROR(ENOMEM);
 
-    vst->codec->codec_type  = CODEC_TYPE_VIDEO;
+    vst->codec->codec_type  = AVMEDIA_TYPE_VIDEO;
     vst->codec->codec_id    = CODEC_ID_JV;
     vst->codec->codec_tag   = 0; /* no fourcc */
     vst->codec->width       = avio_rl16(pb);
     vst->codec->height      = avio_rl16(pb);
+    vst->duration           =
     vst->nb_frames          =
     ast->nb_index_entries   = avio_rl16(pb);
-    av_set_pts_info(vst, 64, avio_rl16(pb), 1000);
+    avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000);
 
     avio_skip(pb, 4);
 
-    ast->codec->codec_type  = CODEC_TYPE_AUDIO;
+    ast->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
     ast->codec->codec_id    = CODEC_ID_PCM_U8;
     ast->codec->codec_tag   = 0; /* no fourcc */
     ast->codec->sample_rate = avio_rl16(pb);
     ast->codec->channels    = 1;
-    av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
+    avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
 
     avio_skip(pb, 10);
 
@@ -116,6 +117,8 @@ static int read_header(AVFormatContext *s,
         jvf->audio_size = avio_rl32(pb);
         jvf->video_size = avio_rl32(pb);
         jvf->palette_size = avio_r8(pb) ? 768 : 0;
+        jvf->video_size = FFMIN(FFMAX(jvf->video_size, 0),
+                                INT_MAX - JV_PREAMBLE_SIZE - jvf->palette_size);
         if (avio_r8(pb))
              av_log(s, AV_LOG_WARNING, "unsupported audio codec\n");
         jvf->video_type = avio_r8(pb);
@@ -137,7 +140,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     AVStream *ast = s->streams[0];
 
-    while (!url_feof(s->pb) && jv->pts < ast->nb_index_entries) {
+    while (!s->pb->eof_reached && jv->pts < ast->nb_index_entries) {
         const AVIndexEntry *e   = ast->index_entries + jv->pts;
         const JVFrame      *jvf = jv->frames + jv->pts;
 
@@ -149,7 +152,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
                     return AVERROR(ENOMEM);
                 pkt->stream_index = 0;
                 pkt->pts          = e->timestamp;
-                pkt->flags       |= PKT_FLAG_KEY;
+                pkt->flags       |= AV_PKT_FLAG_KEY;
                 return 0;
             }
         case JV_VIDEO:
@@ -168,7 +171,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
                 pkt->stream_index = 1;
                 pkt->pts          = jv->pts;
                 if (jvf->video_type != 1)
-                    pkt->flags |= PKT_FLAG_KEY;
+                    pkt->flags |= AV_PKT_FLAG_KEY;
                 return 0;
             }
         case JV_PADDING:
@@ -190,7 +193,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
     int i;
 
     if (flags & (AVSEEK_FLAG_BYTE|AVSEEK_FLAG_FRAME))
-        return AVERROR_NOTSUPP;
+        return AVERROR(ENOSYS);
 
     switch(stream_index) {
     case 0:
@@ -205,10 +208,11 @@ static int read_seek(AVFormatContext *s, int stream_index,
 
     if (i < 0 || i >= ast->nb_index_entries)
         return 0;
+    if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0)
+        return -1;
 
     jv->state = JV_AUDIO;
     jv->pts   = i;
-    avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET);
     return 0;
 }