Merge commit 'd4c2a3740fb95f952a87ba320d2bf31f126bdf68'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 18 Sep 2013 09:24:27 +0000 (11:24 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 18 Sep 2013 09:24:27 +0000 (11:24 +0200)
* commit 'd4c2a3740fb95f952a87ba320d2bf31f126bdf68':
  xmv: Add more sanity checks for parameters read from the bitstream

Conflicts:
libavformat/xmv.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/xmv.c

                             XMV_AUDIO_ADPCM51_FRONTCENTERLOW | \
                             XMV_AUDIO_ADPCM51_REARLEFTRIGHT)
  
 -typedef struct XMVAudioTrack {
 -    uint16_t compression;
 -    uint16_t channels;
 -    uint32_t sample_rate;
 -    uint16_t bits_per_sample;
 -    uint32_t bit_rate;
 -    uint16_t flags;
 -    uint16_t block_align;
 -    uint16_t block_samples;
 -
 -    enum AVCodecID codec_id;
 -} XMVAudioTrack;
 -
+ #define XMV_BLOCK_ALIGN_SIZE 36
 +/** A video packet with an XMV file. */
  typedef struct XMVVideoPacket {
 -    /* The decoder stream index for this video packet. */
 -    int stream_index;
 -
 -    uint32_t data_size;
 -    uint32_t data_offset;
 +    int stream_index; ///< The decoder stream index for this video packet.
  
 -    uint32_t current_frame;
 -    uint32_t frame_count;
 +    uint32_t data_size;   ///< The size of the remaining video data.
 +    uint64_t data_offset; ///< The offset of the video data within the file.
  
 -    /* Does the video packet contain extra data? */
 -    int has_extradata;
 +    uint32_t current_frame; ///< The current frame within this video packet.
 +    uint32_t frame_count;   ///< The amount of frames within this video packet.
  
 -    /* Extra data */
 -    uint8_t extradata[4];
 +    int     has_extradata; ///< Does the video packet contain extra data?
 +    uint8_t extradata[4];  ///< The extra data
  
 -    int64_t last_pts;
 -    int64_t pts;
 +    int64_t last_pts; ///< PTS of the last video frame.
 +    int64_t pts;      ///< PTS of the most current video frame.
  } XMVVideoPacket;
  
 +/** An audio packet with an XMV file. */
  typedef struct XMVAudioPacket {
 -    /* The decoder stream index for this audio packet. */
 -    int stream_index;
 +    int stream_index; ///< The decoder stream index for this audio packet.
  
 -    /* The audio track this packet encodes. */
 -    XMVAudioTrack *track;
 +    /* Stream format properties. */
 +    uint16_t compression;     ///< The type of compression.
 +    uint16_t channels;        ///< Number of channels.
 +    uint32_t sample_rate;     ///< Sampling rate.
 +    uint16_t bits_per_sample; ///< Bits per compressed sample.
 +    uint32_t bit_rate;        ///< Bits of compressed data per second.
 +    uint16_t flags;           ///< Flags
 +    unsigned block_align;     ///< Bytes per compressed block.
 +    uint16_t block_samples;   ///< Decompressed samples per compressed block.
  
 -    uint32_t data_size;
 -    uint32_t data_offset;
 +    enum AVCodecID codec_id; ///< The codec ID of the compression scheme.
  
 -    uint32_t frame_size;
 +    uint32_t data_size;   ///< The size of the remaining audio data.
 +    uint64_t data_offset; ///< The offset of the audio data within the file.
  
 -    uint32_t block_count;
 +    uint32_t frame_size; ///< Number of bytes to put into an audio frame.
 +
 +    uint64_t block_count; ///< Running counter of decompressed audio block.
  } XMVAudioPacket;
  
 +/** Context for demuxing an XMV file. */
  typedef struct XMVDemuxContext {
 -    uint16_t audio_track_count;
 -
 -    XMVAudioTrack *audio_tracks;
 +    uint16_t audio_track_count; ///< Number of audio track in this file.
  
 -    uint32_t this_packet_size;
 -    uint32_t next_packet_size;
 +    uint32_t this_packet_size; ///< Size of the current packet.
 +    uint32_t next_packet_size; ///< Size of the next packet.
  
 -    uint32_t this_packet_offset;
 -    uint32_t next_packet_offset;
 +    uint64_t this_packet_offset; ///< Offset of the current packet.
 +    uint64_t next_packet_offset; ///< Offset of the next packet.
  
 -    uint16_t current_stream;
 -    uint16_t stream_count;
 +    uint16_t current_stream; ///< The index of the stream currently handling.
 +    uint16_t stream_count;   ///< The number of streams in this file.
  
 -    XMVVideoPacket  video;
 -    XMVAudioPacket *audio;
 +    XMVVideoPacket  video; ///< The video packet contained in each packet.
 +    XMVAudioPacket *audio; ///< The audio packets contained in each packet.
  } XMVDemuxContext;
  
  static int xmv_probe(AVProbeData *p)
