]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/riff.c
os: replace select with poll
[ffmpeg] / libavformat / riff.c
index a2791213693d094ef11fad1a8ad28fdd540b29b0..4edccced9935dc226cc0fd66c1ec0f8eaf1ccf6b 100644 (file)
@@ -26,7 +26,7 @@
 
 /* Note: when encoding, the first matching tag is used, so order is
    important if multiple tags possible for a given codec. */
-const AVCodecTag codec_bmp_tags[] = {
+const AVCodecTag ff_codec_bmp_tags[] = {
     { CODEC_ID_H264,         MKTAG('H', '2', '6', '4') },
     { CODEC_ID_H264,         MKTAG('h', '2', '6', '4') },
     { CODEC_ID_H264,         MKTAG('X', '2', '6', '4') },
@@ -59,6 +59,7 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_MPEG4,        MKTAG('S', 'E', 'D', 'G') },
     { CODEC_ID_MPEG4,        MKTAG('R', 'M', 'P', '4') },
     { CODEC_ID_MPEG4,        MKTAG('3', 'I', 'V', '2') },
+    { CODEC_ID_MPEG4,        MKTAG('W', 'A', 'W', 'V') }, /* WaWv MPEG-4 Video Codec */
     { CODEC_ID_MPEG4,        MKTAG('F', 'F', 'D', 'S') },
     { CODEC_ID_MPEG4,        MKTAG('F', 'V', 'F', 'W') },
     { CODEC_ID_MPEG4,        MKTAG('D', 'C', 'O', 'D') },
@@ -77,8 +78,12 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_MPEG4,        MKTAG('E', 'M', '4', 'A') },
     { CODEC_ID_MPEG4,        MKTAG('M', '4', 'C', 'C') }, /* Divio MPEG-4 */
     { CODEC_ID_MPEG4,        MKTAG('S', 'N', '4', '0') },
-    { CODEC_ID_MSMPEG4V3,    MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
+    { CODEC_ID_MPEG4,        MKTAG('V', 'S', 'P', 'X') },
+    { CODEC_ID_MPEG4,        MKTAG('U', 'L', 'D', 'X') },
+    { CODEC_ID_MPEG4,        MKTAG('G', 'E', 'O', 'V') },
+    { CODEC_ID_MPEG4,        MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */
     { CODEC_ID_MSMPEG4V3,    MKTAG('M', 'P', '4', '3') },
+    { CODEC_ID_MSMPEG4V3,    MKTAG('D', 'I', 'V', '3') },
     { CODEC_ID_MSMPEG4V3,    MKTAG('M', 'P', 'G', '3') },
     { CODEC_ID_MSMPEG4V3,    MKTAG('D', 'I', 'V', '5') },
     { CODEC_ID_MSMPEG4V3,    MKTAG('D', 'I', 'V', '6') },
@@ -102,6 +107,7 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_DVVIDEO,      MKTAG('c', 'd', 'v', 'c') }, /* Canopus DV */
     { CODEC_ID_DVVIDEO,      MKTAG('C', 'D', 'V', 'H') }, /* Canopus DV */
     { CODEC_ID_DVVIDEO,      MKTAG('d', 'v', 'c', ' ') },
+    { CODEC_ID_DVVIDEO,      MKTAG('d', 'v', 'c', 's') },
     { CODEC_ID_DVVIDEO,      MKTAG('d', 'v', 'h', '1') },
     { CODEC_ID_MPEG1VIDEO,   MKTAG('m', 'p', 'g', '1') },
     { CODEC_ID_MPEG1VIDEO,   MKTAG('m', 'p', 'g', '2') },
@@ -112,15 +118,21 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_MPEG1VIDEO,   MKTAG('V', 'C', 'R', '2') },
     { CODEC_ID_MPEG1VIDEO,   MKTAG( 1 ,  0 ,  0 ,  16) },
     { CODEC_ID_MPEG2VIDEO,   MKTAG( 2 ,  0 ,  0 ,  16) },
+    { CODEC_ID_MPEG4,        MKTAG( 4 ,  0 ,  0 ,  16) },
     { CODEC_ID_MPEG2VIDEO,   MKTAG('D', 'V', 'R', ' ') },
     { CODEC_ID_MPEG2VIDEO,   MKTAG('M', 'M', 'E', 'S') },
     { CODEC_ID_MPEG2VIDEO,   MKTAG('L', 'M', 'P', '2') }, /* Lead MPEG2 in avi */
