]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/raw.c
Add missing #includes to fix 'make checkheaders'.
[ffmpeg] / libavformat / raw.c
index c70184033a7f584dfee3edb0183d0e613be0ac75..08e75c5f59aa847b42c2c3d460810a6519da845a 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] = {
@@ -37,8 +33,8 @@ static int flac_write_header(struct AVFormatContext *s)
     uint8_t *streaminfo = s->streams[0]->codec->extradata;
     int len = s->streams[0]->codec->extradata_size;
     if(streaminfo != NULL && len > 0) {
-        put_buffer(&s->pb, header, 8);
-        put_buffer(&s->pb, streaminfo, len);
+        put_buffer(s->pb, header, 8);
+        put_buffer(s->pb, streaminfo, len);
     }
     return 0;
 }
@@ -50,16 +46,16 @@ static int roq_write_header(struct AVFormatContext *s)
         0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
     };
 
-    put_buffer(&s->pb, header, 8);
-    put_flush_packet(&s->pb);
+    put_buffer(s->pb, header, 8);
+    put_flush_packet(s->pb);
 
     return 0;
 }
 
 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
-    put_buffer(&s->pb, pkt->data, pkt->size);
-    put_flush_packet(&s->pb);
+    put_buffer(s->pb, pkt->data, pkt->size);
+    put_flush_packet(s->pb);
     return 0;
 }
 #endif //CONFIG_MUXERS
@@ -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) {
@@ -111,11 +107,11 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     size= RAW_PACKET_SIZE;
 
-    ret= av_get_packet(&s->pb, pkt, size);
+    ret= av_get_packet(s->pb, pkt, size);
 
     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->pos= url_ftell(s->pb);
     pkt->stream_index = 0;
-    ret = get_partial_buffer(&s->pb, pkt->data, size);
+    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;
@@ -148,32 +144,32 @@ 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
+    if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
+        return AVERROR(EIO); // FIXME
 
-    size = get_le32(&s->pb);
+    size = get_le32(s->pb);
 
-    w = get_le16(&s->pb);
-    h = get_le16(&s->pb);
+    w = get_le16(s->pb);
+    h = get_le16(s->pb);
 
-    url_fskip(&s->pb, 8); // zero + size (padded?)
-    url_fskip(&s->pb, 2);
-    unk1 = get_le16(&s->pb);
-    unk2 = get_le16(&s->pb);
-    url_fskip(&s->pb, 22); // ascii timestamp
+    url_fskip(s->pb, 8); // zero + size (padded?)
+    url_fskip(s->pb, 2);
+    unk1 = get_le16(s->pb);
+    unk2 = get_le16(s->pb);
+    url_fskip(s->pb, 22); // ascii timestamp
 
     av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
         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->pos = url_ftell(s->pb);
     pkt->stream_index = 0;
-    ret = get_buffer(&s->pb, pkt->data, size);
+    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;
@@ -210,7 +206,7 @@ int pcm_read_seek(AVFormatContext *s,
 
     /* recompute exact position */
     st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
-    url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
+    url_fseek(s->pb, pos + s->data_offset, SEEK_SET);
     return 0;
 }
 
@@ -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)
@@ -412,16 +406,13 @@ static int h261_probe(AVProbeData *p)
 
 static int ac3_probe(AVProbeData *p)
 {
-    int max_frames, first_frames, frames;
+    int max_frames, first_frames = 0, frames;
     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,\
 };
@@ -846,11 +843,11 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (packet_size < 0)
         return -1;
 
-    ret= av_get_packet(&s->pb, pkt, packet_size);
+    ret= av_get_packet(s->pb, pkt, packet_size);
 
     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,
 };