40 #define CHUNK_PREAMBLE_SIZE 4 
   41 #define OPCODE_PREAMBLE_SIZE 4 
   43 #define CHUNK_INIT_AUDIO   0x0000 
   44 #define CHUNK_AUDIO_ONLY   0x0001 
   45 #define CHUNK_INIT_VIDEO   0x0002 
   46 #define CHUNK_VIDEO        0x0003 
   47 #define CHUNK_SHUTDOWN     0x0004 
   48 #define CHUNK_END          0x0005 
   50 #define CHUNK_DONE         0xFFFC 
   51 #define CHUNK_NOMEM        0xFFFD 
   52 #define CHUNK_EOF          0xFFFE 
   53 #define CHUNK_BAD          0xFFFF 
   55 #define OPCODE_END_OF_STREAM           0x00 
   56 #define OPCODE_END_OF_CHUNK            0x01 
   57 #define OPCODE_CREATE_TIMER            0x02 
   58 #define OPCODE_INIT_AUDIO_BUFFERS      0x03 
   59 #define OPCODE_START_STOP_AUDIO        0x04 
   60 #define OPCODE_INIT_VIDEO_BUFFERS      0x05 
   61 #define OPCODE_UNKNOWN_06              0x06 
   62 #define OPCODE_SEND_BUFFER             0x07 
   63 #define OPCODE_AUDIO_FRAME             0x08 
   64 #define OPCODE_SILENCE_FRAME           0x09 
   65 #define OPCODE_INIT_VIDEO_MODE         0x0A 
   66 #define OPCODE_CREATE_GRADIENT         0x0B 
   67 #define OPCODE_SET_PALETTE             0x0C 
   68 #define OPCODE_SET_PALETTE_COMPRESSED  0x0D 
   69 #define OPCODE_UNKNOWN_0E              0x0E 
   70 #define OPCODE_SET_DECODING_MAP        0x0F 
   71 #define OPCODE_UNKNOWN_10              0x10 
   72 #define OPCODE_VIDEO_DATA              0x11 
   73 #define OPCODE_UNKNOWN_12              0x12 
   74 #define OPCODE_UNKNOWN_13              0x13 
   75 #define OPCODE_UNKNOWN_14              0x14 
   76 #define OPCODE_UNKNOWN_15              0x15 
   78 #define PALETTE_COUNT 256 
  123                    "audio codec is known\n");
 
  150         av_dlog(NULL, 
"sending audio frame with pts %"PRId64
" (%d audio frames)\n",
 
  199         av_dlog(NULL, 
"sending video frame with pts %"PRId64
"\n", pkt->
pts);
 
  224     unsigned char opcode_type;
 
  225     unsigned char opcode_version;
 
  227     unsigned char scratch[1024];
 
  229     int first_color, last_color;
 
  231     unsigned char r, 
g, 
b;
 
  245     chunk_size = 
AV_RL16(&chunk_preamble[0]);
 
  246     chunk_type = 
AV_RL16(&chunk_preamble[2]);
 
  248     av_dlog(NULL, 
"chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
 
  250     switch (chunk_type) {
 
  253         av_dlog(NULL, 
"initialize audio\n");
 
  261         av_dlog(NULL, 
"initialize video\n");
 
  265         av_dlog(NULL, 
"video (and audio)\n");
 
  277         av_dlog(NULL, 
"invalid chunk\n");
 
  283     while ((chunk_size > 0) && (chunk_type != 
CHUNK_BAD)) {
 
  296         opcode_size = 
AV_RL16(&opcode_preamble[0]);
 
  297         opcode_type = opcode_preamble[2];
 
  298         opcode_version = opcode_preamble[3];
 
  301         chunk_size -= opcode_size;
 
  302         if (chunk_size < 0) {
 
  303             av_dlog(NULL, 
"chunk_size countdown just went negative\n");
 
  308         av_dlog(NULL, 
"  opcode type %02X, version %d, 0x%04X bytes: ",
 
  309                 opcode_type, opcode_version, opcode_size);
 
  310         switch (opcode_type) {
 
  313             av_dlog(NULL, 
"end of stream\n");
 
  318             av_dlog(NULL, 
"end of chunk\n");
 
  323             av_dlog(NULL, 
"create timer\n");
 
  324             if ((opcode_version > 0) || (opcode_size != 6)) {
 
  325                 av_dlog(NULL, 
"bad create_timer opcode\n");
 
  329             if (
avio_read(pb, scratch, opcode_size) !=
 
  335             av_dlog(NULL, 
"  %.2f frames/second (timer div = %d, subdiv = %d)\n",
 
  341             av_dlog(NULL, 
"initialize audio buffers\n");
 
  342             if (opcode_version > 1 || opcode_size > 10 || opcode_size < 6) {
 
  343                 av_dlog(NULL, 
"bad init_audio_buffers opcode\n");
 
  347             if (
avio_read(pb, scratch, opcode_size) !=
 
  353             audio_flags = 
AV_RL16(&scratch[2]);
 
  357             s->
audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
 
  359             if ((opcode_version == 1) && (audio_flags & 0x4))
 
  365             av_dlog(NULL, 
"audio: %d bits, %d Hz, %s, %s format\n",
 
  369                     "Interplay audio" : 
"PCM");
 
  373             av_dlog(NULL, 
"start/stop audio\n");
 
  378             av_dlog(NULL, 
"initialize video buffers\n");
 
  379             if ((opcode_version > 2) || (opcode_size > 8) || opcode_size < 4
 
  380                 || opcode_version == 2 && opcode_size < 8
 
  382                 av_dlog(NULL, 
"bad init_video_buffers opcode\n");
 
  386             if (
avio_read(pb, scratch, opcode_size) !=
 
  391             width  = 
AV_RL16(&scratch[0]) * 8;
 
  392             height = 
AV_RL16(&scratch[2]) * 8;
 
  401             if (opcode_version < 2 || !
AV_RL16(&scratch[6])) {
 
  406             av_dlog(NULL, 
"video resolution: %d x %d\n",
 
  417             av_dlog(NULL, 
"unknown (but documented) opcode %02X\n", opcode_type);
 
  422             av_dlog(NULL, 
"send buffer\n");
 
  427             av_dlog(NULL, 
"audio frame\n");
 
  436             av_dlog(NULL, 
"silence frame\n");
 
  441             av_dlog(NULL, 
"initialize video mode\n");
 
  446             av_dlog(NULL, 
"create gradient\n");
 
  451             av_dlog(NULL, 
"set palette\n");
 
  454             if (opcode_size > 0x304 || opcode_size < 4) {
 
  455                 av_dlog(NULL, 
"demux_ipmovie: set_palette opcode with invalid size\n");
 
  459             if (
avio_read(pb, scratch, opcode_size) != opcode_size) {
 
  465             first_color = 
AV_RL16(&scratch[0]);
 
  466             last_color = first_color + 
AV_RL16(&scratch[2]) - 1;
 
  468             if (   (first_color > 0xFF) || (last_color > 0xFF)
 
  469                 || (last_color - first_color + 1)*3 + 4 > opcode_size) {
 
  470                 av_dlog(NULL, 
"demux_ipmovie: set_palette indexes out of range (%d -> %d)\n",
 
  471                     first_color, last_color);
 
  476             for (i = first_color; i <= last_color; i++) {
 
  479                 r = scratch[j++] * 4;
 
  480                 g = scratch[j++] * 4;
 
  481                 b = scratch[j++] * 4;
 
  482                 s->
palette[i] = (0xFF
U << 24) | (r << 16) | (g << 8) | (b);
 
  489             av_dlog(NULL, 
"set palette compressed\n");
 
  494             av_dlog(NULL, 
"set decoding map\n");
 
  503             av_dlog(NULL, 
"set video data\n");
 
  512             av_dlog(NULL, 
"*** unknown opcode type\n");
 
  529 static const char signature[] = 
"Interplay MVE File\x1A\0\x1A";
 
  554     avio_read(pb, signature_buffer, 
sizeof(signature_buffer));
 
  556         memmove(signature_buffer, signature_buffer + 1, 
sizeof(signature_buffer) - 1);
 
  557         signature_buffer[
sizeof(signature_buffer) - 1] = 
avio_r8(pb);
 
  569     for (i = 0; i < 256; i++)
 
  570         ipmovie->
palette[i] = 0xFFU << 24;
 
  581     chunk_type = 
AV_RL16(&chunk_preamble[2]);