+    { CODEC_ID_MPEG2VIDEO,   MKTAG('s', 'l', 'i', 'f') },
+    { CODEC_ID_MPEG2VIDEO,   MKTAG('E', 'M', '2', 'V') },
+    { CODEC_ID_MPEG2VIDEO,   MKTAG('M', '7', '0', '1') }, /* Matrox MPEG2 intra-only */
     { CODEC_ID_MJPEG,        MKTAG('M', 'J', 'P', 'G') },
     { CODEC_ID_MJPEG,        MKTAG('L', 'J', 'P', 'G') },
     { CODEC_ID_MJPEG,        MKTAG('d', 'm', 'b', '1') },
+    { CODEC_ID_MJPEG,        MKTAG('m', 'j', 'p', 'a') },
     { CODEC_ID_LJPEG,        MKTAG('L', 'J', 'P', 'G') },
     { CODEC_ID_MJPEG,        MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
     { CODEC_ID_JPEGLS,       MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */
+    { CODEC_ID_JPEGLS,       MKTAG('M', 'J', 'P', 'G') },
     { CODEC_ID_MJPEG,        MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */
     { CODEC_ID_MJPEG,        MKTAG('j', 'p', 'e', 'g') },
     { CODEC_ID_MJPEG,        MKTAG('I', 'J', 'P', 'G') },
@@ -129,6 +141,12 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_MJPEG,        MKTAG('Q', 'I', 'V', 'G') },
     { CODEC_ID_MJPEG,        MKTAG('S', 'L', 'M', 'J') }, /* SL M-JPEG */
     { CODEC_ID_MJPEG,        MKTAG('C', 'J', 'P', 'G') }, /* Creative Webcam JPEG */
+    { CODEC_ID_MJPEG,        MKTAG('I', 'J', 'L', 'V') }, /* Intel JPEG Library Video Codec */
+    { CODEC_ID_MJPEG,        MKTAG('M', 'V', 'J', 'P') }, /* Midvid JPEG Video Codec */
+    { CODEC_ID_MJPEG,        MKTAG('A', 'V', 'I', '1') },
+    { CODEC_ID_MJPEG,        MKTAG('A', 'V', 'I', '2') },
+    { CODEC_ID_MJPEG,        MKTAG('M', 'T', 'S', 'J') },
+    { CODEC_ID_MJPEG,        MKTAG('Z', 'J', 'P', 'G') }, /* Paradigm Matrix M-JPEG Codec */
     { CODEC_ID_HUFFYUV,      MKTAG('H', 'F', 'Y', 'U') },
     { CODEC_ID_FFVHUFF,      MKTAG('F', 'F', 'V', 'H') },
     { CODEC_ID_CYUV,         MKTAG('C', 'Y', 'U', 'V') },
@@ -137,12 +155,33 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_RAWVIDEO,     MKTAG('I', '4', '2', '0') },
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'U', 'Y', '2') },
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', '4', '2', '2') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('V', '4', '2', '2') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'U', 'N', 'V') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('U', 'Y', 'N', 'V') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('U', 'Y', 'N', 'Y') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('u', 'y', 'v', '1') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('2', 'V', 'u', '1') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('2', 'v', 'u', 'y') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('y', 'u', 'v', 's') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('P', '4', '2', '2') },
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'V', '1', '2') },
     { CODEC_ID_RAWVIDEO,     MKTAG('U', 'Y', 'V', 'Y') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('V', 'Y', 'U', 'Y') },
     { CODEC_ID_RAWVIDEO,     MKTAG('I', 'Y', 'U', 'V') },
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', '8', '0', '0') },
     { CODEC_ID_RAWVIDEO,     MKTAG('H', 'D', 'Y', 'C') },
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'V', 'U', '9') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', '4', '1', '1') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('N', 'V', '1', '2') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('N', 'V', '2', '1') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', '4', '1', 'B') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', '4', '2', 'B') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'U', 'V', '9') },
+    { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'V', 'U', '9') },
+    { CODEC_ID_FRWU,         MKTAG('F', 'R', 'W', 'U') },
+    { CODEC_ID_R10K,         MKTAG('R', '1', '0', 'k') },
+    { CODEC_ID_R210,         MKTAG('r', '2', '1', '0') },
     { CODEC_ID_V210,         MKTAG('v', '2', '1', '0') },
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '1') },
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '2') },
@@ -154,6 +193,9 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_VP6,          MKTAG('V', 'P', '6', '0') },
     { CODEC_ID_VP6,          MKTAG('V', 'P', '6', '1') },
     { CODEC_ID_VP6,          MKTAG('V', 'P', '6', '2') },