@@@ -187,23 -196,25 +189,23 @@@ static int xmv_read_header(AVFormatCont
      }
  
      for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
 -        XMVAudioTrack  *track  = &xmv->audio_tracks[audio_track];
 -        XMVAudioPacket *packet = &xmv->audio       [audio_track];
 +        XMVAudioPacket *packet = &xmv->audio[audio_track];
          AVStream *ast = NULL;
  
 -        track->compression     = avio_rl16(pb);
 -        track->channels        = avio_rl16(pb);
 -        track->sample_rate     = avio_rl32(pb);
 -        track->bits_per_sample = avio_rl16(pb);
 -        track->flags           = avio_rl16(pb);
 -
 -        track->bit_rate      = track->bits_per_sample *
 -                               track->sample_rate *
 -                               track->channels;
 -        track->block_align   = XMV_BLOCK_ALIGN_SIZE * track->channels;
 -        track->block_samples = 64;
 -        track->codec_id      = ff_wav_codec_get_id(track->compression,
 -                                                   track->bits_per_sample);
 -
 -        packet->track        = track;
 +        packet->compression     = avio_rl16(pb);
 +        packet->channels        = avio_rl16(pb);
 +        packet->sample_rate     = avio_rl32(pb);
 +        packet->bits_per_sample = avio_rl16(pb);
 +        packet->flags           = avio_rl16(pb);
 +
 +        packet->bit_rate      = packet->bits_per_sample *
 +                                packet->sample_rate *
 +                                packet->channels;
-         packet->block_align   = 36 * packet->channels;
++        packet->block_align   = XMV_BLOCK_ALIGN_SIZE * packet->channels;
 +        packet->block_samples = 64;
 +        packet->codec_id      = ff_wav_codec_get_id(packet->compression,
 +                                                    packet->bits_per_sample);
 +
          packet->stream_index = -1;
  
          packet->frame_size  = 0;
  
          /* TODO: ADPCM'd 5.1 sound is encoded in three separate streams.
           *       Those need to be interleaved to a proper 5.1 stream. */
 -        if (track->flags & XMV_AUDIO_ADPCM51)
 +        if (packet->flags & XMV_AUDIO_ADPCM51)
              av_log(s, AV_LOG_WARNING, "Unsupported 5.1 ADPCM audio stream "
 -                                      "(0x%04X)\n", track->flags);
 +                                      "(0x%04X)\n", packet->flags);
  
-         if (!packet->channels || !packet->sample_rate) {
 -        if (!track->channels || !track->sample_rate ||
 -             track->channels >= UINT16_MAX / XMV_BLOCK_ALIGN_SIZE) {
++        if (!packet->channels || !packet->sample_rate ||
++             packet->channels >= UINT16_MAX / XMV_BLOCK_ALIGN_SIZE) {
              av_log(s, AV_LOG_ERROR, "Invalid parameters for audio track %d.\n",
                     audio_track);
              ret = AVERROR_INVALIDDATA;