]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/xa.c
rtspdec: Move rtsp_read_pause up, next to rtsp_read_play
[ffmpeg] / libavformat / xa.c
index 88f731a3da40341ec355c0449fa20dc5692a6ea2..3a866b992fece39005a83287b8a874e7f0612978 100644 (file)
  */
 
 /**
- * @file xa.c
+ * @file
  * Maxis XA File Demuxer
  * by Robert Marston (rmarston@gmail.com)
  * for more information on the XA audio format see
  *   http://wiki.multimedia.cx/index.php?title=Maxis_XA
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define XA00_TAG MKTAG('X', 'A', 0, 0)
@@ -41,13 +42,24 @@ typedef struct MaxisXADemuxContext {
 
 static int xa_probe(AVProbeData *p)
 {
+    int channels, srate, bits_per_sample;
+    if (p->buf_size < 24)
+        return 0;
     switch(AV_RL32(p->buf)) {
     case XA00_TAG:
     case XAI0_TAG:
     case XAJ0_TAG:
-        return AVPROBE_SCORE_MAX;
+        break;
+    default:
+        return 0;
     }
-    return 0;
+    channels        = AV_RL16(p->buf + 10);
+    srate           = AV_RL32(p->buf + 12);
+    bits_per_sample = AV_RL16(p->buf + 22);
+    if (!channels || channels > 8 || !srate || srate > 192000 ||
+        bits_per_sample < 4 || bits_per_sample > 32)
+        return 0;
+    return AVPROBE_SCORE_MAX/2;
 }
 
 static int xa_read_header(AVFormatContext *s,
@@ -62,7 +74,7 @@ static int xa_read_header(AVFormatContext *s,
     if (!st)
         return AVERROR(ENOMEM);
 
-    st->codec->codec_type   = CODEC_TYPE_AUDIO;
+    st->codec->codec_type   = AVMEDIA_TYPE_AUDIO;
     st->codec->codec_id     = CODEC_ID_ADPCM_EA_MAXIS_XA;
     url_fskip(pb, 4);       /* Skip the XA ID */
     xa->out_size            =  get_le32(pb);
@@ -72,7 +84,7 @@ static int xa_read_header(AVFormatContext *s,
     /* Value in file is average byte rate*/
     st->codec->bit_rate     = get_le32(pb) * 8;
     st->codec->block_align  = get_le16(pb);
-    st->codec->bits_per_sample = get_le16(pb);
+    st->codec->bits_per_coded_sample = get_le16(pb);
 
     av_set_pts_info(st, 64, 1, st->codec->sample_rate);
 
@@ -94,8 +106,8 @@ static int xa_read_packet(AVFormatContext *s,
     packet_size = 15*st->codec->channels;
 
     ret = av_get_packet(pb, pkt, packet_size);
-    if(ret != packet_size)
-        return AVERROR(EIO);
+    if(ret < 0)
+        return ret;
 
     pkt->stream_index = st->index;
     xa->sent_bytes += packet_size;
@@ -108,7 +120,7 @@ static int xa_read_packet(AVFormatContext *s,
 
 AVInputFormat xa_demuxer = {
     "xa",
-    "Maxis XA File Format",
+    NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
     sizeof(MaxisXADemuxContext),
     xa_probe,
     xa_read_header,