+    { CODEC_ID_VP6F,         MKTAG('V', 'P', '6', 'F') },
+    { CODEC_ID_VP6F,         MKTAG('F', 'L', 'V', '4') },
+    { CODEC_ID_VP8,          MKTAG('V', 'P', '8', '0') },
     { CODEC_ID_ASV1,         MKTAG('A', 'S', 'V', '1') },
     { CODEC_ID_ASV2,         MKTAG('A', 'S', 'V', '2') },
     { CODEC_ID_VCR1,         MKTAG('V', 'C', 'R', '1') },
@@ -178,7 +220,6 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_4XM,          MKTAG('4', 'X', 'M', 'V') },
     { CODEC_ID_FLV1,         MKTAG('F', 'L', 'V', '1') },
     { CODEC_ID_FLASHSV,      MKTAG('F', 'S', 'V', '1') },
-    { CODEC_ID_VP6F,         MKTAG('V', 'P', '6', 'F') },
     { CODEC_ID_SVQ1,         MKTAG('s', 'v', 'q', '1') },
     { CODEC_ID_TSCC,         MKTAG('t', 's', 'c', 'c') },
     { CODEC_ID_ULTI,         MKTAG('U', 'L', 'T', 'I') },
@@ -187,6 +228,7 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_QPEG,         MKTAG('Q', '1', '.', '0') },
     { CODEC_ID_QPEG,         MKTAG('Q', '1', '.', '1') },
     { CODEC_ID_WMV3,         MKTAG('W', 'M', 'V', '3') },
+    { CODEC_ID_WMV3,         MKTAG('W', 'M', 'V', 'P') },
     { CODEC_ID_VC1,          MKTAG('W', 'V', 'C', '1') },
     { CODEC_ID_VC1,          MKTAG('W', 'M', 'V', 'A') },
     { CODEC_ID_LOCO,         MKTAG('L', 'O', 'C', 'O') },
@@ -214,10 +256,12 @@ const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_AURA,         MKTAG('A', 'U', 'R', 'A') },
     { CODEC_ID_AURA2,        MKTAG('A', 'U', 'R', '2') },
     { CODEC_ID_DPX,          MKTAG('d', 'p', 'x', ' ') },
+    { CODEC_ID_KGV1,         MKTAG('K', 'G', 'V', '1') },
+    { CODEC_ID_LAGARITH,     MKTAG('L', 'A', 'G', 'S') },
     { CODEC_ID_NONE,         0 }
 };
 
