]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/electronicarts.c
Add a @todo with a comment from Kostya so we don't forget to optimize that at
[ffmpeg] / libavformat / electronicarts.c
index 2dc4f14bd2ff6a3c80597897b0a72233d4f994d9..fe19e70f73fc6dbc14a9ba45d57ae42a6aff6ce4 100644 (file)
  */
 
 /**
- * @file electronicarts.c
+ * @file libavformat/electronicarts.c
  * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
  * by Robin Kay (komadori at gekkou.co.uk)
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
 #define SEAD_TAG MKTAG('S', 'E', 'A', 'D')    /* Sxxx header */
 #define SNDC_TAG MKTAG('S', 'N', 'D', 'C')    /* Sxxx data */
 #define SEND_TAG MKTAG('S', 'E', 'N', 'D')    /* Sxxx end */
+#define SHEN_TAG MKTAG('S', 'H', 'E', 'N')    /* SxEN header */
+#define SDEN_TAG MKTAG('S', 'D', 'E', 'N')    /* SxEN data */
+#define SEEN_TAG MKTAG('S', 'E', 'E', 'N')    /* SxEN end */
 #define ISNh_TAG MKTAG('1', 'S', 'N', 'h')    /* 1SNx header */
 #define EACS_TAG MKTAG('E', 'A', 'C', 'S')
 #define ISNd_TAG MKTAG('1', 'S', 'N', 'd')    /* 1SNx data */
@@ -44,6 +48,9 @@
 #define mTCD_TAG MKTAG('m', 'T', 'C', 'D')    /* MDEC */
 #define MADk_TAG MKTAG('M', 'A', 'D', 'k')    /* MAD i-frame */
 #define MPCh_TAG MKTAG('M', 'P', 'C', 'h')    /* MPEG2 */
+#define TGQs_TAG MKTAG('T', 'G', 'Q', 's')    /* TGQ i-frame (appears in .TGQ files) */
+#define pQGT_TAG MKTAG('p', 'Q', 'G', 'T')    /* TGQ i-frame (appears in .UV files) */
+#define pIQT_TAG MKTAG('p', 'I', 'Q', 'T')    /* TQI/UV2 i-frame (.UV2/.WVE) */
 #define MVhd_TAG MKTAG('M', 'V', 'h', 'd')
 #define MV0K_TAG MKTAG('M', 'V', '0', 'K')
 #define MV0F_TAG MKTAG('M', 'V', '0', 'F')
@@ -182,6 +189,7 @@ static int process_audio_header_elements(AVFormatContext *s)
         switch (revision2) {
         case  8: ea->audio_codec = CODEC_ID_PCM_S16LE_PLANAR; break;
         case 10: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
+        case 16: ea->audio_codec = CODEC_ID_MP3; break;
         case -1: break;
         default:
             av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2);
@@ -304,6 +312,7 @@ static int process_ea_header(AVFormatContext *s) {
                 break;
 
             case SCHl_TAG :
+            case SHEN_TAG :
                 blockid = get_le32(pb);
                 if (blockid == GSTR_TAG) {
                     url_fskip(pb, 4);
@@ -336,6 +345,15 @@ static int process_ea_header(AVFormatContext *s) {
                 ea->video_codec = CODEC_ID_MPEG2VIDEO;
                 break;
 
+            case pQGT_TAG:
+            case TGQs_TAG:
+                ea->video_codec = CODEC_ID_TGQ;
+                break;
+
+            case pIQT_TAG:
+                ea->video_codec = CODEC_ID_TQI;
+                break;
+
             case MVhd_TAG :
                 err = process_video_header_vp6(s);
                 break;
@@ -361,6 +379,7 @@ static int ea_probe(AVProbeData *p)
     case ISNh_TAG:
     case SCHl_TAG:
     case SEAD_TAG:
+    case SHEN_TAG:
     case kVGT_TAG:
     case MADk_TAG:
     case MPCh_TAG:
@@ -405,10 +424,10 @@ static int ea_read_header(AVFormatContext *s,
         st->codec->codec_tag = 0;  /* no tag */
         st->codec->channels = ea->num_channels;
         st->codec->sample_rate = ea->sample_rate;
-        st->codec->bits_per_sample = ea->bytes * 8;
+        st->codec->bits_per_coded_sample = ea->bytes * 8;
         st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
-            st->codec->bits_per_sample / 4;
-        st->codec->block_align = st->codec->channels*st->codec->bits_per_sample;
+            st->codec->bits_per_coded_sample / 4;
+        st->codec->block_align = st->codec->channels*st->codec->bits_per_coded_sample;
         ea->audio_stream_index = st->index;
         ea->audio_frame_counter = 0;
     }
@@ -425,6 +444,7 @@ static int ea_read_packet(AVFormatContext *s,
     int packet_read = 0;
     unsigned int chunk_type, chunk_size;
     int key = 0;
+    int av_uninit(num_samples);
 
     while (!packet_read) {
         chunk_type = get_le32(pb);
@@ -439,11 +459,14 @@ static int ea_read_packet(AVFormatContext *s,
         case ISNd_TAG:
         case SCDl_TAG:
         case SNDC_TAG:
+        case SDEN_TAG:
             if (!ea->audio_codec) {
                 url_fskip(pb, chunk_size);
                 break;
-            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR) {
-                url_fskip(pb, 12);  /* planar header */
+            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||
+                       ea->audio_codec == CODEC_ID_MP3) {
+                num_samples = get_le32(pb);
+                url_fskip(pb, 8);
                 chunk_size -= 12;
             }
             ret = av_get_packet(pb, pkt, chunk_size);
@@ -462,6 +485,10 @@ static int ea_read_packet(AVFormatContext *s,
                     ea->audio_frame_counter += ((chunk_size - 12) * 2) /
                         ea->num_channels;
                         break;
+                    case CODEC_ID_PCM_S16LE_PLANAR:
+                    case CODEC_ID_MP3:
+                        ea->audio_frame_counter += num_samples;
+                        break;
                     default:
                         ea->audio_frame_counter += chunk_size /
                             (ea->bytes * ea->num_channels);
@@ -476,12 +503,15 @@ static int ea_read_packet(AVFormatContext *s,
         case ISNe_TAG:
         case SCEl_TAG:
         case SEND_TAG:
+        case SEEN_TAG:
             ret = AVERROR(EIO);
             packet_read = 1;
             break;
 
         case MVIh_TAG:
         case kVGT_TAG:
+        case pQGT_TAG:
+        case TGQs_TAG:
             key = PKT_FLAG_KEY;
         case MVIf_TAG:
         case fVGT_TAG:
@@ -496,6 +526,7 @@ static int ea_read_packet(AVFormatContext *s,
 
         case MV0K_TAG:
         case MPCh_TAG:
+        case pIQT_TAG:
             key = PKT_FLAG_KEY;
         case MV0F_TAG:
 get_video_packet: