]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/raw.c
remove useless &0xFF
[ffmpeg] / libavformat / raw.c
index 1057aacf89d9f9285e2c70f25c53ef28368a1540..bd9380315ca6b54b1234a48967a8c8ec2fa31fdc 100644 (file)
  */
 #include "avformat.h"
 #include "ac3_parser.h"
+#include "raw.h"
 
 #ifdef CONFIG_MUXERS
 /* simple formats */
-static int raw_write_header(struct AVFormatContext *s)
-{
-    return 0;
-}
-
 static int flac_write_header(struct AVFormatContext *s)
 {
     static const uint8_t header[8] = {
@@ -72,7 +68,7 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
         id = s->iformat->value;
         if (id == CODEC_ID_RAWVIDEO) {
@@ -115,7 +111,7 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->stream_index = 0;
     if (ret <= 0) {
-        return AVERROR_IO;
+        return AVERROR(EIO);
     }
     /* note: we need to modify the packet size here to handle the last
        packet */
@@ -130,14 +126,14 @@ static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
     size = RAW_PACKET_SIZE;
 
     if (av_new_packet(pkt, size) < 0)
-        return AVERROR_IO;
+        return AVERROR(EIO);
 
     pkt->pos= url_ftell(&s->pb);
     pkt->stream_index = 0;
     ret = get_partial_buffer(&s->pb, pkt->data, size);
     if (ret <= 0) {
         av_free_packet(pkt);
-        return AVERROR_IO;
+        return AVERROR(EIO);
     }
     pkt->size = ret;
     return ret;
@@ -149,7 +145,7 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
     int ret, size, w, h, unk1, unk2;
 
     if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
-        return AVERROR_IO; // FIXME
+        return AVERROR(EIO); // FIXME
 
     size = get_le32(&s->pb);
 
@@ -166,14 +162,14 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
         size, w, h, unk1, unk2);
 
     if (av_new_packet(pkt, size) < 0)
-        return AVERROR_IO;
+        return AVERROR(EIO);
 
     pkt->pos = url_ftell(&s->pb);
     pkt->stream_index = 0;
     ret = get_buffer(&s->pb, pkt->data, size);
     if (ret <= 0) {
         av_free_packet(pkt);
-        return AVERROR_IO;
+        return AVERROR(EIO);
     }
     pkt->size = ret;
     return ret;
@@ -222,7 +218,7 @@ static int ac3_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_AC3;
@@ -238,7 +234,7 @@ static int shorten_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_SHORTEN;
     st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -254,7 +250,7 @@ static int flac_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_FLAC;
     st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -270,7 +266,7 @@ static int dts_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_DTS;
@@ -287,7 +283,7 @@ static int aac_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_AAC;
@@ -304,7 +300,7 @@ static int video_read_header(AVFormatContext *s,
 
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
     st->codec->codec_type = CODEC_TYPE_VIDEO;
     st->codec->codec_id = s->iformat->value;
@@ -366,17 +362,15 @@ static int mpeg4video_probe(AVProbeData *probe_packet)
 
     for(i=0; i<probe_packet->buf_size; i++){
         temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
-        if ((temp_buffer & 0xffffff00) == 0x100) {
-            switch(temp_buffer){
-            case VOP_START_CODE:             VOP++; break;
-            case VISUAL_OBJECT_START_CODE:  VISO++; break;
-            case 0x100 ... 0x11F:             VO++; break;
-            case 0x120 ... 0x12F:            VOL++; break;
-            case 0x130 ... 0x1AF:
-            case 0x1B7 ... 0x1B9:
-            case 0x1C4 ... 0x1FF:            res++; break;
-            }
-        }
+        if ((temp_buffer & 0xffffff00) != 0x100)
+            continue;
+
+        if (temp_buffer == VOP_START_CODE)                         VOP++;
+        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
+        else if (temp_buffer < 0x120)                              VO++;
+        else if (temp_buffer < 0x130)                              VOL++;
+        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
+                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
     }
 
     if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
@@ -416,12 +410,9 @@ static int ac3_probe(AVProbeData *p)
     uint8_t *buf, *buf2, *end;
     AC3HeaderInfo hdr;
 
-    if(p->buf_size < 7)
-        return 0;
-
     max_frames = 0;
     buf = p->buf;
-    end = buf + FFMIN(4096, p->buf_size - 7);
+    end = buf + p->buf_size;
 
     for(; buf < end; buf++) {
         buf2 = buf;
@@ -441,6 +432,12 @@ static int ac3_probe(AVProbeData *p)
     else                   return 0;
 }
 
+static int flac_probe(AVProbeData *p)
+{
+    if(memcmp(p->buf, "fLaC", 4)) return 0;
+    else                          return AVPROBE_SCORE_MAX / 2;
+}
+
 AVInputFormat shorten_demuxer = {
     "shn",
     "raw shorten",
@@ -457,7 +454,7 @@ AVInputFormat flac_demuxer = {
     "flac",
     "raw flac",
     0,
-    NULL,
+    flac_probe,
     flac_read_header,
     raw_read_partial_packet,
     raw_read_close,
@@ -503,7 +500,7 @@ AVOutputFormat ac3_muxer = {
     0,
     CODEC_ID_AC3,
     0,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -570,7 +567,7 @@ AVOutputFormat h261_muxer = {
     0,
     0,
     CODEC_ID_H261,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -598,7 +595,7 @@ AVOutputFormat h263_muxer = {
     0,
     0,
     CODEC_ID_H263,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -626,7 +623,7 @@ AVOutputFormat m4v_muxer = {
     0,
     CODEC_ID_NONE,
     CODEC_ID_MPEG4,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -654,7 +651,7 @@ AVOutputFormat h264_muxer = {
     0,
     CODEC_ID_NONE,
     CODEC_ID_H264,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -681,7 +678,7 @@ AVOutputFormat mpeg1video_muxer = {
     0,
     0,
     CODEC_ID_MPEG1VIDEO,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -696,7 +693,7 @@ AVOutputFormat mpeg2video_muxer = {
     0,
     0,
     CODEC_ID_MPEG2VIDEO,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -737,7 +734,7 @@ AVOutputFormat mjpeg_muxer = {
     0,
     0,
     CODEC_ID_MJPEG,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -781,7 +778,7 @@ AVOutputFormat pcm_ ## name ## _muxer = {\
     0,\
     codec,\
     0,\
-    raw_write_header,\
+    NULL,\
     raw_write_packet,\
     .flags= AVFMT_NOTIMESTAMPS,\
 };
@@ -850,7 +847,7 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->stream_index = 0;
     if (ret != packet_size) {
-        return AVERROR_IO;
+        return AVERROR(EIO);
     } else {
         return 0;
     }
@@ -878,7 +875,7 @@ AVOutputFormat rawvideo_muxer = {
     0,
     CODEC_ID_NONE,
     CODEC_ID_RAWVIDEO,
-    raw_write_header,
+    NULL,
     raw_write_packet,
     .flags= AVFMT_NOTIMESTAMPS,
 };
@@ -902,7 +899,7 @@ AVOutputFormat null_muxer = {
     CODEC_ID_PCM_S16LE,
 #endif
     CODEC_ID_RAWVIDEO,
-    raw_write_header,
+    NULL,
     null_write_packet,
     .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
 };