-const AVCodecTag codec_wav_tags[] = {
+const AVCodecTag ff_codec_wav_tags[] = {
     { CODEC_ID_PCM_S16LE,       0x0001 },
     { CODEC_ID_PCM_U8,          0x0001 }, /* must come after s16le in this list */
     { CODEC_ID_PCM_S24LE,       0x0001 },
@@ -250,7 +294,11 @@ const AVCodecTag codec_wav_tags[] = {
     { CODEC_ID_WMALOSSLESS,     0x0163 },
     { CODEC_ID_ADPCM_CT,        0x0200 },
     { CODEC_ID_ATRAC3,          0x0270 },
+    { CODEC_ID_ADPCM_G722,      0x028F },
     { CODEC_ID_IMC,             0x0401 },
+    { CODEC_ID_GSM_MS,          0x1500 },
+    { CODEC_ID_TRUESPEECH,      0x1501 },
+    { CODEC_ID_AAC_LATM,        0x1602 },
     { CODEC_ID_AC3,             0x2000 },
     { CODEC_ID_DTS,             0x2001 },
     { CODEC_ID_SONIC,           0x2048 },
@@ -267,18 +315,18 @@ const AVCodecTag codec_wav_tags[] = {
     { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') },
     { CODEC_ID_MP3,       MKTAG('L', 'A', 'M', 'E') },
     { CODEC_ID_MP3,       MKTAG('M', 'P', '3', ' ') },
-    { 0, 0 },
+    { CODEC_ID_NONE,      0 },
 };
 
 #if CONFIG_MUXERS
-int64_t start_tag(ByteIOContext *pb, const char *tag)
+int64_t ff_start_tag(ByteIOContext *pb, const char *tag)
 {
     put_tag(pb, tag);
     put_le32(pb, 0);
     return url_ftell(pb);
 }
 
-void end_tag(ByteIOContext *pb, int64_t start)
+void ff_end_tag(ByteIOContext *pb, int64_t start)
 {
     int64_t pos;
 
@@ -290,7 +338,7 @@ void end_tag(ByteIOContext *pb, int64_t start)
 
 /* WAVEFORMATEX header */
 /* returns the size or -1 on error */
-int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
+int ff_put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
 {
     int bps, blkalign, bytespersec;
     int hdrsize = 18;
@@ -301,7 +349,9 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
 
     if(!enc->codec_tag || enc->codec_tag > 0xffff)
         return -1;
-    waveformatextensible = enc->channels > 2 && enc->channel_layout;
+    waveformatextensible =   (enc->channels > 2 && enc->channel_layout)
+                          || enc->sample_rate > 48000
+                          || av_get_bits_per_sample(enc->codec_id) > 16;
 
     if (waveformatextensible) {
         put_le16(pb, 0xfffe);
@@ -312,7 +362,7 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
     put_le32(pb, enc->sample_rate);
     if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
         bps = 0;
-    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { //
+    } else if (enc->codec_id == CODEC_ID_ADPCM_G726) {
         bps = 4;
     } else {
         if (!(bps = av_get_bits_per_sample(enc->codec_id)))
@@ -322,9 +372,11 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
         av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
     }
 
-    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_AC3) {
+    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
         blkalign = enc->frame_size; //this is wrong, but it seems many demuxers do not work if this is set correctly
         //blkalign = 144 * enc->bit_rate/enc->sample_rate;
+    } else if (enc->codec_id == CODEC_ID_AC3) {
+            blkalign = 3840; //maximum bytes per frame
     } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
         blkalign = 1;
     } else if (enc->block_align != 0) { /* specified by the codec */
@@ -393,7 +445,7 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
 }
 
 /* BITMAPINFOHEADER header */
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
+void ff_put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
 {
     put_le32(pb, 40 + enc->extradata_size); /* size */
     put_le32(pb, enc->width);
@@ -412,7 +464,7 @@ void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *ta
 
     put_buffer(pb, enc->extradata, enc->extradata_size);
 
-    if (enc->extradata_size & 1)
+    if (!for_asf && enc->extradata_size & 1)
         put_byte(pb, 0);
 }
 #endif //CONFIG_MUXERS
@@ -425,12 +477,12 @@ void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *ta
  * WAVEFORMATEX adds 'WORD  cbSize' and basically makes itself
  * an openended structure.
  */
-void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
+void ff_get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
 {
     int id;
 
     id = get_le16(pb);
-    codec->codec_type = CODEC_TYPE_AUDIO;
+    codec->codec_type = AVMEDIA_TYPE_AUDIO;
     codec->codec_tag = id;
     codec->channels = get_le16(pb);
     codec->sample_rate = get_le32(pb);
@@ -463,14 +515,19 @@ void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
         if (size > 0)
             url_fskip(pb, size);
     }
-    codec->codec_id = wav_codec_get_id(id, codec->bits_per_coded_sample);
+    codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample);
+    if (codec->codec_id == CODEC_ID_AAC_LATM) {
+        /* channels and sample_rate values are those prior to applying SBR and/or PS */
+        codec->channels    = 0;
+        codec->sample_rate = 0;
+    }
 }
 
 
-enum CodecID wav_codec_get_id(unsigned int tag, int bps)
+enum CodecID ff_wav_codec_get_id(unsigned int tag, int bps)
 {
     enum CodecID id;
-    id = codec_get_id(codec_wav_tags, tag);
+    id = ff_codec_get_id(ff_codec_wav_tags, tag);
     if (id <= 0)
         return id;
     /* handle specific u8 codec */
@@ -486,6 +543,23 @@ enum CodecID wav_codec_get_id(unsigned int tag, int bps)
         id = CODEC_ID_PCM_ZORK;
     return id;
 }
+
+int ff_get_bmp_header(ByteIOContext *pb, AVStream *st)
+{
+    int tag1;
+    get_le32(pb); /* size */
+    st->codec->width = get_le32(pb);
+    st->codec->height = (int32_t)get_le32(pb);
+    get_le16(pb); /* planes */
+    st->codec->bits_per_coded_sample= get_le16(pb); /* depth */
+    tag1 = get_le32(pb);
+    get_le32(pb); /* ImageSize */
+    get_le32(pb); /* XPelsPerMeter */
+    get_le32(pb); /* YPelsPerMeter */
+    get_le32(pb); /* ClrUsed */
+    get_le32(pb); /* ClrImportant */
+    return tag1;
+}
 #endif // CONFIG_DEMUXERS
 
 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
@@ -496,7 +570,8 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz
     if(stream->frame_size && stream->sample_rate){
         *au_scale=stream->frame_size;
         *au_rate= stream->sample_rate;
-    }else if(stream->codec_type == CODEC_TYPE_VIDEO){
+    }else if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
+             stream->codec_type == AVMEDIA_TYPE_SUBTITLE){
         *au_scale= stream->time_base.num;
         *au_rate = stream->time_base.den;
     }else{